diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index 789ee1f..ded82fc 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -1,12 +1,93 @@ package de.steamwar.bungeecore; -public enum ArenaMode { - AirShip, +import net.md_5.bungee.config.Configuration; + +import java.util.*; + +public class ArenaMode { + /*AirShip, WarShip, WarGear, MiniWarGear, WarGear7, GearUp, EisZeit, - UNKNOWN + UNKNOWN;*/ + + private static Map byChat = new HashMap<>(); + private static Map byInternal = new HashMap<>(); + private static Random random = new Random(); + + static void init(Configuration config){ + for(String internalName : config.getKeys()){ + new ArenaMode(internalName, config.getSection(internalName)); + } + } + + public static ArenaMode getByChat(String name){ + return byChat.get(name.toLowerCase()); + } + + public static ArenaMode getByInternal(String name){ + return byInternal.get(name); + } + + public static List getAllChatNames() { + List chatNames = new LinkedList<>(); + for(ArenaMode mode : byInternal.values()){ + chatNames.addAll(mode.chatNames); + } + return chatNames; + } + + private final String internalName; + private final String displayName; + private final List chatNames; + private final String serverJar; + private final List maps; + + private ArenaMode(String internalName, Configuration config){ + this.internalName = internalName; + this.displayName = config.getString("displayName"); + this.serverJar = config.getString("serverJar"); + this.chatNames = config.getStringList("chatNames"); + this.maps = config.getStringList("maps"); + + byInternal.put(internalName, this); + for(String name : chatNames){ + byChat.put(name.toLowerCase(), this); + } + } + + public String getInternalName() { + return internalName; + } + + public String getDisplayName() { + return displayName; + } + + public String serverJar() { + return serverJar; + } + + public String hasMap(String map){ + for(String m : maps){ + if(m.equalsIgnoreCase(map)) + return m; + } + return null; + } + + public String getRandomMap(){ + return maps.get(random.nextInt(maps.size())); + } + + public List getMaps() { + return maps; + } + + public String getChatName(){ + return chatNames.get(0); + } } diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 5f04e1e..3470ebc 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -25,7 +25,6 @@ import net.md_5.bungee.config.YamlConfiguration; import java.io.File; import java.io.IOException; import java.time.format.DateTimeFormatter; -import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -47,7 +46,6 @@ public class BungeeCore extends Plugin { public static final Map serverPermissions = new HashMap<>(); public static final Map commands = new HashMap<>(); - public static final Map> arenaMaps = new EnumMap<>(ArenaMode.class); @Override public void onEnable(){ @@ -188,10 +186,7 @@ public class BungeeCore extends Plugin { config.getString("db.password") ); - final Configuration maps = config.getSection("maps"); - for(final String modeName : maps.getKeys()){ - arenaMaps.put(ArenaMode.valueOf(modeName), maps.getStringList(modeName)); - } + ArenaMode.init(config.getSection("games")); final Configuration servers = config.getSection("servers"); for(final String serverName : servers.getKeys()){ diff --git a/src/de/steamwar/bungeecore/SubserverSystem.java b/src/de/steamwar/bungeecore/SubserverSystem.java index 310e0f6..dc9fafa 100644 --- a/src/de/steamwar/bungeecore/SubserverSystem.java +++ b/src/de/steamwar/bungeecore/SubserverSystem.java @@ -30,15 +30,22 @@ public class SubserverSystem { public static Subserver startArena(ArenaMode modus, String map){ int port = freePort(2500); - String serverName = modus.name() + (port - 2500); + String serverName = modus.getDisplayName() + (port - 2500); return new Subserver(Servertype.ARENA, serverName, port, - MC_SCRIPT, "-a", modus.name(), serverName, Integer.toString(port), map, "0"); + MC_SCRIPT, "-a", modus.getInternalName(), serverName, Integer.toString(port), map, "0", modus.serverJar()); } public static Subserver startEventArena(EventFight eventFight, String serverName){ int port = freePort(2500); return new Subserver(Servertype.ARENA, serverName, port, - MC_SCRIPT, "-a", eventFight.getSpielmodus().name(), serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(EventCommand.TIME_FORMAT), Integer.toString(port), eventFight.getMap(), Integer.toString(eventFight.getFightID())); + MC_SCRIPT, "-a", eventFight.getSpielmodus().getInternalName(), serverName.replace(' ', '_') + eventFight.getStartTime().toLocalDateTime().format(EventCommand.TIME_FORMAT), Integer.toString(port), eventFight.getMap(), Integer.toString(eventFight.getFightID()), eventFight.getSpielmodus().serverJar()); + } + + public static void sendToTestServer(ProxiedPlayer p, ArenaMode m, String map){ + int port = freePort(4000); + + new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port, + MC_SCRIPT, "-a", m.getInternalName(), p.getName(), Integer.toString(port), map, "-1", m.serverJar()).sendPlayer(p); } public static void sendToBauServer(ProxiedPlayer p, UUID owner){ @@ -77,20 +84,6 @@ public class SubserverSystem { MC_SCRIPT, "-b", owner.toString(), Integer.toString(port)).sendPlayer(p); } - public static void sendToTestServer(ProxiedPlayer p, ArenaMode m, String map){ - int port = freePort(4000); - - new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port, - MC_SCRIPT, "-a", m.name(), p.getName(), Integer.toString(port), map, "-1").sendPlayer(p); - } - - public static void sendToHistoricTestServer(ProxiedPlayer p, ArenaMode m, String map){ - int port = freePort(4000); - - new Bauserver(p.getName() + "s Bau", p.getUniqueId(), port, - MC_SCRIPT, "-h", m.name(), p.getName(), Integer.toString(port), map, "-1").sendPlayer(p); - } - private static int freePort(int start){ int port = start; boolean isFree = false; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index b401d55..391889b 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -183,8 +183,8 @@ public class BauCommand { return; } - ArenaMode mode = FightCommand.stringToArenaMode(command[2]); - if(mode == ArenaMode.UNKNOWN){ + ArenaMode mode = ArenaMode.getByChat(command[2]); + if(mode == null){ BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + command[2]); return; } @@ -196,10 +196,7 @@ public class BauCommand { break; } } - if(mode == ArenaMode.WarGear7) - SubserverSystem.sendToHistoricTestServer(p, mode, FightCommand.getMap(p, mode, new String[0])); - else - SubserverSystem.sendToTestServer(p, mode, FightCommand.getMap(p, mode, new String[0])); + SubserverSystem.sendToTestServer(p, mode, FightCommand.getMap(p, mode, new String[0])); }); } diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index f58b914..e95a4fa 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -46,8 +46,8 @@ public class ChallengeCommand extends BasicCommand { return; } - ArenaMode mode = FightCommand.stringToArenaMode(args[1]); - if(mode == ArenaMode.UNKNOWN){ + ArenaMode mode = ArenaMode.getByChat(args[1]); + if(mode == null){ BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]); return; } @@ -63,7 +63,7 @@ public class ChallengeCommand extends BasicCommand { arena.sendPlayer(player); arena.sendPlayer(target); - BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.name() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(), + BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.getDisplayName() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(), "§aZuschauen", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); }else{ @@ -73,12 +73,12 @@ public class ChallengeCommand extends BasicCommand { challenges.get(player).add(target); - BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); - BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.name() + "-Kampf §7herausgefordert!"); + BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!"); + BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!"); BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen", "§aHerausforderung annehmen", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.name())); + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName())); } } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index ccab4b5..72541bf 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -9,9 +9,7 @@ import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import java.util.LinkedList; public class FightCommand extends BasicCommand { @@ -21,38 +19,13 @@ public class FightCommand extends BasicCommand { static 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; - } + String realMap = mode.hasMap(args[1].toLowerCase()); + if(realMap != null) + return realMap; BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§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())); - } - } - - static ArenaMode stringToArenaMode(String input){ - switch(input.toLowerCase()){ - case "as": - case "airship": - return ArenaMode.AirShip; - case "ws": - case "warship": - return ArenaMode.WarShip; - case "wg": - case "wargear": - return ArenaMode.WarGear; - case "mwg": - case "miniwargear": - return ArenaMode.MiniWarGear; - case "wargear1.7": - return ArenaMode.WarGear7; - default: - return ArenaMode.UNKNOWN; + return mode.getRandomMap(); } } @@ -77,37 +50,20 @@ public class FightCommand extends BasicCommand { return; } - String map = null; - Subserver arena; - ArenaMode mode = stringToArenaMode(args[0]); + ArenaMode mode = ArenaMode.getByChat(args[0]); - if(mode != ArenaMode.UNKNOWN){ - map = getMap(sender, mode, args); - if(map == null) - return; + if(mode == null){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]); + return; } - switch(mode){ - case AirShip: - arena = SubserverSystem.startArena(ArenaMode.AirShip, map); - break; - case WarShip: - arena = SubserverSystem.startArena(ArenaMode.WarShip, map); - break; - case WarGear: - arena = SubserverSystem.startArena(ArenaMode.WarGear, map); - break; - case MiniWarGear: - arena = SubserverSystem.startArena(ArenaMode.MiniWarGear, map); - break; - case UNKNOWN: - default: - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]); - return; - } + String map = getMap(sender, mode, args); + if(map == null) + return; + Subserver arena = SubserverSystem.startArena(mode, map); arena.sendPlayer(player); - TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.name() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); + TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.getDisplayName() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!"); tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aGegen §7" + player.getName() + " §ekämpfen").create())); tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName())); ProxyServer.getInstance().broadcast(tc); @@ -116,20 +72,14 @@ public class FightCommand extends BasicCommand { @Override public Iterable onTabComplete(CommandSender commandSender, String[] args) { - List gamemodes = new ArrayList<>(); if(args.length == 1){ - gamemodes.add("AirShip"); - gamemodes.add("AS"); - gamemodes.add("WarShip"); - gamemodes.add("WS"); - gamemodes.add("WarGear"); - gamemodes.add("WG"); - gamemodes.add("MiniWarGear"); - gamemodes.add("MWG"); + return ArenaMode.getAllChatNames(); }else if(args.length == 2){ - ArenaMode mode = stringToArenaMode(args[1]); - gamemodes.addAll(BungeeCore.arenaMaps.get(mode)); + ArenaMode mode = ArenaMode.getByChat(args[1]); + if(mode == null) + return new LinkedList<>(); + return mode.getMaps(); } - return gamemodes; + return new LinkedList<>(); } } diff --git a/src/de/steamwar/bungeecore/sql/EventFight.java b/src/de/steamwar/bungeecore/sql/EventFight.java index b638114..cd4f49f 100644 --- a/src/de/steamwar/bungeecore/sql/EventFight.java +++ b/src/de/steamwar/bungeecore/sql/EventFight.java @@ -28,7 +28,7 @@ public class EventFight implements Comparable { eventID = rs.getInt("EventID"); fightID = rs.getInt("FightID"); startTime = rs.getTimestamp("StartTime"); - spielmodus = ArenaMode.valueOf(rs.getString("Spielmodus")); + spielmodus = ArenaMode.getByInternal(rs.getString("Spielmodus")); map = rs.getString("Map"); teamBlue = rs.getInt("TeamBlue"); teamRed = rs.getInt("TeamRed");