mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-01-25 09:01:23 +01:00
Add the Update command
And several related UI changes to SubServers.Client
This commit is contained in:
parent
96a0624b28
commit
be8f87d17c
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -2,6 +2,7 @@ package net.ME1312.SubServers.Bungee.Event;
|
||||
|
||||
import net.ME1312.SubServers.Bungee.Host.Host;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubCreator;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.Library.SubEvent;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
@ -16,6 +17,7 @@ import java.util.UUID;
|
||||
public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
private boolean cancelled = false;
|
||||
private UUID player;
|
||||
private SubServer update;
|
||||
private Host host;
|
||||
private String name;
|
||||
private SubCreator.ServerTemplate template;
|
||||
@ -42,6 +44,17 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public SubCreateEvent(UUID player, SubServer server, Version version) {
|
||||
if (Util.isNull(server)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.update = server;
|
||||
this.name = server.getName();
|
||||
this.host = server.getHost();
|
||||
this.template = server.getTemplate();
|
||||
this.version = version;
|
||||
this.port = server.getAddress().getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Host the SubServer will run on
|
||||
*
|
||||
@ -51,6 +64,24 @@ public class SubCreateEvent extends Event implements SubEvent, Cancellable {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator is being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean isUpdate() {
|
||||
return update != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @return Updating Server
|
||||
*/
|
||||
public SubServer getUpdating() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer will use
|
||||
*
|
||||
|
@ -9,6 +9,7 @@ import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExConfigureHost;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExCreateServer;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
@ -85,7 +86,8 @@ public class ExternalSubCreator extends SubCreator {
|
||||
return new InetSocketAddress(host.getAddress(), i.get());
|
||||
}).getPort();
|
||||
}
|
||||
ExternalSubLogger logger = new ExternalSubLogger(this, name + File.separator + "Creator", log, null);
|
||||
String prefix = name + File.separator + "Creator";
|
||||
ExternalSubLogger logger = new ExternalSubLogger(this, prefix, log, null);
|
||||
thread.put(name.toLowerCase(), new NamedContainer<>(port, logger));
|
||||
|
||||
final int fport = port;
|
||||
@ -96,7 +98,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
host.queue(new PacketExCreateServer(name, template, version, port, logger.getExternalAddress(), data -> {
|
||||
try {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
System.out.println(name + "/Creator > Saving...");
|
||||
Logger.get(prefix).info("Saving...");
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
|
||||
host.plugin.exServers.remove(name.toLowerCase());
|
||||
|
||||
@ -110,6 +112,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
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");
|
||||
@ -127,6 +130,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
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(getTemplate(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);
|
||||
@ -145,7 +149,7 @@ public class ExternalSubCreator extends SubCreator {
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println(name + "/Creator > " + data.getString(0x0003));
|
||||
Logger.get(prefix).info(data.getString(0x0003));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -183,6 +187,51 @@ public class ExternalSubCreator extends SubCreator {
|
||||
return string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(UUID player, SubServer server, Version version, Callback<SubServer> 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())) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
|
||||
String name = server.getName();
|
||||
String prefix = name + File.separator + "Updater";
|
||||
Util.isException(() -> Util.reflect(SubServerContainer.class.getDeclaredField("lock"), server, true));
|
||||
ExternalSubLogger logger = new ExternalSubLogger(this, prefix, log, null);
|
||||
thread.put(name.toLowerCase(), new NamedContainer<>(server.getAddress().getPort(), logger));
|
||||
|
||||
final SubCreateEvent event = new SubCreateEvent(player, server, version);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
logger.start();
|
||||
host.queue(new PacketExCreateServer(server, version, logger.getExternalAddress(), data -> {
|
||||
Util.isException(() -> Util.reflect(SubServerContainer.class.getDeclaredField("lock"), server, false));
|
||||
try {
|
||||
if (data.getInt(0x0001) == 0) {
|
||||
Logger.get(prefix).info("Saving...");
|
||||
if (callback != null) try {
|
||||
callback.run(server);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Logger.get(prefix).info(data.getString(0x0003));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logger.stop();
|
||||
this.thread.remove(name.toLowerCase());
|
||||
}));
|
||||
return true;
|
||||
} else {
|
||||
thread.remove(name.toLowerCase());
|
||||
return false;
|
||||
}
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminate() {
|
||||
HashMap<String, NamedContainer<Integer, ExternalSubLogger>> thread = new HashMap<String, NamedContainer<Integer, ExternalSubLogger>>();
|
||||
|
@ -10,7 +10,7 @@ import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExUpdateServer;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.PacketExEditServer;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@ -72,7 +72,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
|
||||
@Override
|
||||
public boolean start(UUID player) {
|
||||
if (!lock && isEnabled() && !running && getCurrentIncompatibilities().size() == 0) {
|
||||
if (!lock && isAvailable() && isEnabled() && !running && getCurrentIncompatibilities().size() == 0) {
|
||||
lock = true;
|
||||
SubStartEvent event = new SubStartEvent(player, this);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
@ -81,7 +81,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
Logger.get("SubServers").info("Now starting " + getName());
|
||||
running = true;
|
||||
logger.start();
|
||||
host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.START, logger.getExternalAddress().toString()));
|
||||
host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.START, logger.getExternalAddress().toString()));
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
@ -99,7 +99,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
history.add(new LoggedCommand(player, stopcmd));
|
||||
host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.STOP));
|
||||
host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOP));
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
@ -152,7 +152,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
SubStopEvent event = new SubStopEvent(player, this, true);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.TERMINATE));
|
||||
host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.TERMINATE));
|
||||
return true;
|
||||
} else return false;
|
||||
} else return false;
|
||||
@ -167,9 +167,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (!event.isCancelled()) {
|
||||
history.add(new LoggedCommand(player, event.getCommand()));
|
||||
if (event.getCommand().equalsIgnoreCase(stopcmd)) {
|
||||
host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.STOP));
|
||||
host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOP));
|
||||
} else {
|
||||
host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.COMMAND, event.getCommand()));
|
||||
host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.COMMAND, event.getCommand()));
|
||||
}
|
||||
return true;
|
||||
} else return false;
|
||||
@ -186,255 +186,275 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
private int edit(UUID player, ObjectMap<String> edit, boolean perma) {
|
||||
int c = 0;
|
||||
boolean state = isRunning();
|
||||
SubServer forward = null;
|
||||
ObjectMap<String> pending = edit.clone();
|
||||
for (String key : edit.getKeys()) {
|
||||
pending.remove(key);
|
||||
ObjectMapValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), perma);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
switch (key.toLowerCase()) {
|
||||
case "name":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.servers.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.servers.save();
|
||||
if (isAvailable()) {
|
||||
int c = 0;
|
||||
boolean state = isRunning();
|
||||
SubServer forward = null;
|
||||
ObjectMap<String> pending = edit.clone();
|
||||
for (String key : edit.getKeys()) {
|
||||
pending.remove(key);
|
||||
ObjectMapValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), perma);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
switch (key.toLowerCase()) {
|
||||
case "name":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.servers.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "display":
|
||||
if (value.isString()) {
|
||||
Field f = ServerContainer.class.getDeclaredField("nick");
|
||||
f.setAccessible(true);
|
||||
if (value == null || value.asString().length() == 0 || getName().equals(value)) {
|
||||
f.set(this, null);
|
||||
} else {
|
||||
f.set(this, value.asString());
|
||||
}
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
break;
|
||||
case "display":
|
||||
if (value.isString()) {
|
||||
Field f = ServerContainer.class.getDeclaredField("nick");
|
||||
f.setAccessible(true);
|
||||
if (value.isNull() || value.asString().length() == 0 || getName().equals(value.asString())) {
|
||||
f.set(this, null);
|
||||
} else {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
f.set(this, value.asString());
|
||||
}
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "enabled":
|
||||
if (value.isBoolean()) {
|
||||
if (enabled != value.asBoolean()) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_ENABLED, (Boolean) value.asBoolean()));
|
||||
enabled = value.asBoolean();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "host":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "port":
|
||||
if (value.isNumber() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "log":
|
||||
if (value.isBoolean()) {
|
||||
if (log.get() != value.asBoolean()) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_LOGGING, (Boolean) value.asBoolean()));
|
||||
log.set(value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "dir":
|
||||
case "directory":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), value.asRawString(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Directory", server.getPath());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "exec":
|
||||
case "executable":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), value.asRawString(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "state":
|
||||
if (value.isBoolean()) {
|
||||
state = value.asBoolean();
|
||||
}
|
||||
break;
|
||||
case "stop-cmd":
|
||||
case "stop-command":
|
||||
if (value.isString()) {
|
||||
if (!stopcmd.equals(value)) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_STOP_COMMAND, value.asRawString()));
|
||||
stopcmd = value.asRawString();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "stop-action":
|
||||
if (value.isString()) {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
} else {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
}
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "auto-run":
|
||||
case "run-on-launch":
|
||||
if (value.isBoolean()) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "enabled":
|
||||
if (value.isBoolean()) {
|
||||
if (enabled != value.asBoolean()) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_ENABLED, (Boolean) value.asBoolean()));
|
||||
enabled = value.asBoolean();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "incompatible":
|
||||
if (value.isList()) {
|
||||
for (String oname : (List<String>) value.asStringList()) {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
break;
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "host":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "template":
|
||||
if (value.isString()) {
|
||||
Util.reflect(SubServerContainer.class.getDeclaredField("template"), this, value.asString());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Template", value.asString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "port":
|
||||
if (value.isNumber() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (forward != null) {
|
||||
forward.setStopAction(getStopAction());
|
||||
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
|
||||
List<String> groups = new ArrayList<String>();
|
||||
groups.addAll(getGroups());
|
||||
for (String group : groups) {
|
||||
removeGroup(group);
|
||||
forward.addGroup(group);
|
||||
break;
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "log":
|
||||
if (value.isBoolean()) {
|
||||
if (log.get() != value.asBoolean()) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value.asBoolean()));
|
||||
log.set(value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "dir":
|
||||
case "directory":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), value.asRawString(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Directory", server.getPath());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "exec":
|
||||
case "executable":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
waitFor(() -> host.getSubServer(getName()), null);
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), value.asRawString(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "state":
|
||||
if (value.isBoolean()) {
|
||||
state = value.asBoolean();
|
||||
}
|
||||
break;
|
||||
case "stop-cmd":
|
||||
case "stop-command":
|
||||
if (value.isString()) {
|
||||
if (!stopcmd.equals(value)) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_STOP_COMMAND, value.asRawString()));
|
||||
stopcmd = value.asRawString();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "stop-action":
|
||||
if (value.isString()) {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "auto-run":
|
||||
case "run-on-launch":
|
||||
if (value.isBoolean()) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "incompatible":
|
||||
if (value.isList()) {
|
||||
for (SubServer oserver : getIncompatibilities()) toggleCompatibility(oserver);
|
||||
for (String oname : (List<String>) value.asStringList()) {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
}
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "whitelist":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("whitelist"), this, value.asUUIDList());
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (SubServer server : getIncompatibilities()) {
|
||||
toggleCompatibility(server);
|
||||
forward.toggleCompatibility(server);
|
||||
}
|
||||
for (String extra : getExtra().getKeys()) forward.addExtra(extra, getExtra(extra));
|
||||
if (forward != null) {
|
||||
forward.setStopAction(getStopAction());
|
||||
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
|
||||
List<String> groups = new ArrayList<String>();
|
||||
Util.reflect(SubServerContainer.class.getDeclaredField("template"), forward, Util.reflect(SubServerContainer.class.getDeclaredField("template"), this));
|
||||
groups.addAll(getGroups());
|
||||
for (String group : groups) {
|
||||
removeGroup(group);
|
||||
forward.addGroup(group);
|
||||
}
|
||||
for (SubServer server : getIncompatibilities()) {
|
||||
toggleCompatibility(server);
|
||||
forward.toggleCompatibility(server);
|
||||
}
|
||||
for (String extra : getExtra().getKeys()) forward.addExtra(extra, getExtra(extra));
|
||||
|
||||
if (state) pending.set("state", true);
|
||||
c += (perma)?forward.permaEdit(player, pending):forward.edit(player, pending);
|
||||
break;
|
||||
if (state) pending.set("state", true);
|
||||
c += (perma)?forward.permaEdit(player, pending):forward.edit(player, pending);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isRunning() && forward == null && state) start(player);
|
||||
return c;
|
||||
if (!isRunning() && forward == null && state) start(player);
|
||||
return c;
|
||||
} else return -1;
|
||||
} private <V> void waitFor(ReturnRunnable<V> method, V value) throws InterruptedException {
|
||||
while (method.run() != value) {
|
||||
Thread.sleep(250);
|
||||
@ -467,14 +487,14 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return enabled && host.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean value) {
|
||||
if (Util.isNull(value)) throw new NullPointerException();
|
||||
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("enabled", value), false));
|
||||
if (enabled != value) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_ENABLED, (Boolean) value));
|
||||
if (enabled != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_ENABLED, (Boolean) value));
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
@ -487,7 +507,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
public void setLogging(boolean value) {
|
||||
if (Util.isNull(value)) throw new NullPointerException();
|
||||
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("log", value), false));
|
||||
if (log.get() != value) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_LOGGING, (Boolean) value));
|
||||
if (log.get() != value) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_LOGGING, (Boolean) value));
|
||||
log.set(value);
|
||||
}
|
||||
|
||||
@ -520,7 +540,7 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
public void setStopCommand(String value) {
|
||||
if (Util.isNull(value)) throw new NullPointerException();
|
||||
host.plugin.getPluginManager().callEvent(new SubEditServerEvent(null, this, new NamedContainer<String, Object>("stop-cmd", value), false));
|
||||
if (!stopcmd.equals(value)) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_STOP_COMMAND, value));
|
||||
if (!stopcmd.equals(value)) host.queue(new PacketExEditServer(this, PacketExEditServer.UpdateType.SET_STOP_COMMAND, value));
|
||||
stopcmd = value;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
|
||||
import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.SubCreatorException;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
@ -40,10 +41,12 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
private class CreatorTask extends Thread {
|
||||
private final UUID player;
|
||||
private final SubServer update;
|
||||
private final String name;
|
||||
private final ServerTemplate template;
|
||||
private final Version version;
|
||||
private final int port;
|
||||
private final String prefix;
|
||||
private final InternalSubLogger log;
|
||||
private final Callback<SubServer> callback;
|
||||
private Process process;
|
||||
@ -51,11 +54,24 @@ public class InternalSubCreator extends SubCreator {
|
||||
private CreatorTask(UUID player, String name, ServerTemplate template, Version version, int port, Callback<SubServer> callback) {
|
||||
super("SubServers.Bungee::Internal_SubCreator_Process_Handler(" + name + ')');
|
||||
this.player = player;
|
||||
this.update = null;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.log = new InternalSubLogger(null, this, name + File.separator + "Creator", InternalSubCreator.this.log, null);
|
||||
this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Creator", InternalSubCreator.this.log, null);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
private CreatorTask(UUID player, SubServer server, 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.version = version;
|
||||
this.port = server.getAddress().getPort();
|
||||
this.log = new InternalSubLogger(null, this, prefix = name + File.separator + "Updater", InternalSubCreator.this.log, null);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@ -70,26 +86,31 @@ public class InternalSubCreator extends SubCreator {
|
||||
if (templates.keySet().contains(other.toLowerCase())) {
|
||||
if (templates.get(other.toLowerCase()).isEnabled()) {
|
||||
if (version != null || !templates.get(other.toLowerCase()).requiresVersion()) {
|
||||
ObjectMap<String> config = build(dir, templates.get(other.toLowerCase()), history);
|
||||
if (config == null) {
|
||||
throw new SubCreatorException();
|
||||
if (update == null || templates.get(other.toLowerCase()).canUpdate()) {
|
||||
ObjectMap<String> config = build(dir, templates.get(other.toLowerCase()), history);
|
||||
if (config == null) {
|
||||
throw new SubCreatorException();
|
||||
} else {
|
||||
server.setAll(config);
|
||||
}
|
||||
} else {
|
||||
server.setAll(config);
|
||||
Logger.get(prefix).info("Skipping template that cannot be run in update mode: " + other);
|
||||
}
|
||||
} else {
|
||||
System.out.println(name + File.separator + "Creator > Skipping template that requires extra versioning: " + other);
|
||||
Logger.get(prefix).info("Skipping template that requires extra versioning: " + other);
|
||||
}
|
||||
} else {
|
||||
System.out.println(name + File.separator + "Creator > Skipping disabled template: " + other);
|
||||
Logger.get(prefix).info("Skipping disabled template: " + other);
|
||||
}
|
||||
} else {
|
||||
System.out.println(name + File.separator + "Creator > Skipping missing template: " + other);
|
||||
Logger.get(prefix).info("Skipping missing template: " + other);
|
||||
}
|
||||
}
|
||||
server.setAll(template.getConfigOptions());
|
||||
try {
|
||||
System.out.println(name + File.separator + "Creator > Loading Template: " + template.getDisplayName());
|
||||
Logger.get(prefix).info("Loading Template: " + template.getDisplayName());
|
||||
Util.copyDirectory(template.getDirectory(), dir);
|
||||
var.put("mode", (update == null)?"CREATE":"UPDATE");
|
||||
var.put("name", name);
|
||||
var.put("host", host.getName());
|
||||
var.put("template", template.getName());
|
||||
@ -101,7 +122,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
case SPONGE:
|
||||
case FORGE:
|
||||
if (version != null) {
|
||||
System.out.println(name + File.separator + "Creator > Searching Versions...");
|
||||
Logger.get(prefix).info("Searching Versions...");
|
||||
ObjectMap<String> spversionmanifest = new ObjectMap<String>(new Gson().fromJson("{\"versions\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://dl-api.spongepowered.org/v1/org.spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/downloads?type=stable&minecraft=" + version).openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
|
||||
|
||||
ObjectMap<String> spprofile = null;
|
||||
@ -114,11 +135,11 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
if (spversion == null)
|
||||
throw new InvalidServerException("Cannot find Sponge version for Minecraft " + version.toString());
|
||||
System.out.println(name + File.separator + "Creator > Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
||||
Logger.get(prefix).info("Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
|
||||
|
||||
if (template.getType() == ServerType.FORGE) {
|
||||
Version mcfversion = new Version(((spprofile.getMap("dependencies").getRawString("forge").contains("-"))?"":spprofile.getMap("dependencies").getRawString("minecraft") + '-') + spprofile.getMap("dependencies").getRawString("forge"));
|
||||
System.out.println(name + File.separator + "Creator > Found \"forge-" + mcfversion.toString() + '"');
|
||||
Logger.get(prefix).info("Found \"forge-" + mcfversion.toString() + '"');
|
||||
|
||||
var.put("mcf_version", mcfversion.toString());
|
||||
}
|
||||
@ -144,7 +165,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(name + File.separator + "Creator > Launching Build Script...");
|
||||
Logger.get(prefix).info("Launching Build Script...");
|
||||
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(gitBash, template.getBuildOptions().getRawString("Executable"))).directory(dir);
|
||||
pb.environment().putAll(var);
|
||||
process = pb.start();
|
||||
@ -178,7 +199,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
UniversalFile dir = new UniversalFile(new File(host.getPath()), name);
|
||||
File dir = (update != null)?new File(update.getFullPath()):new File(host.getPath(), name);
|
||||
dir.mkdirs();
|
||||
ObjectMap<String> server = new ObjectMap<String>();
|
||||
ObjectMap<String> config;
|
||||
@ -195,43 +216,48 @@ public class InternalSubCreator extends SubCreator {
|
||||
|
||||
if (config != null) {
|
||||
try {
|
||||
System.out.println(name + File.separator + "Creator > Saving...");
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
|
||||
host.plugin.exServers.remove(name.toLowerCase());
|
||||
Logger.get(prefix).info("Saving...");
|
||||
SubServer subserver = update;
|
||||
if (update == null) {
|
||||
if (host.plugin.exServers.keySet().contains(name.toLowerCase()))
|
||||
host.plugin.exServers.remove(name.toLowerCase());
|
||||
|
||||
config = new ObjectMap<String>((Map<String, ?>) convert(config.get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
|
||||
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")),
|
||||
new NamedContainer<>("$address$", host.getAddress().getHostAddress()), new NamedContainer<>("$port$", Integer.toString(port))));
|
||||
config = new ObjectMap<String>((Map<String, ?>) convert(config.get(), new NamedContainer<>("$player$", (player == null)?"":player.toString()), new NamedContainer<>("$name$", name),
|
||||
new NamedContainer<>("$template$", template.getName()), new NamedContainer<>("$type$", template.getType().toString()), new NamedContainer<>("$version$", version.toString().replace(" ", "@")),
|
||||
new NamedContainer<>("$address$", host.getAddress().getHostAddress()), new NamedContainer<>("$port$", Integer.toString(port))));
|
||||
|
||||
server.set("Enabled", true);
|
||||
server.set("Display", "");
|
||||
server.set("Host", host.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);
|
||||
server.setAll(config);
|
||||
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);
|
||||
server.setAll(config);
|
||||
|
||||
SubServer 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"));
|
||||
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();
|
||||
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(getTemplate(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();
|
||||
}
|
||||
|
||||
InternalSubCreator.this.thread.remove(name.toLowerCase());
|
||||
callback.run(subserver);
|
||||
@ -239,7 +265,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println(name + File.separator + "Creator > Couldn't build the server jar. Check the SubCreator logs for more detail.");
|
||||
Logger.get(prefix).info("Couldn't build the server jar. Check the SubCreator logs for more detail.");
|
||||
}
|
||||
InternalSubCreator.this.thread.remove(name.toLowerCase());
|
||||
} private Object convert(Object value, NamedContainer<String, String>... replacements) {
|
||||
@ -300,7 +326,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
if (config.getKeys().contains("Display")) template.setDisplayName(config.getString("Display"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(host.getName() + File.separator + "Creator > Couldn't load template: " + file.getName());
|
||||
Logger.get(host.getName() + File.separator + "Creator").info("Couldn't load template: " + file.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -347,6 +373,39 @@ public class InternalSubCreator extends SubCreator {
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean update(UUID player, SubServer server, Version version, Callback<SubServer> 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())) {
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
|
||||
Util.isException(() -> Util.reflect(SubServerContainer.class.getDeclaredField("lock"), server, true));
|
||||
|
||||
CreatorTask task = new CreatorTask(player, server, version, x -> {
|
||||
Util.isException(() -> Util.reflect(SubServerContainer.class.getDeclaredField("lock"), server, false));
|
||||
if (callback != null && x != null) try {
|
||||
callback.run(x);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
});
|
||||
this.thread.put(server.getName().toLowerCase(), task);
|
||||
|
||||
final SubCreateEvent event = new SubCreateEvent(player, server, version);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
task.start();
|
||||
return true;
|
||||
} else {
|
||||
this.thread.remove(server.getName().toLowerCase());
|
||||
return false;
|
||||
}
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminate() {
|
||||
HashMap<String, CreatorTask> temp = new HashMap<String, CreatorTask>();
|
||||
@ -460,10 +519,12 @@ public class InternalSubCreator extends SubCreator {
|
||||
Files.delete(new UniversalFile(dir, "subservers.client").toPath());
|
||||
if (type == ServerType.SPIGOT) {
|
||||
if (!new UniversalFile(dir, "plugins").exists()) new UniversalFile(dir, "plugins").mkdirs();
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
|
||||
if (!new UniversalFile(dir, "plugins:SubServers.Client.jar").exists())
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
|
||||
} else if (type == ServerType.FORGE || type == ServerType.SPONGE) {
|
||||
if (!new UniversalFile(dir, "mods").exists()) new UniversalFile(dir, "mods").mkdirs();
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
|
||||
if (!new UniversalFile(dir, "mods:SubServers.Client.jar").exists())
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
|
||||
}
|
||||
YAMLSection config = new YAMLSection();
|
||||
FileWriter writer = new FileWriter(new UniversalFile(dir, "subdata.json"), false);
|
||||
@ -473,7 +534,7 @@ public class InternalSubCreator extends SubCreator {
|
||||
writer.write(config.toJSON().toString());
|
||||
writer.close();
|
||||
|
||||
if (new UniversalFile("SubServers:subdata.rsa.key").exists()) {
|
||||
if (!new UniversalFile(dir, "subdata.rsa.key").exists() && new UniversalFile("SubServers:subdata.rsa.key").exists()) {
|
||||
Files.copy(new UniversalFile("SubServers:subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ public class InternalSubServer extends SubServerContainer {
|
||||
|
||||
@Override
|
||||
public boolean start(UUID player) {
|
||||
if (!lock && isEnabled() && !(thread != null && thread.isAlive()) && getCurrentIncompatibilities().size() == 0) {
|
||||
if (!lock && isAvailable() && isEnabled() && !(thread != null && thread.isAlive()) && getCurrentIncompatibilities().size() == 0) {
|
||||
lock = true;
|
||||
SubStartEvent event = new SubStartEvent(player, this);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
@ -269,251 +269,271 @@ public class InternalSubServer extends SubServerContainer {
|
||||
|
||||
@SuppressWarnings({"deprecation", "unchecked"})
|
||||
private int edit(UUID player, ObjectMap<String> edit, boolean perma) {
|
||||
int c = 0;
|
||||
boolean state = isRunning();
|
||||
SubServer forward = null;
|
||||
ObjectMap<String> pending = edit.clone();
|
||||
for (String key : edit.getKeys()) {
|
||||
pending.remove(key);
|
||||
ObjectMapValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), perma);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
switch (key.toLowerCase()) {
|
||||
case "name":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.servers.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.servers.save();
|
||||
if (isAvailable()) {
|
||||
int c = 0;
|
||||
boolean state = isRunning();
|
||||
SubServer forward = null;
|
||||
ObjectMap<String> pending = edit.clone();
|
||||
for (String key : edit.getKeys()) {
|
||||
pending.remove(key);
|
||||
ObjectMapValue value = edit.get(key);
|
||||
SubEditServerEvent event = new SubEditServerEvent(player, this, new NamedContainer<String, ObjectMapValue>(key, value), perma);
|
||||
host.plugin.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
try {
|
||||
switch (key.toLowerCase()) {
|
||||
case "name":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.servers.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.servers.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "display":
|
||||
if (value.isString()) {
|
||||
Field f = ServerContainer.class.getDeclaredField("nick");
|
||||
f.setAccessible(true);
|
||||
if (value == null || value.asString().length() == 0 || getName().equals(value)) {
|
||||
f.set(this, null);
|
||||
} else {
|
||||
f.set(this, value.asString());
|
||||
}
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
break;
|
||||
case "display":
|
||||
if (value.isString()) {
|
||||
Field f = ServerContainer.class.getDeclaredField("nick");
|
||||
f.setAccessible(true);
|
||||
if (value.isNull() || value.asString().length() == 0 || getName().equals(value.asString())) {
|
||||
f.set(this, null);
|
||||
} else {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
f.set(this, value.asString());
|
||||
}
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "enabled":
|
||||
if (value.isBoolean()) {
|
||||
enabled = value.asBoolean();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "host":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "port":
|
||||
if (value.isNumber() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "log":
|
||||
if (value.isBoolean()) {
|
||||
log.set(value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "dir":
|
||||
case "directory":
|
||||
if (value.isString()) {
|
||||
if (isRunning()) {
|
||||
stop(player);
|
||||
waitFor();
|
||||
}
|
||||
dir = value.asRawString();
|
||||
directory = new File(getHost().getPath(), value.asRawString());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Directory", getPath());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "exec":
|
||||
case "executable":
|
||||
if (value.isString()) {
|
||||
if (isRunning()) {
|
||||
stop(player);
|
||||
waitFor();
|
||||
}
|
||||
executable = value.asRawString();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "stop-cmd":
|
||||
case "stop-command":
|
||||
if (value.isString()) {
|
||||
stopcmd = value.asRawString();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "stop-action":
|
||||
if (value.isString()) {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
} else {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
}
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "state":
|
||||
if (value.isBoolean()) {
|
||||
state = value.asBoolean();
|
||||
}
|
||||
break;
|
||||
case "auto-run":
|
||||
case "run-on-launch":
|
||||
if (value.isBoolean()) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "enabled":
|
||||
if (value.isBoolean()) {
|
||||
enabled = value.asBoolean();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "incompatible":
|
||||
if (value.isList()) {
|
||||
for (String oname : (List<String>) value.asStringList()) {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
break;
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asRawStringList());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Group", value.asRawStringList());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "host":
|
||||
if (value.isString() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "template":
|
||||
if (value.isString()) {
|
||||
Util.reflect(SubServerContainer.class.getDeclaredField("template"), this, value.asRawString());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Template", value.asRawString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.servers.save();
|
||||
break;
|
||||
case "port":
|
||||
if (value.isNumber() && host.removeSubServer(player, getName())) {
|
||||
SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), isHidden(), isRestricted());
|
||||
if (server != null) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
forward = server;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (forward != null) {
|
||||
forward.setStopAction(getStopAction());
|
||||
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
|
||||
List<String> groups = new ArrayList<String>();
|
||||
groups.addAll(getGroups());
|
||||
for (String group : groups) {
|
||||
removeGroup(group);
|
||||
forward.addGroup(group);
|
||||
break;
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "log":
|
||||
if (value.isBoolean()) {
|
||||
log.set(value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "dir":
|
||||
case "directory":
|
||||
if (value.isString()) {
|
||||
if (isRunning()) {
|
||||
stop(player);
|
||||
waitFor();
|
||||
}
|
||||
dir = value.asRawString();
|
||||
directory = new File(getHost().getPath(), value.asRawString());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Directory", getPath());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "exec":
|
||||
case "executable":
|
||||
if (value.isString()) {
|
||||
if (isRunning()) {
|
||||
stop(player);
|
||||
waitFor();
|
||||
}
|
||||
executable = value.asRawString();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "stop-cmd":
|
||||
case "stop-command":
|
||||
if (value.isString()) {
|
||||
stopcmd = value.asRawString();
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "stop-action":
|
||||
if (value.isString()) {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "state":
|
||||
if (value.isBoolean()) {
|
||||
state = value.asBoolean();
|
||||
}
|
||||
break;
|
||||
case "auto-run":
|
||||
case "run-on-launch":
|
||||
if (value.isBoolean()) {
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "incompatible":
|
||||
if (value.isList()) {
|
||||
for (SubServer oserver : getIncompatibilities()) toggleCompatibility(oserver);
|
||||
for (String oname : (List<String>) value.asStringList()) {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
}
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (perma && this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
case "whitelist":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("whitelist"), this, value.asUUIDList());
|
||||
c++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
for (SubServer server : getIncompatibilities()) {
|
||||
toggleCompatibility(server);
|
||||
forward.toggleCompatibility(server);
|
||||
}
|
||||
for (String extra : getExtra().getKeys()) forward.addExtra(extra, getExtra(extra));
|
||||
if (forward != null) {
|
||||
forward.setStopAction(getStopAction());
|
||||
if (!getName().equals(getDisplayName())) forward.setDisplayName(getDisplayName());
|
||||
Util.reflect(SubServerContainer.class.getDeclaredField("template"), forward, Util.reflect(SubServerContainer.class.getDeclaredField("template"), this));
|
||||
List<String> groups = new ArrayList<String>();
|
||||
groups.addAll(getGroups());
|
||||
for (String group : groups) {
|
||||
removeGroup(group);
|
||||
forward.addGroup(group);
|
||||
}
|
||||
for (SubServer server : getIncompatibilities()) {
|
||||
toggleCompatibility(server);
|
||||
forward.toggleCompatibility(server);
|
||||
}
|
||||
for (String extra : getExtra().getKeys()) forward.addExtra(extra, getExtra(extra));
|
||||
|
||||
if (state) pending.set("state", true);
|
||||
c += (perma)?forward.permaEdit(player, pending):forward.edit(player, pending);
|
||||
break;
|
||||
if (state) pending.set("state", true);
|
||||
c += (perma)?forward.permaEdit(player, pending):forward.edit(player, pending);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isRunning() && forward == null && state) start(player);
|
||||
return c;
|
||||
if (!isRunning() && forward == null && state) start(player);
|
||||
return c;
|
||||
} else return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -541,7 +561,7 @@ public class InternalSubServer extends SubServerContainer {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
return enabled && host.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -195,7 +195,7 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
@Override
|
||||
public void whitelist(UUID player) {
|
||||
if (Util.isNull(player)) throw new NullPointerException();
|
||||
whitelist.add(player);
|
||||
if (!whitelist.contains(player)) whitelist.add(player);
|
||||
for (Proxy proxy : SubAPI.getInstance().getProxies().values()) if (proxy.getSubData()[0] != null) ((SubDataClient) proxy.getSubData()[0]).sendPacket(new PacketOutExUpdateWhitelist(getName(), true, player));
|
||||
}
|
||||
|
||||
@ -249,7 +249,7 @@ public class ServerContainer extends BungeeServerInfo implements Server {
|
||||
info.set("group", getGroups());
|
||||
info.set("address", getAddress().getAddress().getHostAddress() + ':' + getAddress().getPort());
|
||||
info.set("motd", getMotd());
|
||||
info.set("whitelist", whitelist);
|
||||
info.set("whitelist", getWhitelist());
|
||||
info.set("restricted", isRestricted());
|
||||
info.set("hidden", isHidden());
|
||||
ObjectMap<String> players = new ObjectMap<String>();
|
||||
|
@ -140,6 +140,15 @@ public abstract class SubCreator {
|
||||
return getBuildOptions().getBoolean("Require-Version", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template can be used to update it's servers
|
||||
*
|
||||
* @return Updatable Status
|
||||
*/
|
||||
public boolean canUpdate() {
|
||||
return getBuildOptions().getBoolean("Can-Update", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Build Options for this Template
|
||||
*
|
||||
@ -167,6 +176,7 @@ public abstract class SubCreator {
|
||||
tinfo.set("icon", getIcon());
|
||||
tinfo.set("type", getType().toString());
|
||||
tinfo.set("version-req", requiresVersion());
|
||||
tinfo.set("can-update", canUpdate());
|
||||
return tinfo;
|
||||
}
|
||||
}
|
||||
@ -191,6 +201,7 @@ public abstract class SubCreator {
|
||||
* @param template Server Template
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param callback Callback
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback);
|
||||
@ -216,6 +227,7 @@ public abstract class SubCreator {
|
||||
* @param template Server Template
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param callback Callback
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean create(String name, ServerTemplate template, Version version, Integer port, Callback<SubServer> callback) {
|
||||
@ -235,6 +247,52 @@ public abstract class SubCreator {
|
||||
return create(null, name, template, version, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @param callback Callback
|
||||
* @return Success Status
|
||||
*/
|
||||
public abstract boolean update(UUID player, SubServer server, Version version, Callback<SubServer> callback);
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @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<SubServer> callback) {
|
||||
return update(null, server, version, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @return Success Status
|
||||
*/
|
||||
public boolean update(SubServer server, Version version) {
|
||||
return update(null, server, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminate All SubCreator Instances on this host
|
||||
*/
|
||||
|
@ -226,6 +226,27 @@ public interface SubServer extends Server {
|
||||
*/
|
||||
Host getHost();
|
||||
|
||||
/**
|
||||
* Grabs the Template this Server was created from
|
||||
*
|
||||
* @return The Template
|
||||
*/
|
||||
SubCreator.ServerTemplate getTemplate();
|
||||
|
||||
/**
|
||||
* Sets the Template this Server was created from
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
void setTemplate(SubCreator.ServerTemplate value);
|
||||
|
||||
/**
|
||||
* Is this Host Available?
|
||||
*
|
||||
* @return Availability Status
|
||||
*/
|
||||
boolean isAvailable();
|
||||
|
||||
/**
|
||||
* If the Server is Enabled
|
||||
*
|
||||
|
@ -14,6 +14,8 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class SubServerContainer extends ServerContainer implements SubServer {
|
||||
private List<NamedContainer<String, String>> incompatibilities = new ArrayList<NamedContainer<String, String>>();
|
||||
private String template = null;
|
||||
private boolean lock;
|
||||
|
||||
/**
|
||||
* Creates a SubServer
|
||||
@ -54,6 +56,25 @@ public abstract class SubServerContainer extends ServerContainer implements SubS
|
||||
return permaEdit(null, edit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !lock && getHost().isAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemplate(SubCreator.ServerTemplate template) {
|
||||
this.template = (template != null)?template.getName():null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubCreator.ServerTemplate getTemplate() {
|
||||
if (template != null && getHost().getCreator().getTemplates().keySet().contains(template.toLowerCase())) {
|
||||
return getHost().getCreator().getTemplate(template.toLowerCase());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullPath() {
|
||||
return new File(getHost().getPath(), getPath()).getPath();
|
||||
@ -112,6 +133,8 @@ public abstract class SubServerContainer extends ServerContainer implements SubS
|
||||
ObjectMap<String> sinfo = super.forSubData();
|
||||
sinfo.set("type", "SubServer");
|
||||
sinfo.set("host", getHost().getName());
|
||||
sinfo.set("template", (getTemplate() != null)?getTemplate().getName():null);
|
||||
sinfo.set("available", isAvailable());
|
||||
sinfo.set("enabled", isEnabled());
|
||||
sinfo.set("editable", isEditable());
|
||||
sinfo.set("log", isLogging());
|
||||
|
@ -8,6 +8,16 @@ import net.md_5.bungee.api.plugin.Command;
|
||||
*/
|
||||
public class GalaxiCommand {
|
||||
|
||||
/**
|
||||
* Group similar Commands
|
||||
*
|
||||
* @param commands Command Classes
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static void group(Class<? extends Command>... commands) {
|
||||
Util.isException(() -> Util.reflect(GalaxiCommandWrapper.class.getDeclaredConstructor(Class[].class), (Object) commands));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Description of a Command
|
||||
*
|
||||
|
@ -0,0 +1,75 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Compatibility;
|
||||
|
||||
import net.ME1312.Galaxi.Galaxi;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Plugin.Command.Command;
|
||||
import net.ME1312.Galaxi.Plugin.Command.CommandSender;
|
||||
import net.ME1312.Galaxi.Plugin.Command.CompletionHandler;
|
||||
import net.ME1312.Galaxi.Plugin.PluginManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class GalaxiCommandWrapper extends Command implements CompletionHandler {
|
||||
private HashMap<String, Command> forwards = new HashMap<String, Command>();
|
||||
private Command data;
|
||||
|
||||
@SafeVarargs
|
||||
GalaxiCommandWrapper(Class<? extends Command>... commands) {
|
||||
super(Galaxi.getInstance().getAppInfo());
|
||||
|
||||
Map<String, Command> registered = Util.getDespiteException(() -> Util.reflect(PluginManager.class.getDeclaredField("commands"), Galaxi.getInstance().getPluginManager()), null);
|
||||
ArrayList<String> tmp = new ArrayList<String>();
|
||||
tmp.addAll(registered.keySet());
|
||||
for (String alias : tmp) {
|
||||
Command command = registered.get(alias);
|
||||
for (Class<? extends Command> type : commands) {
|
||||
if (type.isInstance(command)) {
|
||||
forwards.put(alias, command);
|
||||
if (data == null) data = command;
|
||||
registered.remove(alias);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
register(forwards.keySet().toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(CommandSender sender, String label, String[] args) {
|
||||
if (forwards.keySet().contains(label.toLowerCase())) {
|
||||
forwards.get(label.toLowerCase()).command(sender, label, args);
|
||||
} else {
|
||||
throw new IllegalStateException("Command label not recognised in group: " + forwards.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] complete(CommandSender sender, String label, String[] args) {
|
||||
if (forwards.keySet().contains(label.toLowerCase())) {
|
||||
Command command = forwards.get(label.toLowerCase());
|
||||
if (command.autocomplete() != null) {
|
||||
return command.autocomplete().complete(sender, label, args);
|
||||
} else return new String[0];
|
||||
} else {
|
||||
throw new IllegalStateException("Command label not recognised in group: " + forwards.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return (data == null)?super.description():data.description();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] help() {
|
||||
return (data == null)?super.help():data.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] usage() {
|
||||
return (data == null)?super.usage():data.usage();
|
||||
}
|
||||
}
|
@ -154,6 +154,8 @@ public class ConfigUpdater {
|
||||
if (existing.getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").equalsIgnoreCase("DELETE_SERVER"))
|
||||
updated.getMap("Servers").getMap(name).set("Stop-Action", "RECYCLE_SERVER");
|
||||
}
|
||||
|
||||
existing = updated.clone();
|
||||
i++;
|
||||
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||
// // do something
|
||||
@ -177,6 +179,7 @@ public class ConfigUpdater {
|
||||
server.set("Enabled", updated.getMap("Servers").getMap(name).getBoolean("Enabled", false));
|
||||
server.set("Display", updated.getMap("Servers").getMap(name).getRawString("Display", ""));
|
||||
server.set("Host", updated.getMap("Servers").getMap(name).getRawString("Host", "~"));
|
||||
if (updated.getMap("Servers").getMap(name).contains("Template")) server.set("Template", updated.getMap("Servers").getMap(name).getRawString("Template"));
|
||||
server.set("Group", updated.getMap("Servers").getMap(name).getRawStringList("Groups", Collections.emptyList()));
|
||||
server.set("Port", updated.getMap("Servers").getMap(name).getInt("Port", 25567));
|
||||
server.set("Motd", updated.getMap("Servers").getMap(name).getRawString("Motd", "Some SubServer"));
|
||||
@ -220,7 +223,9 @@ public class ConfigUpdater {
|
||||
i++;
|
||||
Logger.get("SubServers").info("Created ./SubServers/lang.yml");
|
||||
} else {
|
||||
if (was.compareTo(new Version("19w17a")) <= 0) {
|
||||
if (was.compareTo(new Version("19w22b")) <= 0) {
|
||||
updated.getMap("Lang").remove("Interface.Host-Admin.SubServers");
|
||||
updated.getMap("Lang").remove("Interface.SubServer-Admin.Command");
|
||||
i++;
|
||||
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||
// // do something
|
||||
@ -274,6 +279,7 @@ public class ConfigUpdater {
|
||||
lang.set("Command.Help.SubServer.Stop", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Help.SubServer.Stop", " &7Stop Server:&f $str$"));
|
||||
lang.set("Command.Help.SubServer.Terminate", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Help.SubServer.Terminate", " &7Terminate Server:&f $str$"));
|
||||
lang.set("Command.Help.SubServer.Command", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Help.SubServer.Command", " &7Command Server:&f $str$"));
|
||||
lang.set("Command.Help.SubServer.Update", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Help.SubServer.Update", " &7Update Server:&f $str$"));
|
||||
lang.set("Command.Version", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Version", "&7SubServers &8&l\u00BB&7 These are the platforms and versions that are running &f$str$&7:"));
|
||||
lang.set("Command.Version.Outdated", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Version.Outdated", "&7$name$ &f$str$ &7is available. You are $int$ version(s) behind."));
|
||||
lang.set("Command.Version.Latest", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Version.Latest", "&7You are on the latest version."));
|
||||
@ -298,6 +304,7 @@ public class ConfigUpdater {
|
||||
lang.set("Command.Start.Invalid", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Invalid", "&cSubServers &4&l\u00BB&c That Server is not a SubServer"));
|
||||
lang.set("Command.Start.Host-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Host-Unavailable", "&cSubServers &4&l\u00BB&c That SubServer\u0027s Host is not available"));
|
||||
lang.set("Command.Start.Host-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Host-Disabled", "&cSubServers &4&l\u00BB&c That SubServer\u0027s Host is not enabled"));
|
||||
lang.set("Command.Start.Server-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Server-Unavailable", "&cSubServers &4&l\u00BB&c That SubServer is not available"));
|
||||
lang.set("Command.Start.Server-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Server-Disabled", "&cSubServers &4&l\u00BB&c That SubServer is not enabled"));
|
||||
lang.set("Command.Start.Server-Incompatible", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Server-Incompatible", "&cSubServers &4&l\u00BB&c That SubServer cannot start while these server(s) are running: &4$str$"));
|
||||
lang.set("Command.Start.Running", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Start.Running", "&cSubServers &4&l\u00BB&c That SubServer is already running"));
|
||||
@ -308,6 +315,7 @@ public class ConfigUpdater {
|
||||
lang.set("Command.Restart.Disappeared", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Restart.Disappeared", "&cSubServers &4&l\u00BB&c Could not restart server: That SubServer has disappeared"));
|
||||
lang.set("Command.Restart.Host-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Restart.Host-Unavailable", "&cSubServers &4&l\u00BB&c Could not restart server: That SubServer\u0027s Host is no longer available"));
|
||||
lang.set("Command.Restart.Host-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Restart.Host-Disabled", "&cSubServers &4&l\u00BB&c Could not restart server: That SubServer\u0027s Host is no longer enabled"));
|
||||
lang.set("Command.Restart.Server-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Restart.Server-Unavailable", "&cSubServers &4&l\u00BB&c Could not restart server: That SubServer is no longer available"));
|
||||
lang.set("Command.Restart.Server-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Restart.Server-Disabled", "&cSubServers &4&l\u00BB&c Could not restart server: That SubServer is no longer enabled"));
|
||||
lang.set("Command.Restart.Server-Incompatible", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Restart.Server-Incompatible", "&cSubServers &4&l\u00BB&c Could not restart server: That SubServer cannot start while these server(s) are running: &4$str$"));
|
||||
lang.set("Command.Stop", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Stop", "&aSubServers &2&l\u00BB&a Stopping SubServer"));
|
||||
@ -331,6 +339,17 @@ public class ConfigUpdater {
|
||||
lang.set("Command.Creator.Template-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Creator.Template-Disabled", "&cSubServers &4&l\u00BB&c That Template is not enabled"));
|
||||
lang.set("Command.Creator.Version-Required", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Creator.Version-Required", "&cSubServers &4&l\u00BB&c That Template requires a Minecraft Version to be specified"));
|
||||
lang.set("Command.Creator.Invalid-Port", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Creator.Invalid-Port", "&cSubServers &4&l\u00BB&c Invalid Port Number"));
|
||||
lang.set("Command.Update", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Creator", "&aSubServers &2&l\u00BB&a Updating SubServer"));
|
||||
lang.set("Command.Update.Unknown", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Unknown", "&cSubServers &4&l\u00BB&c There is no Server with that name"));
|
||||
lang.set("Command.Update.Invalid", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Invalid", "&cSubServers &4&l\u00BB&c That Server is not a SubServer"));
|
||||
lang.set("Command.Update.Host-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Host-Unavailable", "&cSubServers &4&l\u00BB&c That SubServer\u0027s Host is not available"));
|
||||
lang.set("Command.Update.Host-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Host-Disabled", "&cSubServers &4&l\u00BB&c That SubServer\u0027s Host is not enabled"));
|
||||
lang.set("Command.Update.Server-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Server-Unavailable", "&cSubServers &4&l\u00BB&c That SubServer is not available"));
|
||||
lang.set("Command.Update.Running", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Running", "&cSubServers &4&l\u00BB&c Cannot update servers while they are still running"));
|
||||
lang.set("Command.Update.Unknown-Template", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Unknown-Template", "&cSubServers &4&l\u00BB&c We don't know which template created that SubServer"));
|
||||
lang.set("Command.Update.Template-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Template-Disabled", "&cSubServers &4&l\u00BB&c That SubServer's Template is not enabled"));
|
||||
lang.set("Command.Update.Template-Invalid", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Template-Invalid", "&cSubServers &4&l\u00BB&c That SubServer's Template does not support server updating"));
|
||||
lang.set("Command.Update.Version-Required", updated.getMap("Lang", new YAMLSection()).getRawString("Command.Update.Version-Required", "&cSubServers &4&l\u00BB&c That SubServer's Template requires a Minecraft Version to be specified"));
|
||||
lang.set("Interface.Generic.Back", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Generic.Back", "&cBack"));
|
||||
lang.set("Interface.Generic.Back-Arrow", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Generic.Back-Arrow", "&e&l<--"));
|
||||
lang.set("Interface.Generic.Next-Arrow", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Generic.Next-Arrow", "&e&l-->"));
|
||||
@ -355,7 +374,7 @@ public class ConfigUpdater {
|
||||
lang.set("Interface.Host-Menu.Server-Menu", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Menu.Server-Menu", "&a&lView Servers"));
|
||||
lang.set("Interface.Host-Admin.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Admin.Title", "Host/$str$"));
|
||||
lang.set("Interface.Host-Admin.Creator", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Admin.Creator", "&eCreate a SubServer"));
|
||||
lang.set("Interface.Host-Admin.SubServers", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Admin.SubServers", "&aView SubServers"));
|
||||
lang.set("Interface.Host-Admin.SubServers", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Admin.SubServers", "&bView SubServers"));
|
||||
lang.set("Interface.Host-Admin.Plugins", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Admin.Plugins", "&bPlugins..."));
|
||||
lang.set("Interface.Host-Creator.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Creator.Title", "Host/$str$/Create"));
|
||||
lang.set("Interface.Host-Creator.Edit-Name", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Host-Creator.Edit-Name", "Change Name"));
|
||||
@ -392,6 +411,7 @@ public class ConfigUpdater {
|
||||
lang.set("Interface.Server-Menu.SubServer-Temporary", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.SubServer-Temporary", "&9Temporary"));
|
||||
lang.set("Interface.Server-Menu.SubServer-Offline", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.SubServer-Offline", "&6Offline"));
|
||||
lang.set("Interface.Server-Menu.SubServer-Incompatible", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.SubServer-Incompatible", "&4Incompatible with $str$"));
|
||||
lang.set("Interface.Server-Menu.SubServer-Unavailable", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.SubServer-Unavailable", "&4Unavailable"));
|
||||
lang.set("Interface.Server-Menu.SubServer-Disabled", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.SubServer-Disabled", "&4Disabled"));
|
||||
lang.set("Interface.Server-Menu.SubServer-Invalid", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.SubServer-Invalid", "&4Cannot be managed by SubServers"));
|
||||
lang.set("Interface.Server-Menu.No-Servers", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.Server-Menu.No-Servers", "&c&oThere are No Servers"));
|
||||
@ -403,9 +423,12 @@ public class ConfigUpdater {
|
||||
lang.set("Interface.SubServer-Admin.Stop.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Stop.Title", "&cStopping $str$"));
|
||||
lang.set("Interface.SubServer-Admin.Terminate", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Terminate", "&4Terminate SubServer"));
|
||||
lang.set("Interface.SubServer-Admin.Terminate.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Terminate.Title", "&cTerminating $str$"));
|
||||
lang.set("Interface.SubServer-Admin.Command", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Command", "&eSend a Command to the SubServer"));
|
||||
lang.set("Interface.SubServer-Admin.Command", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Command", "&bSend a Command to the SubServer"));
|
||||
lang.set("Interface.SubServer-Admin.Command.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Command.Title", "&eSubServers\n&6Enter a Command to send via Chat"));
|
||||
lang.set("Interface.SubServer-Admin.Command.Message", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Command.Message", "&eSubServers &6&l\u00BB&e Enter a Command to send via Chat"));
|
||||
lang.set("Interface.SubServer-Admin.Update", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Update", "&eUpdate SubServer"));
|
||||
lang.set("Interface.SubServer-Admin.Update.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Update.Title", "&eSubServers\n&6Enter a Server Version to update to"));
|
||||
lang.set("Interface.SubServer-Admin.Update.Message", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Update.Message", "&eSubServers &6&l\u00BB&e Enter a Server Version to update to via Chat"));
|
||||
lang.set("Interface.SubServer-Admin.Plugins", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Admin.Plugins", "&bPlugins..."));
|
||||
lang.set("Interface.SubServer-Plugin.Title", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Plugin.Title", "SubServer/$str$/Plugins"));
|
||||
lang.set("Interface.SubServer-Plugin.No-Plugins", updated.getMap("Lang", new YAMLSection()).getRawString("Interface.SubServer-Plugin.No-Plugins", "&c&oThere are No Plugins Available"));
|
||||
|
@ -51,8 +51,8 @@ public class PacketCommandServer implements PacketObjectIn<Integer>, PacketObjec
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
String server = data.getRawString(0x0001);
|
||||
String command = data.getRawString(0x0002);
|
||||
UUID player = (data.contains(0x0003)?data.getUUID(0x0003):null);
|
||||
|
@ -48,8 +48,8 @@ public class PacketCreateServer implements PacketObjectIn<Integer>, PacketObject
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
try {
|
||||
UUID tracker = (data.contains(0x0000)?data.getUUID(0x0000):null);
|
||||
String name = data.getRawString(0x0001);
|
||||
String host = data.getRawString(0x0002);
|
||||
String template = data.getRawString(0x0003);
|
||||
|
@ -8,6 +8,7 @@ import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.SubDataClient;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
@ -31,6 +32,26 @@ public class PacketExCreateServer implements PacketObjectIn<Integer>, PacketObje
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExCreateServer (Out)
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @param version Server Version
|
||||
* @param log Log Address
|
||||
* @param callback Callbacks
|
||||
*/
|
||||
@SafeVarargs
|
||||
public PacketExCreateServer(SubServer server, Version version, UUID log, Callback<ObjectMap<Integer>>... callback) {
|
||||
if (Util.isNull(server, log, callback)) throw new NullPointerException();
|
||||
this.name = server.getName();
|
||||
this.template = server.getTemplate();
|
||||
this.version = version;
|
||||
this.port = server.getAddress().getPort();
|
||||
this.log = log;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExCreateServer (Out)
|
||||
*
|
||||
|
@ -13,9 +13,9 @@ import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Update External Server Packet
|
||||
* Edit External Server Packet
|
||||
*/
|
||||
public class PacketExUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private SubServer server;
|
||||
private UpdateType type;
|
||||
@ -50,22 +50,22 @@ public class PacketExUpdateServer implements PacketObjectIn<Integer>, PacketObje
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExUpdateServer (In)
|
||||
* New PacketExEditServer (In)
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketExUpdateServer(SubPlugin plugin) {
|
||||
public PacketExEditServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExUpdateServer (Out)
|
||||
* New PacketExEditServer (Out)
|
||||
*
|
||||
* @param server SubServer
|
||||
* @param type Update Type
|
||||
* @param arguments Arguments
|
||||
*/
|
||||
public PacketExUpdateServer(SubServer server, UpdateType type, Object... arguments) {
|
||||
if (arguments.length != type.getArguments().length) throw new IllegalArgumentException("Not enough arguments for type: " + type.toString());
|
||||
public PacketExEditServer(SubServer server, UpdateType type, Object... arguments) {
|
||||
if (arguments.length != type.getArguments().length) throw new IllegalArgumentException(((arguments.length > type.getArguments().length)?"Too many":"Not enough") + " arguments for type: " + type.toString());
|
||||
int i = 0;
|
||||
while (i < arguments.length) {
|
||||
if (!type.getArguments()[i].isInstance(arguments[i])) throw new IllegalArgumentException("Argument " + (i+1) + " is not " + type.getArguments()[i].getCanonicalName());
|
@ -105,8 +105,9 @@ public class PacketOutExRunEvent implements Listener, PacketObjectOut<Integer> {
|
||||
if (!event.isCancelled()) {
|
||||
ObjectMap<String> args = new ObjectMap<String>();
|
||||
if (event.getPlayer() != null) args.set("player", event.getPlayer().toString());
|
||||
args.set("host", event.getHost().getName());
|
||||
args.set("update", event.isUpdate());
|
||||
args.set("name", event.getName());
|
||||
args.set("host", event.getHost().getName());
|
||||
args.set("template", event.getTemplate().getName());
|
||||
if (event.getVersion() != null) args.set("version", event.getVersion());
|
||||
args.set("port", event.getPort());
|
||||
|
@ -62,6 +62,7 @@ public class PacketRestartServer implements PacketObjectIn<Integer>, PacketObjec
|
||||
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isAvailable()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isAvailable()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isEnabled()) {
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
|
@ -78,17 +78,19 @@ public class PacketStartServer implements PacketObjectIn<Integer>, PacketObjectO
|
||||
client.sendPacket(new PacketStartServer(5, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(6, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isEnabled()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isAvailable()) {
|
||||
client.sendPacket(new PacketStartServer(7, tracker));
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isEnabled()) {
|
||||
client.sendPacket(new PacketStartServer(8, tracker));
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).isRunning()) {
|
||||
client.sendPacket(new PacketStartServer(9, tracker));
|
||||
} else if (((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities().size() != 0) {
|
||||
String list = "";
|
||||
for (SubServer server : ((SubServer) servers.get(name.toLowerCase())).getCurrentIncompatibilities()) {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += server.getName();
|
||||
}
|
||||
client.sendPacket(new PacketStartServer(9, list, tracker));
|
||||
client.sendPacket(new PacketStartServer(10, list, tracker));
|
||||
} else {
|
||||
if (((SubServer) servers.get(name.toLowerCase())).start(player)) {
|
||||
client.sendPacket(new PacketStartServer(0, tracker));
|
||||
|
@ -0,0 +1,111 @@
|
||||
package net.ME1312.SubServers.Bungee.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
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.SubPlugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Update Server Packet
|
||||
*/
|
||||
public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private SubPlugin plugin;
|
||||
private int response;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketUpdateServer (In)
|
||||
*
|
||||
* @param plugin SubPlugin
|
||||
*/
|
||||
public PacketUpdateServer(SubPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketUpdateServer (Out)
|
||||
*
|
||||
* @param response Response ID
|
||||
* @param id Receiver ID
|
||||
*/
|
||||
public PacketUpdateServer(int response, UUID id) {
|
||||
this.response = response;
|
||||
this.tracker = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
ObjectMap<Integer> data = new ObjectMap<Integer>();
|
||||
if (tracker != null) data.set(0x0000, tracker);
|
||||
data.set(0x0001, response);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
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);
|
||||
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(name.toLowerCase())) {
|
||||
client.sendPacket(new PacketUpdateServer(3, tracker));
|
||||
} else if (!(servers.get(name.toLowerCase()) instanceof SubServer)) {
|
||||
client.sendPacket(new PacketUpdateServer(4, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isAvailable()) {
|
||||
client.sendPacket(new PacketUpdateServer(5, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).getHost().isEnabled()) {
|
||||
client.sendPacket(new PacketUpdateServer(6, tracker));
|
||||
} else if (!((SubServer) servers.get(name.toLowerCase())).isAvailable()) {
|
||||
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)) {
|
||||
if (waitfor) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
((SubServer) servers.get(name.toLowerCase())).getHost().getCreator().waitFor();
|
||||
client.sendPacket(new PacketUpdateServer(0, tracker));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, "SubServers.Bungee::SubData_SubCreator_Update_Handler(" + client.getAddress().toString() + ')').start();
|
||||
} else {
|
||||
client.sendPacket(new PacketUpdateServer(0, tracker));
|
||||
}
|
||||
} else {
|
||||
client.sendPacket(new PacketUpdateServer(1, tracker));
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
client.sendPacket(new PacketUpdateServer(2, tracker));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -9,12 +9,9 @@ import net.ME1312.SubServers.Bungee.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Bungee.Network.Packet.*;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.ME1312.SubServers.Bungee.SubPlugin;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
@ -68,22 +65,24 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
instance.registerPacket(0x0033, PacketUpdateServer.class);
|
||||
instance.registerPacket(0x0034, PacketEditServer.class);
|
||||
instance.registerPacket(0x0035, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0036, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0037, PacketStopServer.class);
|
||||
instance.registerPacket(0x0038, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0039, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer(plugin));
|
||||
instance.registerPacket(0x0031, new PacketAddServer(plugin));
|
||||
instance.registerPacket(0x0032, new PacketStartServer(plugin));
|
||||
instance.registerPacket(0x0033, new PacketEditServer(plugin));
|
||||
instance.registerPacket(0x0034, new PacketRestartServer(plugin));
|
||||
instance.registerPacket(0x0035, new PacketCommandServer(plugin));
|
||||
instance.registerPacket(0x0036, new PacketStopServer(plugin));
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer(plugin));
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer(plugin));
|
||||
instance.registerPacket(0x0033, new PacketUpdateServer(plugin));
|
||||
instance.registerPacket(0x0034, new PacketEditServer(plugin));
|
||||
instance.registerPacket(0x0035, new PacketRestartServer(plugin));
|
||||
instance.registerPacket(0x0036, new PacketCommandServer(plugin));
|
||||
instance.registerPacket(0x0037, new PacketStopServer(plugin));
|
||||
instance.registerPacket(0x0038, new PacketRemoveServer(plugin));
|
||||
instance.registerPacket(0x0039, new PacketDeleteServer(plugin));
|
||||
|
||||
|
||||
// 50-69: External Host Packets
|
||||
@ -92,7 +91,7 @@ public class SubProtocol extends SubDataProtocol {
|
||||
//instance.registerPacket(0x0052, PacketInExRequestQueue.class);
|
||||
instance.registerPacket(0x0053, PacketExCreateServer.class);
|
||||
instance.registerPacket(0x0054, PacketExAddServer.class);
|
||||
instance.registerPacket(0x0055, PacketExUpdateServer.class);
|
||||
instance.registerPacket(0x0055, PacketExEditServer.class);
|
||||
//instance.registerPacket(0x0056, PacketInExLogMessage.class);
|
||||
instance.registerPacket(0x0057, PacketExDeleteServer.class);
|
||||
instance.registerPacket(0x0058, PacketExRemoveServer.class);
|
||||
@ -102,7 +101,7 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0052, new PacketInExRequestQueue(plugin));
|
||||
instance.registerPacket(0x0053, new PacketExCreateServer(null));
|
||||
instance.registerPacket(0x0054, new PacketExAddServer());
|
||||
instance.registerPacket(0x0055, new PacketExUpdateServer(plugin));
|
||||
instance.registerPacket(0x0055, new PacketExEditServer(plugin));
|
||||
instance.registerPacket(0x0056, new PacketInExLogMessage());
|
||||
instance.registerPacket(0x0057, new PacketExDeleteServer());
|
||||
instance.registerPacket(0x0058, new PacketExRemoveServer());
|
||||
|
@ -149,6 +149,7 @@ public final class SubCommand extends CommandX {
|
||||
case "all":
|
||||
case "system":
|
||||
case "bungee":
|
||||
case "bungeecord":
|
||||
case "network":
|
||||
plugin.getPluginManager().dispatchCommand(ConsoleCommandSender.getInstance(), "greload");
|
||||
break;
|
||||
@ -210,7 +211,7 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
}
|
||||
} else if (((SubServer) server).getHost().isAvailable() && ((SubServer) server).getHost().isEnabled() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).getHost().isAvailable() && ((SubServer) server).getHost().isEnabled() && ((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -243,7 +244,7 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
}
|
||||
} else if (subserver.getHost().isEnabled() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.getHost().isAvailable() && subserver.getHost().isEnabled() && subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -297,9 +298,11 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + ChatColor.WHITE + server.getDisplayName());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + server.getName());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(" -> Available: " + ((((SubServer) server).isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + ChatColor.RED + "no");
|
||||
sender.sendMessage(" -> Host: " + ChatColor.WHITE + ((SubServer) server).getHost().getName());
|
||||
if (((SubServer) server).getTemplate() != null) sender.sendMessage(" -> Template: " + ChatColor.WHITE + ((SubServer) server).getTemplate().getName());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + ChatColor.WHITE + server.getGroups().get(0)));
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + ChatColor.WHITE + group);
|
||||
@ -422,6 +425,8 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not available");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().isEnabled()) {
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not enabled");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isAvailable()) {
|
||||
sender.sendMessage("SubServers > That SubServer is not available");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isEnabled()) {
|
||||
sender.sendMessage("SubServers > That SubServer is not enabled");
|
||||
} else if (((SubServer) servers.get(args[1].toLowerCase())).isRunning()) {
|
||||
@ -449,6 +454,8 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer's Host is no longer available");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().isEnabled()) {
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer's Host is no longer enabled");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isAvailable()) {
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer is no longer available");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isEnabled()) {
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer is no longer enabled");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isRunning()) {
|
||||
@ -600,6 +607,35 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] [Port]");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("update") || args[0].equalsIgnoreCase("upgrade")) {
|
||||
if (args.length > 1) {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
if (!servers.keySet().contains(args[1].toLowerCase())) {
|
||||
sender.sendMessage("SubServers > There is no server with that name");
|
||||
} else if (!(servers.get(args[1].toLowerCase()) instanceof SubServer)) {
|
||||
sender.sendMessage("SubServers > That Server is not a SubServer");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().isAvailable()) {
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not available");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getHost().isEnabled()) {
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not enabled");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).isAvailable()) {
|
||||
sender.sendMessage("SubServers > That SubServer is not available");
|
||||
} else if (((SubServer) servers.get(args[1].toLowerCase())).isRunning()) {
|
||||
sender.sendMessage("SubServers > Cannot update servers while they are still running");
|
||||
} else if (((SubServer) servers.get(args[1].toLowerCase())).getTemplate() == null) {
|
||||
sender.sendMessage("SubServers > We don't know which template created that SubServer");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getTemplate().isEnabled()) {
|
||||
sender.sendMessage("SubServers > That SubServer's Template is not enabled");
|
||||
} else if (!((SubServer) servers.get(args[1].toLowerCase())).getTemplate().canUpdate()) {
|
||||
sender.sendMessage("SubServers > That SubServer's Template does not support server updating");
|
||||
} else if (args.length <= 2 && ((SubServer) servers.get(args[1].toLowerCase())).getTemplate().requiresVersion()) {
|
||||
sender.sendMessage("SubServers > That SubServer's Template requires a Minecraft Version to be specified");
|
||||
} else {
|
||||
((SubServer) servers.get(args[1].toLowerCase())).getHost().getCreator().update(((SubServer) servers.get(args[1].toLowerCase())), (args.length > 2)?new Version(args[2]):null);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <SubServer> [Version]");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("del") || args[0].equalsIgnoreCase("delete")) {
|
||||
if (args.length > 1) {
|
||||
Map<String, Server> servers = plugin.api.getServers();
|
||||
@ -619,6 +655,8 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Usage: " + label + " " + args[0].toLowerCase() + " <SubServer>");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("restore")) {
|
||||
// TODO
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Unknown sub-command: " + args[0]);
|
||||
}
|
||||
@ -647,7 +685,9 @@ public final class SubCommand extends CommandX {
|
||||
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
|
||||
" Sudo Server: /sub sudo <SubServer>",
|
||||
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
|
||||
" Update Server: /sub update <SubServer> [Version]",
|
||||
" Remove Server: /sub delete <SubServer>",
|
||||
//" Restore Server: /sub restore <SubServer>",
|
||||
"",
|
||||
" To see BungeeCord supplied commands, please visit:",
|
||||
" https://www.spigotmc.org/wiki/bungeecord-commands/"
|
||||
@ -687,8 +727,8 @@ public final class SubCommand extends CommandX {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
} else if (args.length <= 1) {
|
||||
List<String> cmds = new ArrayList<>();
|
||||
cmds.addAll(Arrays.asList("help", "list", "info", "status", "version", "start", "stop", "restart", "kill", "terminate", "cmd", "command", "create"));
|
||||
if (!(sender instanceof ProxiedPlayer)) cmds.addAll(Arrays.asList("reload", "sudo", "screen", "delete"));
|
||||
cmds.addAll(Arrays.asList("help", "list", "info", "status", "version", "start", "stop", "restart", "kill", "terminate", "cmd", "command", "create", "update", "upgrade"));
|
||||
if (!(sender instanceof ProxiedPlayer)) cmds.addAll(Arrays.asList("reload", "sudo", "screen", "delete", "restore"));
|
||||
if (last.length() == 0) {
|
||||
return new NamedContainer<>(null, cmds);
|
||||
} else {
|
||||
@ -795,20 +835,28 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
} else if (!(sender instanceof ProxiedPlayer) && args[0].equals("reload")) {
|
||||
List<String> list = new ArrayList<String>(),
|
||||
completes = Arrays.asList("all", "config", "templates");
|
||||
if (args.length == 2) {
|
||||
if (last.length() == 0) {
|
||||
list = completes;
|
||||
} else {
|
||||
for (String complete : completes) {
|
||||
if (complete.toLowerCase().startsWith(last)) list.add(last + complete.substring(last.length()));
|
||||
} else if (!(sender instanceof ProxiedPlayer) && (args[0].equals("reload") || args[0].equals("restore"))) {
|
||||
if (args[0].equals("reload")) {
|
||||
List<String> list = new ArrayList<String>(),
|
||||
completes = Arrays.asList("all", "config", "templates");
|
||||
if (args.length == 2) {
|
||||
if (last.length() == 0) {
|
||||
list = completes;
|
||||
} else {
|
||||
for (String complete : completes) {
|
||||
if (complete.toLowerCase().startsWith(last)) list.add(last + complete.substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown").replace("$str$", args[0]):null, list);
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
} else /* if (args[0].equals("restore")) */ {
|
||||
if (args.length == 2) {
|
||||
return new NamedContainer<>(null, Collections.singletonList("<SubServer>"));
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown").replace("$str$", args[0]):null, list);
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
} else if (args[0].equals("start") ||
|
||||
args[0].equals("restart") ||
|
||||
@ -891,11 +939,6 @@ public final class SubCommand extends CommandX {
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template").replace("$str$", args[0]):null, list);
|
||||
} else if (args.length == 5) {
|
||||
if (last.length() > 0) {
|
||||
if (new Version("1.8").compareTo(new Version(last)) > 0) {
|
||||
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Version"), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
|
||||
} else if (args.length == 6) {
|
||||
if (last.length() > 0) {
|
||||
@ -903,7 +946,23 @@ public final class SubCommand extends CommandX {
|
||||
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>(null, Collections.singletonList("<Port>"));
|
||||
return new NamedContainer<>(null, Collections.singletonList("[Port]"));
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
} else if (args[0].equals("update") || args[0].equals("upgrade")) {
|
||||
if (args.length == 2) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (SubServer server : plugin.api.getSubServers().values()) list.add(server.getName());
|
||||
} else {
|
||||
for (SubServer server : plugin.api.getSubServers().values()) {
|
||||
if (server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", args[0]):null, list);
|
||||
} else if (args.length == 3) {
|
||||
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import net.ME1312.SubServers.Bungee.Host.*;
|
||||
import net.ME1312.SubServers.Bungee.Library.*;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.GalaxiCommand;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.Logger;
|
||||
import net.ME1312.SubServers.Bungee.Library.Fallback.SmartReconnectHandler;
|
||||
import net.ME1312.SubServers.Bungee.Library.Updates.ConfigUpdater;
|
||||
@ -74,7 +75,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public SubProtocol subprotocol;
|
||||
public SubDataServer subdata = null;
|
||||
public SubServer sudo = null;
|
||||
public static final Version version = Version.fromString("2.14a");
|
||||
public static final Version version = Version.fromString("2.14.2a");
|
||||
|
||||
public Proxy redis = null;
|
||||
public boolean canSudo = false;
|
||||
@ -133,22 +134,22 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
|
||||
Logger.get("SubServers").info("Created ./SubServers/Templates/Sponge");
|
||||
} else {
|
||||
if (new UniversalFile(dir, "Templates:Vanilla:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Vanilla:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
|
||||
if (new UniversalFile(dir, "Templates:Vanilla:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Vanilla:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.14.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "Templates:Vanilla").toPath(), new UniversalFile(dir, "Templates:Vanilla.old" + Math.round(Math.random() * 100000) + ".x").toPath());
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new UniversalFile(dir, "Templates"));
|
||||
Logger.get("SubServers").info("Updated ./SubServers/Templates/Vanilla");
|
||||
}
|
||||
if (new UniversalFile(dir, "Templates:Spigot:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Spigot:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
|
||||
if (new UniversalFile(dir, "Templates:Spigot:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Spigot:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.14.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "Templates:Spigot").toPath(), new UniversalFile(dir, "Templates:Spigot.old" + Math.round(Math.random() * 100000) + ".x").toPath());
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new UniversalFile(dir, "Templates"));
|
||||
Logger.get("SubServers").info("Updated ./SubServers/Templates/Spigot");
|
||||
}
|
||||
if (new UniversalFile(dir, "Templates:Forge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Forge:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
|
||||
if (new UniversalFile(dir, "Templates:Forge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Forge:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.14.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "Templates:Forge").toPath(), new UniversalFile(dir, "Templates:Forge.old" + Math.round(Math.random() * 100000) + ".x").toPath());
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new UniversalFile(dir, "Templates"));
|
||||
Logger.get("SubServers").info("Updated ./SubServers/Templates/Forge");
|
||||
}
|
||||
if (new UniversalFile(dir, "Templates:Sponge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Sponge:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.13.2c+")) != 0) {
|
||||
if (new UniversalFile(dir, "Templates:Sponge:template.yml").exists() && ((new YAMLConfig(new UniversalFile(dir, "Templates:Sponge:template.yml"))).get().getVersion("Version", new Version(0))).compareTo(new Version("2.14.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "Templates:Sponge").toPath(), new UniversalFile(dir, "Templates:Sponge.old" + Math.round(Math.random() * 100000) + ".x").toPath());
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
|
||||
Logger.get("SubServers").info("Updated ./SubServers/Templates/Sponge");
|
||||
@ -477,6 +478,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
edits.set("display", this.servers.get().getMap("Servers").getMap(name).getRawString("Display"));
|
||||
if (!this.servers.get().getMap("Servers").getMap(name).getString("Host").equalsIgnoreCase(server.getHost().getName()))
|
||||
edits.set("host", this.servers.get().getMap("Servers").getMap(name).getRawString("Host"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getKeys().contains("Template") && ((this.servers.get().getMap("Servers").getMap(name).getRawString("Template").length() == 0 && server.getTemplate() != null) || (this.servers.get().getMap("Servers").getMap(name).getRawString("Template").length() > 0 && server.getTemplate() == null) || (server.getTemplate() != null && !this.servers.get().getMap("Servers").getMap(name).getString("Template").equalsIgnoreCase(server.getTemplate().getName()))))
|
||||
edits.set("template", this.servers.get().getMap("Servers").getMap(name).getString("Template"));
|
||||
if (!this.servers.get().getMap("Servers").getMap(name).getStringList("Group").equals(server.getGroups()))
|
||||
edits.set("group", this.servers.get().getMap("Servers").getMap(name).getRawStringList("Group"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getInt("Port") != server.getAddress().getPort())
|
||||
@ -537,6 +540,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
autorun.add(name.toLowerCase());
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getKeys().contains("Display") && ((this.servers.get().getMap("Servers").getMap(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !this.servers.get().getMap("Servers").getMap(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(this.servers.get().getMap("Servers").getMap(name).getRawString("Display"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getKeys().contains("Template") && ((this.servers.get().getMap("Servers").getMap(name).getRawString("Template").length() == 0 && server.getTemplate() != null) || (this.servers.get().getMap("Servers").getMap(name).getRawString("Template").length() > 0 && server.getTemplate() == null) || (server.getTemplate() != null && !this.servers.get().getMap("Servers").getMap(name).getString("Template").equalsIgnoreCase(server.getTemplate().getName()))))
|
||||
server.setTemplate(server.getHost().getCreator().getTemplate(this.servers.get().getMap("Servers").getMap(name).getString("Template")));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getKeys().contains("Group")) {
|
||||
for (String group : server.getGroups()) server.removeGroup(group);
|
||||
for (String group : this.servers.get().getMap("Servers").getMap(name).getStringList("Group")) server.addGroup(group);
|
||||
@ -624,6 +629,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());
|
||||
GalaxiCommand.group(SubCommand.class);
|
||||
|
||||
new Metrics(this);
|
||||
new Timer("SubServers.Bungee::Routine_Update_Check").schedule(new TimerTask() {
|
||||
|
@ -48,7 +48,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,11 +1,15 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Library.SubEvent;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -13,6 +17,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SubCreateEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
@ -29,9 +34,10 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port, boolean update) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
@ -48,6 +54,33 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator is being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean isUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer will use
|
||||
*
|
||||
|
@ -316,6 +316,19 @@ public class DefaultUIHandler implements UIHandler, Listener {
|
||||
if (item.equals(plugin.api.getLang("SubServers", "Interface.Generic.Back"))) {
|
||||
player.closeInventory();
|
||||
gui.back();
|
||||
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update"))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.command.*") || player.hasPermission("subservers.subserver.update." + ((String) gui.lastVisitedObjects[0]).toLowerCase())) {
|
||||
if (!gui.sendTitle(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update.Title"), 4 * 20))
|
||||
player.sendMessage(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update.Message"));
|
||||
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(), (String) gui.lastVisitedObjects[0],
|
||||
(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();
|
||||
}));
|
||||
});
|
||||
} else gui.reopen();
|
||||
} else if (item.equals(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start"))) {
|
||||
player.closeInventory();
|
||||
if (player.hasPermission("subservers.subserver.start.*") || player.hasPermission("subservers.subserver.start." + ((String) gui.lastVisitedObjects[0]).toLowerCase())) {
|
||||
|
@ -3,6 +3,7 @@ package net.ME1312.SubServers.Client.Bukkit.Graphic;
|
||||
import net.ME1312.Galaxi.Library.Container;
|
||||
import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Host;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.Server;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.API.SubCreator;
|
||||
@ -240,7 +241,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Admin.Creator")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.host.create." + name.toLowerCase())));
|
||||
} else if (!host.isEnabled()) {
|
||||
} else if (!host.isAvailable() || !host.isEnabled()) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.Host-Admin.Creator")));
|
||||
@ -257,7 +258,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
inv.setItem(11, block);
|
||||
inv.setItem(12, block);
|
||||
|
||||
block = createItem("STAINED_GLASS_PANE", "LIME_STAINED_GLASS_PANE", (short) 5);
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 3);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.Host-Admin.SubServers"));
|
||||
block.setItemMeta(blockMeta);
|
||||
@ -268,7 +269,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
|
||||
if (!host.isEnabled() || hostPlugins.size() <= 0) {
|
||||
if (!host.isAvailable() || !host.isEnabled() || hostPlugins.size() <= 0) {
|
||||
block = div;
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 11);
|
||||
@ -329,7 +330,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
lastVisitedObjects[0] = options;
|
||||
|
||||
plugin.api.getHost(options.getHost(), host -> {
|
||||
if (host == null || !host.isEnabled()) {
|
||||
if (host == null || !host.isAvailable() || !host.isEnabled()) {
|
||||
lastVisitedObjects[0] = null;
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
@ -455,7 +456,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
lastVisitedObjects[0] = options;
|
||||
if (!options.init()) lastVisitedObjects[0] = options.getHost();
|
||||
plugin.api.getHost(options.getHost(), host -> {
|
||||
if (host == null || !host.isEnabled()) {
|
||||
if (host == null || !host.isAvailable() || !host.isEnabled()) {
|
||||
lastVisitedObjects[0] = null;
|
||||
if (hasHistory()) back();
|
||||
} else {
|
||||
@ -854,7 +855,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", offline.name(), offline.get());
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + server.getDisplayName());
|
||||
@ -879,7 +880,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
}
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list));
|
||||
}
|
||||
if (!((SubServer) server).isEnabled()) lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
if (!((SubServer) server).isAvailable() || !((SubServer) server).isEnabled()) lore.add(plugin.api.getLang("SubServers", (!((SubServer) server).isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?server.getAddress().getAddress().getHostAddress()+':':"") + server.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
}
|
||||
@ -1038,7 +1039,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.command." + name.toLowerCase())));
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 3);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Command"));
|
||||
}
|
||||
@ -1055,7 +1056,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.start." + name.toLowerCase())));
|
||||
} else if (!host.isAvailable() || !host.isEnabled() || !subserver.isEnabled() || subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
} else if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || !subserver.isEnabled() || subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start")));
|
||||
@ -1065,15 +1066,47 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Start"));
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(3, block);
|
||||
inv.setItem(4, block);
|
||||
inv.setItem(5, block);
|
||||
inv.setItem(12, block);
|
||||
inv.setItem(13, block);
|
||||
inv.setItem(14, block);
|
||||
SubCreator.ServerTemplate template;
|
||||
if (subserver.getTemplate() == null || !(template = host.getCreator().getTemplate(subserver.getTemplate())).isEnabled() || !template.canUpdate()) {
|
||||
inv.setItem(3, block);
|
||||
inv.setItem(4, block);
|
||||
inv.setItem(5, block);
|
||||
inv.setItem(12, block);
|
||||
inv.setItem(13, block);
|
||||
inv.setItem(14, block);
|
||||
} else {
|
||||
inv.setItem(1, block);
|
||||
inv.setItem(2, block);
|
||||
inv.setItem(3, block);
|
||||
inv.setItem(10, block);
|
||||
inv.setItem(11, block);
|
||||
inv.setItem(12, block);
|
||||
|
||||
if (!(Bukkit.getPlayer(player).hasPermission("subservers.subserver.update.*") || Bukkit.getPlayer(player).hasPermission("subservers.subserver.update." + name.toLowerCase()))) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update")));
|
||||
blockMeta.setLore(Arrays.asList(plugin.api.getLang("SubServers", "Interface.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.update." + name.toLowerCase())));
|
||||
} else if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || subserver.getCurrentIncompatibilities().size() != 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "GRAY_STAINED_GLASS_PANE", (short) 7);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.GRAY+ChatColor.stripColor(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update")));
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(plugin.api.getLang("SubServers", "Interface.SubServer-Admin.Update"));
|
||||
}
|
||||
block.setItemMeta(blockMeta);
|
||||
inv.setItem(5, block);
|
||||
inv.setItem(6, block);
|
||||
inv.setItem(7, block);
|
||||
inv.setItem(14, block);
|
||||
inv.setItem(15, block);
|
||||
inv.setItem(16, block);
|
||||
}
|
||||
}
|
||||
|
||||
if (!host.isAvailable() || !host.isEnabled() || !subserver.isEnabled() || subserverPlugins.size() <= 0) {
|
||||
if (!host.isAvailable() || !host.isEnabled() || !subserver.isAvailable() || !subserver.isEnabled() || subserverPlugins.size() <= 0) {
|
||||
block = div;
|
||||
} else {
|
||||
block = createItem("STAINED_GLASS_PANE", "BLUE_STAINED_GLASS_PANE", (short) 11);
|
||||
@ -1097,7 +1130,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
block = createItem("STAINED_GLASS_PANE", "YELLOW_STAINED_GLASS_PANE", (short) 4);
|
||||
blockMeta = block.getItemMeta();
|
||||
blockMeta.setDisplayName(ChatColor.YELLOW + subserver.getDisplayName());
|
||||
@ -1122,7 +1155,7 @@ public class DefaultUIRenderer extends UIRenderer {
|
||||
}
|
||||
lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list));
|
||||
}
|
||||
if (!subserver.isEnabled()) lore.add(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
if (!subserver.isAvailable() || !subserver.isEnabled()) lore.add(plugin.api.getLang("SubServers", (!subserver.isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled"));
|
||||
lore.add(ChatColor.WHITE + ((plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false))?subserver.getAddress().getAddress().getHostAddress()+':':"") + subserver.getAddress().getPort());
|
||||
blockMeta.setLore(lore);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class BungeeChat {
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())) + ChatColor.RESET);
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message.setColor(ChatColor.YELLOW);
|
||||
hover.setColor(ChatColor.YELLOW);
|
||||
hoverm.add(hover);
|
||||
@ -91,11 +91,11 @@ public class BungeeChat {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += other;
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((((SubServer) server).isEnabled())?"":"\n"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + (((SubServer) server).isAvailable() && (((SubServer) server).isEnabled())?"":"\n"));
|
||||
}
|
||||
if (!((SubServer) server).isEnabled()) {
|
||||
if (!((SubServer) server).isAvailable() || !((SubServer) server).isEnabled()) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", (!((SubServer) server).isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled"));
|
||||
}
|
||||
}
|
||||
hoverm.add(hover);
|
||||
@ -200,7 +200,7 @@ public class BungeeChat {
|
||||
hoverm.add(hover);
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size())) + ChatColor.RESET);
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message.setColor(ChatColor.YELLOW);
|
||||
hover.setColor(ChatColor.YELLOW);
|
||||
hoverm.add(hover);
|
||||
@ -225,11 +225,11 @@ public class BungeeChat {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += other;
|
||||
}
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isEnabled())?"":"\n"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isAvailable() && subserver.isEnabled())?"":"\n"));
|
||||
}
|
||||
if (!subserver.isEnabled()) {
|
||||
if (!subserver.isAvailable() || !subserver.isEnabled()) {
|
||||
hoverm.add(hover);
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", "Interface.Server-Menu.SubServer-Disabled"));
|
||||
hover = new TextComponent(plugin.api.getLang("SubServers", (!subserver.isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled"));
|
||||
}
|
||||
}
|
||||
hoverm.add(hover);
|
||||
|
@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketUpdateServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -95,6 +96,15 @@ public class SubCreator {
|
||||
public boolean requiresVersion() {
|
||||
return raw.getBoolean("version-req");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template can be used to update it's servers
|
||||
*
|
||||
* @return Updatable Status
|
||||
*/
|
||||
public boolean canUpdate() {
|
||||
return raw.getBoolean("can-update");
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
SPIGOT,
|
||||
@ -119,7 +129,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
@ -142,7 +152,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
create(null, name, template, version, port, response);
|
||||
}
|
||||
|
||||
@ -155,7 +165,7 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(player, name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
@ -167,10 +177,64 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void update(UUID player, String server, 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 -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @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 -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
*/
|
||||
public void update(String server, Version version) {
|
||||
update(null, server, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host this creator belongs to
|
||||
*
|
||||
@ -196,7 +260,6 @@ public class SubCreator {
|
||||
* @return Template
|
||||
*/
|
||||
public ServerTemplate getTemplate(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getTemplates().get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -391,6 +391,24 @@ public class SubServer extends Server {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Template this Server was created from
|
||||
*
|
||||
* @return The Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return raw.getRawString("template");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this Server Available?
|
||||
*
|
||||
* @return Availability Status
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
return raw.getBoolean("available");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is Enabled
|
||||
*
|
||||
@ -554,6 +572,35 @@ public class SubServer extends Server {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server) {
|
||||
toggleCompatibility(server, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server, Callback<Boolean> response) {
|
||||
if (Util.isNull(server, response)) throw new NullPointerException();
|
||||
ArrayList<String> value = new ArrayList<String>();
|
||||
value.addAll(getIncompatibilities());
|
||||
if (!value.contains(server)) value.add(server);
|
||||
else value.remove(server);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("incompatible", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("incompatible", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Server is compatible
|
||||
*
|
||||
@ -637,4 +684,220 @@ public class SubServer extends Server {
|
||||
callback.run(current);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
*/
|
||||
public void setDisplayName(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setDisplayName(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("display", (value == null)?"":value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("display", (value == null)?getName():value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
*/
|
||||
public void addGroup(String value) {
|
||||
addGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void addGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<String> v = new ArrayList<String>();
|
||||
v.addAll(getGroups());
|
||||
if (!v.contains(value)) v.add(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
*/
|
||||
public void removeGroup(String value) {
|
||||
removeGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void removeGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> v = new ArrayList<UUID>();
|
||||
v.addAll(getWhitelist());
|
||||
v.remove(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setHidden(boolean value) {
|
||||
setHidden(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setHidden(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setMotd(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setMotd(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("motd", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("motd", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setRestricted(boolean value) {
|
||||
setRestricted(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setRestricted(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
*/
|
||||
public void whitelist(UUID player) {
|
||||
whitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void whitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
if (!value.contains(player)) value.add(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void unwhitelist(UUID player) {
|
||||
unwhitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void unwhitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
value.remove(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
public void run(ObjectMap<String> data) {
|
||||
if (plugin.isEnabled()) {
|
||||
Bukkit.getPluginManager().callEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host"), data.getString("name"),
|
||||
data.getString("template"), (data.contains("version"))?new Version(data.getString("version")):null, data.getInt("port")));
|
||||
data.getString("template"), (data.contains("version"))?new Version(data.getString("version")):null, data.getInt("port"), data.getBoolean("update")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private Version version;
|
||||
private boolean waitfor;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
*/
|
||||
public PacketUpdateServer() {}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.waitfor = waitfor;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
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);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -64,22 +64,24 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
instance.registerPacket(0x0033, PacketUpdateServer.class);
|
||||
instance.registerPacket(0x0034, PacketEditServer.class);
|
||||
instance.registerPacket(0x0035, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0036, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0037, PacketStopServer.class);
|
||||
instance.registerPacket(0x0038, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0039, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||
instance.registerPacket(0x0031, new PacketAddServer());
|
||||
instance.registerPacket(0x0032, new PacketStartServer());
|
||||
instance.registerPacket(0x0033, new PacketEditServer());
|
||||
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||
instance.registerPacket(0x0036, new PacketStopServer());
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||
instance.registerPacket(0x0033, new PacketUpdateServer());
|
||||
instance.registerPacket(0x0034, new PacketEditServer());
|
||||
instance.registerPacket(0x0035, new PacketRestartServer());
|
||||
instance.registerPacket(0x0036, new PacketCommandServer());
|
||||
instance.registerPacket(0x0037, new PacketStopServer());
|
||||
instance.registerPacket(0x0038, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0039, new PacketDeleteServer());
|
||||
|
||||
|
||||
// 70-79: External Misc Packets
|
||||
|
@ -40,7 +40,6 @@ public final class SubCommand extends BukkitCommand {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
label = "/" + label;
|
||||
@ -135,7 +134,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
}
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -174,7 +173,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
}
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -227,9 +226,11 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", ((server instanceof SubServer)?"Sub":"") + "Server") + ChatColor.WHITE + server.getDisplayName());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name") + ChatColor.WHITE + server.getName());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available") + ((((SubServer) server).isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled") + ((((SubServer) server).isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable") + ChatColor.RED + "no");
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host") + ChatColor.WHITE + ((SubServer) server).getHost());
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Template") + ChatColor.WHITE + ((SubServer) server).getTemplate());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group" + ((server.getGroups().size() > 1)?"s":"")) + ((server.getGroups().size() > 1)?"":ChatColor.WHITE + server.getGroups().get(0)));
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" " + plugin.api.getLang("SubServers", "Command.Info.List") + ChatColor.WHITE + group);
|
||||
@ -357,12 +358,15 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled"));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Unavailable"));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Running"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Disabled"));
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Running"));
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Server-Incompatible").replace("$str$", data.getString(0x0002)));
|
||||
break;
|
||||
case 0:
|
||||
@ -393,12 +397,15 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Host-Disabled"));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Disabled"));
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Incompatible").replace("$str$", data.getString(0x0002)));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Unavailable"));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Disabled"));
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Server-Incompatible").replace("$str$", data.getString(0x0002)));
|
||||
break;
|
||||
case 9:
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Restart.Finish"));
|
||||
@ -556,10 +563,10 @@ public final class SubCommand extends BukkitCommand {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Host"));
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Unavailable"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Host-Unavailable"));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Start.Host-Disabled"));
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Host-Disabled"));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Creator.Unknown-Template"));
|
||||
@ -586,6 +593,53 @@ public final class SubCommand extends BukkitCommand {
|
||||
} else {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] [Port]"));
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("update") || args[0].equalsIgnoreCase("upgrade")) {
|
||||
if (args.length > 1) {
|
||||
if (sender.hasPermission("subservers.subserver.update.*") || sender.hasPermission("subservers.subserver.update." + args[1].toLowerCase())) {
|
||||
((SubDataClient) plugin.api.getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, args[1], (args.length > 2)?new Version(args[2]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Unknown"));
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Invalid"));
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Host-Unavailable"));
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Host-Disabled"));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Server-Unavailable"));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Running"));
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template"));
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled"));
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid"));
|
||||
break;
|
||||
case 12:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update.Version-Required"));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Update"));
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.update." + args[1].toLowerCase()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Generic.Usage").replace("$str$", label.toLowerCase() + " " + args[0].toLowerCase() + " <SubServer> [Version]"));
|
||||
}
|
||||
} else if ((args[0].equalsIgnoreCase("view") || args[0].equalsIgnoreCase("open")) && sender instanceof Player) {
|
||||
if (plugin.gui != null) {
|
||||
if (sender.hasPermission("subservers.interface")) {
|
||||
@ -667,6 +721,7 @@ public final class SubCommand extends BukkitCommand {
|
||||
plugin.api.getLang("SubServers", "Command.Help.SubServer.Terminate").replace("$str$", label.toLowerCase() + " kill <SubServer>"),
|
||||
plugin.api.getLang("SubServers", "Command.Help.SubServer.Command").replace("$str$", label.toLowerCase() + " cmd <SubServer> <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 <SubServer> [Version]"),
|
||||
};
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
name: 'SubServers-Client-Bukkit'
|
||||
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
|
||||
version: '2.14a'
|
||||
version: '2.14.2a'
|
||||
authors: [ME1312]
|
||||
softdepend: [Vault, TitleManager]
|
||||
website: 'https://github.com/ME1312/SubServers-2'
|
||||
@ -36,6 +36,9 @@ permissions:
|
||||
description: 'Grants Access to SubServers SubServer Actions'
|
||||
default: op
|
||||
children:
|
||||
subservers.subserver.update.*:
|
||||
description: 'Grants Access to Update a SubServer'
|
||||
default: op
|
||||
subservers.subserver.start.*:
|
||||
description: 'Grants Access to Start a SubServer'
|
||||
default: op
|
||||
|
@ -30,7 +30,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,11 +1,15 @@
|
||||
package net.ME1312.SubServers.Client.Sponge.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.SubServers.Client.Sponge.Library.SubEvent;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -13,6 +17,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
private UUID player;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
@ -29,9 +34,10 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port, boolean update) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
@ -48,6 +54,33 @@ public class SubCreateEvent extends AbstractEvent implements SubEvent {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator is being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean isUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer will use
|
||||
*
|
||||
|
@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketUpdateServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -95,6 +96,15 @@ public class SubCreator {
|
||||
public boolean requiresVersion() {
|
||||
return raw.getBoolean("version-req");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template can be used to update it's servers
|
||||
*
|
||||
* @return Updatable Status
|
||||
*/
|
||||
public boolean canUpdate() {
|
||||
return raw.getBoolean("can-update");
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
SPIGOT,
|
||||
@ -119,7 +129,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
@ -142,7 +152,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
create(null, name, template, version, port, response);
|
||||
}
|
||||
|
||||
@ -155,7 +165,7 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(player, name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
@ -167,10 +177,64 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void update(UUID player, String server, 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 -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @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 -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
*/
|
||||
public void update(String server, Version version) {
|
||||
update(null, server, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host this creator belongs to
|
||||
*
|
||||
@ -196,7 +260,6 @@ public class SubCreator {
|
||||
* @return Template
|
||||
*/
|
||||
public ServerTemplate getTemplate(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getTemplates().get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import net.ME1312.SubServers.Client.Sponge.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Client.Sponge.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -396,6 +397,24 @@ public class SubServer extends Server {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Template this Server was created from
|
||||
*
|
||||
* @return The Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return raw.getRawString("template");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this Server Available?
|
||||
*
|
||||
* @return Availability Status
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
return raw.getBoolean("available");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is Enabled
|
||||
*
|
||||
@ -559,6 +578,35 @@ public class SubServer extends Server {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server) {
|
||||
toggleCompatibility(server, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server, Callback<Boolean> response) {
|
||||
if (Util.isNull(server, response)) throw new NullPointerException();
|
||||
ArrayList<String> value = new ArrayList<String>();
|
||||
value.addAll(getIncompatibilities());
|
||||
if (!value.contains(server)) value.add(server);
|
||||
else value.remove(server);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("incompatible", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("incompatible", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Server is compatible
|
||||
*
|
||||
@ -642,4 +690,220 @@ public class SubServer extends Server {
|
||||
callback.run(current);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
*/
|
||||
public void setDisplayName(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setDisplayName(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("display", (value == null)?"":value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("display", (value == null)?getName():value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
*/
|
||||
public void addGroup(String value) {
|
||||
addGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void addGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<String> v = new ArrayList<String>();
|
||||
v.addAll(getGroups());
|
||||
if (!v.contains(value)) v.add(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
*/
|
||||
public void removeGroup(String value) {
|
||||
removeGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void removeGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> v = new ArrayList<UUID>();
|
||||
v.addAll(getWhitelist());
|
||||
v.remove(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setHidden(boolean value) {
|
||||
setHidden(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setHidden(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setMotd(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setMotd(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("motd", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("motd", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setRestricted(boolean value) {
|
||||
setRestricted(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setRestricted(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
*/
|
||||
public void whitelist(UUID player) {
|
||||
whitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void whitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
if (!value.contains(player)) value.add(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void unwhitelist(UUID player) {
|
||||
unwhitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void unwhitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
value.remove(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
Sponge.getEventManager().post(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getString("host"), data.getString("name"),
|
||||
data.getString("template"), new Version(data.getString("version")), data.getInt("port")));
|
||||
data.getString("template"), new Version(data.getString("version")), data.getInt("port"), data.getBoolean("update")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,84 @@
|
||||
package net.ME1312.SubServers.Client.Sponge.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private Version version;
|
||||
private boolean waitfor;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
*/
|
||||
public PacketUpdateServer() {}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.waitfor = waitfor;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
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);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -71,22 +71,24 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
instance.registerPacket(0x0033, PacketUpdateServer.class);
|
||||
instance.registerPacket(0x0034, PacketEditServer.class);
|
||||
instance.registerPacket(0x0035, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0036, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0037, PacketStopServer.class);
|
||||
instance.registerPacket(0x0038, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0039, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||
instance.registerPacket(0x0031, new PacketAddServer());
|
||||
instance.registerPacket(0x0032, new PacketStartServer());
|
||||
instance.registerPacket(0x0033, new PacketEditServer());
|
||||
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||
instance.registerPacket(0x0036, new PacketStopServer());
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||
instance.registerPacket(0x0033, new PacketUpdateServer());
|
||||
instance.registerPacket(0x0034, new PacketEditServer());
|
||||
instance.registerPacket(0x0035, new PacketRestartServer());
|
||||
instance.registerPacket(0x0036, new PacketCommandServer());
|
||||
instance.registerPacket(0x0037, new PacketStopServer());
|
||||
instance.registerPacket(0x0038, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0039, new PacketDeleteServer());
|
||||
|
||||
|
||||
// 70-79: External Misc Packets
|
||||
|
@ -102,6 +102,11 @@ public final class SubCommand implements CommandExecutor {
|
||||
.executor(new CREATE())
|
||||
.arguments(GenericArguments.optional(GenericArguments.string(Text.of("Name"))), GenericArguments.optional(GenericArguments.string(Text.of("Host"))), GenericArguments.optional(GenericArguments.string(Text.of("Template"))), GenericArguments.optional(GenericArguments.string(Text.of("Version"))), GenericArguments.optional(GenericArguments.string(Text.of("Port"))), GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("extra"))))
|
||||
.build(), "create")
|
||||
.child(CommandSpec.builder()
|
||||
.description(Text.of("The SubServers Command - Update"))
|
||||
.executor(new UPDATE())
|
||||
.arguments(GenericArguments.optional(GenericArguments.string(Text.of("SubServer"))), 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 - Open Menu"))
|
||||
.executor(new OPEN())
|
||||
@ -258,7 +263,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
hover.append(
|
||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(server.getPlayers().size())))
|
||||
);
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message.color(TextColors.YELLOW);
|
||||
hover.color(TextColors.YELLOW);
|
||||
if (!server.getName().equals(server.getDisplayName())) {
|
||||
@ -279,10 +284,10 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += other;
|
||||
}
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((((SubServer) server).isEnabled())?"":"\n")));
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + (((SubServer) server).isAvailable() && (((SubServer) server).isEnabled())?"":"\n")));
|
||||
}
|
||||
if (!((SubServer) server).isEnabled()) {
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
|
||||
if (!((SubServer) server).isAvailable() || !((SubServer) server).isEnabled()) {
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers",(!((SubServer) server).isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled")));
|
||||
}
|
||||
}
|
||||
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||
@ -362,7 +367,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Temporary") + '\n'));
|
||||
}
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.Server-Player-Count").replace("$int$", new DecimalFormat("#,###").format(subserver.getPlayers().size()))));
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message.color(TextColors.YELLOW);
|
||||
hover.color(TextColors.YELLOW);
|
||||
if (!subserver.getName().equals(subserver.getDisplayName())) {
|
||||
@ -381,10 +386,10 @@ public final class SubCommand implements CommandExecutor {
|
||||
if (list.length() != 0) list += ", ";
|
||||
list += other;
|
||||
}
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isEnabled())?"":"\n")));
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Incompatible").replace("$str$", list) + ((subserver.isAvailable() && subserver.isEnabled())?"":"\n")));
|
||||
}
|
||||
if (!subserver.isEnabled()) {
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers","Interface.Server-Menu.SubServer-Disabled")));
|
||||
if (!subserver.isAvailable() || !subserver.isEnabled()) {
|
||||
hover.append(ChatColor.convertColor(plugin.api.getLang("SubServers",(!subserver.isAvailable())?"Interface.Server-Menu.SubServer-Unavailable":"Interface.Server-Menu.SubServer-Disabled")));
|
||||
}
|
||||
}
|
||||
if (plugin.config.get().getMap("Settings").getBoolean("Show-Addresses", false)) {
|
||||
@ -516,9 +521,11 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info").replace("$str$", ((server instanceof SubServer)?"Sub":"") + "Server")).toBuilder().append(Text.builder(server.getDisplayName()).color(TextColors.WHITE).build()).build());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "System Name")).toBuilder().append(Text.builder(server.getName()).color(TextColors.WHITE).build()).build());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Available")).toBuilder().append(Text.builder((((SubServer) server).isAvailable())?"yes":"no").color((((SubServer) server).isAvailable())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Enabled")).toBuilder().append(Text.builder((((SubServer) server).isEnabled())?"yes":"no").color((((SubServer) server).isEnabled())?TextColors.GREEN:TextColors.RED).build()).build());
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Editable")).toBuilder().append(Text.builder("no").color(TextColors.RED).build()).build());
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Host")).toBuilder().append(Text.builder(((SubServer) server).getHost()).color(TextColors.WHITE ).build()).build());
|
||||
if (((SubServer) server).getTemplate() != null) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Template")).toBuilder().append(Text.builder(((SubServer) server).getTemplate()).color(TextColors.WHITE ).build()).build());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Info.Format").replace("$str$", "Group" + ((server.getGroups().size() > 1)?"s":""))).toBuilder().append(Text.builder((server.getGroups().size() > 1)?"":server.getGroups().get(0)).color(TextColors.WHITE).build()).build());
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(ChatColor.convertColor(" " + plugin.api.getLang("SubServers", "Command.Info.List")).toBuilder().append(Text.builder(group).color(TextColors.WHITE).build()).build());
|
||||
@ -658,12 +665,15 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Host-Disabled")));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Disabled")));
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Unavailable")));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Running")));
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Disabled")));
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Running")));
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString(0x0002))));
|
||||
break;
|
||||
case 0:
|
||||
@ -707,12 +717,15 @@ public final class SubCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Host-Disabled")));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Server-Disabled")));
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString(0x0002))));
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Server-Unavailable")));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Server-Disabled")));
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Start.Server-Incompatible").replace("$str$", data.getString(0x0002))));
|
||||
break;
|
||||
case 9:
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Restart.Finish")));
|
||||
@ -960,6 +973,67 @@ public final class SubCommand implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
public final class UPDATE implements CommandExecutor {
|
||||
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
|
||||
if (canRun(sender)) {
|
||||
Optional<String> subserver = args.getOne(Text.of("SubServer"));
|
||||
Optional<String> version = args.getOne(Text.of("Version"));
|
||||
if (subserver.isPresent()) {
|
||||
if (sender.hasPermission("subservers.subserver.update." + subserver.get().toLowerCase())) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer((sender instanceof Player)?((Player) sender).getUniqueId():null, subserver.get(), (version.isPresent() && version.get().length() > 0)?new Version(version.get()):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Unknown")));
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Invalid")));
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Host-Unavailable")));
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Host-Disabled")));
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Server-Unavailable")));
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Running")));
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Unknown-Template")));
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Disabled")));
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Template-Invalid")));
|
||||
break;
|
||||
case 12:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update.Version-Required")));
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers", "Command.Update")));
|
||||
break;
|
||||
}
|
||||
}));
|
||||
return CommandResult.builder().successCount(1).build();
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.subserver.update." + subserver.get().toLowerCase())));
|
||||
return CommandResult.builder().successCount(0).build();
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Usage").replace("$str$", "/sub update <SubServer> [Version]")));
|
||||
return CommandResult.builder().successCount(0).build();
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
|
||||
return CommandResult.builder().successCount(0).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class OPEN implements CommandExecutor {
|
||||
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
|
||||
if (canRun(sender)) {
|
||||
@ -1036,6 +1110,7 @@ public final class SubCommand implements CommandExecutor {
|
||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Terminate").replace("$str$", "/sub kill <SubServer>")),
|
||||
ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Help.SubServer.Command").replace("$str$", "/sub cmd <SubServer> <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 <SubServer> [Version]")),
|
||||
};
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
* SubServers Client Plugin Class
|
||||
*/
|
||||
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.14a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
|
||||
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.14.2a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
|
||||
public final class SubPlugin {
|
||||
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
|
@ -1,4 +1,4 @@
|
||||
name: SubServers-Console
|
||||
main: net.ME1312.SubServers.Console.ConsolePlugin
|
||||
version: 2.14a
|
||||
version: 2.14.2a
|
||||
author: ME1312
|
@ -1,14 +1,14 @@
|
||||
# SubCreator Sponge Forge Build Script
|
||||
# SubCreator SpongeForge Build Script
|
||||
#
|
||||
#!/usr/bin/env bash
|
||||
if [ -z "$mcf_version" ] || [ -z "$sp_version" ]
|
||||
if [[ -z "$mcf_version" ]] || [[ -z "$sp_version" ]]
|
||||
then
|
||||
echo ERROR: No Build Version Supplied
|
||||
rm -Rf "$0"
|
||||
exit 1
|
||||
fi
|
||||
function __DL() {
|
||||
if [ -x "$(command -v wget)" ]; then
|
||||
if [[ -x "$(command -v wget)" ]]; then
|
||||
wget -O "$1" "$2"; return $?
|
||||
else
|
||||
curl -o "$1" "$2"; return $?
|
||||
@ -16,25 +16,49 @@ function __DL() {
|
||||
}
|
||||
echo Downloading the Minecraft Forge Installer...
|
||||
__DL "forge-$mcf_version-installer.jar" "http://files.minecraftforge.net/maven/net/minecraftforge/forge/$mcf_version/forge-$mcf_version-installer.jar"; __RETURN=$?
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
echo Installing Minecraft Forge...
|
||||
java -jar "forge-$mcf_version-installer.jar" --installServer; __RETURN=$?
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
echo Cleaning Up...
|
||||
if [[ -f "Forge.jar" ]]; then
|
||||
if [[ -f "Forge.old.jar.x" ]]; then
|
||||
rm -Rf Forge.old.jar.x
|
||||
fi
|
||||
mv Forge.jar Forge.old.jar.x
|
||||
fi
|
||||
if [[ ! -d "mods" ]]; then
|
||||
mkdir mods
|
||||
fi
|
||||
rm -Rf "forge-$mcf_version-installer.jar"
|
||||
rm -Rf "forge-$mcf_version-installer.jar.log"
|
||||
mv -f "forge-$mcf_version-universal.jar" Forge.jar
|
||||
if [ ! -d "mods" ]; then
|
||||
mkdir mods
|
||||
fi
|
||||
echo Downloading SpongeForge...
|
||||
if [[ -f "mods/Sponge.jar" ]]; then
|
||||
if [[ -f "mods/Sponge.old.jar.x" ]]; then
|
||||
rm -Rf mods/Sponge.old.jar.x
|
||||
fi
|
||||
mv mods/Sponge.jar mods/Sponge.old.jar.x
|
||||
fi
|
||||
__DL mods/Sponge.jar "https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/$sp_version/spongeforge-$sp_version.jar"; __RETURN=$?
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
echo Cleaning Up...
|
||||
rm -Rf "$0"
|
||||
exit 0
|
||||
else
|
||||
echo ERROR: Failed downloading Sponge. Is MinecraftForge.net down?
|
||||
if [[ -f "mods/Sponge.old.jar.x" ]]; then
|
||||
if [[ -f "mods/Sponge.jar" ]]; then
|
||||
rm -Rf mods/Sponge.jar
|
||||
fi
|
||||
mv mods/Sponge.old.jar.x mods/Sponge.jar
|
||||
fi
|
||||
if [[ -f "Forge.old.jar.x" ]]; then
|
||||
if [[ -f "Forge.jar" ]]; then
|
||||
rm -Rf Forge.jar
|
||||
fi
|
||||
mv Forge.old.jar.x Forge.jar
|
||||
fi
|
||||
rm -Rf "$0"
|
||||
exit 5
|
||||
fi
|
||||
|
@ -1,4 +1,4 @@
|
||||
Version: '2.13.2c+'
|
||||
Version: '2.14.2a+'
|
||||
Template:
|
||||
Enabled: true
|
||||
Icon: 'anvil'
|
||||
@ -6,6 +6,7 @@ Template:
|
||||
Server-Type: 'Forge'
|
||||
Use-Cache: false
|
||||
Require-Version: true
|
||||
Can-Update: true
|
||||
Executable: 'bash build.sh'
|
||||
Settings:
|
||||
Executable: 'java -Xmx2048M -jar Forge.jar'
|
@ -1,42 +1,51 @@
|
||||
# SubCreator Spigot Build Script
|
||||
#
|
||||
#!/usr/bin/env bash
|
||||
if [ -z "$version" ]
|
||||
if [[ -z "$version" ]]
|
||||
then
|
||||
echo ERROR: No Build Version Supplied
|
||||
rm -Rf "$0"
|
||||
exit 1
|
||||
fi
|
||||
function __DL() {
|
||||
if [ -x "$(command -v wget)" ]; then
|
||||
if [[ -x "$(command -v wget)" ]]; then
|
||||
wget -O "$1" "$2"; return $?
|
||||
else
|
||||
curl -o "$1" "$2"; return $?
|
||||
fi
|
||||
}
|
||||
if [ -z "$cache" ] || [ ! -f "$cache/Spigot-$version.jar" ]; then
|
||||
if [[ -z "$cache" ]] || [[ ! -f "$cache/Spigot-$version.jar" ]] || [[ "$mode" == "UPDATE" && $(find "$cache/Spigot-$version.jar" -mtime +1 -print) ]]; then
|
||||
echo Downloading Buildtools...
|
||||
__DL Buildtools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar; __RETURN=$?
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [ -d "Buildtools" ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
if [[ -d "Buildtools" ]]; then
|
||||
rm -Rf Buildtools
|
||||
fi
|
||||
mkdir Buildtools
|
||||
cd "Buildtools"
|
||||
echo Launching Buildtools
|
||||
if [ ! -z "$cache" ] && [ -d "$cache" ]; then
|
||||
if [[ ! -z "$cache" ]] && [[ -d "$cache" ]]; then
|
||||
export __HOME="$HOME"
|
||||
export HOME="$cache"
|
||||
fi
|
||||
export MAVEN_OPTS="-Xms2G"
|
||||
java -Xms2G -jar ../Buildtools.jar --rev "$version"; __RETURN=$?
|
||||
if [ ! -z "$cache" ] && [ ! -z "$__HOME" ] && [ "$cache" == "$HOME" ]; then
|
||||
if [[ ! -z "$cache" ]] && [[ ! -z "$__HOME" ]] && [[ "$cache" == "$HOME" ]]; then
|
||||
export HOME="$__HOME"
|
||||
fi
|
||||
cd ../
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
echo Copying Finished Jar...
|
||||
if [ ! -z "$cache" ] && [ -d "$cache" ]; then
|
||||
if [[ -f "Spigot.jar" ]]; then
|
||||
if [[ -f "Spigot.old.jar.x" ]]; then
|
||||
rm -Rf Spigot.old.jar.x
|
||||
fi
|
||||
mv Spigot.jar Spigot.old.jar.x
|
||||
fi
|
||||
if [[ ! -z "$cache" ]] && [[ -d "$cache" ]]; then
|
||||
if [[ -f "$cache/Spigot-$version.jar" ]]; then
|
||||
rm -Rf "$cache/Spigot-$version.jar"
|
||||
fi
|
||||
cp Buildtools/spigot-*.jar "$cache/Spigot-$version.jar"
|
||||
fi
|
||||
cp Buildtools/spigot-*.jar Spigot.jar
|
||||
|
@ -1,10 +1,11 @@
|
||||
Version: '2.13.2c+'
|
||||
Version: '2.14.2a+'
|
||||
Template:
|
||||
Enabled: true
|
||||
Icon: 'lava_bucket'
|
||||
Build:
|
||||
Server-Type: 'Spigot'
|
||||
Require-Version: true
|
||||
Can-Update: true
|
||||
Executable: 'bash build.sh'
|
||||
Settings:
|
||||
Executable: 'java -Xmx1024M -Dorg.bukkit.craftbukkit.libs.jline.terminal=unix -Djansi.passthrough=true -jar Spigot.jar'
|
@ -1,27 +1,39 @@
|
||||
# SubCreator Sponge Build Script
|
||||
# SubCreator SpongeVanilla Build Script
|
||||
#
|
||||
#!/usr/bin/env bash
|
||||
if [ -z "$sp_version" ]
|
||||
if [[ -z "$sp_version" ]]
|
||||
then
|
||||
echo ERROR: No Build Version Supplied
|
||||
rm -Rf "$0"
|
||||
exit 1
|
||||
fi
|
||||
function __DL() {
|
||||
if [ -x "$(command -v wget)" ]; then
|
||||
if [[ -x "$(command -v wget)" ]]; then
|
||||
wget -O "$1" "$2"; return $?
|
||||
else
|
||||
curl -o "$1" "$2"; return $?
|
||||
fi
|
||||
}
|
||||
echo Downloading SpongeVanilla...
|
||||
if [[ -f "Sponge.jar" ]]; then
|
||||
if [[ -f "Sponge.old.jar.x" ]]; then
|
||||
rm -Rf Sponge.old.jar.x
|
||||
fi
|
||||
mv Sponge.jar Sponge.old.jar.x
|
||||
fi
|
||||
__DL Sponge.jar "https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/$sp_version/spongevanilla-$sp_version.jar"; __RETURN=$?
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
echo Cleaning Up...
|
||||
rm -Rf "$0"
|
||||
exit 0
|
||||
else
|
||||
echo ERROR: Failed downloading Sponge. Is MinecraftForge.net down?
|
||||
if [[ -f "Sponge.old.jar.x" ]]; then
|
||||
if [[ -f "Sponge.jar" ]]; then
|
||||
rm -Rf Sponge.jar
|
||||
fi
|
||||
mv Sponge.old.jar.x Sponge.jar
|
||||
fi
|
||||
rm -Rf "$0"
|
||||
exit 3
|
||||
fi
|
||||
|
@ -1,4 +1,4 @@
|
||||
Version: '2.13.2c+'
|
||||
Version: '2.14.2a+'
|
||||
Template:
|
||||
Enabled: true
|
||||
Icon: 'sponge'
|
||||
@ -6,6 +6,7 @@ Template:
|
||||
Server-Type: 'Sponge'
|
||||
Use-Cache: false
|
||||
Require-Version: true
|
||||
Can-Update: true
|
||||
Executable: 'bash build.sh'
|
||||
Settings:
|
||||
Executable: 'java -Xmx1024M -jar Sponge.jar'
|
@ -1,34 +1,40 @@
|
||||
# SubCreator Vanilla Build Script
|
||||
#
|
||||
#!/usr/bin/env bash
|
||||
if [ -z "$version" ]
|
||||
if [[ -z "$version" ]]
|
||||
then
|
||||
echo ERROR: No Build Version Supplied
|
||||
rm -Rf "$0"
|
||||
exit 1
|
||||
fi
|
||||
function __DL() {
|
||||
if [ -x "$(command -v wget)" ]; then
|
||||
if [[ -x "$(command -v wget)" ]]; then
|
||||
wget -O "$1" "$2"; return $?
|
||||
else
|
||||
curl -o "$1" "$2"; return $?
|
||||
fi
|
||||
}
|
||||
if [ -z "$cache" ] || [ ! -f "$cache/Vanilla-$version.jar" ]; then
|
||||
if [ -d "VanillaCord" ]; then
|
||||
if [[ -z "$cache" ]] || [[ ! -f "$cache/Vanilla-$version.jar" ]]; then
|
||||
if [[ -d "VanillaCord" ]]; then
|
||||
rm -Rf VanillaCord
|
||||
fi
|
||||
mkdir VanillaCord
|
||||
echo Downloading the VanillaCord Launcher...
|
||||
__DL VanillaCord/VanillaCord.jar https://src.me1312.net/jenkins/job/VanillaCord/job/master/lastSuccessfulBuild/artifact/artifacts/VanillaCord.jar; __RETURN=$?
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
cd VanillaCord
|
||||
echo Launching VanillaCord
|
||||
java -jar VanillaCord.jar "$version"; __RETURN=$?;
|
||||
if [ $__RETURN -eq 0 ]; then
|
||||
if [[ $__RETURN -eq 0 ]]; then
|
||||
echo Copying Finished Jar...
|
||||
cd ../
|
||||
if [ ! -z "$cache" ] && [ -d "$cache" ]; then
|
||||
if [[ -f "Vanilla.jar" ]]; then
|
||||
if [[ -f "Vanilla.old.jar.x" ]]; then
|
||||
rm -Rf Vanilla.old.jar.x
|
||||
fi
|
||||
mv Vanilla.jar Vanilla.old.jar.x
|
||||
fi
|
||||
if [[ ! -z "$cache" ]] && [[ -d "$cache" ]]; then
|
||||
cp "VanillaCord/out/$version-bungee.jar" "$cache/Vanilla-$version.jar"
|
||||
fi
|
||||
cp "VanillaCord/out/$version-bungee.jar" Vanilla.jar
|
||||
|
@ -1,10 +1,11 @@
|
||||
Version: '2.13.2c+'
|
||||
Version: '2.14.2a+'
|
||||
Template:
|
||||
Enabled: true
|
||||
Icon: 'bukkit:grass'
|
||||
Build:
|
||||
Server-Type: 'Vanilla'
|
||||
Require-Version: true
|
||||
Can-Update: true
|
||||
Executable: 'bash build.sh'
|
||||
Settings:
|
||||
Executable: 'java -Xmx1024M -jar Vanilla.jar nogui'
|
@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,9 +1,13 @@
|
||||
package net.ME1312.SubServers.Host.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Event.Event;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Host.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -11,6 +15,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SubCreateEvent extends Event {
|
||||
private UUID player;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
@ -27,9 +32,10 @@ public class SubCreateEvent extends Event {
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port, boolean update) {
|
||||
if (Util.isNull(host, name, template, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
@ -46,6 +52,33 @@ public class SubCreateEvent extends Event {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator is being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean isUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer will use
|
||||
*
|
||||
|
@ -41,7 +41,7 @@ import java.util.jar.Manifest;
|
||||
/**
|
||||
* SubServers.Host Main Class
|
||||
*/
|
||||
@App(name = "SubServers.Host", version = "2.14a", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
|
||||
@App(name = "SubServers.Host", version = "2.14.2a", authors = "ME1312", description = "Host SubServers from other Machines", website = "https://github.com/ME1312/SubServers-2")
|
||||
public final class ExHost {
|
||||
HashMap<Integer, SubDataClient> subdata = new HashMap<Integer, SubDataClient>();
|
||||
NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
|
@ -156,6 +156,15 @@ public class SubCreator {
|
||||
return getBuildOptions().getBoolean("Require-Version", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template can be used to update it's servers
|
||||
*
|
||||
* @return Updatable Status
|
||||
*/
|
||||
public boolean canUpdate() {
|
||||
return getBuildOptions().getBoolean("Can-Update", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Build Options for this Template
|
||||
*
|
||||
@ -187,6 +196,7 @@ public class SubCreator {
|
||||
}
|
||||
|
||||
private class CreatorTask extends Thread {
|
||||
private final SubServer update;
|
||||
private final String name;
|
||||
private final ServerTemplate template;
|
||||
private final Version version;
|
||||
@ -198,11 +208,12 @@ public class SubCreator {
|
||||
|
||||
private CreatorTask(String name, ServerTemplate template, Version version, int port, UUID address, UUID tracker) {
|
||||
super(SubAPI.getInstance().getAppInfo().getName() + "::SubCreator_Process_Handler(" + name + ')');
|
||||
this.update = host.servers.getOrDefault(name.toLowerCase(), null);
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
this.version = version;
|
||||
this.port = port;
|
||||
this.log = new SubLogger(null, this, name + File.separator + "Creator", address, new Container<Boolean>(true), null);
|
||||
this.log = new SubLogger(null, this, name + File.separator + ((update == null)?"Creator":"Updater"), address, new Container<Boolean>(true), null);
|
||||
this.address = address;
|
||||
this.tracker = tracker;
|
||||
}
|
||||
@ -218,11 +229,16 @@ public class SubCreator {
|
||||
if (host.templates.keySet().contains(other.toLowerCase())) {
|
||||
if (host.templates.get(other.toLowerCase()).isEnabled()) {
|
||||
if (version != null || !host.templates.get(other.toLowerCase()).requiresVersion()) {
|
||||
ObjectMap<String> config = build(dir, host.templates.get(other.toLowerCase()), history);
|
||||
if (config == null) {
|
||||
throw new SubCreatorException();
|
||||
if (update == null || host.templates.get(other.toLowerCase()).canUpdate()) {
|
||||
ObjectMap<String> config = build(dir, host.templates.get(other.toLowerCase()), history);
|
||||
if (config == null) {
|
||||
throw new SubCreatorException();
|
||||
} else {
|
||||
server.setAll(config);
|
||||
}
|
||||
} else {
|
||||
server.setAll(config);
|
||||
log.logger.warn.println("Skipping template that cannot be run in update mode: " + other);
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Skipping template that cannot be run in update mode: " + other));
|
||||
}
|
||||
} else {
|
||||
log.logger.warn.println("Skipping template that requires extra versioning: " + other);
|
||||
@ -242,6 +258,7 @@ public class SubCreator {
|
||||
log.logger.info.println("Loading Template: " + template.getDisplayName());
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketOutExLogMessage(address, "Loading Template: " + template.getDisplayName()));
|
||||
Util.copyDirectory(template.getDirectory(), dir);
|
||||
var.put("mode", (update == null)?"CREATE":"UPDATE");
|
||||
var.put("name", name);
|
||||
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) var.put("host", SubAPI.getInstance().getName());
|
||||
var.put("template", template.getName());
|
||||
@ -334,7 +351,7 @@ public class SubCreator {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
UniversalFile dir = new UniversalFile(new File(host.host.getRawString("Directory")), name);
|
||||
File dir = new File(host.host.getRawString("Directory"), (update != null)?update.getDirectory():name);
|
||||
dir.mkdirs();
|
||||
ObjectMap<String> server;
|
||||
try {
|
||||
@ -430,10 +447,12 @@ public class SubCreator {
|
||||
Files.delete(new UniversalFile(dir, "subservers.client").toPath());
|
||||
if (type == ServerType.SPIGOT) {
|
||||
if (!new UniversalFile(dir, "plugins").exists()) new UniversalFile(dir, "plugins").mkdirs();
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
|
||||
if (!new UniversalFile(dir, "plugins:SubServers.Client.jar").exists())
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(dir, "plugins:SubServers.Client.jar").getPath());
|
||||
} else if (type == ServerType.FORGE || type == ServerType.SPONGE) {
|
||||
if (!new UniversalFile(dir, "mods").exists()) new UniversalFile(dir, "mods").mkdirs();
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
|
||||
if (!new UniversalFile(dir, "mods:SubServers.Client.jar").exists())
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(dir, "mods:SubServers.Client.jar").getPath());
|
||||
}
|
||||
JSONObject config = new JSONObject();
|
||||
FileWriter writer = new FileWriter(new UniversalFile(dir, "subdata.json"), false);
|
||||
@ -443,7 +462,7 @@ public class SubCreator {
|
||||
config.write(writer);
|
||||
writer.close();
|
||||
|
||||
if (new UniversalFile("subdata.rsa.key").exists()) {
|
||||
if (!new UniversalFile(dir, "subdata.rsa.key").exists() && new UniversalFile("subdata.rsa.key").exists()) {
|
||||
Files.copy(new UniversalFile("subdata.rsa.key").toPath(), new UniversalFile(dir, "subdata.rsa.key").toPath());
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketExUpdateServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketExEditServer;
|
||||
import net.ME1312.SubServers.Host.ExHost;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
@ -15,7 +15,6 @@ import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarInputStream;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
* Internal SubServer Class
|
||||
@ -131,10 +130,10 @@ public class SubServer {
|
||||
} catch (IOException | InterruptedException e) {
|
||||
host.log.error.println(e);
|
||||
allowrestart = false;
|
||||
if (falsestart) ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.LAUNCH_EXCEPTION));
|
||||
if (falsestart) ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.LAUNCH_EXCEPTION));
|
||||
}
|
||||
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExEditServer(this, PacketExEditServer.UpdateType.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
|
||||
host.log.info.println(name + " has stopped");
|
||||
process = null;
|
||||
command = null;
|
||||
|
@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.SubServers.Host.Network.Packet.PacketUpdateServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -95,6 +96,15 @@ public class SubCreator {
|
||||
public boolean requiresVersion() {
|
||||
return raw.getBoolean("version-req");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template can be used to update it's servers
|
||||
*
|
||||
* @return Updatable Status
|
||||
*/
|
||||
public boolean canUpdate() {
|
||||
return raw.getBoolean("can-update");
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
SPIGOT,
|
||||
@ -119,7 +129,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
@ -142,7 +152,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
create(null, name, template, version, port, response);
|
||||
}
|
||||
|
||||
@ -155,7 +165,7 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(player, name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
@ -167,10 +177,64 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void update(UUID player, String server, 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 -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @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 -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
*/
|
||||
public void update(String server, Version version) {
|
||||
update(null, server, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host this creator belongs to
|
||||
*
|
||||
@ -196,7 +260,6 @@ public class SubCreator {
|
||||
* @return Template
|
||||
*/
|
||||
public ServerTemplate getTemplate(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getTemplates().get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import net.ME1312.SubServers.Host.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Host.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -396,6 +397,24 @@ public class SubServer extends Server {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Template this Server was created from
|
||||
*
|
||||
* @return The Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return raw.getRawString("template");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this Server Available?
|
||||
*
|
||||
* @return Availability Status
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
return raw.getBoolean("available");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is Enabled
|
||||
*
|
||||
@ -559,6 +578,35 @@ public class SubServer extends Server {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server) {
|
||||
toggleCompatibility(server, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server, Callback<Boolean> response) {
|
||||
if (Util.isNull(server, response)) throw new NullPointerException();
|
||||
ArrayList<String> value = new ArrayList<String>();
|
||||
value.addAll(getIncompatibilities());
|
||||
if (!value.contains(server)) value.add(server);
|
||||
else value.remove(server);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("incompatible", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("incompatible", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Server is compatible
|
||||
*
|
||||
@ -642,4 +690,220 @@ public class SubServer extends Server {
|
||||
callback.run(current);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
*/
|
||||
public void setDisplayName(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setDisplayName(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("display", (value == null)?"":value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("display", (value == null)?getName():value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
*/
|
||||
public void addGroup(String value) {
|
||||
addGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void addGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<String> v = new ArrayList<String>();
|
||||
v.addAll(getGroups());
|
||||
if (!v.contains(value)) v.add(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
*/
|
||||
public void removeGroup(String value) {
|
||||
removeGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void removeGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> v = new ArrayList<UUID>();
|
||||
v.addAll(getWhitelist());
|
||||
v.remove(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setHidden(boolean value) {
|
||||
setHidden(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setHidden(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setMotd(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setMotd(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("motd", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("motd", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setRestricted(boolean value) {
|
||||
setRestricted(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setRestricted(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
*/
|
||||
public void whitelist(UUID player) {
|
||||
whitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void whitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
if (!value.contains(player)) value.add(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void unwhitelist(UUID player) {
|
||||
unwhitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void unwhitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
value.remove(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Update Server Packet
|
||||
* Edit Server Packet
|
||||
*/
|
||||
public class PacketExUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
public class PacketExEditServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private ExHost host;
|
||||
private SubServer server;
|
||||
private UpdateType type;
|
||||
@ -43,21 +43,21 @@ public class PacketExUpdateServer implements PacketObjectIn<Integer>, PacketObje
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExUpdateServer (In)
|
||||
* New PacketExEditServer (In)
|
||||
* @param host ExHost
|
||||
*/
|
||||
public PacketExUpdateServer(ExHost host) {
|
||||
public PacketExEditServer(ExHost host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketExUpdateServer (Out)
|
||||
* New PacketExEditServer (Out)
|
||||
*
|
||||
* @param type Update Type
|
||||
* @param arguments Arguments
|
||||
*/
|
||||
public PacketExUpdateServer(SubServer server, UpdateType type, Object... arguments) {
|
||||
if (arguments.length != type.getArguments().length) throw new IllegalArgumentException("Not enough arguments for type: " + type.toString());
|
||||
public PacketExEditServer(SubServer server, UpdateType type, Object... arguments) {
|
||||
if (arguments.length != type.getArguments().length) throw new IllegalArgumentException(((arguments.length > type.getArguments().length)?"Too many":"Not enough") + " arguments for type: " + type.toString());
|
||||
int i = 0;
|
||||
while (i < arguments.length) {
|
||||
if (!type.getArguments()[i].isInstance(arguments[i])) throw new IllegalArgumentException("Argument " + (i+1) + " is not " + type.getArguments()[i].getCanonicalName());
|
@ -48,7 +48,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
GalaxiEngine.getInstance().getPluginManager().executeEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port")));
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port"), data.getBoolean("update")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,84 @@
|
||||
package net.ME1312.SubServers.Host.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private Version version;
|
||||
private boolean waitfor;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
*/
|
||||
public PacketUpdateServer() {}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.waitfor = waitfor;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
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);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -67,22 +67,24 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
instance.registerPacket(0x0033, PacketUpdateServer.class);
|
||||
instance.registerPacket(0x0034, PacketEditServer.class);
|
||||
instance.registerPacket(0x0035, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0036, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0037, PacketStopServer.class);
|
||||
instance.registerPacket(0x0038, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0039, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||
instance.registerPacket(0x0031, new PacketAddServer());
|
||||
instance.registerPacket(0x0032, new PacketStartServer());
|
||||
instance.registerPacket(0x0033, new PacketEditServer());
|
||||
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||
instance.registerPacket(0x0036, new PacketStopServer());
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||
instance.registerPacket(0x0033, new PacketUpdateServer());
|
||||
instance.registerPacket(0x0034, new PacketEditServer());
|
||||
instance.registerPacket(0x0035, new PacketRestartServer());
|
||||
instance.registerPacket(0x0036, new PacketCommandServer());
|
||||
instance.registerPacket(0x0037, new PacketStopServer());
|
||||
instance.registerPacket(0x0038, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0039, new PacketDeleteServer());
|
||||
|
||||
|
||||
// 50-69: External Host Packets
|
||||
@ -91,7 +93,7 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0052, PacketOutExRequestQueue.class);
|
||||
instance.registerPacket(0x0053, PacketExCreateServer.class);
|
||||
instance.registerPacket(0x0054, PacketExAddServer.class);
|
||||
instance.registerPacket(0x0055, PacketExUpdateServer.class);
|
||||
instance.registerPacket(0x0055, PacketExEditServer.class);
|
||||
instance.registerPacket(0x0056, PacketOutExLogMessage.class);
|
||||
instance.registerPacket(0x0057, PacketExDeleteServer.class);
|
||||
instance.registerPacket(0x0058, PacketExRemoveServer.class);
|
||||
@ -101,7 +103,7 @@ public class SubProtocol extends SubDataProtocol {
|
||||
//instance.registerPacket(0x0052, new PacketOutExRequestQueue(host));
|
||||
instance.registerPacket(0x0053, new PacketExCreateServer(host));
|
||||
instance.registerPacket(0x0054, new PacketExAddServer(host));
|
||||
instance.registerPacket(0x0055, new PacketExUpdateServer(host));
|
||||
instance.registerPacket(0x0055, new PacketExEditServer(host));
|
||||
//instance.registerPacket(0x0056, new PacketOutExLogMessage());
|
||||
instance.registerPacket(0x0057, new PacketExDeleteServer(host));
|
||||
instance.registerPacket(0x0058, new PacketExRemoveServer(host));
|
||||
|
@ -120,7 +120,7 @@ public class SubCommand {
|
||||
} else {
|
||||
message += TextColor.GREEN;
|
||||
}
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += TextColor.YELLOW;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
@ -153,7 +153,7 @@ public class SubCommand {
|
||||
} else {
|
||||
message += TextColor.GREEN;
|
||||
}
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += TextColor.YELLOW;
|
||||
} else {
|
||||
message += TextColor.RED;
|
||||
@ -216,9 +216,11 @@ public class SubCommand {
|
||||
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + TextColor.WHITE + server.getDisplayName());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + TextColor.WHITE + server.getName());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(" -> Available: " + ((((SubServer) server).isAvailable())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?TextColor.GREEN+"yes":TextColor.RED+"no"));
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + TextColor.RED + "no");
|
||||
sender.sendMessage(" -> Host: " + TextColor.WHITE + ((SubServer) server).getHost());
|
||||
if (((SubServer) server).getTemplate() != null) sender.sendMessage(" -> Template: " + TextColor.WHITE + ((SubServer) server).getTemplate());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + TextColor.WHITE + server.getGroups().get(0)));
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + TextColor.WHITE + group);
|
||||
@ -463,12 +465,15 @@ public class SubCommand {
|
||||
sender.sendMessage("That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("That SubServer is not enabled");
|
||||
sender.sendMessage("That SubServer is not available");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("That SubServer is already running");
|
||||
sender.sendMessage("That SubServer is not enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("That SubServer is already running");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
case 0:
|
||||
@ -530,12 +535,15 @@ public class SubCommand {
|
||||
sender.sendMessage("Could not restart server: That SubServer's Host is no longer enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("Could not restart server: That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
sender.sendMessage("Could not restart server: That SubServer is no longer available");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("Could not restart server: That SubServer cannot start while these server(s) are running:", data.getRawString(0x0002));
|
||||
break;
|
||||
case 9:
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Server was started successfully");
|
||||
@ -722,11 +730,11 @@ public class SubCommand {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (canRun()) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 2) {
|
||||
if (args.length > 4 && Util.isException(() -> Integer.parseInt(args[4]))) {
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
} else {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], new Version(args[3]), (args.length > 4)?Integer.parseInt(args[4]):null, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[0], args[1], args[2], (args.length > 3)?new Version(args[3]):null, (args.length > 4)?Integer.parseInt(args[4]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("Server names cannot use spaces");
|
||||
@ -795,7 +803,7 @@ public class SubCommand {
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}).usage("<Name>", "<Host>", "<Template>", "<Version>", "[Port]").description("Creates a SubServer").help(
|
||||
}).usage("<Name>", "<Host>", "<Template>", "[Version]", "[Port]").description("Creates a SubServer").help(
|
||||
"This command is used to create and launch a SubServer on the specified host via the network.",
|
||||
"Templates are downloaded from SubServers.Bungee to ./Templates.",
|
||||
"",
|
||||
@ -819,6 +827,85 @@ public class SubCommand {
|
||||
" /create ExampleServer ExampleHost Spigot 1.12.2",
|
||||
" /create ExampleServer ExampleHost Spigot 1.12.2 25565"
|
||||
).register("create");
|
||||
new Command(host.info) {
|
||||
@Override
|
||||
public void command(CommandSender sender, String handle, String[] args) {
|
||||
if (canRun()) {
|
||||
if (args.length > 0) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(null, args[0], (args.length > 1)?new Version(args[1]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("That SubServer's Host is not available");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("That SubServer is not available");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("Cannot update servers while they are still running");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("We don't know which template created that SubServer");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("That SubServer's Template is not enabled");
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage("That SubServer's Template does not support server updating");
|
||||
break;
|
||||
case 12:
|
||||
sender.sendMessage("That SubServer's Template requires a Minecraft Version to be specified");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("Launching SubCreator...");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: /" + handle + " <SubServer> [Version]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}.autocomplete((sender, handle, args) -> {
|
||||
String last = (args.length > 0)?args[args.length - 1].toLowerCase():"";
|
||||
if (args.length == 1) {
|
||||
updateCache();
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (String server : serverCache.keySet()) if (serverCache.get(server) == Boolean.TRUE) list.add(server);
|
||||
} else {
|
||||
for (String server : serverCache.keySet()) {
|
||||
if (serverCache.get(server) == Boolean.TRUE && server.toLowerCase().startsWith(last));
|
||||
list.add(last + server.substring(last.length()));
|
||||
}
|
||||
}
|
||||
return list.toArray(new String[0]);
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}).usage("<SubServer>", "[Version]").description("Updates a SubServer").help(
|
||||
"This command is used to update a SubServer via the network.",
|
||||
"Templates are downloaded from SubServers.Bungee to ./Templates.",
|
||||
"",
|
||||
"The <SubServer> argument is required, and should be the name of",
|
||||
"the SubServer you want to update.",
|
||||
"",
|
||||
"When the [Version] argument is provided, it will set the",
|
||||
"Minecraft version of the type of server that you want to update to",
|
||||
"",
|
||||
"Examples:",
|
||||
" /update ExampleServer",
|
||||
" /update ExampleServer 1.12.2"
|
||||
).register("update", "upgrade");
|
||||
}
|
||||
|
||||
private static void updateCache() {
|
||||
|
@ -30,13 +30,13 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiUtil</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.ME1312.Galaxi</groupId>
|
||||
<artifactId>GalaxiEngine</artifactId>
|
||||
<version>19w22b</version>
|
||||
<version>19w24a</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,10 +1,14 @@
|
||||
package net.ME1312.SubServers.Sync.Event;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.SubServers.Sync.Library.SubEvent;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Sync.Network.API.SubServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.api.plugin.Event;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -12,6 +16,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class SubCreateEvent extends Event implements SubEvent {
|
||||
private UUID player;
|
||||
private boolean update;
|
||||
private String host;
|
||||
private String name;
|
||||
private String template;
|
||||
@ -28,9 +33,10 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
* @param version Server Version
|
||||
* @param port Server Port Number
|
||||
*/
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port) {
|
||||
public SubCreateEvent(UUID player, String host, String name, String template, Version version, int port, boolean update) {
|
||||
if (Util.isNull(host, name, template, version, port)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.update = update;
|
||||
this.host = host;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
@ -47,6 +53,33 @@ public class SubCreateEvent extends Event implements SubEvent {
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if SubCreator is being run in update mode
|
||||
*
|
||||
* @return Update Mode Status
|
||||
*/
|
||||
public boolean isUpdate() {
|
||||
return update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Server that's being updated
|
||||
*
|
||||
* @param callback Updating Server
|
||||
*/
|
||||
public void getUpdating(Callback<SubServer> callback) {
|
||||
if (!update) {
|
||||
try {
|
||||
callback.run(null);
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
SubAPI.getInstance().getSubServer(name, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name the SubServer will use
|
||||
*
|
||||
|
@ -8,6 +8,16 @@ import net.md_5.bungee.api.plugin.Command;
|
||||
*/
|
||||
public class GalaxiCommand {
|
||||
|
||||
/**
|
||||
* Group similar Commands
|
||||
*
|
||||
* @param commands Command Classes
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static void group(Class<? extends Command>... commands) {
|
||||
Util.isException(() -> Util.reflect(GalaxiCommandWrapper.class.getDeclaredConstructor(Class[].class), (Object) commands));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Description of a Command
|
||||
*
|
||||
|
@ -0,0 +1,62 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Compatibility;
|
||||
|
||||
import net.ME1312.Galaxi.Galaxi;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Plugin.Command.Command;
|
||||
import net.ME1312.Galaxi.Plugin.Command.CommandSender;
|
||||
import net.ME1312.Galaxi.Plugin.PluginManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class GalaxiCommandWrapper extends Command {
|
||||
private HashMap<String, Command> forwards = new HashMap<String, Command>();
|
||||
private Command data;
|
||||
|
||||
@SafeVarargs
|
||||
GalaxiCommandWrapper(Class<? extends Command>... commands) {
|
||||
super(Galaxi.getInstance().getAppInfo());
|
||||
|
||||
Map<String, Command> registered = Util.getDespiteException(() -> Util.reflect(PluginManager.class.getDeclaredField("commands"), Galaxi.getInstance().getPluginManager()), null);
|
||||
ArrayList<String> tmp = new ArrayList<String>();
|
||||
tmp.addAll(registered.keySet());
|
||||
for (String alias : tmp) {
|
||||
Command command = registered.get(alias);
|
||||
for (Class<? extends Command> type : commands) {
|
||||
if (type.isInstance(command)) {
|
||||
forwards.put(alias, command);
|
||||
if (data == null) data = command;
|
||||
registered.remove(alias);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
register(forwards.keySet().toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void command(CommandSender sender, String label, String[] args) {
|
||||
if (forwards.keySet().contains(label.toLowerCase())) {
|
||||
forwards.get(label.toLowerCase()).command(sender, label, args);
|
||||
} else {
|
||||
throw new IllegalStateException("Command label not recognised in group: " + forwards.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return (data == null)?super.description():data.description();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] help() {
|
||||
return (data == null)?super.help():data.help();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] usage() {
|
||||
return (data == null)?super.usage():data.usage();
|
||||
}
|
||||
}
|
@ -71,11 +71,11 @@ public class ConfigUpdater {
|
||||
|
||||
|
||||
YAMLSection sync = new YAMLSection();
|
||||
settings.set("Disabled-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Disabled-Commands", false));
|
||||
settings.set("Forced-Hosts", updated.getMap("Settings", new YAMLSection()).getBoolean("Forced-Hosts", true));
|
||||
settings.set("Motd", updated.getMap("Settings", new YAMLSection()).getBoolean("Motd", false));
|
||||
settings.set("Player-Limit", updated.getMap("Settings", new YAMLSection()).getBoolean("Player-Limit", false));
|
||||
settings.set("Server-Priorities", updated.getMap("Settings", new YAMLSection()).getBoolean("Server-Priorities", true));
|
||||
sync.set("Disabled-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Disabled-Commands", false));
|
||||
sync.set("Forced-Hosts", updated.getMap("Settings", new YAMLSection()).getBoolean("Forced-Hosts", true));
|
||||
sync.set("Motd", updated.getMap("Settings", new YAMLSection()).getBoolean("Motd", false));
|
||||
sync.set("Player-Limit", updated.getMap("Settings", new YAMLSection()).getBoolean("Player-Limit", false));
|
||||
sync.set("Server-Priorities", updated.getMap("Settings", new YAMLSection()).getBoolean("Server-Priorities", true));
|
||||
|
||||
rewritten.set("Sync", sync);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketCreateServer;
|
||||
import net.ME1312.SubServers.Sync.Network.Packet.PacketUpdateServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -95,6 +96,15 @@ public class SubCreator {
|
||||
public boolean requiresVersion() {
|
||||
return raw.getBoolean("version-req");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this Template can be used to update it's servers
|
||||
*
|
||||
* @return Updatable Status
|
||||
*/
|
||||
public boolean canUpdate() {
|
||||
return raw.getBoolean("can-update");
|
||||
}
|
||||
}
|
||||
public enum ServerType {
|
||||
SPIGOT,
|
||||
@ -119,7 +129,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
if (Util.isNull(response)) throw new NullPointerException();
|
||||
StackTraceElement[] origin = new Exception().getStackTrace();
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(player, name, host.getName(), template.getName(), version, port, data -> {
|
||||
@ -142,7 +152,7 @@ public class SubCreator {
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port, Callback<Integer> response) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port, Callback<Integer> response) {
|
||||
create(null, name, template, version, port, response);
|
||||
}
|
||||
|
||||
@ -155,7 +165,7 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(UUID player, String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(player, name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
@ -167,10 +177,64 @@ public class SubCreator {
|
||||
* @param version Server Version (may be null)
|
||||
* @param port Server Port Number (null to auto-select)
|
||||
*/
|
||||
public void create(String name, ServerTemplate template, Version version, int port) {
|
||||
public void create(String name, ServerTemplate template, Version version, Integer port) {
|
||||
create(name, template, version, port, i -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
* @param response Response Code
|
||||
*/
|
||||
public void update(UUID player, String server, 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 -> {
|
||||
try {
|
||||
response.run(data.getInt(0x0001));
|
||||
} catch (Throwable e) {
|
||||
Throwable ew = new InvocationTargetException(e);
|
||||
ew.setStackTrace(origin);
|
||||
ew.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param player Player Updating
|
||||
* @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 -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a SubServer
|
||||
*
|
||||
* @param server Server to Update
|
||||
* @param version Server Version (may be null)
|
||||
*/
|
||||
public void update(String server, Version version) {
|
||||
update(null, server, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the host this creator belongs to
|
||||
*
|
||||
@ -196,7 +260,6 @@ public class SubCreator {
|
||||
* @return Template
|
||||
*/
|
||||
public ServerTemplate getTemplate(String name) {
|
||||
if (Util.isNull(name)) throw new NullPointerException();
|
||||
return getTemplates().get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import net.ME1312.SubServers.Sync.Network.Packet.PacketStopServer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -396,6 +397,24 @@ public class SubServer extends Server {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Template this Server was created from
|
||||
*
|
||||
* @return The Template
|
||||
*/
|
||||
public String getTemplate() {
|
||||
return raw.getRawString("template");
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this Server Available?
|
||||
*
|
||||
* @return Availability Status
|
||||
*/
|
||||
public boolean isAvailable() {
|
||||
return raw.getBoolean("available");
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Server is Enabled
|
||||
*
|
||||
@ -559,6 +578,35 @@ public class SubServer extends Server {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server) {
|
||||
toggleCompatibility(server, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles compatibility with other Servers
|
||||
*
|
||||
* @param server SubServer to toggle
|
||||
*/
|
||||
public void toggleCompatibility(String server, Callback<Boolean> response) {
|
||||
if (Util.isNull(server, response)) throw new NullPointerException();
|
||||
ArrayList<String> value = new ArrayList<String>();
|
||||
value.addAll(getIncompatibilities());
|
||||
if (!value.contains(server)) value.add(server);
|
||||
else value.remove(server);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("incompatible", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("incompatible", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a Server is compatible
|
||||
*
|
||||
@ -642,4 +690,220 @@ public class SubServer extends Server {
|
||||
callback.run(current);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
*/
|
||||
public void setDisplayName(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Display Name for this Server
|
||||
*
|
||||
* @param value Value (or null to reset)
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setDisplayName(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("display", (value == null)?"":value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("display", (value == null)?getName():value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
*/
|
||||
public void addGroup(String value) {
|
||||
addGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this Server to a Group
|
||||
*
|
||||
* @param value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void addGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<String> v = new ArrayList<String>();
|
||||
v.addAll(getGroups());
|
||||
if (!v.contains(value)) v.add(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
*/
|
||||
public void removeGroup(String value) {
|
||||
removeGroup(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this Server from a Group
|
||||
*
|
||||
* @param value value Group name
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void removeGroup(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> v = new ArrayList<UUID>();
|
||||
v.addAll(getWhitelist());
|
||||
v.remove(value);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("group", v);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("group", v);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setHidden(boolean value) {
|
||||
setHidden(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the server is hidden from players
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setHidden(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setMotd(String value) {
|
||||
setMotd(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the MOTD of the Server
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setMotd(String value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("motd", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("motd", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
*/
|
||||
public void setRestricted(boolean value) {
|
||||
setRestricted(value, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the Server is Restricted
|
||||
*
|
||||
* @param value Value
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void setRestricted(boolean value, Callback<Boolean> response) {
|
||||
if (Util.isNull(value, response)) throw new NullPointerException();
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("restricted", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("restricted", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
*/
|
||||
public void whitelist(UUID player) {
|
||||
whitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the whitelist (for use with restricted servers)
|
||||
*
|
||||
* @param player Player to add
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void whitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
if (!value.contains(player)) value.add(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
*/
|
||||
public void unwhitelist(UUID player) {
|
||||
unwhitelist(player, b -> {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a player to the whitelist
|
||||
*
|
||||
* @param player Player to remove
|
||||
* @param response Success Status
|
||||
*/
|
||||
public void unwhitelist(UUID player, Callback<Boolean> response) {
|
||||
if (Util.isNull(player, response)) throw new NullPointerException();
|
||||
ArrayList<UUID> value = new ArrayList<UUID>();
|
||||
value.addAll(getWhitelist());
|
||||
value.remove(player);
|
||||
|
||||
ObjectMap<String> edit = new ObjectMap<String>();
|
||||
edit.set("whitelist", value);
|
||||
edit(edit, r -> {
|
||||
if (r > 0) raw.set("whitelist", value);
|
||||
response.run(r > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class PacketInExRunEvent implements PacketObjectIn<Integer> {
|
||||
@Override
|
||||
public void run(ObjectMap<String> data) {
|
||||
ProxyServer.getInstance().getPluginManager().callEvent(new SubCreateEvent((data.contains("player"))?data.getUUID("player"):null, data.getRawString("host"), data.getRawString("name"),
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port")));
|
||||
data.getRawString("template"), data.getVersion("version"), data.getInt("port"), data.getBoolean("update")));
|
||||
callback("SubCreateEvent", this);
|
||||
}
|
||||
});
|
||||
|
@ -0,0 +1,84 @@
|
||||
package net.ME1312.SubServers.Sync.Network.Packet;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectIn;
|
||||
import net.ME1312.SubData.Client.Protocol.PacketObjectOut;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Create Server Packet
|
||||
*/
|
||||
public class PacketUpdateServer implements PacketObjectIn<Integer>, PacketObjectOut<Integer> {
|
||||
private static HashMap<UUID, Callback<ObjectMap<Integer>>[]> callbacks = new HashMap<UUID, Callback<ObjectMap<Integer>>[]>();
|
||||
private UUID player;
|
||||
private String name;
|
||||
private Version version;
|
||||
private boolean waitfor;
|
||||
private UUID tracker;
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (In)
|
||||
*/
|
||||
public PacketUpdateServer() {}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* New PacketCreateServer (Out)
|
||||
*
|
||||
* @param player Player Creating
|
||||
* @param name Server Name
|
||||
* @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) {
|
||||
if (Util.isNull(name, callback)) throw new NullPointerException();
|
||||
this.player = player;
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.waitfor = waitfor;
|
||||
this.tracker = Util.getNew(callbacks.keySet(), UUID::randomUUID);
|
||||
callbacks.put(tracker, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectMap<Integer> send(SubDataClient client) {
|
||||
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);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive(SubDataClient client, ObjectMap<Integer> data) {
|
||||
for (Callback<ObjectMap<Integer>> callback : callbacks.get(data.getUUID(0x0000))) callback.run(data);
|
||||
callbacks.remove(data.getUUID(0x0000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int version() {
|
||||
return 0x0001;
|
||||
}
|
||||
}
|
@ -72,22 +72,24 @@ public class SubProtocol extends SubDataProtocol {
|
||||
instance.registerPacket(0x0030, PacketCreateServer.class);
|
||||
instance.registerPacket(0x0031, PacketAddServer.class);
|
||||
instance.registerPacket(0x0032, PacketStartServer.class);
|
||||
instance.registerPacket(0x0033, PacketEditServer.class);
|
||||
instance.registerPacket(0x0034, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0035, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0036, PacketStopServer.class);
|
||||
instance.registerPacket(0x0037, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0038, PacketDeleteServer.class);
|
||||
instance.registerPacket(0x0033, PacketUpdateServer.class);
|
||||
instance.registerPacket(0x0034, PacketEditServer.class);
|
||||
instance.registerPacket(0x0035, PacketRestartServer.class);
|
||||
instance.registerPacket(0x0036, PacketCommandServer.class);
|
||||
instance.registerPacket(0x0037, PacketStopServer.class);
|
||||
instance.registerPacket(0x0038, PacketRemoveServer.class);
|
||||
instance.registerPacket(0x0039, PacketDeleteServer.class);
|
||||
|
||||
instance.registerPacket(0x0030, new PacketCreateServer());
|
||||
instance.registerPacket(0x0031, new PacketAddServer());
|
||||
instance.registerPacket(0x0032, new PacketStartServer());
|
||||
instance.registerPacket(0x0033, new PacketEditServer());
|
||||
instance.registerPacket(0x0034, new PacketRestartServer());
|
||||
instance.registerPacket(0x0035, new PacketCommandServer());
|
||||
instance.registerPacket(0x0036, new PacketStopServer());
|
||||
instance.registerPacket(0x0037, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0038, new PacketDeleteServer());
|
||||
instance.registerPacket(0x0033, new PacketUpdateServer());
|
||||
instance.registerPacket(0x0034, new PacketEditServer());
|
||||
instance.registerPacket(0x0035, new PacketRestartServer());
|
||||
instance.registerPacket(0x0036, new PacketCommandServer());
|
||||
instance.registerPacket(0x0037, new PacketStopServer());
|
||||
instance.registerPacket(0x0038, new PacketRemoveServer());
|
||||
instance.registerPacket(0x0039, new PacketDeleteServer());
|
||||
|
||||
|
||||
// 70-79: External Misc Packets
|
||||
|
@ -164,7 +164,7 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
}
|
||||
} else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (((SubServer) server).isAvailable() && ((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -183,7 +183,7 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("Host/SubServer List:");
|
||||
for (Host host : hosts.values()) {
|
||||
String message = " ";
|
||||
if (host.isEnabled()) {
|
||||
if (host.isAvailable() && host.isEnabled()) {
|
||||
message += ChatColor.AQUA;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -197,7 +197,7 @@ public final class SubCommand extends CommandX {
|
||||
} else {
|
||||
message += ChatColor.GREEN;
|
||||
}
|
||||
} else if (subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
} else if (subserver.isAvailable() && subserver.isEnabled() && subserver.getCurrentIncompatibilities().size() == 0) {
|
||||
message += ChatColor.YELLOW;
|
||||
} else {
|
||||
message += ChatColor.RED;
|
||||
@ -249,9 +249,11 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > Info on " + ((server instanceof SubServer)?"Sub":"") + "Server: " + ChatColor.WHITE + server.getDisplayName());
|
||||
if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" -> System Name: " + ChatColor.WHITE + server.getName());
|
||||
if (server instanceof SubServer) {
|
||||
sender.sendMessage(" -> Available: " + ((((SubServer) server).isAvailable())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
sender.sendMessage(" -> Enabled: " + ((((SubServer) server).isEnabled())?ChatColor.GREEN+"yes":ChatColor.RED+"no"));
|
||||
if (!((SubServer) server).isEditable()) sender.sendMessage(" -> Editable: " + ChatColor.RED + "no");
|
||||
sender.sendMessage(" -> Host: " + ChatColor.WHITE + ((SubServer) server).getHost());
|
||||
if (((SubServer) server).getTemplate() != null) sender.sendMessage(" -> Template: " + ChatColor.WHITE + ((SubServer) server).getHost());
|
||||
}
|
||||
if (server.getGroups().size() > 0) sender.sendMessage(" -> Group" + ((server.getGroups().size() > 1)?"s:":": " + ChatColor.WHITE + server.getGroups().get(0)));
|
||||
if (server.getGroups().size() > 1) for (String group : server.getGroups()) sender.sendMessage(" - " + ChatColor.WHITE + group);
|
||||
@ -377,12 +379,15 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("SubServers > That SubServer is not enabled");
|
||||
sender.sendMessage("SubServers > That SubServer is not available");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("SubServers > That SubServer is already running");
|
||||
sender.sendMessage("SubServers > That SubServer is not enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("SubServers > That SubServer is already running");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("SubServers > That SubServer cannot start while these server(s) are running: " + data.getRawString(0x0002));
|
||||
break;
|
||||
case 0:
|
||||
@ -412,12 +417,15 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer's Host is no longer enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer cannot start while these server(s) are running: " + data.getRawString(0x0002));
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer is no longer available");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer is no longer enabled");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("SubServers > Could not restart server: That SubServer cannot start while these server(s) are running: " + data.getRawString(0x0002));
|
||||
break;
|
||||
case 9:
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("SubServers > Server was started successfully");
|
||||
@ -538,11 +546,11 @@ public final class SubCommand extends CommandX {
|
||||
sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <SubServer> <Command> [Args...]");
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("create")) {
|
||||
if (args.length > 4) {
|
||||
if (args.length > 3) {
|
||||
if (args.length > 5 && Util.isException(() -> Integer.parseInt(args[5]))) {
|
||||
sender.sendMessage("Invalid Port Number");
|
||||
} else {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[1], args[2],args[3], new Version(args[4]), (args.length > 5)?Integer.parseInt(args[5]):null, data -> {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketCreateServer(null, args[1], args[2],args[3], (args.length > 4)?new Version(args[4]):null, (args.length > 5)?Integer.parseInt(args[5]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
case 4:
|
||||
@ -576,8 +584,49 @@ public final class SubCommand extends CommandX {
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("update") || args[0].equalsIgnoreCase("upgrade")) {
|
||||
if (args.length > 1) {
|
||||
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketUpdateServer(null, args[1], (args.length > 2)?new Version(args[2]):null, data -> {
|
||||
switch (data.getInt(0x0001)) {
|
||||
case 3:
|
||||
sender.sendMessage("SubServers > There is no server with that name");
|
||||
break;
|
||||
case 4:
|
||||
sender.sendMessage("SubServers > That Server is not a SubServer");
|
||||
break;
|
||||
case 5:
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not available");
|
||||
break;
|
||||
case 6:
|
||||
sender.sendMessage("SubServers > That SubServer's Host is not enabled");
|
||||
break;
|
||||
case 7:
|
||||
sender.sendMessage("SubServers > That SubServer is not available");
|
||||
break;
|
||||
case 8:
|
||||
sender.sendMessage("SubServers > Cannot update servers while they are still running");
|
||||
break;
|
||||
case 9:
|
||||
sender.sendMessage("SubServers > We don't know which template created that SubServer");
|
||||
break;
|
||||
case 10:
|
||||
sender.sendMessage("SubServers > That SubServer's Template is not enabled");
|
||||
break;
|
||||
case 11:
|
||||
sender.sendMessage("SubServers > That SubServer's Template does not support server updating");
|
||||
break;
|
||||
case 12:
|
||||
sender.sendMessage("SubServers > That SubServer's Template requires a Minecraft Version to be specified");
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
sender.sendMessage("SubServers > Launching SubCreator...");
|
||||
break;
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <Name> <Host> <Template> [Version] [Port]");
|
||||
sender.sendMessage("Usage: " + label + " " + args[0].toLowerCase() + " <SubServer> [Version]");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("SubServers > Unknown sub-command: " + args[0]);
|
||||
@ -606,6 +655,7 @@ public final class SubCommand extends CommandX {
|
||||
" Terminate Server: /sub kill <SubServer>",
|
||||
" Command Server: /sub cmd <SubServer> <Command> [Args...]",
|
||||
" Create Server: /sub create <Name> <Host> <Template> [Version] [Port]",
|
||||
" Update Server: /sub update <SubServer> [Version]",
|
||||
"",
|
||||
" To see BungeeCord Supplied Commands, please visit:",
|
||||
" https://www.spigotmc.org/wiki/bungeecord-commands/"
|
||||
@ -648,7 +698,7 @@ public final class SubCommand extends CommandX {
|
||||
}
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
} else if (args.length <= 1) {
|
||||
List<String> cmds = Arrays.asList("help", "list", "info", "status", "version", "start", "restart", "stop", "kill", "terminate", "cmd", "command", "create");
|
||||
List<String> cmds = Arrays.asList("help", "list", "info", "status", "version", "start", "restart", "stop", "kill", "terminate", "cmd", "command", "create", "update", "upgrade");
|
||||
if (last.length() == 0) {
|
||||
return new NamedContainer<>(null, cmds);
|
||||
} else {
|
||||
@ -835,19 +885,30 @@ public final class SubCommand extends CommandX {
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Creator.Invalid-Template").replace("$str$", args[0]):null, list);
|
||||
} else if (args.length == 5) {
|
||||
if (last.length() > 0) {
|
||||
if (new Version("1.8").compareTo(new Version(last)) > 0) {
|
||||
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Version"), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>(null, Collections.singletonList("<Version>"));
|
||||
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
|
||||
} else if (args.length == 6) {
|
||||
if (last.length() > 0) {
|
||||
if (Util.isException(() -> Integer.parseInt(last)) || Integer.parseInt(last) <= 0 || Integer.parseInt(last) > 65535) {
|
||||
return new NamedContainer<>(plugin.api.getLang("SubServers", "Command.Creator.Invalid-Port"), Collections.emptyList());
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>(null, Collections.singletonList("<Port>"));
|
||||
return new NamedContainer<>(null, Collections.singletonList("[Port]"));
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
} else if (args[0].equals("update") || args[0].equals("upgrade")) {
|
||||
if (args.length == 2) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
if (last.length() == 0) {
|
||||
for (ServerContainer server : plugin.servers.values()) list.add(server.getName());
|
||||
} else {
|
||||
for (ServerContainer server : plugin.servers.values()) {
|
||||
if (server.getName().toLowerCase().startsWith(last)) list.add(last + server.getName().substring(last.length()));
|
||||
}
|
||||
}
|
||||
return new NamedContainer<>((list.size() <= 0)?plugin.api.getLang("SubServers", "Command.Generic.Unknown-SubServer").replace("$str$", args[0]):null, list);
|
||||
} else if (args.length == 3) {
|
||||
return new NamedContainer<>(null, Collections.singletonList("[Version]"));
|
||||
} else {
|
||||
return new NamedContainer<>(null, Collections.emptyList());
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import net.ME1312.SubData.Client.Encryption.RSA;
|
||||
import net.ME1312.SubServers.Sync.Event.*;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubServers.Sync.Library.Compatibility.GalaxiCommand;
|
||||
import net.ME1312.SubServers.Sync.Library.Compatibility.Logger;
|
||||
import net.ME1312.SubServers.Sync.Library.Fallback.SmartReconnectHandler;
|
||||
import net.ME1312.SubServers.Sync.Library.Metrics;
|
||||
@ -54,7 +55,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public boolean redis = false;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
public SubProtocol subprotocol;
|
||||
public static final Version version = Version.fromString("2.14a");
|
||||
public static final Version version = Version.fromString("2.14.2a");
|
||||
|
||||
public final boolean isPatched;
|
||||
public final boolean isGalaxi;
|
||||
@ -162,6 +163,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());
|
||||
GalaxiCommand.group(SubCommand.class);
|
||||
|
||||
new Metrics(this);
|
||||
new Timer("SubServers.Sync::Routine_Update_Check").schedule(new TimerTask() {
|
||||
|
Loading…
Reference in New Issue
Block a user