From 229cf77035bf2b7861e232b17242a6b2d99a11f9 Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Thu, 28 Jul 2022 18:00:02 +0200 Subject: [PATCH 01/35] Added BuilderCloudCommand Added BungeeCore.properties message Added BungeeCore_de.properties message Added ServerStarter for the BuilderCloud --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + src/de/steamwar/bungeecore/ServerStarter.java | 13 +++- .../commands/BuilderCloudCommand.java | 72 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 6 +- .../messages/BungeeCore_de.properties | 6 +- 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 8518c97..93a1d63 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -149,6 +149,7 @@ public class BungeeCore extends Plugin { new RankCommand(); new LocalCommand(); new SetLocaleCommand(); + new BuilderCloudCommand(); // Punishment Commands: new PunishmentCommand("ban", Punishment.PunishmentType.Ban); diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 35a97dd..cc2baa6 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -28,6 +28,9 @@ public class ServerStarter { public static final String TUTORIAL_PATH = BACKBONE + "tutorials/"; public static final String WORLDS19_PATH = BACKBONE + "userworlds19/"; + public static final String BUILDER15_PATH = BACKBONE + "builder15/"; + public static final String BUILDER19_PATH = BACKBONE + "builder19/"; + private File directory = null; private String worldDir = null; @@ -48,6 +51,14 @@ public class ServerStarter { private final Set playersToSend = new HashSet<>(); private final Map arguments = new HashMap<>(); + public ServerStarter builderCloud(String serverJar, String map) { + this.serverJar = serverJar; + this.worldName = map; + + this.directory = new File(SERVER_PATH); + return this; + } + public ServerStarter arena(ArenaMode mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.getDisplayName() + (port - portrange.start); @@ -287,4 +298,4 @@ public class ServerStarter { return result; } } -} +} \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java new file mode 100644 index 0000000..c84af0f --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -0,0 +1,72 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.ServerStarter; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.messages.ChatSender; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.io.File; +import java.util.*; + +public class BuilderCloudCommand extends SWCommand { + + private final Map versionMap = new HashMap<>(); + private final Map pathMap = new HashMap<>(); + + public BuilderCloudCommand() { + super("buildercloud", "bungeecore.server.team"); + + versionMap.put("1.19", "spigot-1.19.jar"); + versionMap.put("19", "spigot-1.19.jar"); + versionMap.put("1.15", "spigot-1.15.2.jar"); + versionMap.put("15", "spigot-1.15.2.jar"); + versionMap.put("1.15.2", "spigot-1.15.2.jar"); + + pathMap.put("19", ServerStarter.BUILDER19_PATH); + pathMap.put("1.19", ServerStarter.BUILDER19_PATH); + pathMap.put("15", ServerStarter.BUILDER15_PATH); + pathMap.put("1.15", ServerStarter.BUILDER15_PATH); + pathMap.put("1.15.2", ServerStarter.BUILDER15_PATH); + } + + // /buildercloud [version] [map] + + @Register(description = "BUILDERCLOUD_USAGE") + public void genericCommand(ProxiedPlayer player, @StaticValue({"19", "1.19", "15", "1.15.2", "1.15"}) @ErrorMessage("BUILDERCLOUD_VERSION") String version, File map) { + String jar = this.versionMap.get(version); + new ServerStarter().builderCloud(jar, map.getName()).start(); + } + + @Cached(global = true) + @ClassMapper(value = File.class, local = true) + private TypeMapper mapTypeMapper() { + + return new TypeMapper() { + @Override + public File map(CommandSender commandSender, String[] previousArguments, String s) { + String folder = pathMap.get(previousArguments[previousArguments.length - 1]); + + if(folder == null) + return null; + + File map = new File(folder, s); + if(!map.exists() || !map.isDirectory()) + return null; + + return map; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + String folder = pathMap.get(previousArguments[previousArguments.length - 1]); + + if(folder == null) + return null; + + return Arrays.asList(Objects.requireNonNull(new File(folder).list())); + } + }; + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 7dfaa7c..ba8072c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -631,4 +631,8 @@ FIGHT_MERGE_OFFLINE=§7The proposed arena has been terminated in the meantime, a FIGHT_MERGE_INFO=§e{0}§8: §e{1} #Locale Locking -LOCK_LOCALE_CHANGED=§aLanguage saved \ No newline at end of file +LOCK_LOCALE_CHANGED=§aLanguage saved + +#Builder Cloud +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] +BUILDERCLOUD_VERSION=§cUnknown version. \ No newline at end of file diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 6fc780b..d9fad23 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -609,4 +609,8 @@ FIGHT_MERGE_INFO_LORE_1=§8Von: §e{0} FIGHT_MERGE_OFFLINE=§7Die vorgeschlagene Arena wurde in der Zwischenzeit beendet, es wird eine neue Arena gestartet. #Locale Locking -LOCK_LOCALE_CHANGED=§aSprache gespeichert \ No newline at end of file +LOCK_LOCALE_CHANGED=§aSprache gespeichert + +#Builder Cloud +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] +BUILDERCLOUD_VERSION=§cUnbekannte Version. \ No newline at end of file From abf422478894c8e9becf590c3f23690d415fd60e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 16 Aug 2022 18:25:16 +0200 Subject: [PATCH 02/35] Update WhoisCommand --- src/de/steamwar/bungeecore/commands/WhoisCommand.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/commands/WhoisCommand.java index 83caa0f..9e25ad2 100644 --- a/src/de/steamwar/bungeecore/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/commands/WhoisCommand.java @@ -44,7 +44,7 @@ public class WhoisCommand extends SWCommand { } @Register(description = "WHOIS_USAGE") - public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, @OptionalValue("") @StaticValue({"-all", "-a", ""}) String displayAll) { + public void genericCommand(ProxiedPlayer player, @Mapper("player") String target, @OptionalValue("") @StaticValue(value = {"", "-all", "-a"}, allowISE = true) boolean all) { SteamwarUser user = SteamwarUser.get(target); if (user == null) { try { @@ -64,11 +64,9 @@ public class WhoisCommand extends SWCommand { if (user == null) { Message.send("UNKNOWN_PLAYER", player); - return; + } else { + sendUserinfo(player, user, all); } - - boolean all = displayAll.contains("-"); - sendUserinfo(player, user, all); } @Mapper(value = "player", local = true) From 94398901316fd334d0762c484f0cf5826696ef87 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Aug 2022 11:23:42 +0200 Subject: [PATCH 03/35] Ignore took ms to process event in db Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ErrorLogger.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/bungeecore/ErrorLogger.java b/src/de/steamwar/bungeecore/ErrorLogger.java index c60d7aa..ef80a0b 100644 --- a/src/de/steamwar/bungeecore/ErrorLogger.java +++ b/src/de/steamwar/bungeecore/ErrorLogger.java @@ -90,6 +90,7 @@ public class ErrorLogger extends Handler { contains.add("No client connected for pending server"); contains.add("Error occurred processing connection for"); contains.add("Server is online mode!"); + contains.add(" took "); ignoreContains = Collections.unmodifiableList(contains); } } From 698f710138d9a7b9bdf39ebcafdf0d30a8797950 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Aug 2022 18:15:02 +0200 Subject: [PATCH 04/35] Use /servers for server starts Signed-off-by: Lixfel --- CommonCore | 2 +- src/de/steamwar/bungeecore/ServerStarter.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CommonCore b/CommonCore index 47bd9af..6cb3bc5 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 47bd9af03eb987f94777f3b13f6ae6c30f153393 +Subproject commit 6cb3bc5ff5ee955ccdde281183991d0877e54169 diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index c6bdca0..f452f3f 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -19,12 +19,12 @@ public class ServerStarter { private static final Portrange BAU_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(10100, 20000) : new Portrange(2100, 2200); private static final Portrange ARENA_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(3000, 3100) : (BungeeCore.EVENT_MODE ? new Portrange(4000, 5000) : BAU_PORTS); - private static final String BACKBONE = System.getProperty("user.home") + "/"; - private static final String SERVER_PATH = BACKBONE + "server/"; - private static final String EVENT_PATH = BACKBONE + "event/"; - public static final String TEMP_WORLD_PATH = BACKBONE + "arenaserver/"; - public static final String TUTORIAL_PATH = BACKBONE + "tutorials/"; - public static final String WORLDS19_PATH = BACKBONE + "userworlds19/"; + private static final String SERVER_PATH = "/servers/"; + private static final String USER_HOME = System.getProperty("user.home") + "/"; + private static final String EVENT_PATH = USER_HOME + "event/"; + public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; + public static final String TUTORIAL_PATH = USER_HOME + "tutorials/"; + public static final String WORLDS19_PATH = USER_HOME + "userworlds19/"; private File directory = null; private String worldDir = null; From 43a9b92b41413ba0b830babda550ef903b3af166 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Aug 2022 19:10:26 +0200 Subject: [PATCH 05/35] Bye Bye Mail. Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 2 +- ...erCommand.java => WebpasswordCommand.java} | 49 +++++++------------ .../steamwar/bungeecore/sql/SteamwarUser.java | 4 +- .../steamwar/messages/BungeeCore.properties | 11 ++--- .../messages/BungeeCore_de.properties | 11 ++--- 5 files changed, 29 insertions(+), 48 deletions(-) rename src/de/steamwar/bungeecore/commands/{WebregisterCommand.java => WebpasswordCommand.java} (56%) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 5660af1..a63d71a 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -168,7 +168,7 @@ public class BungeeCore extends Plugin { if(!EVENT_MODE){ new BauCommand(); - new WebregisterCommand(); + new WebpasswordCommand(); new FightCommand(); new ChallengeCommand(); new HistoricCommand(); diff --git a/src/de/steamwar/bungeecore/commands/WebregisterCommand.java b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java similarity index 56% rename from src/de/steamwar/bungeecore/commands/WebregisterCommand.java rename to src/de/steamwar/bungeecore/commands/WebpasswordCommand.java index 6197f0f..d5bc7ec 100644 --- a/src/de/steamwar/bungeecore/commands/WebregisterCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java @@ -20,57 +20,44 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.sql.SWException; import de.steamwar.command.SWCommand; +import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -public class WebregisterCommand extends SWCommand { +public class WebpasswordCommand extends SWCommand { - public WebregisterCommand() { - super("webregister", null, "web", "webpw"); + public WebpasswordCommand() { + super("webpassword", null, "web", "webpw"); } @Register(description = "WEB_USAGE") - public void genericCommand(ProxiedPlayer player, String email) { - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", player.getName(), email); + public void genericCommand(ProxiedPlayer player, String password) { + if(password.length() < 8) { + ChatSender.of(player).system("WEB_PASSWORD_LENGTH"); + return; + } + + ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", player.getName(), password); pb.redirectErrorStream(true); try { Process regProcess = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream())); String errorLine; - boolean error = false; - while((errorLine = reader.readLine()) != null){ - switch(errorLine){ - case "username_exists": - Message.send("WEB_ALREADY", player); - break; - case "email_exists": - Message.send("WEB_ALREADY_EMAIL", player); - // SWException.log("Bungee", "Duplicate E-Mail", player.getName() + " " + args[0]); - break; - case "invalid_email": - Message.send("WEB_NOT_EMAIL", player); - break; - case "email_updated": - Message.send("WEB_EMAIL_REFRESH", player); - break; - default: - Message.send("WEB_INTERNAL_ERROR", player); - SWException.log("Bungee", "Unknown Wordpress User Creation Error", errorLine); + if((errorLine = reader.readLine()) != null) { + if ("updated".equals(errorLine)) { + Message.send("WEB_UPDATED", player); + return; + } else { + throw new SecurityException("Could not create webaccount " + errorLine); } - error = true; } - if(error) - return; - - Message.send("WEB_EMAIL_SEND", player); + Message.send("WEB_CREATED", player); } catch (IOException e) { - Message.send("WEB_INTERNAL_ERROR", player); throw new SecurityException("Could not create webaccount", e); } } diff --git a/src/de/steamwar/bungeecore/sql/SteamwarUser.java b/src/de/steamwar/bungeecore/sql/SteamwarUser.java index 96c92d5..a5cb605 100644 --- a/src/de/steamwar/bungeecore/sql/SteamwarUser.java +++ b/src/de/steamwar/bungeecore/sql/SteamwarUser.java @@ -22,7 +22,7 @@ package de.steamwar.bungeecore.sql; import com.google.gson.JsonParser; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.commands.WebregisterCommand; +import de.steamwar.bungeecore.commands.WebpasswordCommand; import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.messages.ChatSender; @@ -121,7 +121,7 @@ public class SteamwarUser { String userName = connection.getName(); if (!user.userName.equals(userName)) { updateName.update(userName, user.id); - WebregisterCommand.changeUsername(user.userName, userName); + WebpasswordCommand.changeUsername(user.userName, userName); user.userName = userName; } } else { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 203618f..a2ba6ff 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -498,13 +498,10 @@ UNIGNORE_NOT_IGNORED=§cYou are not ignoring this player. UNIGNORE_UNIGNORED=§7You ignored §e{0}§8. #WebregisterCommand -WEB_USAGE=§8/§7webregister §8[§eE-Mail§8] -WEB_ALREADY=§cYou already have a webaccount. -WEB_ALREADY_EMAIL=§cYou already used this E-Mail address on another account... -WEB_NOT_EMAIL=§c[E-Mail], not [free text]! -WEB_EMAIL_REFRESH=§aYour E-Mail was updated. -WEB_INTERNAL_ERROR=§cAn internal error occurred, please contact a developer. -WEB_EMAIL_SEND=§aAn E-Mail to reset your password has been sent. +WEB_USAGE=§8/§7webpassword §8[§epassword§8] +WEB_UPDATED=§7Your password was updated. +WEB_CREATED=§7Your webaccount was created. +WEB_PASSWORD_LENGTH=§cYour password is shorter than 8 characters. #ChatListener CHAT_LIXFEL_ACTION_BAR=§4§lTechnical problems? diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 28df9b1..b23a577 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -477,13 +477,10 @@ UNIGNORE_NOT_IGNORED=§cDu ignorierst diesen Spieler nicht. UNIGNORE_UNIGNORED=§7Du empfängst nun wieder Nachrichten von §e{0}§8. #WebregisterCommand -WEB_USAGE=§8/§7webregister §8[§eE-Mail§8] -WEB_ALREADY=§cDu hast bereits einen Webaccount. -WEB_ALREADY_EMAIL=§cDie E-Mail hast du bereits für einen anderen Account verwendet... -WEB_NOT_EMAIL=§c[E-Mail], nicht [Freitext]! -WEB_EMAIL_REFRESH=§aDeine E-Mail-Adresse wurde aktualisiert. -WEB_INTERNAL_ERROR=§cEin interner Fehler ist aufgetreten, bitte wende dich an einen Developer. -WEB_EMAIL_SEND=§aEine E-Mail zum Setzen des Passworts wurde gesendet. +WEB_USAGE=§8/§7webpassword §8[§ePasswort§8] +WEB_UPDATED=§7Dein Passwort wurde aktualisiert. +WEB_CREATED=§7Dein Webaccount wurde erstellt. +WEB_PASSWORD_LENGTH=§cDein Passwort ist kürzer als 8 Zeichen. #ChatListener CHAT_LIXFEL_ACTION_BAR=§4§lTechnische Probleme? From 11106ab2408c7f99fa71e16a6c9b5bb51d9f8cef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Aug 2022 19:15:28 +0200 Subject: [PATCH 06/35] Bye Bye Mail. Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/WebpasswordCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java index d5bc7ec..39e29b5 100644 --- a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java @@ -19,7 +19,6 @@ package de.steamwar.bungeecore.commands; -import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -49,14 +48,14 @@ public class WebpasswordCommand extends SWCommand { String errorLine; if((errorLine = reader.readLine()) != null) { if ("updated".equals(errorLine)) { - Message.send("WEB_UPDATED", player); + ChatSender.of(player).system("WEB_UPDATED"); return; } else { throw new SecurityException("Could not create webaccount " + errorLine); } } - Message.send("WEB_CREATED", player); + ChatSender.of(player).system("WEB_CREATED"); } catch (IOException e) { throw new SecurityException("Could not create webaccount", e); } From 5cf577c9e5433814ef4fb11911d07197dbaee604 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Aug 2022 19:22:21 +0200 Subject: [PATCH 07/35] Bye Bye Mail. Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/WebpasswordCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java index 39e29b5..ec79a8c 100644 --- a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java @@ -30,7 +30,7 @@ import java.io.InputStreamReader; public class WebpasswordCommand extends SWCommand { public WebpasswordCommand() { - super("webpassword", null, "web", "webpw"); + super("webpassword", null, "webpw", "web"); } @Register(description = "WEB_USAGE") From bd1420cc9091f176eb02b1137b19d323fa0a5189 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Aug 2022 19:35:46 +0200 Subject: [PATCH 08/35] Bye Bye Mail. Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/WebpasswordCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java index ec79a8c..2e45c27 100644 --- a/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java +++ b/src/de/steamwar/bungeecore/commands/WebpasswordCommand.java @@ -33,6 +33,7 @@ public class WebpasswordCommand extends SWCommand { super("webpassword", null, "webpw", "web"); } + @Register(description = "WEB_USAGE") public void genericCommand(ProxiedPlayer player, String password) { if(password.length() < 8) { From b8404a74a7674d9896ded76d9d85102044085451 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Aug 2022 06:50:53 +0200 Subject: [PATCH 09/35] Update to paper 1.19.2 Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ServerStarter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index f452f3f..a0b4ec8 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -109,7 +109,7 @@ public class ServerStarter { public ServerStarter build19(UUID owner) { directory = new File(SERVER_PATH, "Bau19"); - serverJar = "paper-1.19.1.jar"; + serverJar = "paper-1.19.2.jar"; worldDir = WORLDS19_PATH; worldName = String.valueOf(SteamwarUser.get(owner).getId()); buildWithWorld(owner, new File(directory, "Bauwelt").getPath()); From e4cd94aecd0486b53c37c157108aef23c7e7180e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Aug 2022 14:31:04 +0200 Subject: [PATCH 10/35] Fix lobbyconnection on disconnect Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/listeners/ConnectionListener.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java index 95f6a89..44bba9f 100644 --- a/src/de/steamwar/bungeecore/listeners/ConnectionListener.java +++ b/src/de/steamwar/bungeecore/listeners/ConnectionListener.java @@ -105,6 +105,9 @@ public class ConnectionListener extends BasicListener { @EventHandler public void onServerKickEvent(ServerKickEvent ev) { + if(!ev.getPlayer().isConnected()) + return; + ServerInfo kickedFrom; if (ev.getPlayer().getServer() != null){ From ea94195db8d8023b59daab76f882581ab644bd70 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Aug 2022 16:07:21 +0200 Subject: [PATCH 11/35] Fix folder inconsistencies Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 8 -------- src/de/steamwar/bungeecore/ServerStarter.java | 12 +++++++----- src/de/steamwar/bungeecore/commands/BauCommand.java | 4 ++-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index a63d71a..591132a 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -61,11 +61,7 @@ public class BungeeCore extends Plugin { public static boolean MAIN_SERVER; public static String CHAT_PREFIX; - public static String WORLD_FOLDER; - public static String BAUWELT_PROTOTYP; public static String LOBBY_SERVER; - public static String USERWORLDS15; - public static String BAUWELT15; public static boolean EVENT_MODE; private static BungeeCore instance; @@ -299,11 +295,7 @@ public class BungeeCore extends Plugin { } CHAT_PREFIX = config.getString("prefix"); - WORLD_FOLDER = config.getString("worldfolder"); - BAUWELT_PROTOTYP = config.getString("bauweltprototyp"); LOBBY_SERVER = config.getString("lobbyserver"); - USERWORLDS15 = config.getString("userworlds15"); - BAUWELT15 = config.getString("bauwelt15"); EVENT_MODE = config.getBoolean("eventmode"); Broadcaster.setBroadCastMsgs(config.getStringList("broadcasts").toArray(new String[1])); PollSystem.init(config.getString("poll.question"), config.getStringList("poll.answers")); diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index a0b4ec8..a805523 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -24,6 +24,8 @@ public class ServerStarter { private static final String EVENT_PATH = USER_HOME + "event/"; public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; public static final String TUTORIAL_PATH = USER_HOME + "tutorials/"; + public static final String WORLDS12_PATH = USER_HOME + "userworlds/"; + public static final String WORLDS15_PATH = USER_HOME + "userworlds15/"; public static final String WORLDS19_PATH = USER_HOME + "userworlds19/"; private File directory = null; @@ -118,19 +120,19 @@ public class ServerStarter { public ServerStarter build15(UUID owner) { directory = new File(SERVER_PATH, "Bau15"); - worldDir = BungeeCore.USERWORLDS15; + worldDir = WORLDS15_PATH; worldName = String.valueOf(SteamwarUser.get(owner).getId()); - buildWithWorld(owner, BungeeCore.BAUWELT15); + buildWithWorld(owner, new File(directory, "Bauwelt").getPath()); return this; } public ServerStarter build12(UUID owner) { - directory = new File(SERVER_PATH, "UserBau"); + directory = new File(SERVER_PATH, "Bau12"); serverJar = "spigot-1.12.2.jar"; xmx = "256M"; - worldDir = BungeeCore.WORLD_FOLDER; + worldDir = WORLDS12_PATH; worldName = owner.toString(); - buildWithWorld(owner, BungeeCore.BAUWELT_PROTOTYP); + buildWithWorld(owner, new File(directory, "Bauwelt").getPath()); return this; } diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 9f59bf4..41496b9 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -236,8 +236,8 @@ public class BauCommand extends BasicCommand { SteamwarUser user = SteamwarUser.get(p.getUniqueId()); versionSelector(p, args, 1, () -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId())), - () -> deleteConfirmation(p, () -> deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId())), - () -> deleteConfirmation(p, () -> deleteWorld(p, BungeeCore.WORLD_FOLDER + p.getUniqueId().toString())), + () -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())), + () -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS12_PATH + p.getUniqueId().toString())), () -> HelpCommand.sendBauHelp(ChatSender.of(p))); } From c4204cd54d09e1a770bbbb89cfbbacdebe18a73c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 22 Aug 2022 18:43:36 +0200 Subject: [PATCH 12/35] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 47bd9af..d718969 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 47bd9af03eb987f94777f3b13f6ae6c30f153393 +Subproject commit d71896979ed397128306474da352cd56fc039a48 From 6d717eb1b022b543285c51634cf03b9a9660dd83 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 22 Aug 2022 18:43:59 +0200 Subject: [PATCH 13/35] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 6cb3bc5..2c6ebc8 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 6cb3bc5ff5ee955ccdde281183991d0877e54169 +Subproject commit 2c6ebc82f3d8177191bcd7444dfe9607c35c952b From e29fb553f0dd2e99045d2c70cb2f2216f3a53692 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 22 Aug 2022 20:25:36 +0200 Subject: [PATCH 14/35] Remove deprecated guard api --- .../bungeecore/commands/DevCommand.java | 27 ++++++++--------- .../bungeecore/commands/PollCommand.java | 21 +++++-------- .../commands/PollresultCommand.java | 22 ++++++-------- .../bungeecore/commands/TutorialCommand.java | 21 ++++--------- src/de/steamwar/command/GuardChecker.java | 30 ------------------- src/de/steamwar/command/SWCommand.java | 2 +- 6 files changed, 36 insertions(+), 87 deletions(-) delete mode 100644 src/de/steamwar/command/GuardChecker.java diff --git a/src/de/steamwar/bungeecore/commands/DevCommand.java b/src/de/steamwar/bungeecore/commands/DevCommand.java index 4f06408..5858a49 100644 --- a/src/de/steamwar/bungeecore/commands/DevCommand.java +++ b/src/de/steamwar/bungeecore/commands/DevCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.command.*; @@ -42,7 +43,7 @@ public class DevCommand extends SWCommand { } @Register - public void simpleCommand(@Guard ProxiedPlayer player) { + public void simpleCommand(@Validator ProxiedPlayer player) { updateDevServers(); ChatSender sender = ChatSender.of(player); if (devServers.isEmpty()) { @@ -63,7 +64,7 @@ public class DevCommand extends SWCommand { } @Register - public void selectedCommand(@Guard ProxiedPlayer player, @Mapper("dev") String name) { + public void selectedCommand(@Validator ProxiedPlayer player, @Mapper("dev") String name) { updateDevServers(); ChatSender sender = ChatSender.of(player); ServerInfo info = devServers.get(name.toLowerCase()); @@ -75,20 +76,16 @@ public class DevCommand extends SWCommand { player.connect(info); } - @ClassGuard(value = ProxiedPlayer.class, local = true) - public GuardChecker punishmentGuardChecker() { - return (commandSender, guardCheckType, previousArguments, s) -> { - ChatSender sender = ChatSender.of(commandSender); - if (guardCheckType == GuardCheckType.COMMAND) { - if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) { - return GuardResult.DENIED; - } - } else { - if (sender.user().isPunished(Punishment.PunishmentType.NoDevServer)) { - return GuardResult.DENIED; - } + @ClassValidator(value = ProxiedPlayer.class, local = true) + public TypeValidator punishmentGuardChecker() { + return (sender, value, messageSender) -> { + SteamwarUser user = SteamwarUser.get(value); + if (user.isPunished(Punishment.PunishmentType.NoDevServer)) { + Message message = user.punishmentMessage(Punishment.PunishmentType.NoDevServer); + messageSender.send(message.getFormat(), message.getParams()); + return false; } - return GuardResult.ALLOWED; + return true; }; } diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index e6fb755..48400e5 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -23,11 +23,8 @@ import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.sql.PollAnswer; import de.steamwar.bungeecore.sql.SteamwarUser; -import de.steamwar.command.GuardCheckType; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; public class PollCommand extends SWCommand { @@ -42,7 +39,7 @@ public class PollCommand extends SWCommand { } @Register(noTabComplete = true) - public void answerPoll(@Guard ProxiedPlayer player, String answerString) { + public void answerPoll(@Validator ProxiedPlayer player, String answerString) { int answer; try { answer = Integer.parseUnsignedInt(answerString); @@ -62,16 +59,14 @@ public class PollCommand extends SWCommand { pollAnswer.setAnswer(answer); } - @ClassGuard(value = ProxiedPlayer.class, local = true) - public GuardChecker noPoll() { - return (commandSender, guardCheckType, previousArguments, s) -> { + @ClassValidator(value = ProxiedPlayer.class, local = true) + public TypeValidator noPoll() { + return (sender, value, messageSender) -> { if(PollSystem.noCurrentPoll()){ - if (guardCheckType == GuardCheckType.COMMAND) { - Message.send("POLL_NO_POLL", commandSender); - } - return GuardResult.DENIED; + messageSender.send("POLL_NO_POLL"); + return false; } - return GuardResult.ALLOWED; + return true; }; } } diff --git a/src/de/steamwar/bungeecore/commands/PollresultCommand.java b/src/de/steamwar/bungeecore/commands/PollresultCommand.java index 4011f4c..554efcc 100644 --- a/src/de/steamwar/bungeecore/commands/PollresultCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollresultCommand.java @@ -22,10 +22,8 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.PollSystem; import de.steamwar.bungeecore.sql.PollAnswer; -import de.steamwar.command.GuardCheckType; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.Map; @@ -37,7 +35,7 @@ public class PollresultCommand extends SWCommand { } @Register - public void genericCommand(@Guard ProxiedPlayer player) { + public void genericCommand(@Validator ProxiedPlayer player) { Map voted = PollAnswer.getCurrentResults(); Message.send("POLLRESULT_HEADER", player, voted.values().stream().reduce(Integer::sum).orElse(0), PollSystem.getQuestion()); for (Map.Entry e: voted.entrySet()) { @@ -45,16 +43,14 @@ public class PollresultCommand extends SWCommand { } } - @ClassGuard(value = ProxiedPlayer.class, local = true) - public GuardChecker noPoll() { - return (commandSender, guardCheckType, previousArguments, s) -> { - if(PollSystem.noCurrentPoll()){ - if (guardCheckType == GuardCheckType.COMMAND) { - Message.send("POLL_NO_POLL", commandSender); - } - return GuardResult.DENIED; + @ClassValidator(value = ProxiedPlayer.class, local = true) + public TypeValidator noPoll() { + return (sender, value, messageSender) -> { + if (PollSystem.noCurrentPoll()) { + messageSender.send("POLL_NO_POLL"); + return false; } - return GuardResult.ALLOWED; + return true; }; } } diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index e5e3134..72d0e2a 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -26,9 +26,8 @@ import de.steamwar.bungeecore.inventory.SWListInv; import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Tutorial; -import de.steamwar.command.GuardChecker; -import de.steamwar.command.GuardResult; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -78,22 +77,14 @@ public class TutorialCommand extends SWCommand { } @Register("unreleased") - public void unreleased(@Guard("unreleased") ProxiedPlayer player) { + public void unreleased(@Validator("unreleased") ProxiedPlayer player) { openInventory(player, false, false); } - @Guard("unreleased") - public GuardChecker unreleasedChecker() { - return (commandSender, guardCheckType, previousArguments, s) -> { - if (commandSender instanceof ProxiedPlayer) { - if (SteamwarUser.get(((ProxiedPlayer) commandSender).getUniqueId()).getUserGroup().isTeamGroup()) { - return GuardResult.ALLOWED; - } else { - return GuardResult.DENIED_WITH_HELP; - } - } else { - return GuardResult.ALLOWED; - } + @Validator("unreleased") + public TypeValidator unreleasedChecker() { + return (sender, value, messageSender) -> { + return (SteamwarUser.get((value).getUniqueId()).getUserGroup().isTeamGroup()); }; } diff --git a/src/de/steamwar/command/GuardChecker.java b/src/de/steamwar/command/GuardChecker.java deleted file mode 100644 index 06c9110..0000000 --- a/src/de/steamwar/command/GuardChecker.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.command; - -import net.md_5.bungee.api.CommandSender; - -@FunctionalInterface -public interface GuardChecker extends AbstractGuardChecker { - /** - * While guarding the first parameter of the command the parameter s of this method is {@code null} - */ - GuardResult guard(CommandSender commandSender, GuardCheckType guardCheckType, String[] previousArguments, String s); -} diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index f8c3647..3938c61 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -149,7 +149,7 @@ public class SWCommand extends AbstractSWCommand { } if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { - if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { + if (subCommand.validator == null || subCommand.validator.validate(p, p, (s, args1) -> {})) { send(chatSender, subCommand); } }); From 3f99585b350f8e0a401d90c3b06e6fc5a8249052 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 22 Aug 2022 21:09:27 +0200 Subject: [PATCH 15/35] Rebuild --- src/de/steamwar/command/SWCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 3938c61..3242eb5 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -156,6 +156,7 @@ public class SWCommand extends AbstractSWCommand { } } + private void send(ChatSender chatSender, SubCommand subCommand) { try { for (String s : subCommand.description) { From 5c127e0887f18f9b10ee74db4f82f3da23e0b704 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 22 Aug 2022 21:10:35 +0200 Subject: [PATCH 16/35] Rebuild --- CommonCore | 2 +- src/de/steamwar/command/SWCommand.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CommonCore b/CommonCore index 2c6ebc8..3701f6f 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 2c6ebc82f3d8177191bcd7444dfe9607c35c952b +Subproject commit 3701f6f5ff10fa97d6816d5f57c85f7213f7fb3e diff --git a/src/de/steamwar/command/SWCommand.java b/src/de/steamwar/command/SWCommand.java index 3242eb5..3938c61 100644 --- a/src/de/steamwar/command/SWCommand.java +++ b/src/de/steamwar/command/SWCommand.java @@ -156,7 +156,6 @@ public class SWCommand extends AbstractSWCommand { } } - private void send(ChatSender chatSender, SubCommand subCommand) { try { for (String s : subCommand.description) { From a782f811fc02fca7d5273d6e324fea9c77f7f69d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Aug 2022 16:57:19 +0200 Subject: [PATCH 17/35] Add english aliases Signed-off-by: Lixfel --- .../bungeecore/commands/HelpCommand.java | 32 +++++++++---------- .../bungeecore/commands/RegelnCommand.java | 3 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/HelpCommand.java b/src/de/steamwar/bungeecore/commands/HelpCommand.java index 7bcce92..e2a66f8 100644 --- a/src/de/steamwar/bungeecore/commands/HelpCommand.java +++ b/src/de/steamwar/bungeecore/commands/HelpCommand.java @@ -36,17 +36,17 @@ public class HelpCommand extends BasicCommand { if (args.length < 1) { printPage(sender, ClickEvent.Action.RUN_COMMAND, "HELP_LOBBY", "/l", - "HELP_BAU", "/bau", - "HELP_BAUSERVER", "/help bau", + "HELP_BAU", "/build", + "HELP_BAUSERVER", "/help build", "HELP_FIGHT", "/fight", "HELP_CHALLENGE", "/challenge", "HELP_HISTORIC", "/historic", "HELP_TEAM", "/team", "HELP_JOIN", "/join", "HELP_LOCAL", "/local"); - }else if (args[0].equalsIgnoreCase("bauserver")) { + }else if (args[0].equalsIgnoreCase("buildserver")) { sendBauHelp(sender); - }else if (args[0].equalsIgnoreCase("bau")) { + }else if (args[0].equalsIgnoreCase("build")) { bauHelpGroup(sender, args); } } @@ -86,22 +86,22 @@ public class HelpCommand extends BasicCommand { private static void sendBauHelpGroup(ChatSender sender) { printPage(sender, ClickEvent.Action.RUN_COMMAND, - "HELP_BAU_GROUP_ADMIN", "/help bau admin", - "HELP_BAU_GROUP_WORLD", "/help bau world", - "HELP_BAU_GROUP_PLAYER", "/help bau player", - "HELP_BAU_GROUP_WE", "/help bau we", - "HELP_BAU_GROUP_OTHER", "/help bau other"); + "HELP_BAU_GROUP_ADMIN", "/help build admin", + "HELP_BAU_GROUP_WORLD", "/help build world", + "HELP_BAU_GROUP_PLAYER", "/help build player", + "HELP_BAU_GROUP_WE", "/help build we", + "HELP_BAU_GROUP_OTHER", "/help build other"); } static void sendBauHelp(ChatSender sender) { printPage(sender, ClickEvent.Action.SUGGEST_COMMAND, - "HELP_BAU_TP", "/bau tp ", - "HELP_BAU_ADDMEMBER", "/bau addmember ", - "HELP_BAU_DELMEMBER", "/bau delmember ", - "HELP_BAU_TOGGLEWE", "/bau togglewe ", - "HELP_BAU_TOGGLEWORLD", "/bau toggleworld ", - "HELP_BAU_DELETE", "/bau delete ", - "HELP_BAU_TESTARENA", "/bau testarena "); + "HELP_BAU_TP", "/build tp ", + "HELP_BAU_ADDMEMBER", "/build addmember ", + "HELP_BAU_DELMEMBER", "/build delmember ", + "HELP_BAU_TOGGLEWE", "/build togglewe ", + "HELP_BAU_TOGGLEWORLD", "/build toggleworld ", + "HELP_BAU_DELETE", "/build delete ", + "HELP_BAU_TESTARENA", "/build testarena "); } private static void printPage(ChatSender sender, ClickEvent.Action action, String... args) { diff --git a/src/de/steamwar/bungeecore/commands/RegelnCommand.java b/src/de/steamwar/bungeecore/commands/RegelnCommand.java index 2721b73..63731a5 100644 --- a/src/de/steamwar/bungeecore/commands/RegelnCommand.java +++ b/src/de/steamwar/bungeecore/commands/RegelnCommand.java @@ -21,13 +21,12 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.command.SWCommand; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; public class RegelnCommand extends SWCommand { public RegelnCommand() { - super("regeln"); + super("regeln", null, "rules"); } @Register From a27f74af56969217f2e9c8db467dc4708cc80086 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Aug 2022 16:59:53 +0200 Subject: [PATCH 18/35] Fix build Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/PollCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/PollCommand.java b/src/de/steamwar/bungeecore/commands/PollCommand.java index 48400e5..5e179cd 100644 --- a/src/de/steamwar/bungeecore/commands/PollCommand.java +++ b/src/de/steamwar/bungeecore/commands/PollCommand.java @@ -34,7 +34,7 @@ public class PollCommand extends SWCommand { } @Register - public void genericCommand(@Guard ProxiedPlayer player) { + public void genericCommand(ProxiedPlayer player) { PollSystem.sendPoll(player); } From 4217afef59a41063034bce4a84226d63c54628fb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Aug 2022 17:21:49 +0200 Subject: [PATCH 19/35] Fix 7/ replacer Signed-off-by: Lixfel --- .../bungeecore/listeners/ChatListener.java | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index df006f9..827fe3e 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -56,31 +56,43 @@ public class ChatListener extends BasicListener { ProxiedPlayer player = (ProxiedPlayer) e.getSender(); String message = e.getMessage(); + e.setCancelled(true); + if (message.contains("jndi:ldap")) { - e.setCancelled(true); SteamwarUser.get(player).punishPerma(Punishment.PunishmentType.Ban, "Versuchte Exploit-Ausnutzung", 0); return; } - message = sanitize7(message); + if (isCommand(player, message)) + return; - if (message.startsWith("/")) { - if(filteredCommand((CommandSender) e.getSender(), message)) - e.setCancelled(true); + Subserver subserver = Subserver.getSubserver(player); + if(subserver != null && subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getServer().getInfo()) { + localChat(player, message); + } else if (message.startsWith("+")) { + localChat(player, message.substring(1)); } else { - e.setCancelled(true); - - Subserver subserver = Subserver.getSubserver(player); - if(subserver != null && subserver.getType() == Servertype.ARENA && subserver.getServer() == player.getServer().getInfo()) { - localChat(player, message); - } else if (message.startsWith("+")) { - localChat(player, message.substring(1)); - } else { - sendChat(ChatSender.of(player), ChatSender.globalReceivers(), "CHAT_GLOBAL", null, message); - } + sendChat(ChatSender.of(player), ChatSender.globalReceivers(), "CHAT_GLOBAL", null, message); } } + private static boolean isCommand(ProxiedPlayer player, String message) { + String command = message.substring(1); + boolean isCommand = message.startsWith("/") || (message.startsWith("7") && command.split(" ", 2)[0].matches("[7/]?[A-Za-z]+")); + if(isCommand && !ProxyServer.getInstance().getPluginManager().dispatchCommand(player, command)) { + if(command.startsWith("7")) + command = "/" + command.substring(1); + message = "/" + command; + + if(filteredCommand(player, message)) + return true; + + Chat19.chat(player, message); + } + + return isCommand; + } + public static void sendChat(ChatSender sender, Stream receivers, String format, ChatSender msgReceiver, String message) { SteamwarUser user = sender.user(); final String coloredMessage = (user.getUserGroup() != UserGroup.Member || coloredTeams.contains(user.getTeam())) ? ChatColor.translateAlternateColorCodes('&', message) : message; @@ -114,8 +126,6 @@ public class ChatListener extends BasicListener { return; } - message = sanitize7(message); - if(ChatListener.filteredCommand(player, message)) return; @@ -167,17 +177,6 @@ public class ChatListener extends BasicListener { group.getChatColorCode())); } - private static String sanitize7(String message) { - String begin = message.split(" ", 2)[0]; - if(begin.startsWith("7") && begin.substring(1).matches("[A-Za-z]+")){ - message = "/" + message.substring(1); - }else if((begin.startsWith("77") || begin.startsWith("7/") || begin.startsWith("/7")) && begin.substring(2).matches("[A-Za-z]+")){ - message = "//" + message.substring(2); - } - - return message; - } - private static boolean filteredCommand(CommandSender sender, String message) { String command = message.split(" ", 2)[0]; if(command.startsWith("/") && command.contains(":")) { From a6407d6bb04dd9c2df69c6ffa379ea15be9eaaba Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Aug 2022 18:10:52 +0200 Subject: [PATCH 20/35] Fix tablist failure on softreload Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/tablist/Tablist.java | 9 +++++++-- src/de/steamwar/bungeecore/tablist/TablistManager.java | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/tablist/Tablist.java b/src/de/steamwar/bungeecore/tablist/Tablist.java index b9acc96..ad400cb 100644 --- a/src/de/steamwar/bungeecore/tablist/Tablist.java +++ b/src/de/steamwar/bungeecore/tablist/Tablist.java @@ -62,7 +62,7 @@ public class Tablist extends MessageToMessageDecoder { this.player = player; this.viewer = ChatSender.of(player); this.directTabItems = Storage.directTabItems.computeIfAbsent(player, p -> new HashMap<>()); - onServerSwitch(); + injection(); } public void update(TablistPart global, int seconds) { @@ -145,12 +145,17 @@ public class Tablist extends MessageToMessageDecoder { } public void onServerSwitch() { - connection = (ServerConnection) player.getServer(); + injection(); + synchronized (directTabItems) { sendNpcPacket(npcs.stream().map(npc -> directTabItems.get(npc).getUsername()).collect(Collectors.toList()), true); directTabItems.clear(); npcs.clear(); } + } + + private void injection() { + connection = (ServerConnection) player.getServer(); if(connection != null) { ChannelPipeline pipeline = connection.getCh().getHandle().pipeline(); diff --git a/src/de/steamwar/bungeecore/tablist/TablistManager.java b/src/de/steamwar/bungeecore/tablist/TablistManager.java index 0f02f55..b6e7875 100644 --- a/src/de/steamwar/bungeecore/tablist/TablistManager.java +++ b/src/de/steamwar/bungeecore/tablist/TablistManager.java @@ -51,7 +51,9 @@ public class TablistManager extends BasicListener { public TablistManager() { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::updateTablist, 1, 1, TimeUnit.SECONDS); - ProxyServer.getInstance().getPlayers().forEach(player -> tablists.put(player, new Tablist(player))); + synchronized (tablists) { + ProxyServer.getInstance().getPlayers().forEach(player -> tablists.put(player, new Tablist(player))); + } } @EventHandler From 6b89afd07d06ea772d295dfa9c9d7f84bbc5ed4e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 27 Aug 2022 17:16:02 +0200 Subject: [PATCH 21/35] Finish BuilderCloud command Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ServerStarter.java | 73 ++++++++++-- .../commands/BuilderCloudCommand.java | 105 +++++++++++++----- .../steamwar/messages/BungeeCore.properties | 2 +- .../messages/BungeeCore_de.properties | 2 +- 4 files changed, 142 insertions(+), 40 deletions(-) diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index c8abf86..a00b531 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -7,7 +7,9 @@ import de.steamwar.bungeecore.sql.Tutorial; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; +import java.io.IOException; import java.net.InetSocketAddress; +import java.nio.file.Files; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.function.BooleanSupplier; @@ -28,8 +30,7 @@ public class ServerStarter { public static final String WORLDS15_PATH = USER_HOME + "userworlds15/"; public static final String WORLDS19_PATH = USER_HOME + "userworlds19/"; - public static final String BUILDER15_PATH = BACKBONE + "builder15/"; - public static final String BUILDER19_PATH = BACKBONE + "builder19/"; + public static final String BUILDER_BASE_PATH = USER_HOME + "builder"; private File directory = null; private String worldDir = null; @@ -51,14 +52,6 @@ public class ServerStarter { private final Set playersToSend = new HashSet<>(); private final Map arguments = new HashMap<>(); - public ServerStarter builderCloud(String serverJar, String map) { - this.serverJar = serverJar; - this.worldName = map; - - this.directory = new File(SERVER_PATH); - return this; - } - public ServerStarter arena(ArenaMode mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.getDisplayName() + (port - portrange.start); @@ -207,6 +200,40 @@ public class ServerStarter { serverNameProvider = port -> bauServerName(SteamwarUser.get(owner)); } + public ServerStarter builder(Version version, String map, File generator) { + serverJar = version.getServerJar(); + directory = version.getServerDirectory("Builder"); + worldDir = version.getWorldFolder(BUILDER_BASE_PATH); + worldName = map; + serverNameProvider = port -> "⛏" + map; + constructor = (serverName, port, builder, shutdownCallback) -> new Builderserver(serverName, worldName, port, builder, shutdownCallback); + + // Send players to existing server + startCondition = () -> { + for(Subserver subserver : Subserver.getServerList()) { + if(subserver.getType() == Servertype.BUILDER && ((Builderserver)subserver).getMap().equals(worldName)) { + for(ProxiedPlayer p : playersToSend) + SubserverSystem.sendPlayer(subserver, p); + return false; + } + } + return true; + }; + + if(generator != null) { + worldSetup = () -> { + File leveldat = new File(new File(worldDir, worldName), "level.dat"); + try { + Files.copy(generator.toPath(), leveldat.toPath()); + } catch (IOException e) { + throw new SecurityException(e); + } + }; + } + + return this; + } + public ServerStarter send(ProxiedPlayer player) { playersToSend.add(player); return this; @@ -298,4 +325,30 @@ public class ServerStarter { return result; } } + + public enum Version { + SPIGOT_12("spigot-1.12.2.jar", 12), + SPIGOT_15("spigot-1.15.2.jar", 15), + PAPER_19("paper-1.19.2.jar", 19); + + private final String serverJar; + private final int versionSuffix; + + Version(String serverJar, int versionSuffix) { + this.serverJar = serverJar; + this.versionSuffix = versionSuffix; + } + + public String getServerJar() { + return serverJar; + } + + public String getWorldFolder(String base) { + return base + versionSuffix + "/"; + } + + public File getServerDirectory(String base) { + return new File(SERVER_PATH, base + versionSuffix); + } + } } \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index c84af0f..9e615e6 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -3,70 +3,119 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; -import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; import java.util.*; +import java.util.stream.Collectors; public class BuilderCloudCommand extends SWCommand { - private final Map versionMap = new HashMap<>(); - private final Map pathMap = new HashMap<>(); + private final Map versionMap = new HashMap<>(); public BuilderCloudCommand() { super("buildercloud", "bungeecore.server.team"); - versionMap.put("1.19", "spigot-1.19.jar"); - versionMap.put("19", "spigot-1.19.jar"); - versionMap.put("1.15", "spigot-1.15.2.jar"); - versionMap.put("15", "spigot-1.15.2.jar"); - versionMap.put("1.15.2", "spigot-1.15.2.jar"); - - pathMap.put("19", ServerStarter.BUILDER19_PATH); - pathMap.put("1.19", ServerStarter.BUILDER19_PATH); - pathMap.put("15", ServerStarter.BUILDER15_PATH); - pathMap.put("1.15", ServerStarter.BUILDER15_PATH); - pathMap.put("1.15.2", ServerStarter.BUILDER15_PATH); + versionMap.put("15", ServerStarter.Version.SPIGOT_15); + versionMap.put("1.15", ServerStarter.Version.SPIGOT_15); + versionMap.put("1.15.2", ServerStarter.Version.SPIGOT_15); + versionMap.put("19", ServerStarter.Version.PAPER_19); + versionMap.put("1.19", ServerStarter.Version.PAPER_19); + versionMap.put("1.19.2", ServerStarter.Version.PAPER_19); } - // /buildercloud [version] [map] - @Register(description = "BUILDERCLOUD_USAGE") - public void genericCommand(ProxiedPlayer player, @StaticValue({"19", "1.19", "15", "1.15.2", "1.15"}) @ErrorMessage("BUILDERCLOUD_VERSION") String version, File map) { - String jar = this.versionMap.get(version); - new ServerStarter().builderCloud(jar, map.getName()).start(); + public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") Optional generator) { + new ServerStarter().builder(version, map, generator.orElse(null)).send(player).start(); + } + + @ClassMapper(value = ServerStarter.Version.class, local = true) + private TypeMapper versionTypeMapper() { + return new TypeMapper() { + @Override + public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) { + return versionMap.get(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return versionMap.keySet().stream().filter(key -> key.startsWith(s)).collect(Collectors.toList()); + } + }; } @Cached(global = true) - @ClassMapper(value = File.class, local = true) - private TypeMapper mapTypeMapper() { + @Mapper(value = "map", local = true) + private TypeMapper mapTypeMapper() { - return new TypeMapper() { + return new TypeMapper() { @Override - public File map(CommandSender commandSender, String[] previousArguments, String s) { - String folder = pathMap.get(previousArguments[previousArguments.length - 1]); + public String map(CommandSender commandSender, String[] previousArguments, String s) { + File folder = getWorldFolder(previousArguments, 1); if(folder == null) return null; File map = new File(folder, s); - if(!map.exists() || !map.isDirectory()) + if(!map.exists() && !map.mkdir()) return null; - return map; + return map.getName(); } @Override public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - String folder = pathMap.get(previousArguments[previousArguments.length - 1]); + File folder = getWorldFolder(previousArguments, 1); + + String[] files; + if(folder == null || (files = folder.list()) == null) + return Collections.emptyList(); + + return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).collect(Collectors.toList()); + } + }; + } + + @Cached(global = true) + @Mapper(value = "generator", local = true) + private TypeMapper> generatorTypeMapper() { + + return new TypeMapper>() { + @Override + public Optional map(CommandSender commandSender, String[] previousArguments, String s) { + if(s.equals("")) + return Optional.empty(); + + File folder = getWorldFolder(previousArguments, 2); if(folder == null) return null; - return Arrays.asList(Objects.requireNonNull(new File(folder).list())); + File generator = new File(folder, s + ".dat"); + if(!generator.exists() || !generator.isFile()) + return null; + + return Optional.of(generator); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + File folder = getWorldFolder(previousArguments, 2); + + String[] files; + if(folder == null || (files = folder.list()) == null) + return Collections.emptyList(); + + return Arrays.stream(files).filter(file -> new File(folder, file).isFile()).filter(file -> file.endsWith(".dat")).map(file -> file.substring(0, file.length() - 4)).collect(Collectors.toList()); } }; } + + private File getWorldFolder(String[] previousArguments, int offset) { + ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]); + if(v == null) + return null; + return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH)); + } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 5a39d73..8a4a678 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -632,5 +632,5 @@ FIGHT_MERGE_INFO=§e{0}§8: §e{1} LOCK_LOCALE_CHANGED=§aLanguage saved #Builder Cloud -BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8> BUILDERCLOUD_VERSION=§cUnknown version. \ No newline at end of file diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 18194ca..c2bc2d3 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -610,5 +610,5 @@ FIGHT_MERGE_OFFLINE=§7Die vorgeschlagene Arena wurde in der Zwischenzeit beende LOCK_LOCALE_CHANGED=§aSprache gespeichert #Builder Cloud -BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8> BUILDERCLOUD_VERSION=§cUnbekannte Version. \ No newline at end of file From f1f159a33066773d45b37e4915c1f7f812c7acba Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 27 Aug 2022 18:01:16 +0200 Subject: [PATCH 22/35] Finish BuilderCloud command Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 9e615e6..f790fe7 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -40,7 +40,7 @@ public class BuilderCloudCommand extends SWCommand { @Override public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - return versionMap.keySet().stream().filter(key -> key.startsWith(s)).collect(Collectors.toList()); + return versionMap.keySet(); } }; } From f5675811baa5e08733b16c926201a5d44a830de6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 28 Aug 2022 08:43:07 +0200 Subject: [PATCH 23/35] Hotfix join permissions Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/JoinmeCommand.java | 4 ++++ src/de/steamwar/bungeecore/commands/TpCommand.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java index 105063c..e897ba0 100644 --- a/src/de/steamwar/bungeecore/commands/JoinmeCommand.java +++ b/src/de/steamwar/bungeecore/commands/JoinmeCommand.java @@ -69,6 +69,10 @@ public class JoinmeCommand extends BasicCommand { SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); Message.send("JOIN_PLAYER_BLOCK", player); } + } else if(type == Servertype.BUILDER && !player.hasPermission("bungeecore.server.team")) { + Message.send("JOIN_PLAYER_BLOCK", player); + } else { + SubserverSystem.sendPlayer(subserver, player); } }else if(serverPerm != null && !player.hasPermission(serverPerm)){ Message.send("JOIN_PLAYER_BLOCK", player); diff --git a/src/de/steamwar/bungeecore/commands/TpCommand.java b/src/de/steamwar/bungeecore/commands/TpCommand.java index a31cd78..1ac1a22 100644 --- a/src/de/steamwar/bungeecore/commands/TpCommand.java +++ b/src/de/steamwar/bungeecore/commands/TpCommand.java @@ -102,6 +102,8 @@ public class TpCommand extends BasicCommand { sender.system("JOIN_PLAYER_BLOCK"); } + } else if(subserver instanceof Builderserver && !player.hasPermission("bungeecore.server.team")) { + sender.system("JOIN_PLAYER_BLOCK"); } else if (serverPerm != null && !player.hasPermission(serverPerm)) { sender.system("JOIN_PLAYER_BLOCK"); } else if (serverPerm == null && !player.getGroups().contains("team")) { From d14d7489116477fd88fd2be8a70d67667b41aff5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Mon, 29 Aug 2022 14:33:34 +0200 Subject: [PATCH 24/35] Improve Blocked Logging --- src/de/steamwar/bungeecore/network/NetworkReceiver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/network/NetworkReceiver.java b/src/de/steamwar/bungeecore/network/NetworkReceiver.java index d3de8c8..f01bf44 100644 --- a/src/de/steamwar/bungeecore/network/NetworkReceiver.java +++ b/src/de/steamwar/bungeecore/network/NetworkReceiver.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.network; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.commands.TeamCommand; import de.steamwar.bungeecore.listeners.BasicListener; +import de.steamwar.bungeecore.sql.SWException; import de.steamwar.network.packets.NetworkPacket; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.Server; @@ -31,8 +32,8 @@ import net.md_5.bungee.event.EventPriority; import java.net.InetSocketAddress; import java.util.Arrays; +import java.util.Base64; import java.util.List; -import java.util.logging.Level; public class NetworkReceiver extends BasicListener { @@ -41,7 +42,7 @@ public class NetworkReceiver extends BasicListener { @EventHandler(priority = EventPriority.HIGHEST) public void onPluginMessage(PluginMessageEvent event) { if (blockedTags.contains(event.getTag()) && !TeamCommand.isLocalhost(((InetSocketAddress) event.getSender().getSocketAddress()).getAddress())) { - BungeeCore.log(Level.SEVERE, ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag()); + SWException.log("Bungee", ((InetSocketAddress) event.getSender().getSocketAddress()).getHostString() + " tried to send a plugin message with tag " + event.getTag(), Base64.getEncoder().encodeToString(event.getData())); event.setCancelled(true); return; } From cb591fda59d8ba35e5919423d21bb5a65434d802 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:01:51 +0200 Subject: [PATCH 25/35] WIP --- CommonCore | 2 +- .../commands/BuilderCloudCommand.java | 18 +-- .../bungeecore/commands/ChallengeCommand.java | 121 ++++++++++-------- 3 files changed, 79 insertions(+), 62 deletions(-) diff --git a/CommonCore b/CommonCore index 3701f6f..6e6d349 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 3701f6f5ff10fa97d6816d5f57c85f7213f7fb3e +Subproject commit 6e6d34905ac39bd2ed9548729041febadd42da2f diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index f790fe7..5436919 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -26,8 +26,8 @@ public class BuilderCloudCommand extends SWCommand { } @Register(description = "BUILDERCLOUD_USAGE") - public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") Optional generator) { - new ServerStarter().builder(version, map, generator.orElse(null)).send(player).start(); + public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { + new ServerStarter().builder(version, map, generator).send(player).start(); } @ClassMapper(value = ServerStarter.Version.class, local = true) @@ -79,24 +79,24 @@ public class BuilderCloudCommand extends SWCommand { @Cached(global = true) @Mapper(value = "generator", local = true) - private TypeMapper> generatorTypeMapper() { + private TypeMapper generatorTypeMapper() { - return new TypeMapper>() { + return new TypeMapper() { @Override - public Optional map(CommandSender commandSender, String[] previousArguments, String s) { + public File map(CommandSender commandSender, String[] previousArguments, String s) { if(s.equals("")) - return Optional.empty(); + return null; File folder = getWorldFolder(previousArguments, 2); if(folder == null) - return null; + throw new SecurityException(); File generator = new File(folder, s + ".dat"); if(!generator.exists() || !generator.isFile()) - return null; + throw new SecurityException(); - return Optional.of(generator); + return generator; } @Override diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 92fa0a7..143ae94 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -22,86 +22,103 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.sql.IgnoreSystem; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedList; +import java.util.stream.Collectors; import static de.steamwar.bungeecore.Storage.challenges; -public class ChallengeCommand extends BasicCommand { +public class ChallengeCommand extends SWCommand { public ChallengeCommand() { - super("challenge", ""); + super("challenge"); } - @Override - public void execute(CommandSender sender, String[] args) { - if(args.length < 1){ - Message.send("CHALLENGE_USAGE", sender); - return; - } - - if (!(sender instanceof ProxiedPlayer)) - return; - - if(ModLoaderBlocker.isFabric((ProxiedPlayer) sender)) { - Message.send("MODLOADER_DENIED", sender); - return; - } - - ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]); - if(target == null){ - Message.send("CHALLENGE_OFFLINE", sender); - return; - }else if(target == sender){ - Message.send("CHALLENGE_SELF", sender); - return; - }else if (IgnoreSystem.isIgnored(target, (ProxiedPlayer) sender)) { - Message.send("CHALLENGE_IGNORED", sender); - return; - } - - Subserver subserver = Subserver.getSubserver(target); - if(subserver != null && subserver.getType() == Servertype.ARENA){ - Message.send("CHALLENGE_INARENA", sender); - return; - } - - FightCommand.createArena(sender, "/challenge " + target.getName() + " ", false, args, 1, false, (player, mode, map) -> { - if(challenges.containsKey(target) && challenges.get(target).contains(player)){ + @Register(description = "CHALLENGE_USAGE") + public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("target") ProxiedPlayer target, String... args) { + FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, args, 0, false, (p, mode, map) -> { + if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); - challenges.remove(player); + challenges.remove(p); Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).start(); Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName(), target.getName()); + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()); }else{ - if(!challenges.containsKey(player)){ - challenges.put(player, new LinkedList<>()); + if(!challenges.containsKey(p)){ + challenges.put(p, new LinkedList<>()); } - challenges.get(player).add(target); + challenges.get(p).add(target); - Message.send("CHALLENGE_CHALLENGED", player, target.getName(), mode.getDisplayName()); - Message.send("CHALLENGE_CHALLENGED_TARGET", target, player.getName(), mode.getDisplayName(), mode.getMaps().size()!=1?Message.parse("CHALLENGE_CHALLENGED_MAP", target, map):""); + Message.send("CHALLENGE_CHALLENGED", p, target.getName(), mode.getDisplayName()); + Message.send("CHALLENGE_CHALLENGED_TARGET", target, p.getName(), mode.getDisplayName(), mode.getMaps().size()!=1?Message.parse("CHALLENGE_CHALLENGED_MAP", target, map):""); - Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName() + " " + map)); + Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + map)); } }); } + @Validator("fabric") + public TypeValidator fabricChecker() { + return (sender, value, messageSender) -> { + if (ModLoaderBlocker.isFabric(value)) { + messageSender.send("MODLOADER_DENIED"); + return false; + } + return true; + }; + } + + @Mapper("target") + public TypeMapper targetMapper() { + return new TypeMapper() { + @Override + public ProxiedPlayer map(CommandSender commandSender, String[] previousArguments, String s) { + return BungeeCord.getInstance().getPlayer(s); + } + + @Override + public boolean validate(CommandSender sender, ProxiedPlayer value, MessageSender messageSender) { + if (value == null) { + messageSender.send("CHALLENGE_OFFLINE"); + return false; + } + if (sender == value) { + messageSender.send("CHALLENGE_SELF"); + return false; + } + if (IgnoreSystem.isIgnored(value, (ProxiedPlayer) sender)) { + messageSender.send("CHALLENGE_IGNORED"); + return false; + } + + Subserver subserver = Subserver.getSubserver(value); + if (subserver != null && subserver.getType() == Servertype.ARENA) { + messageSender.send("CHALLENGE_INARENA"); + return false; + } + return true; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getDisplayName).collect(Collectors.toList()); + } + }; + } + public static void remove(ProxiedPlayer player){ challenges.remove(player); } - - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 2) - return ArenaMode.getAllChatNames(false); - return new ArrayList<>(); - } } From 7de6402a630d83bf6683f68367f94dba20233a83 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:24:56 +0200 Subject: [PATCH 26/35] Update ChallengeCommand --- .../bungeecore/commands/ChallengeCommand.java | 62 ++++--------- .../bungeecore/commands/TypeMappers.java | 88 +++++++++++++++++++ src/de/steamwar/command/TypeUtils.java | 3 + 3 files changed, 110 insertions(+), 43 deletions(-) create mode 100644 src/de/steamwar/bungeecore/commands/TypeMappers.java diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 143ae94..6f300f3 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -45,7 +45,7 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("target") ProxiedPlayer target, String... args) { + public void challenge(@Validator("fabric") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, args, 0, false, (p, mode, map) -> { if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); @@ -69,55 +69,31 @@ public class ChallengeCommand extends SWCommand { }); } - @Validator("fabric") - public TypeValidator fabricChecker() { + @Validator("target") + public TypeValidator targetValidator() { return (sender, value, messageSender) -> { - if (ModLoaderBlocker.isFabric(value)) { - messageSender.send("MODLOADER_DENIED"); + if (value == null) { + messageSender.send("CHALLENGE_OFFLINE"); + return false; + } + if (sender == value) { + messageSender.send("CHALLENGE_SELF"); + return false; + } + if (IgnoreSystem.isIgnored(value, (ProxiedPlayer) sender)) { + messageSender.send("CHALLENGE_IGNORED"); + return false; + } + + Subserver subserver = Subserver.getSubserver(value); + if (subserver != null && subserver.getType() == Servertype.ARENA) { + messageSender.send("CHALLENGE_INARENA"); return false; } return true; }; } - @Mapper("target") - public TypeMapper targetMapper() { - return new TypeMapper() { - @Override - public ProxiedPlayer map(CommandSender commandSender, String[] previousArguments, String s) { - return BungeeCord.getInstance().getPlayer(s); - } - - @Override - public boolean validate(CommandSender sender, ProxiedPlayer value, MessageSender messageSender) { - if (value == null) { - messageSender.send("CHALLENGE_OFFLINE"); - return false; - } - if (sender == value) { - messageSender.send("CHALLENGE_SELF"); - return false; - } - if (IgnoreSystem.isIgnored(value, (ProxiedPlayer) sender)) { - messageSender.send("CHALLENGE_IGNORED"); - return false; - } - - Subserver subserver = Subserver.getSubserver(value); - if (subserver != null && subserver.getType() == Servertype.ARENA) { - messageSender.send("CHALLENGE_INARENA"); - return false; - } - return true; - } - - @Override - public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { - return BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getDisplayName).collect(Collectors.toList()); - } - }; - } - public static void remove(ProxiedPlayer player){ challenges.remove(player); } diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java new file mode 100644 index 0000000..4f3d7bd --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -0,0 +1,88 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.ArenaMode; +import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import de.steamwar.command.TypeValidator; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.connection.ProxiedPlayer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +@UtilityClass +public class TypeMappers { + + public static void init() { + SWCommandUtils.addValidator("fabric", fabricChecker()); + SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false)); + SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true)); + SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); + } + + public static TypeValidator fabricChecker() { + return (sender, value, messageSender) -> { + if (ModLoaderBlocker.isFabric(value)) { + messageSender.send("MODLOADER_DENIED"); + return false; + } + return true; + }; + } + + public static TypeMapper arenaModeTypeMapper(boolean historic) { + return new TypeMapper() { + @Override + public ArenaMode map(CommandSender commandSender, String[] previousArguments, String s) { + return ArenaMode.getByChat(s); + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + return ArenaMode.getAllChatNames(historic); + } + }; + } + + public static TypeMapper arenaMapTypeMapper() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (s.equalsIgnoreCase("random")) return "random"; + ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); + if (arenaMode.getMaps().contains(s)) return s; + return null; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); + List stringList = new ArrayList<>(arenaMode.getMaps()); + stringList.add("random"); + return stringList; + } + }; + } +} diff --git a/src/de/steamwar/command/TypeUtils.java b/src/de/steamwar/command/TypeUtils.java index df779d9..833cd4b 100644 --- a/src/de/steamwar/command/TypeUtils.java +++ b/src/de/steamwar/command/TypeUtils.java @@ -19,6 +19,7 @@ package de.steamwar.command; +import de.steamwar.bungeecore.commands.TypeMappers; import de.steamwar.bungeecore.sql.SteamwarUser; import lombok.experimental.UtilityClass; import net.md_5.bungee.BungeeCord; @@ -32,5 +33,7 @@ public class TypeUtils { static void init() { SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); + + TypeMappers.init(); } } From 669375e7519b5c59b61457c48283de8105c55115 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Sep 2022 18:39:08 +0200 Subject: [PATCH 27/35] Update ChallengeCommand Update FightCommand Update HistoricCommand --- .../bungeecore/commands/ChallengeCommand.java | 6 +- .../bungeecore/commands/FightCommand.java | 63 +++++++++++++------ .../bungeecore/commands/HistoricCommand.java | 32 +++------- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 6f300f3..e69eaaf 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -46,7 +46,7 @@ public class ChallengeCommand extends SWCommand { @Register(description = "CHALLENGE_USAGE") public void challenge(@Validator("fabric") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, args, 0, false, (p, mode, map) -> { + FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (p, mode, m) -> { if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); challenges.remove(p); @@ -62,9 +62,9 @@ public class ChallengeCommand extends SWCommand { challenges.get(p).add(target); Message.send("CHALLENGE_CHALLENGED", p, target.getName(), mode.getDisplayName()); - Message.send("CHALLENGE_CHALLENGED_TARGET", target, p.getName(), mode.getDisplayName(), mode.getMaps().size()!=1?Message.parse("CHALLENGE_CHALLENGED_MAP", target, map):""); + Message.send("CHALLENGE_CHALLENGED_TARGET", target, p.getName(), mode.getDisplayName(), mode.getMaps().size() != 1 ? Message.parse("CHALLENGE_CHALLENGED_MAP", target, m) : ""); - Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + map)); + Message.send("CHALLENGE_ACCEPT", target, Message.parse("CHALLENGE_ACCEPT_HOVER", target), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + p.getName() + " " + mode.getChatName() + " " + m)); } }); } diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index 3273016..c1fcd89 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.sql.Punishment; +import de.steamwar.command.SWCommand; import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatMessageType; @@ -45,7 +46,7 @@ import java.util.LinkedList; * Sollte die Map fehlen, kann sie mit getMap() bestimmt werden. */ -public class FightCommand extends BasicCommand { +public class FightCommand extends SWCommand { public FightCommand() { super("fight", "", "f"); @@ -129,6 +130,43 @@ public class FightCommand extends BasicCommand { return false; } + static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { + ChatSender sender = ChatSender.of(player); + if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { + return; + } + + if(alreadyInArena(player)) + return; + + if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) { + sender.system("MODLOADER_DENIED"); + return; + } + + if (arenaMode == null) { + getModes(sender, precommand, historic); + return; + } + + if (map == null) { + if (arenaMode.getMaps().size() == 1) { + map = arenaMode.getRandomMap(); + } else { + getMaps(sender, precommand, arenaMode); + return; + } + } else if (map.equalsIgnoreCase("random")) { + map = arenaMode.getRandomMap(); + } + + if (!allowMerging) { + callback.run(player, arenaMode, map); + } else { + suggestMerging(player, arenaMode, map, callback); + } + } + static void createArena(CommandSender s, String precommand, boolean allowMerging, String[] args, int startArg, boolean historic, FightCallback callback){ if(!(s instanceof ProxiedPlayer)) return; @@ -216,28 +254,15 @@ public class FightCommand extends BasicCommand { inventory.open(); } - @Override - public void execute(CommandSender sender, String[] args) { - createArena(sender, "/fight ", true, args, 0, false, (player, mode, map) -> { - Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).start(); + @Register(description = "CHALLENGE_USAGE") + public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + createArena(player, "/fight", true, arenaMode, map, false, (p, mode, m) -> { + Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" - , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), player.getName()); + , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); }); } - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1){ - return ArenaMode.getAllChatNames(false); - }else if(args.length == 2){ - ArenaMode mode = ArenaMode.getByChat(args[1]); - if(mode == null) - return new LinkedList<>(); - return mode.getMaps(); - } - return new LinkedList<>(); - } - /** * Is called when arena parameters are clear. */ diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index b056c91..e1fa176 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -23,35 +23,21 @@ import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.bungeecore.Subserver; -import net.md_5.bungee.api.CommandSender; +import de.steamwar.command.SWCommand; import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.LinkedList; - -public class HistoricCommand extends BasicCommand { +public class HistoricCommand extends SWCommand { public HistoricCommand() { super("historic", null); } - @Override - public void execute(CommandSender sender, String[] args) { - 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()); + @Register(description = "CHALLENGE_USAGE") + public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(player, "/historic", true, arenaMode, map, true, (p, mode, m) -> { + Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); + Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); }); } - - @Override - public Iterable onTabComplete(CommandSender commandSender, String[] args) { - if(args.length == 1){ - return ArenaMode.getAllChatNames(true); - }else if(args.length == 2){ - ArenaMode mode = ArenaMode.getByChat(args[1]); - if(mode == null) - return new LinkedList<>(); - return mode.getMaps(); - } - return new LinkedList<>(); - } } From 2325190cf1ec0b51d1e7678467947d39a60e104c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 3 Sep 2022 14:33:00 +0200 Subject: [PATCH 28/35] Fix stuff --- .../bungeecore/commands/ChallengeCommand.java | 4 ++-- .../bungeecore/commands/FightCommand.java | 16 +++------------- .../bungeecore/commands/HistoricCommand.java | 8 ++++---- .../bungeecore/commands/TypeMappers.java | 15 +++++++++++---- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index e69eaaf..9ec135e 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -45,7 +45,7 @@ public class ChallengeCommand extends SWCommand { } @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Validator("target") ProxiedPlayer target, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/challenge " + target.getName() + " ", false, arenaMode, map, false, (p, mode, m) -> { if(challenges.containsKey(target) && challenges.get(target).contains(p)){ challenges.remove(target); @@ -69,7 +69,7 @@ public class ChallengeCommand extends SWCommand { }); } - @Validator("target") + @Validator(value = "target", local = true) public TypeValidator targetValidator() { return (sender, value, messageSender) -> { if (value == null) { diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index c1fcd89..d041815 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -35,8 +35,6 @@ import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.LinkedList; - /** * Jeder Fightcommand (auch bau testarena und challenge) haben folgende Optionskette: * @@ -132,18 +130,10 @@ public class FightCommand extends SWCommand { static void createArena(ProxiedPlayer player, String precommand, boolean allowMerging, ArenaMode arenaMode, String map, boolean historic, FightCallback callback) { ChatSender sender = ChatSender.of(player); - if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { - return; - } if(alreadyInArena(player)) return; - if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) { - sender.system("MODLOADER_DENIED"); - return; - } - if (arenaMode == null) { getModes(sender, precommand, historic); return; @@ -254,9 +244,9 @@ public class FightCommand extends SWCommand { inventory.open(); } - @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - createArena(player, "/fight", true, arenaMode, map, false, (p, mode, m) -> { + @Register + public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + createArena(player, "/fight ", true, arenaMode, map, false, (p, mode, m) -> { Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index e1fa176..6c77fab 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -32,11 +32,11 @@ public class HistoricCommand extends SWCommand { super("historic", null); } - @Register(description = "CHALLENGE_USAGE") - public void challenge(@Validator("fabric") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { - FightCommand.createArena(player, "/historic", true, arenaMode, map, true, (p, mode, m) -> { + @Register + public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); - Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", + Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); }); } diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index 4f3d7bd..b503748 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -21,9 +21,11 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; +import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.ChatSender; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -36,14 +38,19 @@ import java.util.List; public class TypeMappers { public static void init() { - SWCommandUtils.addValidator("fabric", fabricChecker()); + SWCommandUtils.addValidator("arenaPlayer", fabricChecker()); SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false)); SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true)); SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); } - public static TypeValidator fabricChecker() { + private static TypeValidator fabricChecker() { return (sender, value, messageSender) -> { + ChatSender player = ChatSender.of(value); + if (player.user().isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { + return false; + } + if (ModLoaderBlocker.isFabric(value)) { messageSender.send("MODLOADER_DENIED"); return false; @@ -52,7 +59,7 @@ public class TypeMappers { }; } - public static TypeMapper arenaModeTypeMapper(boolean historic) { + private static TypeMapper arenaModeTypeMapper(boolean historic) { return new TypeMapper() { @Override public ArenaMode map(CommandSender commandSender, String[] previousArguments, String s) { @@ -66,7 +73,7 @@ public class TypeMappers { }; } - public static TypeMapper arenaMapTypeMapper() { + private static TypeMapper arenaMapTypeMapper() { return new TypeMapper() { @Override public String map(CommandSender commandSender, String[] previousArguments, String s) { From 16c3f9374155e4389f141086012f37da8dc2c154 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 6 Sep 2022 15:36:27 +0200 Subject: [PATCH 29/35] Fix stuff --- src/de/steamwar/bungeecore/commands/TypeMappers.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index b503748..6310171 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -38,13 +38,13 @@ import java.util.List; public class TypeMappers { public static void init() { - SWCommandUtils.addValidator("arenaPlayer", fabricChecker()); + SWCommandUtils.addValidator("arenaPlayer", arenaPlayer()); SWCommandUtils.addMapper("nonHistoricArenaMode", arenaModeTypeMapper(false)); SWCommandUtils.addMapper("historicArenaMode", arenaModeTypeMapper(true)); SWCommandUtils.addMapper("arenaMap", arenaMapTypeMapper()); } - private static TypeValidator fabricChecker() { + private static TypeValidator arenaPlayer() { return (sender, value, messageSender) -> { ChatSender player = ChatSender.of(value); if (player.user().isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { From 2676f97cfb0c7e88a8052a2c19f0d13ef46b5751 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 6 Sep 2022 16:45:56 +0200 Subject: [PATCH 30/35] Hotfix TypeMappers --- CommonCore | 2 +- src/de/steamwar/bungeecore/commands/TypeMappers.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 6e6d349..9df9259 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 6e6d34905ac39bd2ed9548729041febadd42da2f +Subproject commit 9df92595b2f344585bd3e1639cedc761680b7761 diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index 6310171..f1927e3 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -77,6 +77,7 @@ public class TypeMappers { return new TypeMapper() { @Override public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (previousArguments.length == 0) return null; if (s.equalsIgnoreCase("random")) return "random"; ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); if (arenaMode.getMaps().contains(s)) return s; @@ -85,6 +86,7 @@ public class TypeMappers { @Override public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + if (previousArguments.length == 0) return null; ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); List stringList = new ArrayList<>(arenaMode.getMaps()); stringList.add("random"); From 43d5cb47bb728ee12352b6d73ed5855eb445e430 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 6 Sep 2022 19:08:00 +0200 Subject: [PATCH 31/35] Overload protection Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 4 +- src/de/steamwar/bungeecore/Node.java | 220 +++++++----------- src/de/steamwar/bungeecore/ServerStarter.java | 12 +- .../bungeecore/commands/BauCommand.java | 2 +- .../bungeecore/commands/ChallengeCommand.java | 14 +- .../bungeecore/commands/FightCommand.java | 10 +- .../bungeecore/commands/HistoricCommand.java | 8 +- .../bungeecore/commands/StatCommand.java | 2 +- .../bungeecore/commands/TutorialCommand.java | 4 +- src/de/steamwar/bungeecore/sql/Tutorial.java | 4 +- .../steamwar/messages/BungeeCore.properties | 4 +- .../messages/BungeeCore_de.properties | 4 +- src/de/steamwar/messages/ChatSender.java | 8 + 13 files changed, 137 insertions(+), 159 deletions(-) diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index a182752..e319ed6 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -69,6 +69,7 @@ public class BungeeCore extends Plugin { public static final Map serverPermissions = new HashMap<>(); public static final Map commands = new HashMap<>(); + public static Node local; private ErrorLogger errorLogger; private TablistManager tablistManager; @@ -110,9 +111,8 @@ public class BungeeCore extends Plugin { new Fabric(); new SubserverProtocolFixer(); - new Node.LocalNode(); + local = new Node.LocalNode(); //new Node.RemoteNode("lx"); - //new Node.RemoteNode("az"); commands.put("/tp", null); commands.put("/bc", null); diff --git a/src/de/steamwar/bungeecore/Node.java b/src/de/steamwar/bungeecore/Node.java index f07293a..6c22120 100644 --- a/src/de/steamwar/bungeecore/Node.java +++ b/src/de/steamwar/bungeecore/Node.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore; +import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.ProxyServer; import java.io.*; @@ -30,7 +31,6 @@ import java.util.logging.Level; public abstract class Node { private static final List OPENJ9_ARGS = Arrays.asList("-Xgc:excessiveGCratio=80", "-Xsyslog:none", "-Xtrace:none", "-Xdisableexplicitgc", "-XX:+AlwaysPreTouch", "-XX:+CompactStrings", "-XX:-HeapDumpOnOutOfMemory", "-XX:+ExitOnOutOfMemoryError", "-Dlog4j.configurationFile=log4j2.xml"); - private static final double MIN_FREE_MEM = 4.0 * 1024 * 1024; // 4 GiB private static final Set JAVA_8 = new HashSet<>(); static { JAVA_8.add("paper-1.8.8.jar"); @@ -40,43 +40,57 @@ public abstract class Node { JAVA_8.add("spigot-1.10.2.jar"); } + private static final long MIN_FREE_MEM = 4 * 1024 * 1024L; // 4 GiB + private static final double MAX_LOAD = 0.8; + private static final List nodes = new ArrayList<>(); - public static Node local = null; public static Node getNode() { - Node node = local; - double minLoad = local.getLoad(); - if(minLoad < 0.5) - return local; - - synchronized (nodes) { - Iterator it = nodes.iterator(); - while(it.hasNext()) { - Node n = it.next(); - double load = n.getLoad(); - if (load < minLoad) { - minLoad = load; - node = n; - } else if (load == Double.POSITIVE_INFINITY) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Removing " + n.getName() + " due to infinite load!"); - it.remove(); - } - } + for(Node node : nodes) { + if(node.belowLoadLimit) + return node; } - return node; + return null; } public static void forEach(Consumer consumer) { - consumer.accept(local); - synchronized (nodes) { - nodes.forEach(consumer); - } + nodes.forEach(consumer); } public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams); - public abstract void execute(String... command); - public abstract String getName(); - public abstract double getLoad(); + + protected abstract ProcessBuilder prepareExecution(String... command); + protected abstract void calcLoadLimit(); + + protected final String hostname; + protected volatile boolean belowLoadLimit = true; + + private long previousCpuLoaded = 0; + private long previousCpuTotal = 0; + + protected Node(String hostname) { + this.hostname = hostname; + nodes.add(this); + BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), this::calcLoadLimit, 1, 2, TimeUnit.SECONDS); + } + + public void execute(String... command) { + try { + prepareExecution(command).start().waitFor(); + } catch (IOException e) { + throw new SecurityException("Could not execute command", e); + } catch (InterruptedException e) { + ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted during execution", e); + Thread.currentThread().interrupt(); + } + } + + public boolean belowLoadLimit() { + return belowLoadLimit; + } + public String getName() { + return hostname; + } protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String xmx, String... dParams) { if (JAVA_8.contains(serverJar)) @@ -106,26 +120,31 @@ public abstract class Node { cmd.add("nogui"); } - protected void execute(ProcessBuilder builder) { - try { - builder.start().waitFor(); - } catch (IOException e) { - throw new SecurityException("Could not execute command", e); - } catch (InterruptedException e) { - ProxyServer.getInstance().getLogger().log(Level.SEVERE, "Interrupted during execution", e); - Thread.currentThread().interrupt(); + protected void calcLoadLimit(BufferedReader stat, BufferedReader meminfo) throws IOException { + String[] cpuline = stat.readLine().split(" "); // 0-1: prefix, 2: user, 3: nice, 4: system, 5: idle, 6: iowait, 7: irq, 8: softirq, 9: steal, 10: guest, 11: guest_nice + long cpuLoaded = Long.parseLong(cpuline[2]) + Long.parseLong(cpuline[4]) + Long.parseLong(cpuline[6]) + Long.parseLong(cpuline[7]) + Long.parseLong(cpuline[8]) + Long.parseLong(cpuline[9]) + Long.parseLong(cpuline[10]) + Long.parseLong(cpuline[11]); + long cpuTotal = cpuLoaded + Long.parseLong(cpuline[3]) + Long.parseLong(cpuline[5]); + + cpuLoaded -= previousCpuLoaded; + cpuTotal -= previousCpuTotal; + previousCpuLoaded += cpuLoaded; + previousCpuTotal += cpuTotal; + + String line = meminfo.readLine(); + while(!line.startsWith("MemAvailable")) { + line = meminfo.readLine(); } + + long availableMem = Long.parseLong(line.replaceAll(" +", " ").split(" ")[1]); + belowLoadLimit = cpuLoaded / (double)cpuTotal <= MAX_LOAD && availableMem >= MIN_FREE_MEM; } public static class LocalNode extends Node { - private static final File meminfo = new File("/proc/meminfo"); - private static final File loadavg = new File("/proc/loadavg"); - - private final int cores; + private static final File MEMINFO = new File("/proc/meminfo"); + private static final File STAT = new File("/proc/stat"); public LocalNode() { - this.cores = Runtime.getRuntime().availableProcessors(); - local = this; + super("sw"); } @Override @@ -138,74 +157,28 @@ public abstract class Node { } @Override - public void execute(String... command) { - execute(new ProcessBuilder(command)); + protected void calcLoadLimit() { + try (BufferedReader loadavg = new BufferedReader(new InputStreamReader(new FileInputStream(STAT)))) { + try (BufferedReader meminfo = new BufferedReader(new InputStreamReader(new FileInputStream(MEMINFO)))) { + calcLoadLimit(loadavg, meminfo); + } + } catch (IOException e) { + BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read local load", e); + belowLoadLimit = false; + } } @Override - public String getName() { - return "local"; - } - - @Override - public double getLoad() { - double totalMem; - double freeMem; - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(meminfo)))) { - totalMem = Double.parseDouble(bufferedReader.readLine().replaceAll(" +", " ").split(" ")[1]); - bufferedReader.readLine(); - freeMem = Double.parseDouble(bufferedReader.readLine().replaceAll(" +", " ").split(" ")[1]); - } catch (IOException e) { - throw new SecurityException("Could not read local memory", e); - } - - double cpuLoad; - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(loadavg)))) { - cpuLoad = Double.parseDouble(bufferedReader.readLine().split(" ")[0]); - } catch (IOException e) { - throw new SecurityException("Could not read local cpu", e); - } - - return cpuLoad / cores + (freeMem > MIN_FREE_MEM ? 0 : ((totalMem - freeMem) / totalMem)); + protected ProcessBuilder prepareExecution(String... command) { + return new ProcessBuilder(command); } } public static class RemoteNode extends Node { - private final int cores; - private final String remote; - public RemoteNode(String remote) { - this.remote = remote; - - //Determine core count - Process process; - try { - process = new ProcessBuilder("ssh", remote, "nproc").start(); - if(!process.waitFor(5, TimeUnit.SECONDS)) - throw new IOException("Timeout of " + remote + " on init"); - } catch (IOException e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could not initialize " + remote); - cores = 1; - return; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - cores = 1; - return; - } - - int c; - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { - c = Integer.parseInt(bufferedReader.readLine()); - } catch (IOException | NumberFormatException e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read cores of" + remote, e); - c = 1; - } - cores = c; - BungeeCore.get().getLogger().log(Level.INFO, "Adding node " + remote + " with " + cores + " cores."); - - synchronized (nodes) { - nodes.add(this); - } + public RemoteNode(String hostname) { + super(hostname); + BungeeCore.get().getLogger().log(Level.INFO, "Added node " + hostname); } @Override @@ -214,7 +187,7 @@ public abstract class Node { cmd.add("ssh"); cmd.add("-L"); cmd.add(port + ":localhost:" + port); - cmd.add(remote); + cmd.add(hostname); cmd.add("cd"); cmd.add(directory.getPath()); cmd.add(";"); @@ -223,43 +196,30 @@ public abstract class Node { } @Override - public void execute(String... command) { + protected ProcessBuilder prepareExecution(String... command) { List cmd = new ArrayList<>(); cmd.add("ssh"); - cmd.add(remote); + cmd.add(hostname); cmd.addAll(Arrays.asList(command)); - execute(new ProcessBuilder(cmd)); + return new ProcessBuilder(cmd); } @Override - public String getName() { - return remote; - } - - @Override - public double getLoad() { - Process process; + protected void calcLoadLimit() { try { - process = new ProcessBuilder("ssh", remote, "cat /proc/loadavg;cat /proc/meminfo").start(); - if(!process.waitFor(1, TimeUnit.SECONDS)) - return Double.POSITIVE_INFINITY; + Process process = prepareExecution("cat /proc/stat /proc/meminfo").start(); + if(process.waitFor(1, TimeUnit.SECONDS)) + throw new IOException(hostname + " timeout"); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + calcLoadLimit(reader, reader); + } } catch (IOException e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could starting process to read load", e); - return Double.POSITIVE_INFINITY; + if(belowLoadLimit) + BungeeCore.get().getLogger().log(Level.SEVERE, "Could read remote load", e); + belowLoadLimit = false; } catch (InterruptedException e) { Thread.currentThread().interrupt(); - return Double.POSITIVE_INFINITY; - } - - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { - double cpuLoad = Double.parseDouble(bufferedReader.readLine().split(" ")[0]); - double totalMem = Double.parseDouble(bufferedReader.readLine().replaceAll(" +", " ").split(" ")[1]); - bufferedReader.readLine(); - double freeMem = Double.parseDouble(bufferedReader.readLine().replaceAll(" +", " ").split(" ")[1]); - return cpuLoad / cores + (freeMem > MIN_FREE_MEM ? 0 : ((totalMem - freeMem) / totalMem)); - } catch (IOException e) { - BungeeCore.get().getLogger().log(Level.SEVERE, "Could read load", e); - return Double.POSITIVE_INFINITY; + belowLoadLimit = false; } } } diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index a00b531..9373b57 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -4,6 +4,7 @@ import de.steamwar.bungeecore.sql.EventFight; import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.Team; import de.steamwar.bungeecore.sql.Tutorial; +import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; @@ -67,7 +68,7 @@ public class ServerStarter { public ServerStarter event(EventFight eventFight) { arena(eventFight.getSpielmodus(), eventFight.getMap()); - node = Node.local; + node = BungeeCore.local; worldDir = EVENT_PATH; worldCleanup = () -> {}; arguments.put("fightID", String.valueOf(eventFight.getFightID())); @@ -246,8 +247,15 @@ public class ServerStarter { int port = portrange.freePort(); String serverName = serverNameProvider.apply(port); - if(node == null) + if(node == null) { node = Node.getNode(); + if(node == null) { + for (ProxiedPlayer p : playersToSend) + ChatSender.of(p).system("SERVER_START_OVERLOAD"); + + return null; + } + } if(worldName == null) worldName = serverToWorldName(serverName); diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 41496b9..069b086 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 { break; } } - SubserverSystem.deleteFolder(Node.local, world); + SubserverSystem.deleteFolder(BungeeCore.local, world); Message.send("BAU_DELETE_DELETED", player); }); } diff --git a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java index 9ec135e..6f050ac 100644 --- a/src/de/steamwar/bungeecore/commands/ChallengeCommand.java +++ b/src/de/steamwar/bungeecore/commands/ChallengeCommand.java @@ -20,21 +20,13 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; -import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.sql.IgnoreSystem; import de.steamwar.command.SWCommand; -import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; -import net.md_5.bungee.BungeeCord; -import net.md_5.bungee.api.CommandSender; -import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import java.util.ArrayList; -import java.util.Collection; import java.util.LinkedList; -import java.util.stream.Collectors; import static de.steamwar.bungeecore.Storage.challenges; @@ -52,8 +44,10 @@ public class ChallengeCommand extends SWCommand { challenges.remove(p); Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).start(); - Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()); + if(arena != null) { + Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName()); + } }else{ if(!challenges.containsKey(p)){ challenges.put(p, new LinkedList<>()); diff --git a/src/de/steamwar/bungeecore/commands/FightCommand.java b/src/de/steamwar/bungeecore/commands/FightCommand.java index d041815..ad6b08a 100644 --- a/src/de/steamwar/bungeecore/commands/FightCommand.java +++ b/src/de/steamwar/bungeecore/commands/FightCommand.java @@ -97,7 +97,7 @@ public class FightCommand extends SWCommand { String command = precommand + mode.getChatName() + " Random"; start.setBold(true); start.setColor(ChatColor.GRAY); - start.setText(sender.parseToLegacy("FIGHT_ARENA_RANDOM") + " "); + start.setText(sender.parseToPlain("FIGHT_ARENA_RANDOM") + " "); start.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command))); start.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); current = new TextComponent(); @@ -245,11 +245,13 @@ public class FightCommand extends SWCommand { } @Register - public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { createArena(player, "/fight ", true, arenaMode, map, false, (p, mode, m) -> { Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); - Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" - , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); + if(arena != null) { + Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" + , new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); + } }); } diff --git a/src/de/steamwar/bungeecore/commands/HistoricCommand.java b/src/de/steamwar/bungeecore/commands/HistoricCommand.java index 6c77fab..03e7abb 100644 --- a/src/de/steamwar/bungeecore/commands/HistoricCommand.java +++ b/src/de/steamwar/bungeecore/commands/HistoricCommand.java @@ -33,11 +33,13 @@ public class HistoricCommand extends SWCommand { } @Register - public void challenge(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { + public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); - Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", - new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); + if(arena != null) { + Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", + new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); + } }); } } diff --git a/src/de/steamwar/bungeecore/commands/StatCommand.java b/src/de/steamwar/bungeecore/commands/StatCommand.java index 753f253..ffae168 100644 --- a/src/de/steamwar/bungeecore/commands/StatCommand.java +++ b/src/de/steamwar/bungeecore/commands/StatCommand.java @@ -52,6 +52,6 @@ public class StatCommand extends SWCommand { throw new SecurityException(e.getMessage(), e); } - Node.forEach(node -> Message.send("STAT_SERVER", sender, node.getName(), node.getLoad(), serverCount.getOrDefault(node.getName(), 0))); + Node.forEach(node -> Message.send("STAT_SERVER", sender, node.getName(), node.belowLoadLimit(), serverCount.getOrDefault(node.getName(), 0))); } } diff --git a/src/de/steamwar/bungeecore/commands/TutorialCommand.java b/src/de/steamwar/bungeecore/commands/TutorialCommand.java index 72d0e2a..30cc296 100644 --- a/src/de/steamwar/bungeecore/commands/TutorialCommand.java +++ b/src/de/steamwar/bungeecore/commands/TutorialCommand.java @@ -156,8 +156,8 @@ public class TutorialCommand extends SWCommand { File tutorialWorld = tutorial.world(); if (tutorialWorld.exists()) - SubserverSystem.deleteFolder(Node.local, tutorialWorld.getPath()); - ServerStarter.copyWorld(Node.local, tempWorld.getPath(), tutorialWorld.getPath()); + SubserverSystem.deleteFolder(BungeeCore.local, tutorialWorld.getPath()); + ServerStarter.copyWorld(BungeeCore.local, tempWorld.getPath(), tutorialWorld.getPath()); Message.send("TUTORIAL_CREATED", player); }, 1, TimeUnit.SECONDS); } diff --git a/src/de/steamwar/bungeecore/sql/Tutorial.java b/src/de/steamwar/bungeecore/sql/Tutorial.java index 75916f2..7c82f06 100644 --- a/src/de/steamwar/bungeecore/sql/Tutorial.java +++ b/src/de/steamwar/bungeecore/sql/Tutorial.java @@ -19,7 +19,7 @@ package de.steamwar.bungeecore.sql; -import de.steamwar.bungeecore.Node; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.bungeecore.SubserverSystem; @@ -124,7 +124,7 @@ public class Tutorial { public void delete() { delete.update(id); - SubserverSystem.deleteFolder(Node.local, world().getPath()); + SubserverSystem.deleteFolder(BungeeCore.local, world().getPath()); } public File world() { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 8a4a678..9872dfe 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -18,6 +18,8 @@ DEV_UNKNOWN_SERVER=§cPlease specify a dev server. DISABLED=§cCurrently disabled. +SERVER_START_OVERLOAD=§cServer start cancelled due to overload. Please try again later. + #ModLoader blocker MODLOADER_INSTALLED=§7You play with §e{0} §7client. Therefore you can't join arenas. MODLOADER_INSTALLED_FABRIC=§7You play with §e{0} §7client. You can join arenas only with the FabricModSender https://steamwar.de/downloads installed. @@ -112,7 +114,7 @@ MOD_YELLOW_PLUR=§7Deactivate the mods\n§e{0}\n§7to continue playing on §eSte #Various commands ALERT=§f{0} -STAT_SERVER=§7Server §e{0}§8: §7Load §e{1} §7Server count §e{2} +STAT_SERVER=§7Server §e{0}§8: §7Below limit §e{1} §7Server count §e{2} #Ban&Mute-Command PUNISHMENT_USAGE=§8/§7{0} §8[§eplayer§8] [§edd§8.§emm§8.§eyyyy §7or §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7or §eperma§8] [§ereason§8] diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index c2bc2d3..e0341a7 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -14,6 +14,8 @@ DEV_UNKNOWN_SERVER=§cBitte gib einen DevServer an. DISABLED=§cDerzeit deaktiviert. +SERVER_START_OVERLOAD=§cDer Serverstart wurde aufgrund von Überlastung abgebrochen. Versuche es später erneut. + #ModLoader blocker MODLOADER_INSTALLED=§7Du spielst mit §e{0} §7Client. Daher kannst du keinen Arenen beitreten. MODLOADER_INSTALLED_FABRIC=§7Du spielst mit §e{0} §7Client. Nur mit dem FabricModSender https://steamwar.de/downloads kannst du Arenen beitreten. @@ -97,7 +99,7 @@ MOD_YELLOW_SING=§7Deaktiviere den Mod §e{0}§7, um weiter auf §eSteam§8War MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War §7spielen zu können. #Various commands -STAT_SERVER=§7Server §e{0}§8: §7Load §e{1} §7Serveranzahl §e{2} +STAT_SERVER=§7Server §e{0}§8: §7Startfähig §e{1} §7Serveranzahl §e{2} #Ban&Mute-Command PUNISHMENT_USAGE=§8/§7{0} §8[§eSpieler§8] [§edd§8.§emm§8.§eyyyy §7oder §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7oder §eperma§8] [§eGrund§8] diff --git a/src/de/steamwar/messages/ChatSender.java b/src/de/steamwar/messages/ChatSender.java index 6879505..5b79204 100644 --- a/src/de/steamwar/messages/ChatSender.java +++ b/src/de/steamwar/messages/ChatSender.java @@ -107,6 +107,14 @@ public interface ChatSender { return new TextComponent(parse(prefixed, message)); } + default String parseToPlain(String format, Object... params) { + return parseToPlain(new Message(format, params)); + } + + default String parseToPlain(Message message) { + return parseToComponent(false, message).toPlainText(); + } + default String parseToLegacy(String format, Object... params) { return parseToLegacy(new Message(format, params)); } From 3d958800fce3ca8f8c52ea41f9b049db4b427e1d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 8 Sep 2022 17:29:25 +0200 Subject: [PATCH 32/35] Remove sorted checker in fabric Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/listeners/mods/Fabric.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index b2b949f..c244de2 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -41,7 +41,6 @@ import java.nio.charset.UnsupportedCharsetException; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.stream.Collectors; public class Fabric extends BasicListener { @@ -124,12 +123,14 @@ public class Fabric extends BasicListener { mods.add(Mod.get(mod.getAsString(), Mod.Platform.FABRIC)); } + /* boolean isSorted = isSortedAlphabetically(mods); if(!isSorted) { banPlayer(user, player, "Mods are not sorted alphabetically: " + mods.stream().map(Mod::getModName).collect(Collectors.joining(", "))); return; } + */ if(!neededModsContained(mods)) { banPlayer(user, player, "Needed mods are not contained"); From e3e68af80fd5b1bacae27fc6bbadedc725bdf462 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 8 Sep 2022 18:24:31 +0200 Subject: [PATCH 33/35] Hotfix ServerTeamchatCommand --- .../bungeecore/commands/ServerTeamchatCommand.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java index ea4ce9f..e22c68f 100644 --- a/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java +++ b/src/de/steamwar/bungeecore/commands/ServerTeamchatCommand.java @@ -31,13 +31,7 @@ public class ServerTeamchatCommand extends SWCommand { } @Register(description = "STC_USAGE") - public void genericCommand(CommandSender commandSender, String... message) { - ChatSender sender = ChatSender.of(commandSender); - if(message.length == 0) { - sender.system("STC_USAGE"); - return; - } - - ChatListener.sendChat(sender, ChatSender.serverteamReceivers(), "CHAT_SERVERTEAM", null, String.join(" ", message)); + public void genericCommand(CommandSender commandSender, @ErrorMessage(value = "STC_USAGE", allowEAs = false) String... message) { + ChatListener.sendChat(ChatSender.of(commandSender), ChatSender.serverteamReceivers(), "CHAT_SERVERTEAM", null, String.join(" ", message)); } } From 42898b0d4dfc1765c9e6406be52de5a875e227b1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 8 Sep 2022 19:45:20 +0200 Subject: [PATCH 34/35] Hotfix npe --- src/de/steamwar/bungeecore/commands/TypeMappers.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/bungeecore/commands/TypeMappers.java b/src/de/steamwar/bungeecore/commands/TypeMappers.java index f1927e3..94b27e4 100644 --- a/src/de/steamwar/bungeecore/commands/TypeMappers.java +++ b/src/de/steamwar/bungeecore/commands/TypeMappers.java @@ -88,6 +88,7 @@ public class TypeMappers { public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { if (previousArguments.length == 0) return null; ArenaMode arenaMode = ArenaMode.getByChat(previousArguments[previousArguments.length - 1]); + if (arenaMode == null) return null; List stringList = new ArrayList<>(arenaMode.getMaps()); stringList.add("random"); return stringList; From 6ab0d3d9832f2dfaa09f1699be7468b507b16f37 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 9 Sep 2022 08:40:49 +0200 Subject: [PATCH 35/35] Remove could not decode from ErrorLogger Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/ErrorLogger.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/ErrorLogger.java b/src/de/steamwar/bungeecore/ErrorLogger.java index ef80a0b..2ac83ae 100644 --- a/src/de/steamwar/bungeecore/ErrorLogger.java +++ b/src/de/steamwar/bungeecore/ErrorLogger.java @@ -33,7 +33,6 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; public class ErrorLogger extends Handler { - private int ddosRate = 0; ErrorLogger(){ Logger.getLogger("").addHandler(this); @@ -57,12 +56,7 @@ public class ErrorLogger extends Handler { if(logRecord.getThrown() != null) logRecord.getThrown().printStackTrace(new PrintStream(stacktraceOutput)); String stacktrace = stacktraceOutput.toString(); - if(stacktrace.contains("Cannot request protocol")) { - if(++ddosRate % 1000 == 0) { - SWException.log("Bungee", "DDOS", ddosRate + ""); - } - return; - } else if (stacktrace.contains("ErrorLogger")) { + if (stacktrace.contains("ErrorLogger")) { return; } @@ -86,6 +80,7 @@ public class ErrorLogger extends Handler { List contains = new ArrayList<>(); contains.add("Error authenticating "); contains.add("read timed out"); + contains.add("could not decode packet"); contains.add("Connection reset by peer"); contains.add("No client connected for pending server"); contains.add("Error occurred processing connection for");