From ffa69b1929862ca0163b4301d706554d22e661a5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 2 Jun 2019 22:31:21 +0200 Subject: [PATCH] Adding support to multiple arenas --- src/de/steamwar/bungeecore/BungeeCore.java | 18 ++++++--- .../bungeecore/arenasystem/Arena.java | 12 +++--- .../bungeecore/arenasystem/ArenaSystem.java | 4 +- .../bungeecore/commands/DenyCommand.java | 21 ---------- .../bungeecore/commands/FightCommand.java | 40 ++++++++++++++++--- 5 files changed, 54 insertions(+), 41 deletions(-) delete mode 100644 src/de/steamwar/bungeecore/commands/DenyCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 135e04d2..cbbd0b58 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -1,8 +1,8 @@ package de.steamwar.bungeecore; +import de.steamwar.bungeecore.arenasystem.ArenaMode; import de.steamwar.bungeecore.arenasystem.ArenaSystem; import de.steamwar.bungeecore.commands.*; -import de.warking.bungeecore.commands.*; import de.steamwar.bungeecore.sql.sql; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.plugin.Command; @@ -16,12 +16,12 @@ import java.io.IOException; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.logging.Level; public class BungeeCore extends Plugin { - private Configuration config; public static BungeeCore instance; public static String ChatPrefix; public static final String TeamchatPrefix = "§4T§7c§r §e"; @@ -29,12 +29,14 @@ public class BungeeCore extends Plugin { public static String LobbyServer; public static String [] BroadCastMsgs; public static int LastBroadCast = 0; - public static final HashMap serverPermissions = new HashMap<>(); - public static final HashMap commands = new HashMap<>(); + public static final Map serverPermissions = new HashMap<>(); + public static final Map commands = new HashMap<>(); + public static final Map> arenaMaps = new HashMap<>(); @Override public void onEnable(){ instance = this; + Configuration config; try{ if(!getDataFolder().exists()){ getDataFolder().mkdir(); @@ -89,11 +91,15 @@ public class BungeeCore extends Plugin { commands.put("/bau", ""); commands.remove("/bauserver"); + final Configuration maps = config.getSection("maps"); + for(final String modeName : maps.getKeys()){ + arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName)); + } + addCmd(new TeamchatCommand()); addCmd(new MsgCommand()); addCmd(new RCommand()); addCmd(new PingCommand()); - //addCmd(new DenyCommand("list", "pl", "plugins", "ver", "version", "about")); addCmd(new WebpwCommand()); addCmd(new AlertCommand()); addCmd(new KickCommand()); @@ -109,7 +115,7 @@ public class BungeeCore extends Plugin { if(LastBroadCast == BroadCastMsgs.length){ LastBroadCast = 0; } - }, 5, 5, TimeUnit.MINUTES); + }, 10, 10, TimeUnit.MINUTES); } @Override diff --git a/src/de/steamwar/bungeecore/arenasystem/Arena.java b/src/de/steamwar/bungeecore/arenasystem/Arena.java index f7c5de5f..57e62347 100644 --- a/src/de/steamwar/bungeecore/arenasystem/Arena.java +++ b/src/de/steamwar/bungeecore/arenasystem/Arena.java @@ -16,29 +16,27 @@ import java.util.List; public class Arena implements Runnable{ - public final String serverName; - public final int arenenNummer; + final String serverName; + final int arenenNummer; public final ArenaMode spielModus; private Process p; private PrintWriter writer; public ServerInfo server; - private String map; private boolean started = false; private final List cachedPlayers = new ArrayList<>(); private final List players = new ArrayList<>(); - public Arena(ArenaMode modus, int id, String map){ + Arena(ArenaMode modus, int id, String map){ spielModus = modus; arenenNummer = id; serverName = modus.name() + id; - this.map = map; int port = 2500 + arenenNummer; ProcessBuilder pb = new ProcessBuilder( "/home/minecraft/mc", - "-a", modus.name(), serverName, Integer.toString(port), "Arena"); + "-a", modus.name(), serverName, Integer.toString(port), map); try{ p = pb.start(); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.instance, this); @@ -108,7 +106,7 @@ public class Arena implements Runnable{ stop(); } - public boolean inArena(ProxiedPlayer p){ + boolean inArena(ProxiedPlayer p){ for(ProxiedPlayer ap : cachedPlayers) if(ap.equals(p)) return true; diff --git a/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java b/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java index 67383da6..e8fad388 100644 --- a/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java +++ b/src/de/steamwar/bungeecore/arenasystem/ArenaSystem.java @@ -25,8 +25,8 @@ public class ArenaSystem { return id; } - public static Arena startServer(ArenaMode modus){ - Arena arena = new Arena(modus, freeId()); + public static Arena startServer(ArenaMode modus, String map){ + Arena arena = new Arena(modus, freeId(), map); arenen.add(arena); return arena; } diff --git a/src/de/steamwar/bungeecore/commands/DenyCommand.java b/src/de/steamwar/bungeecore/commands/DenyCommand.java deleted file mode 100644 index a3cb22b3..00000000 --- a/src/de/steamwar/bungeecore/commands/DenyCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.steamwar.bungeecore.commands; - -import de.steamwar.bungeecore.BungeeCore; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -public class DenyCommand extends Command { - - public DenyCommand(String cmd, String ...aliases) { - super(cmd, "", aliases); - } - - @Override - public void execute(CommandSender sender, String[] args) { - if(sender instanceof ProxiedPlayer){ - ProxiedPlayer player = (ProxiedPlayer) sender; - player.sendMessage(new TextComponent(BungeeCore.ChatPrefix + "§cUnbekannter Befehl.")); - } - } -} diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 04ce4157..148ac8d0 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -14,6 +14,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; import java.util.List; +import java.util.Random; public class FightCommand extends Command { @@ -21,9 +22,25 @@ public class FightCommand extends Command { super("fight", ""); } + private String getMap(CommandSender sender, ArenaMode mode, String[] args){ + if(args.length == 2){ + String map = args[1].toLowerCase(); + for(String realMap : BungeeCore.arenaMaps.get(mode)){ + if(map.equalsIgnoreCase(realMap)) + return realMap; + } + sender.sendMessage(BungeeCore.ChatPrefix + "§cDie gewünschte Arena gibt es nicht."); + return null; + }else{ + List l = BungeeCore.arenaMaps.get(mode); + Random rand = new Random(); + return l.get(rand.nextInt(l.size())); + } + } + @Override public void execute(CommandSender sender, String[] args) { - if(args.length != 1){ + if(args.length != 1 && args.length != 2){ sender.sendMessage(BungeeCore.ChatPrefix + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!"); sender.sendMessage(BungeeCore.ChatPrefix + "/fight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!"); sender.sendMessage(BungeeCore.ChatPrefix + "/fight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!"); @@ -40,23 +57,36 @@ public class FightCommand extends Command { return; } + String map; Arena arena; switch(args[0].toLowerCase()){ case "as": case "airship": - arena = ArenaSystem.startServer(ArenaMode.AirShip); + map = getMap(sender, ArenaMode.AirShip, args); + if(map == null) + return; + arena = ArenaSystem.startServer(ArenaMode.AirShip, map); break; case "ws": case "warship": - arena = ArenaSystem.startServer(ArenaMode.WarShip); + map = getMap(sender, ArenaMode.WarShip, args); + if(map == null) + return; + arena = ArenaSystem.startServer(ArenaMode.WarShip, map); break; case "wg": case "wargear": - arena = ArenaSystem.startServer(ArenaMode.WarGear); + map = getMap(sender, ArenaMode.WarGear, args); + if(map == null) + return; + arena = ArenaSystem.startServer(ArenaMode.WarGear, map); break; case "mwg": case "miniwargear": - arena = ArenaSystem.startServer(ArenaMode.MiniWarGear); + map = getMap(sender, ArenaMode.MiniWarGear, args); + if(map == null) + return; + arena = ArenaSystem.startServer(ArenaMode.MiniWarGear, map); break; default: sender.sendMessage(BungeeCore.ChatPrefix + "§cUnbekannter Spielmodus: " + args[0]);