From fa77eeeab08422447b76c834a327b1189091b2a8 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Wed, 19 Aug 2020 21:15:55 -0400 Subject: [PATCH] Allow a subserver's template to be changed --- .../Bungee/Host/External/ExternalHost.java | 5 +- .../Host/External/ExternalSubCreator.java | 145 +++++++++--------- .../Host/Internal/InternalSubCreator.java | 61 ++++---- .../SubServers/Bungee/Host/SubCreator.java | 55 +++++-- .../Bungee/Library/ConfigUpdater.java | 5 + .../Network/Packet/PacketExCreateServer.java | 18 ++- .../Network/Packet/PacketUpdateServer.java | 45 +++--- .../ME1312/SubServers/Bungee/SubCommand.java | 38 +++-- .../ME1312/SubServers/Bungee/SubProxy.java | 2 +- .../Bukkit/Graphic/DefaultUIHandler.java | 2 +- .../Client/Bukkit/Network/API/SubCreator.java | 39 ++++- .../Network/Packet/PacketUpdateServer.java | 19 ++- .../SubServers/Client/Bukkit/SubCommand.java | 19 ++- .../Client/Sponge/Network/API/SubCreator.java | 39 ++++- .../Network/Packet/PacketUpdateServer.java | 19 ++- .../SubServers/Client/Sponge/SubCommand.java | 36 ++++- .../Host/Executable/SubCreatorImpl.java | 11 +- .../Host/Network/API/SubCreator.java | 39 ++++- .../Network/Packet/PacketExCreateServer.java | 7 +- .../Network/Packet/PacketUpdateServer.java | 19 ++- .../ME1312/SubServers/Host/SubCommand.java | 22 ++- .../Sync/Network/API/SubCreator.java | 39 ++++- .../Network/Packet/PacketUpdateServer.java | 19 ++- .../ME1312/SubServers/Sync/SubCommand.java | 23 ++- 24 files changed, 481 insertions(+), 245 deletions(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java index d145fff7..02129d4b 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java @@ -193,9 +193,10 @@ public class ExternalHost extends Host implements ClientHandler { server.stop(); server.waitFor(); } + servers.remove(name.toLowerCase()); queue(new PacketExRemoveServer(name.toLowerCase(), data -> { - if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) { - servers.remove(name.toLowerCase()); + if (data.getInt(0x0001) != 0 && data.getInt(0x0001) != 1) { + servers.put(name.toLowerCase(), server); } })); return true; diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java index 4b4b3735..981cd8c6 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java @@ -109,58 +109,7 @@ public class ExternalSubCreator extends SubCreator { if (!event.isCancelled()) { logger.start(); host.queue(new PacketExCreateServer(player, name, template, version, port, logger.getExternalAddress(), data -> { - try { - if (data.getInt(0x0001) == 0) { - Logger.get(prefix).info("Saving..."); - if (host.plugin.exServers.keySet().contains(name.toLowerCase())) - host.plugin.exServers.remove(name.toLowerCase()); - - ObjectMap server = new ObjectMap(); - ObjectMap config = new ObjectMap((Map) data.getObject(0x0002)); - - server.set("Enabled", true); - server.set("Display", ""); - server.set("Host", host.getName()); - server.set("Template", template.getName()); - server.set("Group", new ArrayList()); - server.set("Port", fport); - server.set("Motd", "Some SubServer"); - server.set("Log", true); - server.set("Directory", "./" + name); - server.set("Executable", "java -Xmx1024M -jar " + template.getType().toString() + ".jar"); - server.set("Stop-Command", "stop"); - server.set("Stop-Action", "NONE"); - server.set("Run-On-Launch", false); - server.set("Restricted", false); - server.set("Incompatible", new ArrayList()); - server.set("Hidden", false); - server.setAll(config); - - SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), fport, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"), server.getRawString("Directory"), - server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted")); - if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display")); - subserver.setTemplate(server.getRawString("Template")); - for (String group : server.getStringList("Group")) subserver.addGroup(group); - SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null); - if (action != null) subserver.setStopAction(action); - if (server.contains("Extra")) for (String extra : server.getMap("Extra").getKeys()) - subserver.addExtra(extra, server.getMap("Extra").getObject(extra)); - host.plugin.servers.get().getMap("Servers").set(name, server); - host.plugin.servers.save(); - if (template.getBuildOptions().getBoolean("Run-On-Finish", true)) - subserver.start(); - - host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, fport, subserver, false, true)); - callback(origin, callback, subserver); - } else { - Logger.get(prefix).info(data.getString(0x0003)); - host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, fport, null, false, false)); - callback(origin, callback, null); - } - } catch (Exception e) { - e.printStackTrace(); - callback(origin, callback, null); - } + finish(player, null, name, template, version, fport, prefix, origin, data, callback); logger.stop(); this.thread.remove(name.toLowerCase()); })); @@ -181,9 +130,10 @@ public class ExternalSubCreator extends SubCreator { } @Override - public boolean update(UUID player, SubServer server, Version version, Callback callback) { + public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback callback) { if (Util.isNull(server)) throw new NullPointerException(); - if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && server.getTemplate() != null && server.getTemplate().isEnabled() && server.getTemplate().canUpdate() && (version != null || !server.getTemplate().requiresVersion())) { + final ServerTemplate ft = (template == null)?server.getTemplate():template; + if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && ft != null && ft.isEnabled() && ft.canUpdate() && (version != null || !ft.requiresVersion())) { StackTraceElement[] origin = new Exception().getStackTrace(); String name = server.getName(); @@ -196,22 +146,11 @@ public class ExternalSubCreator extends SubCreator { host.plugin.getPluginManager().callEvent(event); if (!event.isCancelled()) { logger.start(); - host.queue(new PacketExCreateServer(player, server, version, logger.getExternalAddress(), data -> { - Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, false)); - if (data.getInt(0x0001) == 0) { - Logger.get(prefix).info("Saving..."); - } else { - Logger.get(prefix).info(data.getString(0x0003)); - } - - host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, server.getTemplate(), version, server.getAddress().getPort(), server, true, data.getInt(0x0001) == 0)); - if (callback != null) try { - callback.run(data.getInt(0x0001) == 0); - } catch (Throwable e) { - Throwable ew = new InvocationTargetException(e); - ew.setStackTrace(origin); - ew.printStackTrace(); - } + host.queue(new PacketExCreateServer(player, server, ft, version, logger.getExternalAddress(), data -> { + finish(player, server, server.getName(), ft, version, server.getAddress().getPort(), prefix, origin, data, s -> { + Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, false)); + if (callback != null) callback.run(s != null); + }); logger.stop(); this.thread.remove(name.toLowerCase()); })); @@ -223,6 +162,72 @@ public class ExternalSubCreator extends SubCreator { } else return false; } + private void finish(UUID player, SubServer update, String name, ServerTemplate template, Version version, int port, String prefix, StackTraceElement[] origin, ObjectMap data, Callback callback) { + try { + if (data.getInt(0x0001) == 0) { + Logger.get(prefix).info("Saving..."); + SubServer subserver = update; + if (update == null || update.getTemplate() != template || template.getBuildOptions().getBoolean("Update-Settings", false)) { + if (host.plugin.exServers.keySet().contains(name.toLowerCase())) + host.plugin.exServers.remove(name.toLowerCase()); + + ObjectMap server = new ObjectMap(); + ObjectMap config = new ObjectMap((Map) data.getObject(0x0002)); + + if (update == null) { + server.set("Enabled", true); + server.set("Display", ""); + server.set("Host", host.getName()); + server.set("Template", template.getName()); + server.set("Group", new ArrayList()); + server.set("Port", port); + server.set("Motd", "Some SubServer"); + server.set("Log", true); + server.set("Directory", "./" + name); + server.set("Executable", "java -Xmx1024M -jar " + template.getType().toString() + ".jar"); + server.set("Stop-Command", "stop"); + server.set("Stop-Action", "NONE"); + server.set("Run-On-Launch", false); + server.set("Restricted", false); + server.set("Incompatible", new ArrayList()); + server.set("Hidden", false); + } else { + server.setAll(host.plugin.servers.get().getMap("Servers").getMap(name, new HashMap<>())); + server.set("Template", template.getName()); + } + server.setAll(config); + + if (update != null) Util.isException(() -> update.getHost().forceRemoveSubServer(name)); + subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"), + server.getRawString("Directory"), server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted")); + + if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display")); + subserver.setTemplate(server.getRawString("Template")); + for (String group : server.getStringList("Group")) subserver.addGroup(group); + SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(server.getRawString("Stop-Action").toUpperCase().replace('-', '_').replace(' ', '_')), null); + if (action != null) subserver.setStopAction(action); + if (server.contains("Extra")) for (String extra : server.getMap("Extra").getKeys()) + subserver.addExtra(extra, server.getMap("Extra").getObject(extra)); + host.plugin.servers.get().getMap("Servers").set(name, server); + host.plugin.servers.save(); + + if (update == null && template.getBuildOptions().getBoolean("Run-On-Finish", true)) + subserver.start(); + } + + host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, subserver, update != null, true)); + callback(origin, callback, subserver); + } else { + Logger.get(prefix).info(data.getString(0x0003)); + host.plugin.getPluginManager().callEvent(new SubCreatedEvent(player, host, name, template, version, port, update, update != null, false)); + callback(origin, callback, null); + } + } catch (Exception e) { + e.printStackTrace(); + callback(origin, callback, null); + } + } + @Override public void terminate() { HashMap> thread = new HashMap>(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java index 5b3a96ee..c0ee524f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java @@ -72,12 +72,12 @@ public class InternalSubCreator extends SubCreator { this.callback = callback; } - private CreatorTask(UUID player, SubServer server, Version version, Callback callback) { + private CreatorTask(UUID player, SubServer server, ServerTemplate template, Version version, Callback callback) { super("SubServers.Bungee::Internal_SubCreator_Process_Handler(" + server.getName() + ')'); this.player = player; this.update = server; this.name = server.getName(); - this.template = server.getTemplate(); + this.template = template; this.version = version; this.port = server.getAddress().getPort(); this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Updater", InternalSubCreator.this.log, null); @@ -128,7 +128,7 @@ public class InternalSubCreator extends SubCreator { var.putAll(replacements); var.put("java", System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"); - var.put("mode", (update == null)?"CREATE":"UPDATE"); + var.put("mode", (update == null)? "CREATE" : ((CreatorTask.this.template.equals(update.getTemplate()))?"UPDATE":"SWITCH")); if (player != null) var.put("player", player.toString().toUpperCase()); else var.remove("player"); var.put("name", name); @@ -267,32 +267,39 @@ public class InternalSubCreator extends SubCreator { try { Logger.get(prefix).info("Saving..."); SubServer subserver = update; - if (update == null) { + if (update == null || update.getTemplate() != template || template.getBuildOptions().getBoolean("Update-Settings", false)) { if (host.plugin.exServers.keySet().contains(name.toLowerCase())) host.plugin.exServers.remove(name.toLowerCase()); config = new ObjectMap((Map) replacements.replace(config.get())); - server.set("Enabled", true); - server.set("Display", ""); - server.set("Host", host.getName()); - server.set("Template", template.getName()); - server.set("Group", new ArrayList()); - server.set("Port", port); - server.set("Motd", "Some SubServer"); - server.set("Log", true); - server.set("Directory", "./" + name); - server.set("Executable", "java -Xmx1024M -jar " + template.getType().toString() + ".jar"); - server.set("Stop-Command", "stop"); - server.set("Stop-Action", "NONE"); - server.set("Run-On-Launch", false); - server.set("Restricted", false); - server.set("Incompatible", new ArrayList()); - server.set("Hidden", false); + if (update == null) { + server.set("Enabled", true); + server.set("Display", ""); + server.set("Host", host.getName()); + server.set("Template", template.getName()); + server.set("Group", new ArrayList()); + server.set("Port", port); + server.set("Motd", "Some SubServer"); + server.set("Log", true); + server.set("Directory", "./" + name); + server.set("Executable", "java -Xmx1024M -jar " + template.getType().toString() + ".jar"); + server.set("Stop-Command", "stop"); + server.set("Stop-Action", "NONE"); + server.set("Run-On-Launch", false); + server.set("Restricted", false); + server.set("Incompatible", new ArrayList()); + server.set("Hidden", false); + } else { + server.setAll(host.plugin.servers.get().getMap("Servers").getMap(name, new HashMap<>())); + server.set("Template", template.getName()); + } server.setAll(config); - subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"), server.getRawString("Directory"), - server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted")); + if (update != null) Util.isException(() -> update.getHost().forceRemoveSubServer(name)); + subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, ChatColor.translateAlternateColorCodes('&', server.getString("Motd")), server.getBoolean("Log"), + server.getRawString("Directory"), server.getRawString("Executable"), server.getRawString("Stop-Command"), server.getBoolean("Hidden"), server.getBoolean("Restricted")); + if (server.getString("Display").length() > 0) subserver.setDisplayName(server.getString("Display")); subserver.setTemplate(server.getRawString("Template")); for (String group : server.getStringList("Group")) subserver.addGroup(group); @@ -302,7 +309,8 @@ public class InternalSubCreator extends SubCreator { subserver.addExtra(extra, server.getMap("Extra").getObject(extra)); host.plugin.servers.get().getMap("Servers").set(name, server); host.plugin.servers.save(); - if (template.getBuildOptions().getBoolean("Run-On-Finish", true)) + + if (update == null && template.getBuildOptions().getBoolean("Run-On-Finish", true)) subserver.start(); } @@ -406,14 +414,15 @@ public class InternalSubCreator extends SubCreator { @SuppressWarnings("deprecation") @Override - public boolean update(UUID player, SubServer server, Version version, Callback callback) { + public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback callback) { if (Util.isNull(server)) throw new NullPointerException(); - if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && server.getTemplate() != null && server.getTemplate().isEnabled() && server.getTemplate().canUpdate() && (version != null || !server.getTemplate().requiresVersion())) { + final ServerTemplate ft = (template == null)?server.getTemplate():template; + if (host.isAvailable() && host.isEnabled() && host == server.getHost() && server.isAvailable() && !server.isRunning() && ft != null && ft.isEnabled() && ft.canUpdate() && (version != null || !ft.requiresVersion())) { StackTraceElement[] origin = new Exception().getStackTrace(); Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, true)); - CreatorTask task = new CreatorTask(player, server, version, x -> { + CreatorTask task = new CreatorTask(player, server, ft, version, x -> { Util.isException(() -> Util.reflect(SubServerImpl.class.getDeclaredField("updating"), server, false)); if (callback != null) try { callback.run(x != null); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java index 0d2adff7..39ab6983 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubCreator.java @@ -252,11 +252,50 @@ public abstract class SubCreator { * * @param player Player Updating * @param server Server to Update + * @param template Server Template * @param version Server Version (may be null) * @param callback Callback * @return Success Status */ - public abstract boolean update(UUID player, SubServer server, Version version, Callback callback); + public abstract boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback callback); + + /** + * Update a SubServer + * + * @param player Player Updating + * @param server Server to Update + * @param template Server Template + * @param version Server Version (may be null) + * @return Success Status + */ + public boolean update(UUID player, SubServer server, ServerTemplate template, Version version) { + return update(player, server, template, version, null); + } + + /** + * Update a SubServer + * + * @param server Server to Update + * @param template Server Template + * @param version Server Version (may be null) + * @param callback Callback + * @return Success Status + */ + public boolean update(SubServer server, ServerTemplate template, Version version, Callback callback) { + return update(null, server, template, version, callback); + } + + /** + * Update a SubServer + * + * @param server Server to Update + * @param template Server Template + * @param version Server Version (may be null) + * @return Success Status + */ + public boolean update(SubServer server, ServerTemplate template, Version version) { + return update(null, server, template, version); + } /** * Update a SubServer @@ -267,19 +306,7 @@ public abstract class SubCreator { * @return Success Status */ public boolean update(UUID player, SubServer server, Version version) { - return update(player, server, version, null); - } - - /** - * Update a SubServer - * - * @param server Server to Update - * @param version Server Version (may be null) - * @param callback Callback - * @return Success Status - */ - public boolean update(SubServer server, Version version, Callback callback) { - return update(null, server, version, callback); + return update(player, server, null, version); } /** 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 c91fd40e..7bf1d42a 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/ConfigUpdater.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/ConfigUpdater.java @@ -317,6 +317,10 @@ public class ConfigUpdater { existing = updated.clone(); i++; + } if (was.compareTo(new Version("20w34c")) <= 0) { + + //existing = updated.clone(); + i++; }// if (was.compareTo(new Version("99w99a")) <= 0) { // // do something // i++ @@ -428,6 +432,7 @@ public class ConfigUpdater { def.put("Command.Creator.Host-Disabled", "&cSubServers &4&l\\u00BB&c That host is not enabled"); def.put("Command.Creator.Unknown-Template", "&cSubServers &4&l\\u00BB&c There is no template with that name"); def.put("Command.Creator.Template-Disabled", "&cSubServers &4&l\\u00BB&c That template is not enabled"); + def.put("Command.Creator.Template-Invalid", "&cSubServers &4&l\\u00BB&c That template does not support subserver updating"); def.put("Command.Creator.Version-Required", "&cSubServers &4&l\\u00BB&c That template requires a Minecraft version to be specified"); def.put("Command.Creator.Invalid-Port", "&cSubServers &4&l\\u00BB&c Invalid port number"); def.put("Command.Update", "&aSubServers &2&l\\u00BB&a Updating &2$int$&a subserver(s)"); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExCreateServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExCreateServer.java index d4b9b196..d6433f53 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExCreateServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketExCreateServer.java @@ -23,7 +23,7 @@ public class PacketExCreateServer implements PacketObjectIn, PacketObje private SubCreator.ServerTemplate template; private Version version; private int port; - private String dir; + private Boolean mode; private UUID log; private UUID tracker = null; @@ -39,19 +39,20 @@ public class PacketExCreateServer implements PacketObjectIn, PacketObje * * @param player Player * @param server Server to Update + * @param template Server Template * @param version Server Version * @param log Log Address * @param callback Callbacks */ @SafeVarargs - public PacketExCreateServer(UUID player, SubServer server, Version version, UUID log, Callback>... callback) { - if (Util.isNull(server, log, callback)) throw new NullPointerException(); + public PacketExCreateServer(UUID player, SubServer server, SubCreator.ServerTemplate template, Version version, UUID log, Callback>... callback) { + if (Util.isNull(server, template, log, callback)) throw new NullPointerException(); this.player = player; this.name = server.getName(); - this.template = server.getTemplate(); + this.template = template; this.version = version; this.port = server.getAddress().getPort(); - this.dir = server.getPath(); + this.mode = template == server.getTemplate(); this.log = log; this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID); callbacks.put(tracker, callback); @@ -76,6 +77,7 @@ public class PacketExCreateServer implements PacketObjectIn, PacketObje this.template = template; this.version = version; this.port = port; + this.mode = null; this.log = log; this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID); callbacks.put(tracker, callback); @@ -93,8 +95,10 @@ public class PacketExCreateServer implements PacketObjectIn, PacketObje data.set(0x0004, version); data.set(0x0005, port); data.set(0x0006, log); + if (mode != null) + data.set(0x0007, mode); if (player != null) - data.set(0x0007, player); + data.set(0x0008, player); } return data; } @@ -107,6 +111,6 @@ public class PacketExCreateServer implements PacketObjectIn, PacketObje @Override public int version() { - return 0x0001; + return 0x0002; } } \ No newline at end of file diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketUpdateServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketUpdateServer.java index ab73e212..c556c0b8 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketUpdateServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketUpdateServer.java @@ -6,6 +6,7 @@ import net.ME1312.SubData.Server.Protocol.PacketObjectIn; import net.ME1312.SubData.Server.Protocol.PacketObjectOut; import net.ME1312.SubData.Server.SubDataClient; import net.ME1312.SubServers.Bungee.Host.Server; +import net.ME1312.SubServers.Bungee.Host.SubCreator; import net.ME1312.SubServers.Bungee.Host.SubServer; import net.ME1312.SubServers.Bungee.SubProxy; @@ -53,9 +54,10 @@ public class PacketUpdateServer implements PacketObjectIn, PacketObject UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null); try { String name = data.getRawString(0x0001); - Version version = (data.contains(0x0002)?data.getVersion(0x0002):null); - UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null); - boolean waitfor = (data.contains(0x0004)?data.getBoolean(0x0004):false); + String template = (data.contains(0x0002)?data.getRawString(0x0002):null); + Version version = (data.contains(0x0003)?data.getVersion(0x0003):null); + UUID player = (data.contains(0x0004)?data.getUUID(0x0004):null); + boolean waitfor = (data.contains(0x0005)?data.getBoolean(0x0005):false); Map servers = plugin.api.getServers(); if (!servers.keySet().contains(name.toLowerCase())) { @@ -70,25 +72,28 @@ public class PacketUpdateServer implements PacketObjectIn, PacketObject client.sendPacket(new PacketUpdateServer(7, tracker)); } else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) { client.sendPacket(new PacketUpdateServer(8, tracker)); - } else if (((SubServer) servers.get(name.toLowerCase())).getTemplate() == null) { - client.sendPacket(new PacketUpdateServer(9, tracker)); - } else if (!((SubServer) servers.get(name.toLowerCase())).getTemplate().isEnabled()) { - client.sendPacket(new PacketUpdateServer(10, tracker)); - } else if (!((SubServer) servers.get(name.toLowerCase())).getTemplate().canUpdate()) { - client.sendPacket(new PacketUpdateServer(11, tracker)); - } else if (version == null && ((SubServer) servers.get(name.toLowerCase())).getTemplate().requiresVersion()) { - client.sendPacket(new PacketUpdateServer(12, tracker)); } else { - if (((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().update(player, (SubServer) servers.get(name.toLowerCase()), version, success -> { - if (waitfor) client.sendPacket(new PacketUpdateServer((!success)?13:0, tracker)); - })) { - if (!waitfor) { - client.sendPacket(new PacketUpdateServer(0, tracker)); - } + SubCreator.ServerTemplate ft = (template != null)?((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().getTemplate(template):((SubServer) servers.get(name.toLowerCase())).getTemplate(); + if (ft == null) { + client.sendPacket(new PacketUpdateServer(9, tracker)); + } else if (!ft.isEnabled()) { + client.sendPacket(new PacketUpdateServer(10, tracker)); + } else if (!ft.canUpdate()) { + client.sendPacket(new PacketUpdateServer(11, tracker)); + } else if (version == null && ft.requiresVersion()) { + client.sendPacket(new PacketUpdateServer(12, tracker)); } else { - client.sendPacket(new PacketUpdateServer(1, tracker)); - } + if (((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().update(player, (SubServer) servers.get(name.toLowerCase()), ft, version, success -> { + if (waitfor) client.sendPacket(new PacketUpdateServer((!success)?13:0, tracker)); + })) { + if (!waitfor) { + client.sendPacket(new PacketUpdateServer(0, tracker)); + } + } else { + client.sendPacket(new PacketUpdateServer(1, tracker)); + } + } } } catch (Throwable e) { client.sendPacket(new PacketUpdateServer(2, tracker)); @@ -98,6 +103,6 @@ public class PacketUpdateServer implements PacketObjectIn, PacketObject @Override public int version() { - return 0x0001; + return 0x0002; } } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java index ab50e403..3c1225fe 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java @@ -608,6 +608,9 @@ public final class SubCommand extends CommandX { if (args.length > 1) { ServerSelection select = selectServers(sender, args, 1, true); if (select.subservers.length > 0) { + String template = (select.args.length > 3)?select.args[2].toLowerCase():null; + Version version = (select.args.length > 2)?new Version(select.args[(template == null)?2:3]):null; + int success = 0; for (SubServer server : select.subservers) { if (!server.isAvailable()) { @@ -618,22 +621,29 @@ public final class SubCommand extends CommandX { sender.sendMessage("SubServers > Subserver " + server.getName() + " is not available"); } else if (server.isRunning()) { sender.sendMessage("SubServers > Cannot update " + server.getName() + " while it is still running"); - } else if (server.getTemplate() == null) { - sender.sendMessage("SubServers > We don't know which template built " + server.getName()); - } else if (!server.getTemplate().isEnabled()) { - sender.sendMessage("SubServers > The template that created " + server.getName() + " is not enabled"); - } else if (!server.getTemplate().canUpdate()) { - sender.sendMessage("SubServers > The template that created " + server.getName() + " does not support subserver updating"); - } else if (select.args.length <= 2 && server.getTemplate().requiresVersion()) { - sender.sendMessage("SubServers > The template that created " + server.getName() + " requires a Minecraft version to be specified"); - } else if (server.getHost().getCreator().update(server, (select.args.length > 2)?new Version(select.args[2]):null)) { - success++; + } else { + SubCreator.ServerTemplate ft = (template != null)?server.getHost().getCreator().getTemplate(template):server.getTemplate(); + boolean ts = template == null; + if (ft == null) { + if (ts) sender.sendMessage("SubServers > We don't know which template built " + server.getName()); + else sender.sendMessage("SubServers > There is no template with that name"); + } else if (!ft.isEnabled()) { + if (ts) sender.sendMessage("SubServers > The template that created " + server.getName() + " is not enabled"); + else sender.sendMessage("SubServers > That template is not enabled"); + } else if (!ft.canUpdate()) { + if (ts) sender.sendMessage("SubServers > The template that created " + server.getName() + " does not support subserver updating"); + else sender.sendMessage("SubServers > That template does not support subserver updating"); + } else if (version == null && ft.requiresVersion()) { + sender.sendMessage("SubServers > The template that created " + server.getName() + " requires a Minecraft version to be specified"); + } else if (server.getHost().getCreator().update(server, ft, version)) { + success++; + } } } if (success > 0) sender.sendMessage("SubServers > Updating " + success + " subserver"+((success == 1)?"":"s")); } } else { - sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " [Version]"); + sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " [[Template] ]"); } } else if (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) { if (args.length > 1) { @@ -826,7 +836,7 @@ public final class SubCommand extends CommandX { " Command Server: /sub cmd [Args...]", " Sudo Server: /sub sudo ", " Create Server: /sub create