Work has been done

This commit is contained in:
2022-12-20 16:13:45 -05:00
parent 6113228196
commit 6c4776f88a
8 changed files with 221 additions and 16 deletions

View File

@@ -0,0 +1,76 @@
package org.lunamc.letthemeatcake;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
public class Game {
private JavaPlugin plugin;
private boolean openStatus;
private List<Player> players;
public Game(JavaPlugin plugin) {
this.plugin = plugin;
openStatus = true;
players = new ArrayList<>();
}
/**
* Adds player to the game queue
* @param player player that will join the game queue
* @return 0 if the player has been added, 1 if the game is full
*/
public int addPlayer(Player player) {
players.add(player);
if (players.size() == 8) {
openStatus = false;
return 0;
}
return 1;
}
/**
* Adds multiple players to the game queue
* @param players array of players to be added
* @return 0 if the players have been added, 1 if the game is full, or 2 if the players have been added AND the queue is full (use to trigger start early)
*/
public int addPlayers(Player ... players) {
if (players.length <= (8 - this.players.size())) {
this.players.addAll(List.of(players));
if (this.players.size() == 8) {
openStatus = false;
return 2;
}
return 0;
}
return 1;
}
/**
* Adds multiple players to the game queue
* @param players array of players to be added
* @return 0 if the players have been added, 1 if the game is full, or 2 if the players have been added AND the queue is full (use to trigger start early)
*/
public int addPlayers(List<Player> players) {
if (players.size() <= (8 - this.players.size())) {
this.players.addAll(players);
if (this.players.size() == 8) {
openStatus = false;
return 2;
}
return 0;
}
return 1;
}
public void start() {
openStatus = false;
}
public boolean isOpen() {
return openStatus;
}
}

View File

@@ -0,0 +1,20 @@
package org.lunamc.letthemeatcake;
import java.util.ArrayList;
import java.util.List;
public class GamesManager {
private static List<Game> games = new ArrayList<>();
public static void addToGame() {
for (Game game : games) {
if (game.isOpen()) {
switch (game.addPlayers()) {
case 0: {} // Success
case 1: {} // Full
case 2: {} // Success and Full
}
}
}
}
}

View File

@@ -0,0 +1,26 @@
package org.lunamc.letthemeatcake;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
public class JoinGameCommand implements CommandExecutor {
private final JavaPlugin plugin;
public JoinGameCommand(JavaPlugin plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (sender instanceof Player player) {
}
return true;
}
}

View File

@@ -1,24 +1,48 @@
package org.lunamc.letthemeatcake;
import com.grinderwolf.swm.api.SlimePlugin;
import com.grinderwolf.swm.api.exceptions.CorruptedWorldException;
import com.grinderwolf.swm.api.exceptions.NewerFormatException;
import com.grinderwolf.swm.api.exceptions.UnknownWorldException;
import com.grinderwolf.swm.api.exceptions.WorldInUseException;
import com.grinderwolf.swm.api.loaders.SlimeLoader;
import com.grinderwolf.swm.api.world.SlimeWorld;
import com.grinderwolf.swm.api.world.properties.SlimeProperties;
import com.grinderwolf.swm.api.world.properties.SlimeProperty;
import com.grinderwolf.swm.api.world.properties.SlimePropertyMap;
import com.grinderwolf.swm.api.world.properties.type.SlimePropertyString;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
public final class LetThemEatCake extends JavaPlugin {
private SlimePropertyMap properties;
private SlimePlugin swm;
private SlimeLoader swmLoader;
private SlimeWorld swmWorld;
@Override
public void onEnable() {
SlimePropertyMap propertymap = new SlimePropertyMap();
propertymap.setValue(SlimeProperties.SPAWN_X, 0);
propertymap.setValue(SlimeProperties.SPAWN_Y, 0);
propertymap.setValue(SlimeProperties.SPAWN_Z, 0);
}
@Override
public void onDisable() {
// Plugin shutdown logic
// Unload swm worlds
}
private void loadSWM() {
properties = new SlimePropertyMap();
properties.setValue(SlimeProperties.SPAWN_X, 0);
properties.setValue(SlimeProperties.SPAWN_Y, 0);
properties.setValue(SlimeProperties.SPAWN_Z, 0);
swm = (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager");
swmLoader = swm.getLoader("file");
try {
swmWorld = swm.loadWorld(swmLoader, "map", true, properties);
swm.generateWorld(swmWorld);
} catch (UnknownWorldException | IOException | CorruptedWorldException | NewerFormatException | WorldInUseException e) {
e.printStackTrace();
}
}
}

View File

@@ -2,15 +2,62 @@ package org.lunamc.letthemeatcake;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public class PointsManager {
private int playerSize;
private Player[] players;
private int[] points;
private Map<Player, Integer> playerPoints;
public PointsManager() {
playerPoints = new HashMap<>();
public PointsManager(int playerSize) {
this.playerSize = playerSize;
players = new Player[playerSize];
points = new int[playerSize];
}
public Player[] getPlayers() {
return players;
}
public int getPlayerNumber(Player player) {
for (int i = 0; i < players.length; i++) {
if (players[i].equals(player)) {
return i;
}
}
return -1;
}
public Player getPlayerByNumber(int player) {
if (player < 0 || player > playerSize) {
return null;
}
return players[player];
}
/**
* If player does not exist, returns -1;
* @param player player to get points from
* @return int value of points
*/
public int getPlayerPoints(int player) {
if (player < 0 || player > playerSize) {
return -1;
}
return points[player];
}
/**
* Use {@link org.lunamc.letthemeatcake.PointsManager#getPlayerPoints(int)} if possible for performance reasons.<br>
* If player does not exist, returns -1;
* @param player player to get points from
* @return int value of points
*/
public int getPlayerPoints(Player player) {
for (int i = 0; i < players.length; i++) {
if (players[i].equals(player)) {
return points[i];
}
}
return -1;
}
}