From 7179911d4cacce127da95a9e6e3afdebbdc14c0c Mon Sep 17 00:00:00 2001 From: ME1312 Date: Wed, 1 Dec 2021 04:50:25 -0500 Subject: [PATCH] Allow commands to be sent to external servers --- SubServers.Bungee/common/pom.xml | 2 +- .../Bungee/Event/SubSendCommandEvent.java | 25 +- .../Host/External/ExternalSubServer.java | 2 +- .../Host/Internal/InternalSubServer.java | 2 +- .../ME1312/SubServers/Bungee/Host/Server.java | 28 ++ .../SubServers/Bungee/Host/ServerImpl.java | 19 + .../SubServers/Bungee/Host/SubServer.java | 34 +- .../Bungee/Host/SubServerController.java | 2 +- .../SubServers/Bungee/Host/SubServerImpl.java | 25 - .../Bungee/Library/ConfigUpdater.java | 40 +- .../Network/Packet/PacketCommandServer.java | 23 +- .../Network/Packet/PacketExAddServer.java | 2 +- .../Network/Packet/PacketExControlPlayer.java | 62 +++ .../Network/Packet/PacketOutExRunEvent.java | 21 +- .../Network/Packet/PacketStopServer.java | 40 +- .../Bungee/Network/SubProtocol.java | 4 +- .../net/ME1312/SubServers/Bungee/SubAPI.java | 14 +- .../ME1312/SubServers/Bungee/SubCommand.java | 39 +- .../ME1312/SubServers/Bungee/SubProxy.java | 2 +- .../Bukkit/Event/SubSendCommandEvent.java | 19 +- .../Bukkit/Graphic/DefaultUIHandler.java | 71 +-- .../Bukkit/Graphic/DefaultUIRenderer.java | 435 +++++++++--------- .../Client/Bukkit/Graphic/UIRenderer.java | 33 +- .../Library/Compatibility/BungeeChat.java | 7 +- .../Network/Packet/PacketExControlPlayer.java | 68 +++ .../Network/Packet/PacketInExRunEvent.java | 2 +- .../Client/Bukkit/Network/SubProtocol.java | 4 +- .../SubServers/Client/Bukkit/SubCommand.java | 18 +- SubServers.Client/Common/pom.xml | 2 +- .../Client/Common/Network/API/Server.java | 75 +++ .../Client/Common/Network/API/SubServer.java | 50 -- .../Network/Packet/PacketCommandServer.java | 8 +- .../Network/Packet/PacketDeleteServer.java | 2 +- .../Network/Packet/PacketEditServer.java | 2 +- .../Network/Packet/PacketRemoveServer.java | 2 +- .../Network/Packet/PacketRestartServer.java | 2 +- .../Network/Packet/PacketStartServer.java | 2 +- .../Network/Packet/PacketStopServer.java | 2 +- SubServers.Client/Sponge/pom.xml | 2 +- .../Sponge/Event/SubSendCommandEvent.java | 19 +- .../Client/Sponge/Graphic/UIRenderer.java | 29 +- .../Network/Packet/PacketExControlPlayer.java | 69 +++ .../Network/Packet/PacketInExRunEvent.java | 2 +- .../Client/Sponge/Network/SubProtocol.java | 4 +- .../SubServers/Client/Sponge/SubCommand.java | 25 +- SubServers.Creator/Spigot/template.yml | 2 +- SubServers.Creator/Sponge/template.yml | 2 +- SubServers.Host/pom.xml | 4 +- .../Host/Event/SubSendCommandEvent.java | 13 +- .../Network/Packet/PacketInExRunEvent.java | 2 +- .../SubServers/Host/Network/SubProtocol.java | 2 +- .../ME1312/SubServers/Host/SubCommand.java | 16 +- .../Sync/Event/SubSendCommandEvent.java | 13 +- .../Network/Packet/PacketInExRunEvent.java | 2 +- .../SubServers/Sync/Network/SubProtocol.java | 2 +- .../ME1312/SubServers/Sync/SubCommand.java | 27 +- .../Velocity/Event/SubSendCommandEvent.java | 13 +- .../Network/Packet/PacketInExRunEvent.java | 2 +- .../Velocity/Network/SubProtocol.java | 2 +- .../SubServers/Velocity/SubCommand.java | 21 +- 60 files changed, 908 insertions(+), 555 deletions(-) create mode 100644 SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExControlPlayer.java create mode 100644 SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketExControlPlayer.java create mode 100644 SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/Packet/PacketExControlPlayer.java diff --git a/SubServers.Bungee/common/pom.xml b/SubServers.Bungee/common/pom.xml index 5536adf3..1f40e479 100644 --- a/SubServers.Bungee/common/pom.xml +++ b/SubServers.Bungee/common/pom.xml @@ -28,7 +28,7 @@ net.ME1312.Galaxi GalaxiUtil - 21w47d + 21w49a compile diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Event/SubSendCommandEvent.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Event/SubSendCommandEvent.java index 20340b8e..e7ae75ad 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Event/SubSendCommandEvent.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Event/SubSendCommandEvent.java @@ -1,7 +1,7 @@ package net.ME1312.SubServers.Bungee.Event; import net.ME1312.Galaxi.Library.Util; -import net.ME1312.SubServers.Bungee.Host.SubServer; +import net.ME1312.SubServers.Bungee.Host.Server; import net.ME1312.SubServers.Bungee.Library.SubEvent; import net.md_5.bungee.api.plugin.Cancellable; @@ -15,20 +15,24 @@ import java.util.UUID; public class SubSendCommandEvent extends Event implements SubEvent, Cancellable { private boolean cancelled = false; private UUID player; - private SubServer server; + private Server server; private String command; + private UUID target; /** * Server Command Event * - * @param player Player Commanding Server - * @param server Server being Commanded + * @param player Player Commanding + * @param server Target Server + * @param command Command to Send + * @param target Player that will send */ - public SubSendCommandEvent(UUID player, SubServer server, String command) { + public SubSendCommandEvent(UUID player, Server server, String command, UUID target) { Util.nullpo(server, command); this.player = player; this.server = server; this.command = command; + this.target = target; } /** @@ -36,7 +40,7 @@ public class SubSendCommandEvent extends Event implements SubEvent, Cancellable * * @return The Server Effected */ - public SubServer getServer() { return server; } + public Server getServer() { return server; } /** * Gets the player that triggered the Event @@ -63,6 +67,15 @@ public class SubSendCommandEvent extends Event implements SubEvent, Cancellable command = value; } + /** + * Gets the Player that will be forced to send the Command + * + * @return Target Player or null if Console + */ + public UUID getTarget() { + return target; + } + /** * Gets the Cancelled Status * diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java index 3bde6cb0..9b993d32 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java @@ -214,7 +214,7 @@ public class ExternalSubServer extends SubServerImpl { public boolean command(UUID player, String command) { Util.nullpo(command); if (running) { - SubSendCommandEvent event = new SubSendCommandEvent(player, this, command); + SubSendCommandEvent event = new SubSendCommandEvent(player, this, command, null); host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) { history.add(new LoggedCommand(player, event.getCommand())); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java index 9547d873..e6bcaab0 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java @@ -278,7 +278,7 @@ public class InternalSubServer extends SubServerImpl { public boolean command(UUID player, String command) { Util.nullpo(command); if (thread != null && thread.isAlive()) { - SubSendCommandEvent event = new SubSendCommandEvent(player, this, command); + SubSendCommandEvent event = new SubSendCommandEvent(player, this, command, null); host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled() && (player == null || !DISALLOWED_COMMANDS.matcher(command).find())) { try { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java index 2ab30937..645c88ac 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java @@ -58,6 +58,34 @@ public interface Server extends ServerInfo, ClientHandler, ExtraDataHandler getRemotePlayers() { return SubAPI.getInstance().getRemotePlayers(this).values(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java index ff602504..88de2ca6 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java @@ -3,6 +3,7 @@ package net.ME1312.SubServers.Bungee.Host; import net.ME1312.Galaxi.Library.Map.ObjectMap; import net.ME1312.Galaxi.Library.Util; +import java.io.File; import java.util.*; /** @@ -114,7 +115,9 @@ public interface SubServer extends Server { * * @return Success Status */ - boolean start(); + default boolean start() { + return start(null); + } /** * Stops the Server @@ -129,7 +132,9 @@ public interface SubServer extends Server { * * @return Success Status */ - boolean stop(); + default boolean stop() { + return stop(null); + } /** * Terminates the Server @@ -144,24 +149,9 @@ public interface SubServer extends Server { * * @return Success Status */ - boolean terminate(); - - /** - * Commands the Server - * - * @param player Player who Commanded - * @param command Command to Send - * @return Success Status - */ - boolean command(UUID player, String command); - - /** - * Commands the Server - * - * @param command Command to Send - * @return Success Status - */ - boolean command(String command); + default boolean terminate() { + return terminate(null); + } /** * Edits the Server @@ -325,7 +315,9 @@ public interface SubServer extends Server { * * @return Full Server Directory Path */ - String getFullPath(); + default String getFullPath() { + return new File(getHost().getPath(), getPath()).getPath(); + } /** * Get the Server's Executable String diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerController.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerController.java index cd402a5f..92ec00db 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerController.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerController.java @@ -231,7 +231,7 @@ public abstract class SubServerController { /** * Commands the Server * - * @param player Player who Commanded + * @param player Player who's Commanding * @param command Command to Send * @return Success Status */ diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerImpl.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerImpl.java index fe2d4f54..2e381d1c 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerImpl.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServerImpl.java @@ -58,26 +58,6 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer { super(name, new InetSocketAddress(host.getAddress().getHostAddress(), port), motd, hidden, restricted); } - @Override - public boolean start() { - return start(null); - } - - @Override - public boolean stop() { - return stop(null); - } - - @Override - public boolean terminate() { - return terminate(null); - } - - @Override - public boolean command(String command) { - return command(null, command); - } - public int edit(UUID player, ObjectMap edit) { return edit(player, edit, false); } @@ -136,11 +116,6 @@ public abstract class SubServerImpl extends ServerImpl implements SubServer { } } - @Override - public String getFullPath() { - return new File(getHost().getPath(), getPath()).getPath(); - } - @Override public void toggleCompatibility(SubServer... server) { for (SubServer s : server) { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/ConfigUpdater.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/ConfigUpdater.java index 1b6bd038..b723c30a 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/ConfigUpdater.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/ConfigUpdater.java @@ -309,7 +309,7 @@ public class ConfigUpdater { if (was.compareTo(new Version("19w22b")) <= 0) { if (existing.contains("Lang")) { updated.getMap("Lang").remove("Interface.Host-Admin.SubServers"); - updated.getMap("Lang").remove("Interface.SubServer-Admin.Command"); + updated.getMap("Lang").remove("Interface.Server-Admin.Command"); } existing = updated.clone(); @@ -324,7 +324,7 @@ public class ConfigUpdater { existing = updated.clone(); i++; - } if (was.compareTo(new Version("21w27b")) <= 0) { + } if (was.compareTo(new Version("21w49b")) <= 0) { //existing = updated.clone(); i++; @@ -430,9 +430,10 @@ public class ConfigUpdater { def.put("Command.Terminate", "&aSubServers &2&l\\u00BB&a Terminated &2$int$&a subserver(s)"); def.put("Command.Terminate.Disappeared", "&cSubServers &4&l\\u00BB&c Subserver &4$str$&c has disappeared"); def.put("Command.Terminate.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 subserver(s) were already offline"); - def.put("Command.Command", "&aSubServers &2&l\\u00BB&a Sent command to &2$int$&a subserver(s)"); + def.put("Command.Command", "&aSubServers &2&l\\u00BB&a Sent command to &2$int$&a server(s)"); + def.put("Command.Command.Disappeared", "&cSubServers &4&l\\u00BB&c Server &4$str$&c has disappeared"); def.put("Command.Command.No-Command", "&cSubServers &4&l\\u00BB&c No command was entered"); - def.put("Command.Command.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 subserver(s) were offline"); + def.put("Command.Command.Not-Running", "&7SubServers &8&l\\u00BB&7 &f$int$&7 server(s) were unavailable"); def.put("Command.Creator", "&aSubServers &2&l\\u00BB&a Creating subserver &2$str$&a"); def.put("Command.Creator.Exists", "&cSubServers &4&l\\u00BB&c There is already a subserver with that name"); def.put("Command.Creator.Unknown-Host", "&cSubServers &4&l\\u00BB&c There is no host with that name"); @@ -520,24 +521,23 @@ public class ConfigUpdater { def.put("Interface.Server-Menu.SubServer-Incompatible", "&4Incompatible with $str$"); def.put("Interface.Server-Menu.SubServer-Unavailable", "&4Unavailable"); def.put("Interface.Server-Menu.SubServer-Disabled", "&4Disabled"); - def.put("Interface.Server-Menu.SubServer-Invalid", "&4Cannot be managed by SubServers"); def.put("Interface.Server-Menu.No-Servers", "&c&oThere are No Servers"); def.put("Interface.Server-Menu.Host-Menu", "&b&lView Hosts"); - def.put("Interface.SubServer-Admin.Title", "SubServer/$str$"); - def.put("Interface.SubServer-Admin.Start", "&aStart SubServer"); - def.put("Interface.SubServer-Admin.Start.Title", "&aStarting SubServer"); - def.put("Interface.SubServer-Admin.Stop", "&cStop SubServer"); - def.put("Interface.SubServer-Admin.Stop.Title", "&cStopping $str$"); - def.put("Interface.SubServer-Admin.Terminate", "&4Terminate SubServer"); - def.put("Interface.SubServer-Admin.Terminate.Title", "&cTerminating $str$"); - def.put("Interface.SubServer-Admin.Command", "&bSend a Command to the SubServer"); - def.put("Interface.SubServer-Admin.Command.Title", "&eSubServers\\n&6Enter a Command to send via Chat"); - def.put("Interface.SubServer-Admin.Command.Message", "&eSubServers &6&l\\u00BB&e Enter a Command to send via Chat"); - def.put("Interface.SubServer-Admin.Update", "&eUpdate SubServer"); - def.put("Interface.SubServer-Admin.Update.Title", "&eSubServers\\n&6Enter a Server Version to update to"); - def.put("Interface.SubServer-Admin.Update.Message", "&eSubServers &6&l\\u00BB&e Enter a Server Version to update to via Chat"); - def.put("Interface.SubServer-Admin.Plugins", "&bPlugins..."); - def.put("Interface.SubServer-Plugin.Title", "SubServer/$str$/Plugins"); + def.put("Interface.Server-Admin.Title", "Server/$str$"); + def.put("Interface.Server-Admin.Start", "&aStart SubServer"); + def.put("Interface.Server-Admin.Start.Title", "&aStarting SubServer"); + def.put("Interface.Server-Admin.Stop", "&cStop SubServer"); + def.put("Interface.Server-Admin.Stop.Title", "&cStopping $str$"); + def.put("Interface.Server-Admin.Terminate", "&4Terminate SubServer"); + def.put("Interface.Server-Admin.Terminate.Title", "&cTerminating $str$"); + def.put("Interface.Server-Admin.Command", "&bSend a Command to the Server"); + def.put("Interface.Server-Admin.Command.Title", "&eSubServers\\n&6Enter a Command to send via Chat"); + def.put("Interface.Server-Admin.Command.Message", "&eSubServers &6&l\\u00BB&e Enter a Command to send via Chat"); + def.put("Interface.Server-Admin.Update", "&eUpdate SubServer"); + def.put("Interface.Server-Admin.Update.Title", "&eSubServers\\n&6Enter a Server Version to update to"); + def.put("Interface.Server-Admin.Update.Message", "&eSubServers &6&l\\u00BB&e Enter a Server Version to update to via Chat"); + def.put("Interface.Server-Admin.Plugins", "&bPlugins..."); + def.put("Interface.SubServer-Plugin.Title", "Server/$str$/Plugins"); def.put("Interface.SubServer-Plugin.No-Plugins", "&c&oThere are No Plugins Available"); YAMLSection lang = new YAMLSection(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCommandServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCommandServer.java index 665a451b..b1bca120 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCommandServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketCommandServer.java @@ -51,27 +51,28 @@ public class PacketCommandServer implements PacketObjectIn, PacketObjec @Override public void receive(SubDataClient client, ObjectMap data) { - UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null); + UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null); try { String server = data.getString(0x0001); String command = data.getString(0x0002); - UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null); + UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null); + UUID target = (data.contains(0x0004)?data.getUUID(0x0004):null); Map servers = plugin.api.getServers(); if (!server.equals("*") && !servers.keySet().contains(server.toLowerCase())) { client.sendPacket(new PacketCommandServer(3, tracker)); - } else if (!server.equals("*") && !(servers.get(server.toLowerCase()) instanceof SubServer)) { + } else if (!server.equals("*") && !(target == null && servers.get(server.toLowerCase()) instanceof SubServer) && servers.get(server.toLowerCase()).getSubData()[0] == null) { client.sendPacket(new PacketCommandServer(4, tracker)); - } else if (!server.equals("*") && !((SubServer) servers.get(server.toLowerCase())).isRunning()) { + } else if (!server.equals("*") && servers.get(server.toLowerCase()) instanceof SubServer && !((SubServer) servers.get(server.toLowerCase())).isRunning()) { client.sendPacket(new PacketCommandServer(5, tracker)); } else { if (server.equals("*")) { boolean sent = false; for (Server next : servers.values()) { - if (next instanceof SubServer && ((SubServer) next).isRunning()) { - if (((SubServer) next).command(player, command)) { - sent = true; - } + if (target == null) { + sent |= next.command(player, command); + } else { + sent |= next.command(player, target, command); } } if (sent) { @@ -80,10 +81,10 @@ public class PacketCommandServer implements PacketObjectIn, PacketObjec client.sendPacket(new PacketCommandServer(1, tracker)); } } else { - if (((SubServer) servers.get(server.toLowerCase())).command(player, command)) { - client.sendPacket(new PacketCommandServer(0, tracker)); + if (target == null) { + client.sendPacket(new PacketCommandServer((servers.get(server.toLowerCase()).command(player, command))? 0 : 1, tracker)); } else { - client.sendPacket(new PacketCommandServer(1, tracker)); + client.sendPacket(new PacketCommandServer((servers.get(server.toLowerCase()).command(player, target, command))? 0 : 1, tracker)); } } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExAddServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExAddServer.java index 221c3e44..deba5032 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExAddServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExAddServer.java @@ -60,7 +60,7 @@ public class PacketExAddServer implements PacketObjectIn, PacketObjectO data.set(0x0005, directory); data.set(0x0006, executable); data.set(0x0007, stopcmd); - if (running != null) data.set(0x0008, running.toString()); + if (running != null) data.set(0x0008, running); return data; } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExControlPlayer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExControlPlayer.java new file mode 100644 index 00000000..fc7afe9c --- /dev/null +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExControlPlayer.java @@ -0,0 +1,62 @@ +package net.ME1312.SubServers.Bungee.Network.Packet; + +import net.ME1312.Galaxi.Library.Map.ObjectMap; +import net.ME1312.Galaxi.Library.Util; +import net.ME1312.SubData.Server.Protocol.PacketObjectIn; +import net.ME1312.SubData.Server.Protocol.PacketObjectOut; +import net.ME1312.SubData.Server.SubDataClient; + +import java.util.HashMap; +import java.util.UUID; +import java.util.function.Consumer; + +/** + * External Player Control Packet + */ +public class PacketExControlPlayer implements PacketObjectIn, PacketObjectOut { + private static HashMap>[]> callbacks = new HashMap>[]>(); + private String command; + private UUID target; + private UUID tracker; + + /** + * New PacketExControlPlayer (In) + */ + public PacketExControlPlayer() {} + + /** + * New PacketExControlPlayer (Out) + * + * @param target Target Player + * @param command Command to send + * @param callback Callbacks + */ + @SafeVarargs + public PacketExControlPlayer(UUID target, String command, Consumer>... callback) { + Util.nullpo(command, callback); + this.target = target; + this.command = command; + this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID); + callbacks.put(tracker, callback); + } + + @Override + public ObjectMap send(SubDataClient client) { + ObjectMap data = new ObjectMap(); + data.set(0x0000, tracker); + data.set(0x0001, command); + if (target != null) data.set(0x0002, target); + return data; + } + + @Override + public void receive(SubDataClient client, ObjectMap data) { + for (Consumer> callback : callbacks.get(data.getUUID(0x0000))) callback.accept(data); + callbacks.remove(data.getUUID(0x0000)); + } + + @Override + public int version() { + return 0x0001; + } +} diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketOutExRunEvent.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketOutExRunEvent.java index 0052bfc1..e5a29d60 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketOutExRunEvent.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketOutExRunEvent.java @@ -86,7 +86,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubAddHostEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("host", event.getHost().getName()); broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args)); } @@ -96,7 +96,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubAddServerEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); if (event.getHost() != null) args.set("host", event.getHost().getName()); args.set("server", event.getServer().getName()); broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args)); @@ -107,7 +107,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubCreateEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("update", event.isUpdate()); args.set("name", event.getName()); args.set("host", event.getHost().getName()); @@ -121,7 +121,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { @EventHandler(priority = Byte.MAX_VALUE) public void event(SubCreatedEvent event) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("success", event.wasSuccessful()); args.set("update", event.wasUpdate()); args.set("name", event.getName()); @@ -136,9 +136,10 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubSendCommandEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("server", event.getServer().getName()); args.set("command", event.getCommand()); + if (event.getTarget() != null) args.set("target", event.getTarget()); broadcast(new PacketOutExRunEvent(event.getClass(), args)); } } @@ -147,7 +148,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubEditServerEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("server", event.getServer().getName()); args.set("edit", event.getEdit().key()); args.set("value", event.getEdit().value().asObject()); @@ -159,7 +160,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubStartEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("server", event.getServer().getName()); broadcast(new PacketOutExRunEvent(event.getClass(), args)); } @@ -176,7 +177,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubStopEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("server", event.getServer().getName()); args.set("force", event.isForced()); broadcast(new PacketOutExRunEvent(event.getClass(), args)); @@ -195,7 +196,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubRemoveServerEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); if (event.getHost() != null) args.set("host", event.getHost().getName()); args.set("server", event.getServer().getName()); broadcast(event.getServer(), new PacketOutExRunEvent(event.getClass(), args)); @@ -206,7 +207,7 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut { public void event(SubRemoveHostEvent event) { if (!event.isCancelled()) { ObjectMap args = new ObjectMap(); - if (event.getPlayer() != null) args.set("player", event.getPlayer().toString()); + if (event.getPlayer() != null) args.set("player", event.getPlayer()); args.set("host", event.getHost().getName()); broadcast(event.getHost(), new PacketOutExRunEvent(event.getClass(), args)); } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketStopServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketStopServer.java index 2748af00..57f18ab2 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketStopServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketStopServer.java @@ -68,44 +68,28 @@ public class PacketStopServer implements PacketObjectIn, PacketObjectOu boolean sent = false; if (force) { for (Server server : servers.values()) { - if (server instanceof SubServer && ((SubServer) server).isRunning()) { - if (((SubServer) server).terminate(player)) { - sent = true; - } + if (server instanceof SubServer) { + sent |= ((SubServer) server).terminate(player); } } - if (sent) { - client.sendPacket(new PacketStopServer(0, tracker)); - } else { - client.sendPacket(new PacketStopServer(1, tracker)); - } } else { for (Server server : servers.values()) { - if (server instanceof SubServer && ((SubServer) server).isRunning()) { - if (((SubServer) server).stop(player)) { - sent = true; - } + if (server instanceof SubServer) { + sent |= ((SubServer) server).stop(player); } } - if (sent) { - client.sendPacket(new PacketStopServer(0, tracker)); - } else { - client.sendPacket(new PacketStopServer(1, tracker)); - } + } + + if (sent) { + client.sendPacket(new PacketStopServer(0, tracker)); + } else { + client.sendPacket(new PacketStopServer(1, tracker)); } } else { if (force) { - if (((SubServer) servers.get(name.toLowerCase())).terminate(player)) { - client.sendPacket(new PacketStopServer(0, tracker)); - } else { - client.sendPacket(new PacketStopServer(1, tracker)); - } + client.sendPacket(new PacketStopServer((((SubServer) servers.get(name.toLowerCase())).terminate(player))? 0 : 1, tracker)); } else { - if (((SubServer) servers.get(name.toLowerCase())).stop(player)) { - client.sendPacket(new PacketStopServer(0, tracker)); - } else { - client.sendPacket(new PacketStopServer(1, tracker)); - } + client.sendPacket(new PacketStopServer((((SubServer) servers.get(name.toLowerCase())).stop(player))? 0 : 1, tracker)); } } } catch (Throwable e) { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubProtocol.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubProtocol.java index d14f0930..83927485 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubProtocol.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/SubProtocol.java @@ -27,7 +27,7 @@ public class SubProtocol extends SubDataProtocol { SubProxy plugin = SubAPI.getInstance().getInternals(); setName("SubServers 2"); - setVersion(new Version("2.16a+")); + setVersion(new Version("2.18a+")); // 00-0F: Object Link Packets @@ -129,6 +129,7 @@ public class SubProtocol extends SubDataProtocol { registerPacket(0x0075, PacketExTransferPlayer.class); registerPacket(0x0076, PacketExDisconnectPlayer.class); registerPacket(0x0077, PacketExMessagePlayer.class); + registerPacket(0x0078, PacketExControlPlayer.class); //registerPacket(0x0070, new PacketOutRunEvent()); //registerPacket(0x0071, new PacketOutReset()); @@ -138,6 +139,7 @@ public class SubProtocol extends SubDataProtocol { registerPacket(0x0075, new PacketExTransferPlayer()); registerPacket(0x0076, new PacketExDisconnectPlayer()); registerPacket(0x0077, new PacketExMessagePlayer()); + registerPacket(0x0078, new PacketExControlPlayer()); } @SuppressWarnings("deprecation") diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java index 7e624898..cb7e9d8c 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java @@ -464,8 +464,11 @@ public final class SubAPI implements BungeeAPI { * @return Success Status */ public boolean removeServer(UUID player, String name) { - Util.nullpo(name, getServer(name)); - SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name)); + Util.nullpo(name); + Server server = getServer(name); + if (server == null) return true; + + SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, server); plugin.getPluginManager().callEvent(event); if (!event.isCancelled()) { plugin.exServers.remove(name.toLowerCase()); @@ -491,8 +494,11 @@ public final class SubAPI implements BungeeAPI { * @return Success Status */ public boolean forceRemoveServer(UUID player, String name) { - Util.nullpo(name, getServer(name)); - SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, getServer(name)); + Util.nullpo(name); + Server server = getServer(name); + if (server == null) return true; + + SubRemoveServerEvent event = new SubRemoveServerEvent(player, null, server); plugin.getPluginManager().callEvent(event); plugin.exServers.remove(name.toLowerCase()); return true; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java index 43c118e1..13b85c77 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java @@ -523,8 +523,8 @@ public final class SubCommand extends Command implements TabExecutor { } } else if (args[0].equalsIgnoreCase("cmd") || args[0].equalsIgnoreCase("command")) { if (args.length > 1) { - ServerSelection select = selectServers(sender, args, 1, true); - if (select.subservers.length > 0) { + ServerSelection select = selectServers(sender, args, 1, false); + if (select.servers.length > 0) { if (select.args.length > 2) { StringBuilder builder = new StringBuilder(select.args[2]); for (int i = 3; i < select.args.length; i++) { @@ -534,21 +534,29 @@ public final class SubCommand extends Command implements TabExecutor { int success = 0, running = 0; String command = builder.toString(); - for (SubServer server : select.subservers) { - if (!server.isRunning()) { - running++; - } else if (server.command(command)) { - success++; + for (Server server : select.servers) { + if (server instanceof SubServer) { + if (!((SubServer) server).isRunning()) { + running++; + } else if (server.command(command)) { + success++; + } + } else { + if (server.getSubData()[0] == null) { + running++; + } else if (server.command(command)) { + success++; + } } } - if (running > 0) sender.sendMessage("SubServers > " + running + " subserver"+((running == 1)?" was":"s were") + " offline"); - if (success > 0) sender.sendMessage("SubServers > Sent command to " + success + " subserver"+((success == 1)?"":"s")); + if (running > 0) sender.sendMessage("SubServers > " + running + " server"+((running == 1)?" was":"s were") + " unavailable"); + if (success > 0) sender.sendMessage("SubServers > Sent command to " + success + " server"+((success == 1)?"":"s")); } else { sender.sendMessage("SubServers > No command was entered"); } } } else { - sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " [Args...]"); + sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " [Args...]"); } } else if (args[0].equalsIgnoreCase("sudo") || args[0].equalsIgnoreCase("screen")) { if (plugin.canSudo) { @@ -822,7 +830,7 @@ public final class SubCommand extends Command implements TabExecutor { " Restart Server: /sub restart ", " Stop Server: /sub stop ", " Terminate Server: /sub kill ", - " Command Server: /sub cmd [Args...]", + " Command Server: /sub cmd [Args...]", " Sudo Server: /sub sudo ", " Create Server: /sub create