From fa8c1c9004dfd876bae0c23fbbac14fd99a382c8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 3 Apr 2022 20:58:21 +0200 Subject: [PATCH] :white_check_mark: PR Stuff --- src/de/steamwar/bungeecore/ArenaMode.java | 6 +++++ src/de/steamwar/bungeecore/ServerStarter.java | 4 ++-- .../bungeecore/commands/BauCommand.java | 2 +- .../bungeecore/commands/ChallengeCommand.java | 2 +- .../bungeecore/commands/FightCommand.java | 24 ++++++++++--------- .../bungeecore/commands/HistoricCommand.java | 2 +- .../steamwar/messages/BungeeCore.properties | 1 + 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index 13db3f4..9057691 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -95,11 +95,13 @@ public class ArenaMode { private final String config; private final List maps; private final boolean historic; + private final String internalName; private final boolean ranked; private final String schemType; private ArenaMode(String internalName, Configuration config){ + this.internalName = internalName; this.folder = config.getString("Server.Folder"); this.serverJar = config.getString("Server.ServerJar"); this.config = internalName + ".yml"; @@ -172,4 +174,8 @@ public class ArenaMode { public String getSchemType() { return schemType; } + + public String getInternalName() { + return internalName; + } } diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index e8cd6e3..5d23ae4 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -51,7 +51,7 @@ public class ServerStarter { serverJar = mode.serverJar(); directory = new File(SERVER_PATH, mode.getFolder()); arguments.put("config", mode.getConfig()); - constructor = (serverName, port, builder, shutdownCallback) -> new Arenaserver(serverName, mode.getDisplayName(), map, !mode.isRanked(), port, builder, shutdownCallback); + constructor = (serverName, port, builder, shutdownCallback) -> new Arenaserver(serverName, mode.getInternalName(), map, true, port, builder, shutdownCallback); tempWorld(SERVER_PATH + mode.getFolder() + "/arenas/" + map); return this; } @@ -62,7 +62,7 @@ public class ServerStarter { worldDir = EVENT_PATH; worldCleanup = () -> {}; arguments.put("fightID", String.valueOf(eventFight.getFightID())); - constructor = (serverName, port, builder, shutdownCallback) -> new Arenaserver(serverName, eventFight.getSpielmodus().getDisplayName(), eventFight.getMap(), false, port, builder, shutdownCallback); + constructor = (serverName, port, builder, shutdownCallback) -> new Arenaserver(serverName, eventFight.getSpielmodus().getInternalName(), eventFight.getMap(), false, port, builder, shutdownCallback); String serverName = Team.get(eventFight.getTeamBlue()).getTeamKuerzel() + " vs " + Team.get(eventFight.getTeamRed()).getTeamKuerzel(); serverNameProvider = port -> serverName; diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 93c4866..744d48f 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -261,7 +261,7 @@ public class BauCommand extends BasicCommand { } private static void testarena(ProxiedPlayer p, String[] args){ - FightCommand.createArena(p, "/bau testarena ", args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, map, p).start())); + FightCommand.createArena(p, "/bau testarena ", false, args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, map, p).start())); } private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){ diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 7f480c1..ed80159 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -71,7 +71,7 @@ public class ChallengeCommand extends BasicCommand { return; } - FightCommand.createArena(sender, "/challenge " + target.getName() + " ", args, 1, false, (player, mode, map) -> { + FightCommand.createArena(sender, "/challenge " + target.getName() + " ", true, args, 1, false, (player, mode, map) -> { if(challenges.containsKey(target) && challenges.get(target).contains(player)){ challenges.remove(target); challenges.remove(player); diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index b71736f..5653052 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -125,7 +125,7 @@ public class FightCommand extends BasicCommand { return false; } - static void createArena(CommandSender sender, String precommand, String[] args, int startArg, boolean historic, FightCallback callback){ + static void createArena(CommandSender sender, String precommand, boolean allowMerging, String[] args, int startArg, boolean historic, FightCallback callback){ if(!(sender instanceof ProxiedPlayer)) return; @@ -160,7 +160,7 @@ public class FightCommand extends BasicCommand { if(map == null) return; - if(precommand.equals("/bau testarena ") || precommand.startsWith("/challenge ")) { + if(!allowMerging) { callback.run(player, mode, map); } else if(suggestMerging(player, mode, map, callback)) { callback.run(player, mode, map); @@ -169,12 +169,14 @@ public class FightCommand extends BasicCommand { public static boolean suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) { Arenaserver mergable = null; - for (Subserver subserver : Subserver.getServerList()) { - if(subserver instanceof Arenaserver) { - Arenaserver arenaserver = (Arenaserver) subserver; - if(mode.getDisplayName().equals(arenaserver.getMode()) && map.equals(arenaserver.getMap()) && arenaserver.isAllowMerge() && arenaserver.getServer().getPlayers().size() == 1) { - mergable = arenaserver; - break; + synchronized (Subserver.getServerList()) { + for (Subserver subserver : Subserver.getServerList()) { + if(subserver instanceof Arenaserver) { + Arenaserver arenaserver = (Arenaserver) subserver; + if(mode.getInternalName().equals(arenaserver.getMode()) && map.equals(arenaserver.getMap()) && arenaserver.isAllowMerge() && arenaserver.getServer().getPlayers().size() == 1) { + mergable = arenaserver; + break; + } } } } @@ -186,11 +188,11 @@ public class FightCommand extends BasicCommand { declineMerge.run(player, mode, map); }); Arenaserver finalMergable = mergable; - SWItem item = new SWItem("§e" + ArenaMode.getByInternal(finalMergable.getMode()).getDisplayName() + "§7: §e" + finalMergable.getMap().toUpperCase(), 11); + SWItem item = new SWItem(Message.parse("FIGHT_MERGE_INFO", player, mode.getDisplayName(), finalMergable.getMap()), 11); item.addLore(Message.parse("FIGHT_MERGE_INFO_LORE_1", player, finalMergable.getServer().getPlayers().stream().map(ProxiedPlayer::getDisplayName).reduce((player1, player2) -> player1 + ", " + player2).orElse("Error?"))); inventory.addItem(4, item, click -> {}); inventory.addItem(8, new SWItem(Message.parse("FIGHT_MERGE_ACCEPT", player), 10), click -> { - if(BungeeCore.get().getProxy().getServerInfo(finalMergable.getServer().getName()) != null) { + if(Subserver.getServerList().contains(finalMergable)) { finalMergable.sendPlayer(player); } else { Message.send("FIGHT_MERGE_OFFLINE", player); @@ -205,7 +207,7 @@ public class FightCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { - createArena(sender, "/fight ", args, 0, false, (player, mode, map) -> { + createArena(sender, "/fight ", true, args, 0, false, (player, mode, map) -> { Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start(); Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index f07a6a3..d26730f 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -32,7 +32,7 @@ public class HistoricCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { - FightCommand.createArena(sender, "/historic ", args, 0, true, (player, mode, map) -> { + FightCommand.createArena(sender, "/historic ", true, args, 0, true, (player, mode, map) -> { Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start(); Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER" , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5ec4361..9cc792b 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -595,3 +595,4 @@ FIGHT_MERGE_DECLINE=Neue Arena starten FIGHT_MERGE_ACCEPT=Fight beitreten FIGHT_MERGE_INFO_LORE_1=§7Von: §e{0} FIGHT_MERGE_OFFLINE=Der Server dem du beitreten wolltest ist nicht mehr online +FIGHT_MERGE_INFO=§e{0}§7: §e{1} \ No newline at end of file