diff --git a/.vscode/settings.json b/.vscode/settings.json index 2d99b8d..e38425f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,6 +12,7 @@ "Gson", "Minecraft", "Mojang", + "addspawns", "cliffbreak", "koords", "mkdir", diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java index 5593951..b552156 100644 --- a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java @@ -1,6 +1,8 @@ package de.cliffbreak.varo.commands; import java.io.IOException; +import java.util.HashMap; +import java.util.UUID; import com.destroystokyo.paper.Title; @@ -12,6 +14,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryCloseEvent.Reason; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; import org.json.simple.parser.ParseException; @@ -22,6 +26,7 @@ import de.cliffbreak.varo.uitls.WebUtils; public class VaroCommand implements CommandExecutor { private final Varo plugin; + private final HashMap addSpawnsCounter = new HashMap(); public VaroCommand(final Varo plugin) { this.plugin = plugin; @@ -93,15 +98,80 @@ public class VaroCommand implements CommandExecutor { } else { sender.sendMessage("§c§lFehler: §r§cBitte überprüfe deine Eingabe."); } + + } else if (args.length == 1 && args[0].equals("addspawns")) { + if (!(sender instanceof Player)) { + sender.sendMessage("§c§lFehler: §r§cDieses Kommando kann nur von einem Spieler ausgeführt werden."); + return true; + } + final Player p = (Player) sender; + TeamPlayerId teamPlayerId; + boolean firstRun = false; + if (this.addSpawnsCounter.containsKey(p.getUniqueId())) { + teamPlayerId = this.addSpawnsCounter.get(p.getUniqueId()); + } else { + p.sendMessage("§aDer Spawn-Erstellungs-Wizard wird gestartet..."); + teamPlayerId = new TeamPlayerId(0, 0); + this.addSpawnsCounter.put(p.getUniqueId(), teamPlayerId); + firstRun = true; + } + final JSONArray teams = this.plugin.getTeamManager().getTeams(); + final JSONObject team = (JSONObject) teams.get(teamPlayerId.team); + final JSONArray players = (JSONArray) team.get("players"); + + if (!firstRun) { + p.sendMessage("§a§lErfolg."); + this.plugin.getTeamManager().setPlayerSpawnByKeys(teamPlayerId.team, teamPlayerId.player, + p.getLocation()); + if (teamPlayerId.player + 1 == players.size()) { + if (teamPlayerId.team + 1 == teams.size()) { + p.sendMessage("§a§lErfolg: §r§aAlle Spawns wurden erfolgreich gesetzt."); + this.addSpawnsCounter.remove(p.getUniqueId()); + return true; + } else { + this.addSpawnsCounter.replace(p.getUniqueId(), new TeamPlayerId(teamPlayerId.team + 1, 0)); + } + } else { + this.addSpawnsCounter.replace(p.getUniqueId(), + new TeamPlayerId(teamPlayerId.team, teamPlayerId.player + 1)); + } + } + + String playerName = ""; + String teamName = ""; + if (teamPlayerId.player + 1 == players.size()) { + final JSONObject tmpTeam = (JSONObject) teams.get(teamPlayerId.team + 1); + teamName = (String) tmpTeam.get("name"); + playerName = (String) ((JSONObject) ((JSONArray) tmpTeam.get("players")).get(0)).get("name"); + } else { + teamName = (String) team.get("name"); + playerName = (String) ((JSONObject) players.get(teamPlayerId.player + 1)).get("name"); + } + if (firstRun) { + teamName = (String) team.get("name"); + playerName = (String) ((JSONObject) players.get(0)).get("name"); + } + p.sendMessage("Begebe dich in Position um den Spawn für Spieler: §6" + playerName + "§r vom Team: §6" + + teamName + "§r zu setzen.\nFühre danach dieses Kommando erneut aus, um den Spawn zu setzten."); } else { sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n "); sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!"); sender.sendMessage("§a/varo ban [Spieler]: §rSpieler bannen"); sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen"); sender.sendMessage("§a/varo portal [enable/disable]: §rAktiviere/Deaktiviere die Portal-Erstellung"); + sender.sendMessage("§a/varo addspawns: §rStarte den Spawn-Erstellungs-Wizard"); sender.sendMessage("\n§6=========================================="); } return true; } + private class TeamPlayerId { + public final int team; + public final int player; + + public TeamPlayerId(final int team, final int player) { + this.team = team; + this.player = player; + } + } } \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java index 2ff3bf0..27a1f0a 100644 --- a/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java @@ -26,10 +26,8 @@ public class VaroTabCompleter implements TabCompleter { list.add("unban"); list.add("ban"); list.add("start"); - list.add("teamcolors"); list.add("portal"); - list.add("test"); - list.add("testremove"); + list.add("addspawns"); } else if (args.length == 2 && args[0].equals("unban")) { final ArrayList bans = this.plugin.getBanUtils().getBans(); for (String uuid : bans) { diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java index 2f23dbd..7280979 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/GameTimeManager.java @@ -22,10 +22,10 @@ public class GameTimeManager { private static final LocalTime firstPlayStart = LocalTime.of(19, 10, 00); private static final int playTimeMinutes = 30; private static final int playTimeLoginMinutes = 5; - private static final LocalTime playStart = LocalTime.of(19, 30, 00); + // private static final LocalTime playStart = LocalTime.of(19, 30, 00); // private static final LocalTime playStart = LocalTime.now().plusMinutes(30); // private static final LocalTime playStart = LocalTime.now().plusMinutes(1); - // private static final LocalTime playStart = LocalTime.now(); + private static final LocalTime playStart = LocalTime.now(); public GameTimeManager(final Varo plugin) { this.plugin = plugin; diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java index 7996d84..11a108c 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/TeamManager.java @@ -7,6 +7,7 @@ import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; @@ -40,7 +41,7 @@ public class TeamManager { } private void init() { - final JSONArray jsonTeams = config.getArray("teams"); + final JSONArray jsonTeams = this.config.getArray("teams"); int teamKey = -1; for (final Object jsonRawTeam : jsonTeams) { teamKey++; @@ -95,6 +96,10 @@ public class TeamManager { } } + public JSONArray getTeams() { + return this.config.getArray("teams"); + } + public Team getTeamByPlayer(final String player) { for (final Team team : this.teams) { if (team.hasEntry(player)) { @@ -132,6 +137,10 @@ public class TeamManager { return ""; } + public void setPlayerSpawnByKeys(final int teamKey, final int playerKey, final Location location) { + this.config.updatePlayerSpawn(teamKey, playerKey, location); + } + public void setAFK(final String player) { final Team oldTeam = getTeamByPlayer(player); for (final Team team : this.teams) { diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/JSONConfig.java b/varo/src/main/java/de/cliffbreak/varo/uitls/JSONConfig.java index f8789ec..ff4c560 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/JSONConfig.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/JSONConfig.java @@ -11,6 +11,7 @@ import java.util.TreeMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.bukkit.Location; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -127,4 +128,18 @@ public class JSONConfig { .get(playerKey)).put("name", name); this.save(); } + + @SuppressWarnings("unchecked") + public void updatePlayerSpawn(final int teamKey, final int playerKey, final Location location) { + JSONObject loc = new JSONObject(); + loc.put("world", location.getWorld().getName()); + loc.put("x", location.getX()); + loc.put("y", location.getY()); + loc.put("z", location.getZ()); + loc.put("yaw", (double) location.getYaw()); + loc.put("pitch", (double) location.getPitch()); + ((JSONObject) ((JSONArray) ((JSONObject) ((JSONArray) this.json.get("teams")).get(teamKey)).get("players")) + .get(playerKey)).put("spawn", loc); + this.save(); + } } \ No newline at end of file