From f8618a7a82c0f5344b6cfaf4442ba2c36e902abd Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 29 May 2021 17:39:06 +0200 Subject: [PATCH 1/2] Remove bau passthrough Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/commands/BauCommand.java | 106 +++++++++--------- .../bungeecore/comms/PacketIdManager.java | 1 + .../comms/packets/BaumemberUpdatePacket.java | 36 ++++++ .../bungeecore/listeners/ChatListener.java | 6 - 5 files changed, 93 insertions(+), 57 deletions(-) create mode 100644 src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 2344d56..e3a11b0 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -123,6 +123,7 @@ public class BungeeCore extends Plugin { new ResourcereloadCommand(); if(!EVENT_MODE){ + new BauCommand(); new WebregisterCommand(); new FightCommand(); new ChallengeCommand(); diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index 43944d7..d50f7a7 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -20,38 +20,38 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.*; +import de.steamwar.bungeecore.comms.packets.BaumemberUpdatePacket; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.sql.BauweltMember; import de.steamwar.bungeecore.sql.SteamwarUser; +import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; -import net.md_5.bungee.api.event.ChatEvent; -public class BauCommand { +public class BauCommand extends BasicCommand { - private BauCommand(){} + public BauCommand(){ + super("bau", null, "b", "gs"); + } - public static void onBau(ChatEvent e, String[] command){ - if(BungeeCore.EVENT_MODE) + @Override + public void execute(CommandSender sender, String[] args) { + if(!(sender instanceof ProxiedPlayer)) return; - ProxiedPlayer p = (ProxiedPlayer) e.getSender(); - Subserver server = Subserver.getSubserver(p); - Bauserver bau = (server != null && server.getType() == Servertype.BAUSERVER) ? (Bauserver)server : null; - boolean ownBau = bau != null && bau.getOwner().equals(p.getUniqueId()); - e.setCancelled(true); - BungeeCore.log(p, e.getMessage()); + ProxiedPlayer p = (ProxiedPlayer) sender; - if(command.length == 1){ - if(bau15(p, command, 1)) + if(args.length == 0){ + if(bau15(p, args, 0)) SubserverSystem.sendToBau15(p, p.getUniqueId()); else SubserverSystem.sendToBauServer(p, p.getUniqueId()); return; } - switch(command[1].toLowerCase()){ + switch(args[0].toLowerCase()){ case "ws": case "warship": case "12": @@ -72,52 +72,44 @@ public class BauCommand { SubserverSystem.sendToBau15paper(p, p.getUniqueId()); break; case "addmember": - addmember(p, command); + addmember(p, args); break; case "tp": case "teleport": - teleport(p, command); + teleport(p, args); break; case "info": - if (bau != null) { - e.setCancelled(false); - } + p.chat("/bauinfo"); break; case "togglewe": - if(ownBau && command.length > 2) - e.setCancelled(false); - else - togglewe(p, command); + togglewe(p, args); break; case "toggleworld": - if(ownBau && command.length > 2) - e.setCancelled(false); - else - toggleworld(p, command); + toggleworld(p, args); break; case "delmember": - delmember(p, command); + delmember(p, args); break; case "resetall": case "delete": - delete(p, command); + delete(p, args); break; case "testarena": case "test": - testarena(p, command); + testarena(p, args); break; default: HelpCommand.sendBauHelp(p); } } - private static void addmember(ProxiedPlayer p, String[] command){ - if (command.length == 2) { + private static void addmember(ProxiedPlayer p, String[] args){ + if (args.length == 1) { Message.send("BAU_ADDMEMBER_USAGE", p); return; } - SteamwarUser target = SteamwarUser.get(command[2]); + SteamwarUser target = SteamwarUser.get(args[1]); if (target == null) { Message.send("UNKNOWN_PLAYER", p); return; @@ -137,13 +129,13 @@ public class BauCommand { Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName()); } - private static void teleport(ProxiedPlayer p, String[] command){ - if (command.length == 2) { + private static void teleport(ProxiedPlayer p, String[] args){ + if (args.length == 1) { Message.send("BAU_TP_USAGE", p); return; } - SteamwarUser worldOwner = SteamwarUser.get(command[2]); + SteamwarUser worldOwner = SteamwarUser.get(args[1]); if (worldOwner == null) { Message.send("UNKNOWN_PLAYER", p); return; @@ -153,7 +145,7 @@ public class BauCommand { return; } - if(bau15(p, command, 3)) + if(bau15(p, args, 2)) SubserverSystem.sendToBau15(p, worldOwner.getUuid()); else SubserverSystem.sendToBauServer(p, worldOwner.getUuid()); @@ -183,31 +175,43 @@ public class BauCommand { } } - private static void togglewe(ProxiedPlayer p, String[] command){ - BauweltMember target = toggle(p, command, "togglewe"); + private static void togglewe(ProxiedPlayer p, String[] args){ + BauweltMember target = toggle(p, args, "togglewe"); if(target == null) return; target.setWorldEdit(!target.isWorldEdit()); + clearMembercache(p); isAllowedTo(target.isWorldEdit(), p, target, "WorldEdit verwenden"); } - private static void toggleworld(ProxiedPlayer p, String[] command){ - BauweltMember target = toggle(p, command, "toggleworld"); + private static void toggleworld(ProxiedPlayer p, String[] args){ + BauweltMember target = toggle(p, args, "toggleworld"); if(target == null) return; target.setWorld(!target.isWorld()); + clearMembercache(p); isAllowedTo(target.isWorld(), p, target, "Einstellungen vornehmen"); } - private static void delmember(ProxiedPlayer p, String[] command){ - if (command.length == 2) { + private static void clearMembercache(ProxiedPlayer p){ + for(ServerInfo info : ProxyServer.getInstance().getServers().values()){ + Subserver server = Subserver.getSubserver(info); + if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){ + info.getPlayers().stream().findAny().ifPresent(player -> new BaumemberUpdatePacket().send(player)); + break; + } + } + } + + private static void delmember(ProxiedPlayer p, String[] args){ + if (args.length == 1) { Message.send("BAU_DELMEMBER_USAGE", p); return; } - BauweltMember target = member(p, SteamwarUser.get(command[2])); + BauweltMember target = member(p, SteamwarUser.get(args[1])); if(target == null) return; @@ -228,13 +232,13 @@ public class BauCommand { Message.send("BAU_DELMEMBER_DELETED", p); } - private static void delete(ProxiedPlayer p, String[] command){ + private static void delete(ProxiedPlayer p, String[] args){ SWInventory inventory = new SWInventory(p, 9, Message.parse("BAU_DELETE_GUI_NAME", p)); inventory.addItem(8, new SWItem(Message.parse("BAU_DELETE_GUI_CANCEL", p), 1), click -> inventory.close() ); inventory.addItem(0, new SWItem(Message.parse("BAU_DELETE_GUI_DELETE", p), 10), click -> { - if(bau15(p, command, 2)){ + if(bau15(p, args, 1)){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); deleteWorld(p, BungeeCore.USERWORLDS15 + user.getId()); }else{ @@ -275,8 +279,8 @@ public class BauCommand { } } - private static void testarena(ProxiedPlayer p, String[] command){ - FightCommand.createArena(p, "/bau testarena ", command, 2, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { + private static void testarena(ProxiedPlayer p, String[] args){ + FightCommand.createArena(p, "/bau testarena ", args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { stopBauserver(p); SubserverSystem.startTestServer(p, mode, map, 0, 0); })); @@ -296,13 +300,13 @@ public class BauCommand { return target; } - private static BauweltMember toggle(ProxiedPlayer p, String[] command, String subcommand){ - if (command.length == 2) { + private static BauweltMember toggle(ProxiedPlayer p, String[] args, String subcommand){ + if (args.length == 1) { Message.send("BAU_MEMBER_TOGGLE_USAGE", p, subcommand); return null; } - SteamwarUser member = SteamwarUser.get(command[2]); + SteamwarUser member = SteamwarUser.get(args[1]); return member(p, member); } diff --git a/src/de/steamwar/bungeecore/comms/PacketIdManager.java b/src/de/steamwar/bungeecore/comms/PacketIdManager.java index 8376d59..1d48745 100644 --- a/src/de/steamwar/bungeecore/comms/PacketIdManager.java +++ b/src/de/steamwar/bungeecore/comms/PacketIdManager.java @@ -25,6 +25,7 @@ public class PacketIdManager { public static final byte PING_PACKET = 0x01; public static final byte TABLIST_NAME = 0x02; public static final byte PREPARE_SCHEM = 0x03; + public static final byte BAUMEMBER_UPDATE = 0x04; //0x1(X) Bungee Inventory public static final byte INVENTORY_PACKET = 0x10; diff --git a/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java b/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java new file mode 100644 index 0000000..ddb4021 --- /dev/null +++ b/src/de/steamwar/bungeecore/comms/packets/BaumemberUpdatePacket.java @@ -0,0 +1,36 @@ +/* + 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.comms.packets; + +import com.google.common.io.ByteArrayDataOutput; +import de.steamwar.bungeecore.comms.BungeePacket; +import de.steamwar.bungeecore.comms.PacketIdManager; + +public class BaumemberUpdatePacket extends BungeePacket { + @Override + public int getId() { + return PacketIdManager.BAUMEMBER_UPDATE; + } + + @Override + public void writeVars(ByteArrayDataOutput byteArrayDataOutput) { + // empty + } +} diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index b41ea78..774747b 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -23,7 +23,6 @@ import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; -import de.steamwar.bungeecore.commands.BauCommand; import de.steamwar.bungeecore.commands.TpCommand; import de.steamwar.bungeecore.comms.packets.PingPacket; import de.steamwar.bungeecore.sql.SteamwarUser; @@ -77,11 +76,6 @@ public class ChatListener extends BasicListener { } switch(command[0].toLowerCase()){ - case "/bau": - case "/b": - case "/gs": - BauCommand.onBau(e, command); - break; case "/bc": case "/bauchat": case "/local": From b60422245088aa26a52fc8a957592a4474078f65 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 5 Sep 2021 18:47:04 +0200 Subject: [PATCH 2/2] Deny launching multiple bauservers Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/commands/BauCommand.java | 11 ++++++----- .../steamwar/bungeecore/commands/CheckCommand.java | 13 ++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BauCommand.java b/src/de/steamwar/bungeecore/commands/BauCommand.java index d50f7a7..e827427 100644 --- a/src/de/steamwar/bungeecore/commands/BauCommand.java +++ b/src/de/steamwar/bungeecore/commands/BauCommand.java @@ -261,12 +261,12 @@ public class BauCommand extends BasicCommand { }); } - public static void stopBauserver(ProxiedPlayer p){ + public static boolean stopBauserver(ProxiedPlayer p){ for (Subserver subserver : Subserver.getServerList()) { if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) { - if(subserver.getServer().getPlayers().isEmpty()){ + if(!subserver.hasStarted()){ Message.send("BAU_START_ALREADY", p); - return; + return false; } subserver.stop(); try { @@ -277,12 +277,13 @@ public class BauCommand extends BasicCommand { break; } } + return true; } private static void testarena(ProxiedPlayer p, String[] args){ FightCommand.createArena(p, "/bau testarena ", args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - stopBauserver(p); - SubserverSystem.startTestServer(p, mode, map, 0, 0); + if(stopBauserver(p)) + SubserverSystem.startTestServer(p, mode, map, 0, 0); })); } diff --git a/src/de/steamwar/bungeecore/commands/CheckCommand.java b/src/de/steamwar/bungeecore/commands/CheckCommand.java index c110b3c..e61dd71 100644 --- a/src/de/steamwar/bungeecore/commands/CheckCommand.java +++ b/src/de/steamwar/bungeecore/commands/CheckCommand.java @@ -234,7 +234,10 @@ public class CheckCommand extends BasicCommand { this.checkList = checkQuestions.get(schematic.getSchemType()).listIterator(); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { - BauCommand.stopBauserver(checker); + if(!BauCommand.stopBauserver(checker)){ + remove(); + return; + } ArenaMode mode = ArenaMode.getBySchemType(schematic.getSchemType().fightType()); SubserverSystem.startTestServer(checker, mode, FightCommand.getMap(checker, mode, "Random"), schematic.getSchemID(), 0); @@ -323,8 +326,7 @@ public class CheckCommand extends BasicCommand { } private void stop(){ - currentCheckers.remove(checker.getUniqueId()); - currentSchems.remove(schematic.getSchemID()); + remove(); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { for (Subserver subserver : Subserver.getServerList()) { if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) { @@ -334,5 +336,10 @@ public class CheckCommand extends BasicCommand { } }); } + + private void remove() { + currentCheckers.remove(checker.getUniqueId()); + currentSchems.remove(schematic.getSchemID()); + } } }