Allow a subserver's template to be changed

This commit is contained in:
ME1312 2020-08-19 21:15:55 -04:00
parent 443e3c2d44
commit fa77eeeab0
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
24 changed files with 481 additions and 245 deletions

View File

@ -193,9 +193,10 @@ public class ExternalHost extends Host implements ClientHandler {
server.stop();
server.waitFor();
}
queue(new PacketExRemoveServer(name.toLowerCase(), data -> {
if (data.getInt(0x0001) == 0 || data.getInt(0x0001) == 1) {
servers.remove(name.toLowerCase());
queue(new PacketExRemoveServer(name.toLowerCase(), data -> {
if (data.getInt(0x0001) != 0 && data.getInt(0x0001) != 1) {
servers.put(name.toLowerCase(), server);
}
}));
return true;

View File

@ -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<String> server = new ObjectMap<String>();
ObjectMap<String> config = new ObjectMap<String>((Map<String, ?>) 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<String>());
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<String>());
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<Boolean> callback) {
public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Boolean> 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 -> {
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 (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();
}
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<Integer> data, Callback<SubServer> 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<String> server = new ObjectMap<String>();
ObjectMap<String> config = new ObjectMap<String>((Map<String, ?>) 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<String>());
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<String>());
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<String, NamedContainer<Integer, ExternalSubLogger>> thread = new HashMap<String, NamedContainer<Integer, ExternalSubLogger>>();

View File

@ -72,12 +72,12 @@ public class InternalSubCreator extends SubCreator {
this.callback = callback;
}
private CreatorTask(UUID player, SubServer server, Version version, Callback<SubServer> callback) {
private CreatorTask(UUID player, SubServer server, ServerTemplate template, Version version, Callback<SubServer> 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,12 +267,13 @@ 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<String>((Map<String, ?>) replacements.replace(config.get()));
if (update == null) {
server.set("Enabled", true);
server.set("Display", "");
server.set("Host", host.getName());
@ -289,10 +290,16 @@ public class InternalSubCreator extends SubCreator {
server.set("Restricted", false);
server.set("Incompatible", new ArrayList<String>());
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<Boolean> callback) {
public boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Boolean> 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);

View File

@ -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<Boolean> callback);
public abstract boolean update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Boolean> 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<Boolean> 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<Boolean> callback) {
return update(null, server, version, callback);
return update(player, server, null, version);
}
/**

View File

@ -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)");

View File

@ -23,7 +23,7 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, 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<Integer>, 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<ObjectMap<Integer>>... callback) {
if (Util.isNull(server, log, callback)) throw new NullPointerException();
public PacketExCreateServer(UUID player, SubServer server, SubCreator.ServerTemplate template, Version version, UUID log, Callback<ObjectMap<Integer>>... 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<Integer>, 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<Integer>, 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<Integer>, PacketObje
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -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<Integer>, 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<String, Server> servers = plugin.api.getServers();
if (!servers.keySet().contains(name.toLowerCase())) {
@ -70,16 +72,18 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, 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) {
} else {
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 (!((SubServer) servers.get(name.toLowerCase())).getTemplate().isEnabled()) {
} else if (!ft.isEnabled()) {
client.sendPacket(new PacketUpdateServer(10, tracker));
} else if (!((SubServer) servers.get(name.toLowerCase())).getTemplate().canUpdate()) {
} else if (!ft.canUpdate()) {
client.sendPacket(new PacketUpdateServer(11, tracker));
} else if (version == null && ((SubServer) servers.get(name.toLowerCase())).getTemplate().requiresVersion()) {
} else if (version == null && ft.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 (((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) {
@ -90,6 +94,7 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
}
}
}
} catch (Throwable e) {
client.sendPacket(new PacketUpdateServer(2, tracker));
e.printStackTrace();
@ -98,6 +103,6 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -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()) {
} 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, (select.args.length > 2)?new Version(select.args[2]):null)) {
} 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() + " <Subservers> [Version]");
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Subservers> [[Template] <Version>]");
}
} 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 <Subservers> <Command> [Args...]",
" Sudo Server: /sub sudo <Subserver>",
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
" Update Server: /sub update <Subservers> [Version]",
" Update Server: /sub update <Subservers> [[Template] <Version>]",
" Remove Server: /sub delete <Subservers>",
//" Restore Server: /sub restore <Subservers>",
"",
@ -1044,7 +1054,9 @@ public final class SubCommand extends CommandX {
}
} else if (args[0].equals("update") || args[0].equals("upgrade")) {
if (select.args.length == 3) {
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
return new NamedContainer<>(null, Arrays.asList("[Template]", "[Version]"));
} else if (select.args.length == 4) {
return new NamedContainer<>(null, Collections.singletonList("<Version>"));
}
}
return new NamedContainer<>(null, Collections.emptyList());

View File

@ -854,7 +854,7 @@ public final class SubProxy extends BungeeCord implements Listener {
RemotePlayer player = rPlayers.get(e.getConnection().getUniqueId());
if (player.getProxy() == null || player.getProxy().isMaster()) {
getPlayer(player.getUniqueId()).disconnect(new TextComponent(getTranslation("already_connected_proxy")));
} else {
} else if (player.getProxy().getSubData()[0] != null) {
((SubDataClient) player.getProxy().getSubData()[0]).sendPacket(new PacketExDisconnectPlayer(player.getUniqueId(), getTranslation("already_connected_proxy")));
}
}

View File

@ -325,7 +325,7 @@ public class DefaultUIHandler implements UIHandler, Listener {
input.put(player.getUniqueId(), m -> {
gui.setDownloading(plugin.api.getLang("SubServers", "Interface.Generic.Downloading.Response"));
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player.getUniqueId(), ((SubServer) gui.lastVisitedObjects[0]).getName(),
(m.getString("message").length() == 0 || m.getString("message").equals("/"))?null:new Version((m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message")), data -> {
null, (m.getString("message").length() == 0 || m.getString("message").equals("/"))?null:new Version((m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message")), data -> {
gui.reopen();
}));
});

View File

@ -189,13 +189,14 @@ public class SubCreator {
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
* @param response Response Code
*/
public void update(UUID player, String server, Version version, Callback<Integer> response) {
public void update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
if (Util.isNull(response)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server, version, data -> {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server.getName(), template.getName(), version, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -204,17 +205,41 @@ public class SubCreator {
ew.printStackTrace();
}
}));
};
/**
* Update a SubServer
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(UUID player, SubServer server, ServerTemplate template, Version version) {
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 response Response Code
*/
public void update(String server, Version version, Callback<Integer> response) {
update(null, server, version, response);
public void update(SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
update(null, server, template, version, response);
}
/**
* Update a SubServer
*
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(SubServer server, ServerTemplate template, Version version) {
update(null, server, template, version);
}
/**
@ -224,8 +249,8 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(UUID player, String server, Version version) {
update(player, server, version, i -> {});
public void update(UUID player, SubServer server, Version version) {
update(player, server, null, version);
}
/**
@ -234,7 +259,7 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(String server, Version version) {
public void update(SubServer server, Version version) {
update(null, server, version);
}

View File

@ -19,6 +19,7 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private UUID player;
private String name;
private String template;
private Version version;
private boolean waitfor;
private UUID tracker;
@ -33,12 +34,13 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, version, false, callback);
public PacketUpdateServer(UUID player, String name, String template, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, template, version, false, callback);
}
/**
@ -46,15 +48,17 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param waitfor Wait until completion to send callback
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
public PacketUpdateServer(UUID player, String name, String template, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
this.player = player;
this.name = name;
this.template = template;
this.version = version;
this.waitfor = waitfor;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -66,9 +70,10 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, name);
if (version != null) data.set(0x0002, version);
if (player != null) data.set(0x0003, player);
if (waitfor) data.set(0x0004, true);
if (template != null) data.set(0x0002, template);
if (version != null) data.set(0x0003, version);
if (player != null) data.set(0x0004, player);
if (waitfor) data.set(0x0005, true);
return data;
}
@ -80,6 +85,6 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -666,13 +666,17 @@ public final class SubCommand extends BukkitCommand {
if (args.length > 1) {
selectServers(sender, args, 1, true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.update"), select -> {
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;
boolean ts = template == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update").replace("$int$", success.value.toString()));
});
for (SubServer server : select.subservers) {
merge.reserve();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, server.getName(), (select.args.length > 2)?new Version(select.args[2]):null, data -> {
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, server.getName(), template, version, data -> {
switch (data.getInt(0x0001)) {
case 3:
case 4:
@ -691,13 +695,16 @@ public final class SubCommand extends BukkitCommand {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Running").replace("$str$", server.getName()));
break;
case 9:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template").replace("$str$", server.getName()));
if (ts) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template").replace("$str$", server.getName()));
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Template"));
break;
case 10:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled").replace("$str$", server.getName()));
if (ts) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled").replace("$str$", server.getName()));
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Template-Disabled"));
break;
case 11:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid").replace("$str$", server.getName()));
if (ts) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid").replace("$str$", server.getName()));
else sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Template-Invalid"));
break;
case 12:
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Version-Required").replace("$str$", server.getName()));
@ -712,7 +719,7 @@ public final class SubCommand extends BukkitCommand {
}
});
} else {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers> [Version]"));
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Subservers> [[Template] <Version>]"));
}
} else if (args[0].equalsIgnoreCase("tp") || args[0].equalsIgnoreCase("teleport")) {
if (args.length > ((sender instanceof Player)?1:2)) {
@ -1063,7 +1070,7 @@ public final class SubCommand extends BukkitCommand {
plugin.api.getLang("SubServers", "Command.Help.SubServer.Terminate").replace("$str$", label.toLowerCase() + " kill <Subservers>"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Command").replace("$str$", label.toLowerCase() + " cmd <Subservers> <Command> [Args...]"),
plugin.api.getLang("SubServers", "Command.Help.Host.Create").replace("$str$", label.toLowerCase() + " create <Name> <Host> <Template> [Version] [Port]"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Update").replace("$str$", label.toLowerCase() + " update <Subservers> [Version]"),
plugin.api.getLang("SubServers", "Command.Help.SubServer.Update").replace("$str$", label.toLowerCase() + " update <Subservers> [[Template] <Version>]"),
};
}
}

View File

@ -189,13 +189,14 @@ public class SubCreator {
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
* @param response Response Code
*/
public void update(UUID player, String server, Version version, Callback<Integer> response) {
public void update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
if (Util.isNull(response)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server, version, data -> {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server.getName(), template.getName(), version, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -204,17 +205,41 @@ public class SubCreator {
ew.printStackTrace();
}
}));
};
/**
* Update a SubServer
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(UUID player, SubServer server, ServerTemplate template, Version version) {
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 response Response Code
*/
public void update(String server, Version version, Callback<Integer> response) {
update(null, server, version, response);
public void update(SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
update(null, server, template, version, response);
}
/**
* Update a SubServer
*
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(SubServer server, ServerTemplate template, Version version) {
update(null, server, template, version);
}
/**
@ -224,8 +249,8 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(UUID player, String server, Version version) {
update(player, server, version, i -> {});
public void update(UUID player, SubServer server, Version version) {
update(player, server, null, version);
}
/**
@ -234,7 +259,7 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(String server, Version version) {
public void update(SubServer server, Version version) {
update(null, server, version);
}

View File

@ -18,6 +18,7 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private UUID player;
private String name;
private String template;
private Version version;
private boolean waitfor;
private UUID tracker;
@ -32,12 +33,13 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, version, false, callback);
public PacketUpdateServer(UUID player, String name, String template, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, template, version, false, callback);
}
/**
@ -45,15 +47,17 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param waitfor Wait until completion to send callback
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
public PacketUpdateServer(UUID player, String name, String template, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
this.player = player;
this.name = name;
this.template = template;
this.version = version;
this.waitfor = waitfor;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -65,9 +69,10 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, name);
if (version != null) data.set(0x0002, version);
if (player != null) data.set(0x0003, player);
if (waitfor) data.set(0x0004, true);
if (template != null) data.set(0x0002, template);
if (version != null) data.set(0x0003, version);
if (player != null) data.set(0x0004, player);
if (waitfor) data.set(0x0005, true);
return data;
}
@ -79,6 +84,6 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -112,7 +112,7 @@ public final class SubCommand implements CommandExecutor {
.child(CommandSpec.builder()
.description(Text.of("The SubServers Command - Update"))
.executor(new UPDATE())
.arguments(GenericArguments.optional(new ListArgument(Text.of("Subservers"))), GenericArguments.optional(GenericArguments.string(Text.of("Version"))), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("extra"))))
.arguments(GenericArguments.optional(new ListArgument(Text.of("Subservers"))), GenericArguments.optional(GenericArguments.string(Text.of("Template"))), GenericArguments.optional(GenericArguments.string(Text.of("Version"))), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("extra"))))
.build(), "update", "upgrade")
.child(CommandSpec.builder()
.description(Text.of("The SubServers Command - Teleport"))
@ -1017,7 +1017,7 @@ public final class SubCommand implements CommandExecutor {
break;
case 0:
case 1:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Creator").replace("$str$", name.get())));
break;
}
}));
@ -1042,17 +1042,34 @@ public final class SubCommand implements CommandExecutor {
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender)) {
Optional<String[]> s = args.getOne(Text.of("Subservers"));
Optional<String> template = args.getOne(Text.of("Template"));
Optional<String> version = args.getOne(Text.of("Version"));
final String ft;
final Version fv;
if (version.isPresent()) {
ft = template.get();
fv = new Version(version.get());
} else if (template.isPresent()) {
ft = null;
fv = new Version(template.get());
} else {
ft = null;
fv = null;
}
if (s.isPresent()) {
selectServers(sender, s.get(), true, Arrays.asList("subservers.subserver.%.*", "subservers.subserver.%.update"), select -> {
if (select.subservers.length > 0) {
boolean ts = ft == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update").replace("$int$", success.value.toString())));
});
for (SubServer server : select.subservers) {
merge.reserve();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, server.getName(), (version.isPresent() && version.get().length() > 0)?new Version(version.get()):null, data -> {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, server.getName(), ft, fv, data -> {
switch (data.getInt(0x0001)) {
case 3:
case 4:
@ -1071,13 +1088,16 @@ public final class SubCommand implements CommandExecutor {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Running").replace("$str$", server.getName())));
break;
case 9:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template").replace("$str$", server.getName())));
if (ts) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template").replace("$str$", server.getName())));
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Template")));
break;
case 10:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled").replace("$str$", server.getName())));
if (ts) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled").replace("$str$", server.getName())));
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Creator.Template-Disabled")));
break;
case 11:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid").replace("$str$", server.getName())));
if (ts) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid").replace("$str$", server.getName())));
else sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Creator.Template-Invalid")));
break;
case 12:
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Version-Required").replace("$str$", server.getName())));
@ -1093,7 +1113,7 @@ public final class SubCommand implements CommandExecutor {
});
return CommandResult.builder().successCount(1).build();
} else {
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub update <Subservers> [Version]")));
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub update <Subservers> [[Template] <Version>]")));
return CommandResult.builder().successCount(0).build();
}
} else {
@ -1451,7 +1471,7 @@ public final class SubCommand implements CommandExecutor {
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <Subservers>")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <Subservers> <Command> [Args...]")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.Host.Create").replace("$str$", "/sub create <Name> <Host> <Template> [Version] [Port]")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Update").replace("$str$", "/sub update <Subservers> [Version]")),
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Update").replace("$str$", "/sub update <Subservers> [[Template] <Version>]")),
};
}
}

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Host.Executable;
import com.sun.org.apache.xpath.internal.operations.Bool;
import net.ME1312.Galaxi.Engine.GalaxiEngine;
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
import net.ME1312.Galaxi.Library.Config.YAMLSection;
@ -234,13 +235,14 @@ public class SubCreatorImpl {
private final ServerTemplate template;
private final Version version;
private final int port;
private final Boolean mode;
private final UUID address;
private final UUID tracker;
private final SubLoggerImpl log;
private final HashMap<String, String> replacements;
private Process process;
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, UUID address, UUID tracker) {
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Boolean mode, UUID address, UUID tracker) {
super(SubAPI.getInstance().getAppInfo().getName() + "::SubCreator_Process_Handler(" + name + ')');
this.templates = new HashMap<String, ServerTemplate>();
this.update = host.servers.getOrDefault(name.toLowerCase(), null);
@ -249,6 +251,7 @@ public class SubCreatorImpl {
this.template = template;
this.version = version;
this.port = port;
this.mode = mode;
this.log = new SubLoggerImpl(null, this, name + File.separator + ((update == null)?"Creator":"Updater"), address, new Container<Boolean>(true), null);
this.replacements = new HashMap<String, String>();
this.address = address;
@ -306,7 +309,7 @@ public class SubCreatorImpl {
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" : ((mode)?"UPDATE":"SWITCH"));
if (player != null) var.put("player", player.toString().toUpperCase());
else var.remove("player");
var.put("name", name);
@ -465,9 +468,9 @@ public class SubCreatorImpl {
this.thread = new TreeMap<>();
}
public boolean create(UUID player, String name, ServerTemplate template, Version version, int port, UUID address, UUID tracker) {
public boolean create(UUID player, String name, ServerTemplate template, Version version, int port, Boolean mode, UUID address, UUID tracker) {
if (Util.isNull(name, template, port, address)) throw new NullPointerException();
CreatorTask task = new CreatorTask(player, name, template, version, port, address, tracker);
CreatorTask task = new CreatorTask(player, name, template, version, port, mode, address, tracker);
this.thread.put(name.toLowerCase(), task);
task.start();
return true;

View File

@ -189,13 +189,14 @@ public class SubCreator {
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
* @param response Response Code
*/
public void update(UUID player, String server, Version version, Callback<Integer> response) {
public void update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
if (Util.isNull(response)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server, version, data -> {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server.getName(), template.getName(), version, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -204,17 +205,41 @@ public class SubCreator {
ew.printStackTrace();
}
}));
};
/**
* Update a SubServer
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(UUID player, SubServer server, ServerTemplate template, Version version) {
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 response Response Code
*/
public void update(String server, Version version, Callback<Integer> response) {
update(null, server, version, response);
public void update(SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
update(null, server, template, version, response);
}
/**
* Update a SubServer
*
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(SubServer server, ServerTemplate template, Version version) {
update(null, server, template, version);
}
/**
@ -224,8 +249,8 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(UUID player, String server, Version version) {
update(player, server, version, i -> {});
public void update(UUID player, SubServer server, Version version) {
update(player, server, null, version);
}
/**
@ -234,7 +259,7 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(String server, Version version) {
public void update(SubServer server, Version version) {
update(null, server, version);
}

View File

@ -89,12 +89,13 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
Version version = (data.contains(0x0004)?data.getVersion(0x0004):null);
Integer port = data.getInt(0x0005);
UUID log = data.getUUID(0x0006);
UUID player = (data.contains(0x0007)?data.getUUID(0x0007):null);
Boolean mode = (data.contains(0x0007)?data.getBoolean(0x0007):null);
UUID player = (data.contains(0x0008)?data.getUUID(0x0008):null);
SubCreatorImpl.ServerTemplate templateV = host.templates.get(template.toLowerCase());
if (templateV == null) templateV = host.templatesR.get(template.toLowerCase());
host.creator.create(player, name, templateV, version, port, log, tracker);
host.creator.create(player, name, templateV, version, port, mode, log, tracker);
}
} catch (Throwable e) {
host.log.error.println(e);
@ -103,6 +104,6 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -18,6 +18,7 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private UUID player;
private String name;
private String template;
private Version version;
private boolean waitfor;
private UUID tracker;
@ -32,12 +33,13 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, version, false, callback);
public PacketUpdateServer(UUID player, String name, String template, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, template, version, false, callback);
}
/**
@ -45,15 +47,17 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param waitfor Wait until completion to send callback
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
public PacketUpdateServer(UUID player, String name, String template, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
this.player = player;
this.name = name;
this.template = template;
this.version = version;
this.waitfor = waitfor;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -65,9 +69,10 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, name);
if (version != null) data.set(0x0002, version);
if (player != null) data.set(0x0003, player);
if (waitfor) data.set(0x0004, true);
if (template != null) data.set(0x0002, template);
if (version != null) data.set(0x0003, version);
if (player != null) data.set(0x0004, player);
if (waitfor) data.set(0x0005, true);
return data;
}
@ -79,6 +84,6 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -831,13 +831,17 @@ public class SubCommand {
if (args.length > 0) {
selectServers(sender, args, 0, true, select -> {
if (select.subservers.length > 0) {
String template = (select.args.length > 2)?select.args[1].toLowerCase():null;
Version version = (select.args.length > 1)?new Version(select.args[(template == null)?1:2]):null;
boolean ts = template == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("Updating " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
for (SubServer server : select.subservers) {
merge.reserve();
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(null, server.getName(), (select.args.length > 1)?new Version(select.args[1]):null, data -> {
((SubDataClient) host.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(null, server.getName(), template, version, data -> {
switch (data.getInt(0x0001)) {
case 3:
case 4:
@ -856,13 +860,16 @@ public class SubCommand {
sender.sendMessage("Cannot update " + server.getName() + " while it is still running");
break;
case 9:
sender.sendMessage("We don't know which template built " + server.getName());
if (ts) sender.sendMessage("We don't know which template built " + server.getName());
else sender.sendMessage("There is no template with that name");
break;
case 10:
sender.sendMessage("The template that created " + server.getName() + " is not enabled");
if (ts) sender.sendMessage("The template that created " + server.getName() + " is not enabled");
else sender.sendMessage("That template is not enabled");
break;
case 11:
sender.sendMessage("The template that created " + server.getName() + " does not support subserver updating");
if (ts) sender.sendMessage("The template that created " + server.getName() + " does not support subserver updating");
else sender.sendMessage("That template does not support subserver updating");
break;
case 12:
sender.sendMessage("The template that created " + server.getName() + " requires a Minecraft version to be specified");
@ -877,11 +884,11 @@ public class SubCommand {
}
});
} else {
sender.sendMessage("Usage: /" + handle + " <Subservers> [Version]");
sender.sendMessage("Usage: /" + handle + " <Subservers> [[Template] <Version>]");
}
}
}
}.autocomplete(defaultCompletor).usage("<Subservers>", "[Version]").description("Updates one or more subservers").help(
}.autocomplete(defaultCompletor).usage("<Subservers>", "[[Template]", "<Version>]").description("Updates one or more subservers").help(
"Updates one or more subservers on the network.",
"",
"The version argument is template-dependent in this command,",
@ -897,7 +904,8 @@ public class SubCommand {
"",
"Examples:",
" /update Server2",
" /update Server2 1.14.4"
" /update Server2 1.14.4",
" /update Server2 Paper 1.14.4"
).register("update", "upgrade");
new Command(host.info) {
@Override

View File

@ -189,13 +189,14 @@ public class SubCreator {
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
* @param response Response Code
*/
public void update(UUID player, String server, Version version, Callback<Integer> response) {
public void update(UUID player, SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
if (Util.isNull(response)) throw new NullPointerException();
StackTraceElement[] origin = new Exception().getStackTrace();
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server, version, data -> {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(player, server.getName(), template.getName(), version, data -> {
try {
response.run(data.getInt(0x0001));
} catch (Throwable e) {
@ -204,17 +205,41 @@ public class SubCreator {
ew.printStackTrace();
}
}));
};
/**
* Update a SubServer
*
* @param player Player Updating
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(UUID player, SubServer server, ServerTemplate template, Version version) {
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 response Response Code
*/
public void update(String server, Version version, Callback<Integer> response) {
update(null, server, version, response);
public void update(SubServer server, ServerTemplate template, Version version, Callback<Integer> response) {
update(null, server, template, version, response);
}
/**
* Update a SubServer
*
* @param server Server to Update
* @param template Server Template
* @param version Server Version (may be null)
*/
public void update(SubServer server, ServerTemplate template, Version version) {
update(null, server, template, version);
}
/**
@ -224,8 +249,8 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(UUID player, String server, Version version) {
update(player, server, version, i -> {});
public void update(UUID player, SubServer server, Version version) {
update(player, server, null, version);
}
/**
@ -234,7 +259,7 @@ public class SubCreator {
* @param server Server to Update
* @param version Server Version (may be null)
*/
public void update(String server, Version version) {
public void update(SubServer server, Version version) {
update(null, server, version);
}

View File

@ -18,6 +18,7 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
private UUID player;
private String name;
private String template;
private Version version;
private boolean waitfor;
private UUID tracker;
@ -32,12 +33,13 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, version, false, callback);
public PacketUpdateServer(UUID player, String name, String template, Version version, Callback<ObjectMap<Integer>>... callback) {
this(player, name, template, version, false, callback);
}
/**
@ -45,15 +47,17 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
*
* @param player Player Creating
* @param name Server Name
* @param template Server Template
* @param version Server Version
* @param waitfor Wait until completion to send callback
* @param callback Callbacks
*/
@SafeVarargs
public PacketUpdateServer(UUID player, String name, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
public PacketUpdateServer(UUID player, String name, String template, Version version, boolean waitfor, Callback<ObjectMap<Integer>>... callback) {
if (Util.isNull(name, callback)) throw new NullPointerException();
this.player = player;
this.name = name;
this.template = template;
this.version = version;
this.waitfor = waitfor;
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
@ -65,9 +69,10 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
ObjectMap<Integer> data = new ObjectMap<Integer>();
data.set(0x0000, tracker);
data.set(0x0001, name);
if (version != null) data.set(0x0002, version);
if (player != null) data.set(0x0003, player);
if (waitfor) data.set(0x0004, true);
if (template != null) data.set(0x0002, template);
if (version != null) data.set(0x0003, version);
if (player != null) data.set(0x0004, player);
if (waitfor) data.set(0x0005, true);
return data;
}
@ -79,6 +84,6 @@ public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObject
@Override
public int version() {
return 0x0001;
return 0x0002;
}
}

View File

@ -643,13 +643,17 @@ public final class SubCommand extends CommandX {
if (args.length > 1) {
selectServers(sender, args, 1, true, select -> {
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;
boolean ts = template == null;
PrimitiveContainer<Integer> success = new PrimitiveContainer<Integer>(0);
AsyncConsolidator merge = new AsyncConsolidator(() -> {
if (success.value > 0) sender.sendMessage("SubServers > Updating " + success.value + " subserver"+((success.value == 1)?"":"s"));
});
for (SubServer server : select.subservers) {
merge.reserve();
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(null, server.getName(), (select.args.length > 2)?new Version(select.args[2]):null, data -> {
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(null, server.getName(), template, version, data -> {
switch (data.getInt(0x0001)) {
case 3:
case 4:
@ -668,13 +672,16 @@ public final class SubCommand extends CommandX {
sender.sendMessage("SubServers > Cannot update " + server.getName() + " while it is still running");
break;
case 9:
sender.sendMessage("SubServers > We don't know which template built " + server.getName());
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");
break;
case 10:
sender.sendMessage("SubServers > The template that created " + server.getName() + " is not enabled");
if (ts) sender.sendMessage("SubServers > The template that created " + server.getName() + " is not enabled");
else sender.sendMessage("SubServers > That template is not enabled");
break;
case 11:
sender.sendMessage("SubServers > The template that created " + server.getName() + " does not support subserver updating");
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");
break;
case 12:
sender.sendMessage("SubServers > The template that created " + server.getName() + " requires a Minecraft version to be specified");
@ -689,7 +696,7 @@ public final class SubCommand extends CommandX {
}
});
} else {
sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <Subservers> [Version]");
sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <Subservers> [[Template] <Version>]");
}
} else if (args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) {
if (args.length > 1) {
@ -935,7 +942,7 @@ public final class SubCommand extends CommandX {
" Terminate Server: /sub kill <Subservers>",
" Command Server: /sub cmd <Subservers> <Command> [Args...]",
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
" Update Server: /sub update <Subservers> [Version]",
" Update Server: /sub update <Subservers> [[Template] <Version>]",
" Remove Server: /sub delete <Subservers>",
"",
" To see BungeeCord Supplied Commands, please visit:",
@ -1150,7 +1157,9 @@ public final class SubCommand extends CommandX {
}
} else if (args[0].equals("update") || args[0].equals("upgrade")) {
if (select.args.length == 3) {
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
return new NamedContainer<>(null, Arrays.asList("[Template]", "[Version]"));
} else if (select.args.length == 4) {
return new NamedContainer<>(null, Collections.singletonList("<Version>"));
}
}
return new NamedContainer<>(null, Collections.emptyList());