mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 19:56:24 +01:00
Config Updater & Smart Fallback Update
This commit is contained in:
parent
472c83f975
commit
776183510e
@ -36,7 +36,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>19w16b</version>
|
||||
<version>19w18a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -210,13 +210,13 @@ public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
ObjectMap<String> info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?plugin.servers.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -247,13 +247,13 @@ public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
ObjectMap<String> info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?plugin.servers.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -286,13 +286,13 @@ public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
ObjectMap<String> info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?plugin.servers.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -323,13 +323,13 @@ public class ExternalHost extends Host implements SerializableClientHandler {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
ObjectMap<String> info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?plugin.config.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
ObjectMap<String> info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?plugin.servers.get().getMap("Servers").getMap(server).clone():new ObjectMap<String>();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -132,8 +132,8 @@ public class ExternalSubCreator extends SubCreator {
|
||||
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.config.get().getMap("Servers").set(name, server);
|
||||
host.plugin.config.save();
|
||||
host.plugin.servers.get().getMap("Servers").set(name, server);
|
||||
host.plugin.servers.save();
|
||||
if (template.getBuildOptions().getBoolean("Run-On-Finish", true))
|
||||
subserver.start();
|
||||
|
||||
|
@ -16,6 +16,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -28,7 +29,7 @@ public class ExternalSubLogger extends SubLogger {
|
||||
protected UUID id = null;
|
||||
protected String name;
|
||||
protected Container<Boolean> log;
|
||||
private List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
|
||||
private List<SubLogFilter> filters = new CopyOnWriteArrayList<>();
|
||||
protected File file;
|
||||
private PrintWriter writer = null;
|
||||
private boolean started = false;
|
||||
|
@ -119,9 +119,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
host.deleteSubServer(getName());
|
||||
} else {
|
||||
try {
|
||||
if (host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
host.plugin.config.save();
|
||||
if (host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.servers.get().getMap("Servers").remove(getName());
|
||||
host.plugin.servers.save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -195,11 +195,11 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.config.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -217,13 +217,13 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
}
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
} else {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
}
|
||||
this.host.plugin.config.save();
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
@ -232,9 +232,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (value.isBoolean()) {
|
||||
if (enabled != value.asBoolean()) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_ENABLED, (Boolean) value.asBoolean()));
|
||||
enabled = value.asBoolean();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -242,9 +242,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -254,9 +254,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -268,9 +268,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -280,9 +280,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -291,9 +291,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -303,9 +303,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Directory", server.getPath());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -317,9 +317,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -335,9 +335,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
if (value.isString()) {
|
||||
if (!stopcmd.equals(value)) host.queue(new PacketExUpdateServer(this, PacketExUpdateServer.UpdateType.SET_STOP_COMMAND, value.asRawString()));
|
||||
stopcmd = value.asRawString();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -347,9 +347,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -357,9 +357,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "auto-run":
|
||||
if (value.isBoolean()) {
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -370,9 +370,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
}
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -380,9 +380,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -390,9 +390,9 @@ public class ExternalSubServer extends SubServerContainer {
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
|
@ -168,13 +168,13 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
YAMLSection info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.servers.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||
@ -213,13 +213,13 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
YAMLSection info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.servers.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"), false);
|
||||
@ -257,13 +257,13 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
YAMLSection info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.servers.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"));
|
||||
@ -302,13 +302,13 @@ public class InternalHost extends Host {
|
||||
}
|
||||
|
||||
System.out.println("SubServers > Saving...");
|
||||
YAMLSection info = (plugin.config.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.config.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
YAMLSection info = (plugin.servers.get().getMap("Servers").getKeys().contains(server))?new YAMLSection(plugin.servers.get().getMap("Servers").getMap(server).get()):new YAMLSection();
|
||||
info.set("Name", server);
|
||||
info.set("Timestamp", Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
if (plugin.config.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.config.get().getMap("Servers").remove(server);
|
||||
plugin.config.save();
|
||||
if (plugin.servers.get().getMap("Servers").getKeys().contains(server)) {
|
||||
plugin.servers.get().getMap("Servers").remove(server);
|
||||
plugin.servers.save();
|
||||
}
|
||||
if (!to.exists()) to.mkdirs();
|
||||
FileWriter writer = new FileWriter(new File(to, "info.json"), false);
|
||||
|
@ -223,8 +223,8 @@ public class InternalSubCreator extends SubCreator {
|
||||
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.config.get().getMap("Servers").set(name, server);
|
||||
host.plugin.config.save();
|
||||
host.plugin.servers.get().getMap("Servers").set(name, server);
|
||||
host.plugin.servers.save();
|
||||
if (template.getBuildOptions().getBoolean("Run-On-Finish", true))
|
||||
subserver.start();
|
||||
|
||||
|
@ -11,6 +11,7 @@ import java.io.*;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -23,7 +24,7 @@ public class InternalSubLogger extends SubLogger {
|
||||
private Object handle;
|
||||
protected String name;
|
||||
protected Container<Boolean> log;
|
||||
private List<SubLogFilter> filters = new ArrayList<SubLogFilter>();
|
||||
private List<SubLogFilter> filters = new CopyOnWriteArrayList<>();
|
||||
protected File file;
|
||||
private PrintWriter writer = null;
|
||||
private boolean started = false;
|
||||
|
@ -155,9 +155,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
host.deleteSubServer(getName());
|
||||
} else {
|
||||
try {
|
||||
if (host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
host.plugin.config.save();
|
||||
if (host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
host.plugin.servers.get().getMap("Servers").remove(getName());
|
||||
host.plugin.servers.save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -275,11 +275,11 @@ public class InternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
ObjectMap<String> config = this.host.plugin.config.get().getMap("Servers").getMap(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").remove(getName());
|
||||
this.host.plugin.config.get().getMap("Servers").set(server.getName(), config);
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -297,13 +297,13 @@ public class InternalSubServer extends SubServerContainer {
|
||||
}
|
||||
f.setAccessible(false);
|
||||
logger.name = getDisplayName();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (this.host.plugin.servers.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
if (getName().equals(getDisplayName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).remove("Display");
|
||||
} else {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
this.host.plugin.servers.get().getMap("Servers").getMap(getName()).set("Display", getDisplayName());
|
||||
}
|
||||
this.host.plugin.config.save();
|
||||
this.host.plugin.servers.save();
|
||||
}
|
||||
c++;
|
||||
}
|
||||
@ -311,9 +311,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "enabled":
|
||||
if (value.isBoolean()) {
|
||||
enabled = value.asBoolean();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Enabled", isEnabled());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -321,9 +321,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "group":
|
||||
if (value.isList()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("groups"), this, value.asStringList());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Group", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -332,9 +332,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Host", server.getHost().getName());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -345,9 +345,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
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 (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Port", server.getAddress().getPort());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
@ -357,9 +357,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "motd":
|
||||
if (value.isString()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("motd"), this, ChatColor.translateAlternateColorCodes('&', value.asString()));
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Motd", value.asString());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -367,9 +367,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "log":
|
||||
if (value.isBoolean()) {
|
||||
log.set(value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Log", isLogging());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -382,9 +382,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
}
|
||||
dir = value.asRawString();
|
||||
directory = new File(getHost().getPath(), value.asRawString());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Directory", getPath());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -396,9 +396,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
waitFor();
|
||||
}
|
||||
executable = value.asRawString();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Executable", value.asRawString());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -406,9 +406,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "stop-cmd":
|
||||
if (value.isString()) {
|
||||
stopcmd = value.asRawString();
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Command", getStopCommand());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -418,9 +418,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
StopAction action = Util.getDespiteException(() -> StopAction.valueOf(value.asRawString().toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null) {
|
||||
stopaction = action;
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Stop-Action", getStopAction().toString());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -433,9 +433,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
break;
|
||||
case "auto-run":
|
||||
if (value.isBoolean()) {
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Run-On-Launch", value.asBoolean());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -446,9 +446,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
SubServer oserver = host.plugin.api.getSubServer(oname);
|
||||
if (oserver != null && isCompatible(oserver)) toggleCompatibility(oserver);
|
||||
}
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Incompatible", value.asStringList());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -456,9 +456,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "restricted":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(BungeeServerInfo.class.getDeclaredField("restricted"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Restricted", isRestricted());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
@ -466,9 +466,9 @@ public class InternalSubServer extends SubServerContainer {
|
||||
case "hidden":
|
||||
if (value.isBoolean()) {
|
||||
Util.reflect(ServerContainer.class.getDeclaredField("hidden"), this, value.asBoolean());
|
||||
if (this.host.plugin.config.get().getMap("Servers").getKeys().contains(getName())) {
|
||||
this.host.plugin.config.get().getMap("Servers").getMap(getName()).set("Hidden", isHidden());
|
||||
this.host.plugin.config.save();
|
||||
if (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++;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public abstract class SubServerContainer extends ServerContainer implements SubS
|
||||
sinfo.set("running", isRunning());
|
||||
sinfo.set("stop-cmd", getStopCommand());
|
||||
sinfo.set("stop-action", getStopAction().toString());
|
||||
sinfo.set("auto-run", SubAPI.getInstance().getInternals().config.get().getMap("Servers").getMap(getName(), new ObjectMap<String>()).getBoolean("Run-On-Launch", false));
|
||||
sinfo.set("auto-run", SubAPI.getInstance().getInternals().servers.get().getMap("Servers").getMap(getName(), new ObjectMap<String>()).getBoolean("Run-On-Launch", false));
|
||||
List<String> incompatibleCurrent = new ArrayList<String>();
|
||||
List<String> incompatible = new ArrayList<String>();
|
||||
for (SubServer server : getCurrentIncompatibilities()) incompatibleCurrent.add(server.getName());
|
||||
|
@ -0,0 +1,205 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Compatibility.Updates;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLSection;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* SubServers Configuration Updater
|
||||
*/
|
||||
public class ConfigUpdater {
|
||||
private static final Version UNSIGNED = new Version(new SimpleDateFormat("yy'w'ww'zz'").format(Calendar.getInstance().getTime()));
|
||||
|
||||
/**
|
||||
* Update SubServers' config.yml
|
||||
*
|
||||
* @param file File to bring up-to-date
|
||||
*/
|
||||
public static void updateConfig(File file) throws IOException {
|
||||
YAMLConfig config = new YAMLConfig(file);
|
||||
YAMLSection updated = config.get().clone();
|
||||
YAMLSection rewritten = new YAMLSection();
|
||||
|
||||
Version was = updated.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
|
||||
Version now = SubAPI.getInstance().getWrapperBuild();
|
||||
|
||||
int i = 0;
|
||||
if (now == null) now = UNSIGNED;
|
||||
if (!updated.contains("Settings") || !updated.getMap("Settings").contains("Version")) {
|
||||
YAMLSection hosts = new YAMLSection();
|
||||
YAMLSection host = new YAMLSection();
|
||||
host.set("Enabled", true);
|
||||
host.set("Display", "Default");
|
||||
hosts.set("~", host);
|
||||
updated.set("Hosts", hosts);
|
||||
|
||||
i++;
|
||||
System.out.println("SubServers > Created ./SubServers/config.yml");
|
||||
} else {
|
||||
if (was.compareTo(new Version("19w17a")) <= 0) {
|
||||
if (updated.getMap("Settings", new YAMLSection()).contains("Log-Creator")) for (String name : updated.getMap("Hosts", new YAMLSection()).getKeys())
|
||||
updated.getMap("Hosts").getMap(name).safeSet("Log-Creator", updated.getMap("Settings").getBoolean("Log-Creator"));
|
||||
|
||||
if (updated.getMap("Settings", new YAMLSection()).contains("SubData") && !updated.getMap("Settings", new YAMLSection()).getMap("SubData").contains("Encryption"))
|
||||
updated.getMap("Settings").getMap("SubData").set("Encryption", "NONE");
|
||||
|
||||
if (updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).contains("Allowed-Connections"))
|
||||
updated.getMap("Settings").getMap("SubData").safeSet("Whitelist", updated.getMap("Settings").getMap("SubData").getRawStringList("Allowed-Connections"));
|
||||
|
||||
if (updated.contains("Servers")) {
|
||||
YAMLConfig sc = new YAMLConfig(new File(file.getParentFile(), "servers.yml"));
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", was.toString());
|
||||
settings.set("Run-On-Launch-Timeout", (updated.getMap("Settings", new YAMLSection()).contains("Run-On-Launch-Timeout"))?updated.getMap("Settings").getInt("Run-On-Launch-Timeout"):0);
|
||||
sc.get().safeSet("Settings", settings);
|
||||
|
||||
sc.get().safeSet("Servers", new YAMLSection());
|
||||
sc.get().getMap("Servers").safeSetAll(updated.getMap("Servers"));
|
||||
System.out.println("SubServers > Created ./SubServers/servers.yml (using existing data)");
|
||||
sc.save();
|
||||
}
|
||||
i++;
|
||||
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||
// // do something
|
||||
// i++
|
||||
//}
|
||||
|
||||
if (i > 0) System.out.println("SubServers > Updated ./SubServers/config.yml (" + i + " pass" + ((i != 1)?"es":"") + ")");
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||
settings.set("Override-Bungee-Commands", updated.getMap("Settings", new YAMLSection()).getBoolean("Override-Bungee-Commands", true));
|
||||
|
||||
YAMLSection upnp = new YAMLSection();
|
||||
upnp.set("Forward-Proxy", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-Proxy", true));
|
||||
upnp.set("Forward-SubData", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-SubData", false));
|
||||
upnp.set("Forward-Servers", updated.getMap("Settings", new YAMLSection()).getMap("UPnP", new YAMLSection()).getBoolean("Forward-Servers", false));
|
||||
settings.set("UPnP", upnp);
|
||||
|
||||
YAMLSection subdata = new YAMLSection();
|
||||
subdata.set("Address", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Address", "127.0.0.1:4391"));
|
||||
subdata.set("Password", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Password", ""));
|
||||
subdata.set("Encryption", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawString("Encryption", "RSA/AES"));
|
||||
subdata.set("Whitelist", updated.getMap("Settings", new YAMLSection()).getMap("SubData", new YAMLSection()).getRawStringList("Whitelist", Collections.emptyList()));
|
||||
settings.set("SubData", subdata);
|
||||
|
||||
rewritten.set("Settings", settings);
|
||||
|
||||
|
||||
YAMLSection hosts = new YAMLSection();
|
||||
for (String name : updated.getMap("Hosts", new YAMLSection()).getKeys()) {
|
||||
YAMLSection host = new YAMLSection();
|
||||
host.set("Enabled", updated.getMap("Hosts").getMap(name).getBoolean("Enabled", false));
|
||||
host.set("Display", updated.getMap("Hosts").getMap(name).getRawString("Display", ""));
|
||||
host.set("Driver", updated.getMap("Hosts").getMap(name).getRawString("Driver", "BUILT-IN"));
|
||||
host.set("Address", updated.getMap("Hosts").getMap(name).getRawString("Address", "127.0.0.1"));
|
||||
host.set("Port-Range", updated.getMap("Hosts").getMap(name).getRawString("Port-Range", "25500-25559"));
|
||||
host.set("Directory", updated.getMap("Hosts").getMap(name).getRawString("Directory", (host.getRawString("Driver").equalsIgnoreCase("BUILT-IN"))?"./SubServers/Servers":"./Servers"));
|
||||
host.set("Git-Bash", updated.getMap("Hosts").getMap(name).getRawString("Git-Bash", "%ProgramFiles%\\Git"));
|
||||
host.set("Log-Creator", updated.getMap("Hosts").getMap(name).getBoolean("Log-Creator", true));
|
||||
if (updated.getMap("Hosts").getMap(name).contains("Extra")) host.set("Extra", updated.getMap("Hosts").getMap(name).getMap("Extra"));
|
||||
hosts.set(name, host);
|
||||
}
|
||||
rewritten.set("Hosts", hosts);
|
||||
|
||||
config.set(rewritten);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update SubServers' servers.yml
|
||||
*
|
||||
* @param file File to bring up-to-date
|
||||
*/
|
||||
public static void updateServers(File file) throws IOException {
|
||||
YAMLConfig config = new YAMLConfig(file);
|
||||
YAMLSection updated = config.get().clone();
|
||||
YAMLSection rewritten = new YAMLSection();
|
||||
|
||||
Version was = updated.getMap("Settings", new ObjectMap<>()).getVersion("Version", new Version(0));
|
||||
Version now = SubAPI.getInstance().getWrapperBuild();
|
||||
|
||||
int i = 0;
|
||||
if (now == null) now = UNSIGNED;
|
||||
if (!updated.contains("Settings") || !updated.getMap("Settings").contains("Version")) {
|
||||
YAMLSection servers = new YAMLSection();
|
||||
servers.set("Example", new YAMLSection());
|
||||
updated.set("Servers", servers);
|
||||
|
||||
i++;
|
||||
System.out.println("SubServers > Created ./SubServers/servers.yml");
|
||||
} else {
|
||||
if (was.compareTo(new Version("19w17a")) <= 0) {
|
||||
for (String name : updated.getMap("Servers", new YAMLSection()).getKeys()) {
|
||||
if (updated.getMap("Servers").getMap(name).getBoolean("Auto-Restart", true))
|
||||
updated.getMap("Servers").getMap(name).safeSet("Stop-Action", "RESTART");
|
||||
|
||||
if (updated.getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").equalsIgnoreCase("DELETE_SERVER"))
|
||||
updated.getMap("Servers").getMap(name).set("Stop-Action", "RECYCLE_SERVER");
|
||||
}
|
||||
i++;
|
||||
}// if (was.compareTo(new Version("99w99a")) <= 0) {
|
||||
// // do something
|
||||
// i++
|
||||
//}
|
||||
|
||||
if (i > 0) System.out.println("SubServers > Updated ./SubServers/servers.yml (" + i + " pass" + ((i != 1)?"es":"") + ")");
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
YAMLSection settings = new YAMLSection();
|
||||
settings.set("Version", ((now.compareTo(was) <= 0)?was:now).toString());
|
||||
settings.set("Smart-Fallback", updated.getMap("Settings", new YAMLSection()).getBoolean("Smart-Fallback", true));
|
||||
settings.set("Run-On-Launch-Timeout", updated.getMap("Settings", new YAMLSection()).getInt("Run-On-Launch-Timeout", 0));
|
||||
|
||||
rewritten.set("Settings", settings);
|
||||
|
||||
|
||||
YAMLSection servers = new YAMLSection();
|
||||
for (String name : updated.getMap("Servers", new YAMLSection()).getKeys()) {
|
||||
YAMLSection server = new YAMLSection();
|
||||
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", "~"));
|
||||
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"));
|
||||
server.set("Log", updated.getMap("Servers").getMap(name).getBoolean("Log", true));
|
||||
server.set("Directory", updated.getMap("Servers").getMap(name).getRawString("Directory", "." + File.separatorChar));
|
||||
server.set("Executable", updated.getMap("Servers").getMap(name).getRawString("Executable", "java -Xmx1024M -Djline.terminal=jline.UnsupportedTerminal -jar Spigot.jar"));
|
||||
server.set("Stop-Command", updated.getMap("Servers").getMap(name).getRawString("Stop-Command", "stop"));
|
||||
server.set("Stop-Action", updated.getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE"));
|
||||
server.set("Run-On-Launch", updated.getMap("Servers").getMap(name).getBoolean("Run-On-Launch", false));
|
||||
server.set("Restricted", updated.getMap("Servers").getMap(name).getBoolean("Restricted", false));
|
||||
server.set("Incompatible", updated.getMap("Servers").getMap(name).getRawStringList("Incompatible", Collections.emptyList()));
|
||||
server.set("Hidden", updated.getMap("Servers").getMap(name).getBoolean("Hidden", false));
|
||||
if (updated.getMap("Servers").getMap(name).contains("Extra")) server.set("Extra", updated.getMap("Servers").getMap(name).getMap("Extra"));
|
||||
servers.set(name, server);
|
||||
}
|
||||
rewritten.set("Servers", servers);
|
||||
|
||||
config.set(rewritten);
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update SubServers' lang.yml
|
||||
*
|
||||
* @param file File to bring up-to-date
|
||||
*/
|
||||
public static void updateLang(File file) throws IOException {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Fallback;
|
||||
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
/**
|
||||
* Fallback Server Inspector Layout Class
|
||||
*/
|
||||
public interface FallbackInspector {
|
||||
|
||||
/**
|
||||
* Inspect a fallback server and modify it's confidence score
|
||||
*
|
||||
* @param server Server to inspect
|
||||
* @return A Positive Value to add points, a Negative Value to subtract points, a Null Value to invalidate the server, or a Zero Value to do nothing
|
||||
*/
|
||||
Integer inspect(ServerInfo server);
|
||||
}
|
@ -0,0 +1,152 @@
|
||||
package net.ME1312.SubServers.Bungee.Library.Fallback;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.SubServers.Bungee.Host.Server;
|
||||
import net.ME1312.SubServers.Bungee.Host.SubServer;
|
||||
import net.ME1312.SubServers.Bungee.SubAPI;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ReconnectHandler;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Smart Reconnect Handler Class
|
||||
*/
|
||||
public class SmartReconnectHandler implements ReconnectHandler {
|
||||
private static List<FallbackInspector> inspectors = new CopyOnWriteArrayList<FallbackInspector>();
|
||||
|
||||
@Override
|
||||
public ServerInfo getServer(ProxiedPlayer player) {
|
||||
ServerInfo forced = getForcedHost(player.getPendingConnection());
|
||||
if (forced != null) {
|
||||
return forced;
|
||||
} else {
|
||||
Map<String, ServerInfo> fallbacks = getFallbackServers(player.getPendingConnection().getListener());
|
||||
if (fallbacks.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
if (player instanceof UserConnection) ((UserConnection) player).setServerJoinQueue(new LinkedBlockingQueue<>(fallbacks.keySet()));
|
||||
return new LinkedList<Map.Entry<String, ServerInfo>>(fallbacks.entrySet()).getFirst().getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Forced Host Server for this connection
|
||||
*
|
||||
* @see AbstractReconnectHandler#getForcedHost(PendingConnection) Essentially the same method, but more ambigous
|
||||
* @param connection Connection to check
|
||||
* @return Forced Host Server (or null if there is none)
|
||||
*/
|
||||
public static ServerInfo getForcedHost(PendingConnection connection) {
|
||||
if (connection.getVirtualHost() == null) {
|
||||
return null;
|
||||
} else {
|
||||
String forced = connection.getListener().getForcedHosts().get(connection.getVirtualHost().getHostString());
|
||||
//if (forced == null && con.getListener().isForceDefault()) { // This is the part of the method that made it ambiguous
|
||||
// forced = con.getListener().getDefaultServer(); // Aside from that, everything else was fine
|
||||
//} // :(
|
||||
|
||||
return ProxyServer.getInstance().getServerInfo(forced);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a <i>smart</i> sorted map of fallback servers using a generated confidence score
|
||||
*
|
||||
* @param listener Listener to grab fallback servers from
|
||||
* @return Fallback Server Map (with legacy bungee case-sensitive keys)
|
||||
*/
|
||||
public static Map<String, ServerInfo> getFallbackServers(ListenerInfo listener) {
|
||||
TreeMap<Integer, List<ServerInfo>> score = new TreeMap<Integer, List<ServerInfo>>(Collections.reverseOrder());
|
||||
for (String name : listener.getServerPriority()) {
|
||||
ServerInfo server = SubAPI.getInstance().getServer(name.toLowerCase());
|
||||
if (server == null) server = ProxyServer.getInstance().getServerInfo(name);
|
||||
if (server != null) {
|
||||
boolean valid = true;
|
||||
int confidence = 0;
|
||||
if (server instanceof Server) {
|
||||
if (!((Server) server).isHidden()) confidence++;
|
||||
if (!((Server) server).isRestricted()) confidence++;
|
||||
if (((Server) server).getSubData() != null) confidence++;
|
||||
} if (server instanceof SubServer) {
|
||||
if (!((SubServer) server).isRunning()) valid = false;
|
||||
}
|
||||
|
||||
List<FallbackInspector> inspectors = new ArrayList<FallbackInspector>();
|
||||
inspectors.addAll(SmartReconnectHandler.inspectors);
|
||||
for (FallbackInspector inspector : inspectors) try {
|
||||
Integer response = inspector.inspect(server);
|
||||
if (response == null) {
|
||||
valid = false;
|
||||
} else {
|
||||
confidence += response;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
new InvocationTargetException(e, "Exception while running inspecting fallback server: " + server.getName()).printStackTrace();
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
List<ServerInfo> servers = (score.keySet().contains(confidence))?score.get(confidence):new LinkedList<ServerInfo>();
|
||||
servers.add(server);
|
||||
score.put(confidence, servers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
LinkedHashMap<String, ServerInfo> map = new LinkedHashMap<String, ServerInfo>();
|
||||
for (List<ServerInfo> servers : score.values()) {
|
||||
while (!servers.isEmpty()) {
|
||||
ServerInfo next = servers.get(random.nextInt(servers.size()));
|
||||
map.put(next.getName(), next);
|
||||
servers.remove(next);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Fallback Server Inspector
|
||||
*
|
||||
* @param inspector Inspector
|
||||
*/
|
||||
public static void addInspector(FallbackInspector inspector) {
|
||||
if (Util.isNull(inspector)) throw new NullPointerException();
|
||||
inspectors.add(inspector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Fallback Server Inspector
|
||||
*
|
||||
* @param inspector Inspector
|
||||
*/
|
||||
public static void removeInspector(FallbackInspector inspector) {
|
||||
if (Util.isNull(inspector)) throw new NullPointerException();
|
||||
Util.isException(() -> inspectors.remove(inspector));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServer(ProxiedPlayer player) {
|
||||
// Ignore server switching
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Nothing to close
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
Settings:
|
||||
Version: '2.11.2a+'
|
||||
Override-Bungee-Commands: true
|
||||
Run-On-Launch-Timeout: 0
|
||||
UPnP:
|
||||
Forward-Proxy: true
|
||||
Forward-SubData: false
|
||||
Forward-Servers: false
|
||||
SubData:
|
||||
Address: '0.0.0.0:4391'
|
||||
Password: ''
|
||||
Encryption: 'RSA/AES'
|
||||
Allowed-Connections: []
|
||||
|
||||
Hosts:
|
||||
'~':
|
||||
Enabled: true
|
||||
Display: 'Default'
|
||||
Driver: 'BUILT-IN'
|
||||
Address: '127.0.0.1'
|
||||
Port-Range: '25500-25559'
|
||||
Directory: './SubServers/Servers'
|
||||
Git-Bash: '%ProgramFiles%\Git'
|
||||
Log-Creator: true
|
||||
|
||||
Servers:
|
||||
'Example':
|
||||
Enabled: false
|
||||
Display: ''
|
||||
Host: '~'
|
||||
Group: []
|
||||
Port: 25567
|
||||
Motd: '&aThis is a SubServer'
|
||||
Log: true
|
||||
Directory: './Example'
|
||||
Executable: 'java -Djline.terminal=jline.UnsupportedTerminal -jar Spigot.jar'
|
||||
Stop-Command: 'stop'
|
||||
Stop-Action: 'NONE'
|
||||
Run-On-Launch: false
|
||||
Restricted: false
|
||||
Incompatible: []
|
||||
Hidden: false
|
@ -1,6 +1,7 @@
|
||||
Version: '2.14a+'
|
||||
Lang:
|
||||
'Bungee.Feature.Return': '&6Returning to $str$: &r$msg$'
|
||||
'Bungee.Feature.Smart-Fallback': '&6Returning from $str$: &r$msg$'
|
||||
'Bungee.Feature.Smart-Fallback.Result': '&6You are now on $str$.'
|
||||
'Bungee.Ping.Offline': '&6&l[&e&lWarning&6&l] &7Backend server(s) are not running'
|
||||
'Bungee.Server.Current': '&6You are currently connected to $str$'
|
||||
'Bungee.Server.Available': '&6You may connect to the following servers at this time:'
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Bungee.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.SubDataProtocol;
|
||||
import net.ME1312.SubData.Server.SubDataServer;
|
||||
@ -18,14 +19,13 @@ import java.util.logging.Logger;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
private static SubProtocol instance;
|
||||
private SubProtocol(Logger logger) {
|
||||
super(logger);
|
||||
}
|
||||
private static Logger log;
|
||||
private SubProtocol() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static SubProtocol get() {
|
||||
if (instance == null) {
|
||||
Logger log = Logger.getAnonymousLogger();
|
||||
log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private boolean open = true;
|
||||
@ -46,7 +46,7 @@ public class SubProtocol extends SubDataProtocol {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
instance = new SubProtocol(log);
|
||||
instance = new SubProtocol();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
plugin.getPluginManager().registerListener(null, new PacketOutExRunEvent(plugin));
|
||||
|
||||
@ -145,8 +145,8 @@ public class SubProtocol extends SubDataProtocol {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public SubDataServer open(InetAddress address, int port, String cipher) throws IOException {
|
||||
SubDataServer subdata = super.open(address, port, cipher);
|
||||
public SubDataServer open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port, String cipher) throws IOException {
|
||||
SubDataServer subdata = super.open(scheduler, logger, address, port, cipher);
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
subdata.on.closed(server -> plugin.subdata = null);
|
||||
@ -159,4 +159,8 @@ public class SubProtocol extends SubDataProtocol {
|
||||
|
||||
return subdata;
|
||||
}
|
||||
|
||||
public SubDataServer open(InetAddress address, int port, String cipher) throws IOException {
|
||||
return open(log, address, port, cipher);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import net.ME1312.Galaxi.Library.NamedContainer;
|
||||
import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
import net.ME1312.Galaxi.Library.Util;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Server.SubDataServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@ -575,9 +574,9 @@ public final class SubAPI {
|
||||
*/
|
||||
public void setLang(String channel, String key, String value) {
|
||||
if (Util.isNull(channel, key, value)) throw new NullPointerException();
|
||||
LinkedHashMap<String, String> map = (plugin.lang.keySet().contains(channel.toLowerCase()))?plugin.lang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
|
||||
LinkedHashMap<String, String> map = (plugin.exLang.keySet().contains(channel.toLowerCase()))?plugin.exLang.get(channel.toLowerCase()):new LinkedHashMap<String, String>();
|
||||
map.put(key, value);
|
||||
plugin.lang.put(channel.toLowerCase(), map);
|
||||
plugin.exLang.put(channel.toLowerCase(), map);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -586,7 +585,7 @@ public final class SubAPI {
|
||||
* @return SubServers Lang Channel list
|
||||
*/
|
||||
public Collection<String> getLangChannels() {
|
||||
return plugin.lang.keySet();
|
||||
return plugin.exLang.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -597,7 +596,7 @@ public final class SubAPI {
|
||||
*/
|
||||
public Map<String, String> getLang(String channel) {
|
||||
if (Util.isNull(channel)) throw new NullPointerException();
|
||||
return new LinkedHashMap<>(plugin.lang.get(channel.toLowerCase()));
|
||||
return new LinkedHashMap<>(plugin.exLang.get(channel.toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,8 @@ 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.Fallback.SmartReconnectHandler;
|
||||
import net.ME1312.SubServers.Bungee.Library.Compatibility.Updates.ConfigUpdater;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidHostException;
|
||||
import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
@ -22,8 +24,10 @@ import net.ME1312.SubServers.Bungee.Network.Packet.PacketOutExReload;
|
||||
import net.ME1312.SubServers.Bungee.Network.SubProtocol;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.BungeeServerInfo;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -42,26 +46,29 @@ import java.nio.file.Files;
|
||||
import java.security.SecureRandom;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Main Plugin Class
|
||||
*/
|
||||
public final class SubPlugin extends BungeeCord implements Listener {
|
||||
protected final LinkedHashMap<String, LinkedHashMap<String, String>> lang = new LinkedHashMap<String, LinkedHashMap<String, String>>();
|
||||
protected final LinkedHashMap<String, LinkedHashMap<String, String>> exLang = new LinkedHashMap<String, LinkedHashMap<String, String>>();
|
||||
protected final HashMap<String, Class<? extends Host>> hostDrivers = new HashMap<String, Class<? extends Host>>();
|
||||
public final HashMap<String, Proxy> proxies = new HashMap<String, Proxy>();
|
||||
public final HashMap<String, Host> hosts = new HashMap<String, Host>();
|
||||
public final HashMap<String, Server> exServers = new HashMap<String, Server>();
|
||||
private final HashMap<String, ServerInfo> legServers = new HashMap<String, ServerInfo>();
|
||||
private final HashMap<UUID, List<ServerInfo>> fallbackLimbo = new HashMap<UUID, List<ServerInfo>>();
|
||||
|
||||
public final PrintStream out;
|
||||
public final UniversalFile dir = new UniversalFile(new File(System.getProperty("user.dir")));
|
||||
public YAMLConfig config;
|
||||
private YAMLConfig bungeeconfig;
|
||||
public YAMLConfig langconfig;
|
||||
public YAMLConfig servers;
|
||||
private YAMLConfig bungee;
|
||||
public YAMLConfig lang;
|
||||
public final SubAPI api = new SubAPI(this);
|
||||
public SubDataProtocol subprotocol;
|
||||
public SubProtocol subprotocol;
|
||||
public SubDataServer subdata = null;
|
||||
public SubServer sudo = null;
|
||||
public static final Version version = Version.fromString("2.14a");
|
||||
@ -85,67 +92,63 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
YAMLConfig tmp = new YAMLConfig(new UniversalFile("config.yml"));
|
||||
tmp.get().set("stats", UUID.randomUUID().toString());
|
||||
tmp.save();
|
||||
System.out.println("SubServers > Created ~/config.yml");
|
||||
System.out.println("SubServers > Created ./config.yml");
|
||||
}
|
||||
bungeeconfig = new YAMLConfig(new UniversalFile(dir, "config.yml"));
|
||||
bungee = new YAMLConfig(new UniversalFile(dir, "config.yml"));
|
||||
|
||||
UniversalFile dir = new UniversalFile(this.dir, "SubServers");
|
||||
dir.mkdir();
|
||||
if (!(new UniversalFile(dir, "config.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
|
||||
System.out.println("SubServers > Created ~/SubServers/config.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getMap("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "config.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/config.yml", new UniversalFile(dir, "config.yml").getPath());
|
||||
System.out.println("SubServers > Updated ~/SubServers/config.yml");
|
||||
}
|
||||
ConfigUpdater.updateConfig(new UniversalFile(dir, "config.yml"));
|
||||
config = new YAMLConfig(new UniversalFile(dir, "config.yml"));
|
||||
|
||||
if (!(new UniversalFile(dir, "lang.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath());
|
||||
System.out.println("SubServers > Created ~/SubServers/lang.yml");
|
||||
System.out.println("SubServers > Created ./SubServers/lang.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getVersion("Version", new Version(9))).compareTo(new Version("2.14a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "lang.yml").toPath(), new UniversalFile(dir, "lang.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/lang.yml", new UniversalFile(dir, "lang.yml").getPath());
|
||||
System.out.println("SubServers > Updated ~/SubServers/lang.yml");
|
||||
System.out.println("SubServers > Updated ./SubServers/lang.yml");
|
||||
}
|
||||
langconfig = new YAMLConfig(new UniversalFile(dir, "lang.yml"));
|
||||
lang = new YAMLConfig(new UniversalFile(dir, "lang.yml"));
|
||||
|
||||
ConfigUpdater.updateServers(new UniversalFile(dir, "servers.yml"));
|
||||
servers = new YAMLConfig(new UniversalFile(dir, "servers.yml"));
|
||||
|
||||
if (!(new UniversalFile(dir, "Templates").exists())) {
|
||||
new UniversalFile(dir, "Templates").mkdirs();
|
||||
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/vanilla.zip"), new UniversalFile(dir, "Templates"));
|
||||
System.out.println("SubServers > Created ~/SubServers/Templates/Vanilla");
|
||||
System.out.println("SubServers > Created ./SubServers/Templates/Vanilla");
|
||||
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/spigot.zip"), new UniversalFile(dir, "Templates"));
|
||||
System.out.println("SubServers > Created ~/SubServers/Templates/Spigot");
|
||||
System.out.println("SubServers > Created ./SubServers/Templates/Spigot");
|
||||
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/forge.zip"), new UniversalFile(dir, "Templates"));
|
||||
System.out.println("SubServers > Created ~/SubServers/Templates/Forge");
|
||||
System.out.println("SubServers > Created ./SubServers/Templates/Forge");
|
||||
|
||||
Util.unzip(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/Templates/sponge.zip"), new UniversalFile(dir, "Templates"));
|
||||
System.out.println("SubServers > Created ~/SubServers/Templates/Sponge");
|
||||
System.out.println("SubServers > 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) {
|
||||
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"));
|
||||
System.out.println("SubServers > Updated ~/SubServers/Templates/Vanilla");
|
||||
System.out.println("SubServers > 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) {
|
||||
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"));
|
||||
System.out.println("SubServers > Updated ~/SubServers/Templates/Spigot");
|
||||
System.out.println("SubServers > 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) {
|
||||
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"));
|
||||
System.out.println("SubServers > Updated ~/SubServers/Templates/Forge");
|
||||
System.out.println("SubServers > 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) {
|
||||
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"));
|
||||
System.out.println("SubServers > Updated ~/SubServers/Templates/Sponge");
|
||||
System.out.println("SubServers > Updated ./SubServers/Templates/Sponge");
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,25 +167,25 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - info.getLong("Timestamp")) >= 7) {
|
||||
Util.deleteDirectory(file);
|
||||
f--;
|
||||
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||
System.out.println("SubServers > Removed ./SubServers/Recently Deleted/" + file.getName());
|
||||
}
|
||||
} else {
|
||||
Util.deleteDirectory(file);
|
||||
f--;
|
||||
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||
System.out.println("SubServers > Removed ./SubServers/Recently Deleted/" + file.getName());
|
||||
}
|
||||
} else {
|
||||
Util.deleteDirectory(file);
|
||||
f--;
|
||||
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||
System.out.println("SubServers > Removed ./SubServers/Recently Deleted/" + file.getName());
|
||||
}
|
||||
} else {
|
||||
Files.delete(file.toPath());
|
||||
f--;
|
||||
System.out.println("SubServers > Removed ~/SubServers/Recently Deleted/" + file.getName());
|
||||
System.out.println("SubServers > Removed ./SubServers/Recently Deleted/" + file.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("SubServers > Problem scanning ~/SubServers/Recently Deleted/" + file.getName());
|
||||
System.out.println("SubServers > Problem scanning .SubServers/Recently Deleted/" + file.getName());
|
||||
e.printStackTrace();
|
||||
Files.delete(file.toPath());
|
||||
}
|
||||
@ -209,11 +212,11 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
getPluginManager().registerListener(null, this);
|
||||
|
||||
System.out.println("SubServers > Pre-Parsing Config...");
|
||||
for (String name : config.get().getMap("Servers").getKeys()) {
|
||||
for (String name : servers.get().getMap("Servers").getKeys()) {
|
||||
try {
|
||||
if (Util.getCaseInsensitively(config.get().getMap("Hosts").get(), config.get().getMap("Servers").getMap(name).getString("Host")) == null) throw new InvalidServerException("There is no host with this name: " + config.get().getMap("Servers").getMap(name).getString("Host"));
|
||||
legServers.put(name, new BungeeServerInfo(name, new InetSocketAddress(InetAddress.getByName((String) ((Map<String, ?>) Util.getCaseInsensitively(config.get().getMap("Hosts").get(), config.get().getMap("Servers").getMap(name).getString("Host"))).get("Address")), config.get().getMap("Servers").getMap(name).getInt("Port")),
|
||||
ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")), config.get().getMap("Servers").getMap(name).getBoolean("Restricted")));
|
||||
if (Util.getCaseInsensitively(config.get().getMap("Hosts").get(), servers.get().getMap("Servers").getMap(name).getString("Host")) == null) throw new InvalidServerException("There is no host with this name: " + servers.get().getMap("Servers").getMap(name).getString("Host"));
|
||||
legServers.put(name, new BungeeServerInfo(name, new InetSocketAddress(InetAddress.getByName((String) ((Map<String, ?>) Util.getCaseInsensitively(config.get().getMap("Hosts").get(), servers.get().getMap("Servers").getMap(name).getString("Host"))).get("Address")), servers.get().getMap("Servers").getMap(name).getInt("Port")),
|
||||
ChatColor.translateAlternateColorCodes('&', servers.get().getMap("Servers").getMap(name).getString("Motd")), servers.get().getMap("Servers").getMap(name).getBoolean("Restricted")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -264,11 +267,16 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
boolean status;
|
||||
if (!(status = running)) resetDate = begin;
|
||||
|
||||
ConfigUpdater.updateConfig(new UniversalFile(dir, "SubServers:config.yml"));
|
||||
ConfigUpdater.updateServers(new UniversalFile(dir, "SubServers:servers.yml"));
|
||||
ConfigUpdater.updateLang(new UniversalFile(dir, "SubServers:lang.yml"));
|
||||
|
||||
YAMLSection prevconfig = config.get();
|
||||
config.reload();
|
||||
langconfig.reload();
|
||||
for (String key : langconfig.get().getMap("Lang").getKeys())
|
||||
api.setLang("SubServers", key, ChatColor.translateAlternateColorCodes('&', langconfig.get().getMap("Lang").getString(key)));
|
||||
servers.reload();
|
||||
lang.reload();
|
||||
for (String key : lang.get().getMap("Lang").getKeys())
|
||||
api.setLang("SubServers", key, ChatColor.translateAlternateColorCodes('&', lang.get().getMap("Lang").getString(key)));
|
||||
|
||||
if (subdata == null || // SubData Server must be reset
|
||||
!config.get().getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391").equals(prevconfig.getMap("Settings").getMap("SubData").getRawString("Address", "127.0.0.1:4391")) ||
|
||||
@ -395,33 +403,33 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
int servers = 0;
|
||||
System.out.println("SubServers > "+((status)?"Rel":"L")+"oading Servers...");
|
||||
bungeeconfig.reload();
|
||||
for (String name : bungeeconfig.get().getMap("servers").getKeys()) {
|
||||
bungee.reload();
|
||||
for (String name : bungee.get().getMap("servers").getKeys()) {
|
||||
if (!ukeys.contains(name.toLowerCase())) try {
|
||||
Server server = api.getServer(name);
|
||||
if (server == null || !(server instanceof SubServer)) {
|
||||
if (server == null || // Server must be reset
|
||||
bungeeconfig.get().getMap("servers").getMap(name).getRawString("address").equals(server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort())
|
||||
bungee.get().getMap("servers").getMap(name).getRawString("address").equals(server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort())
|
||||
) {
|
||||
if (server != null) api.forceRemoveServer(name);
|
||||
server = api.addServer(name, InetAddress.getByName(bungeeconfig.get().getMap("servers").getMap(name).getRawString("address").split(":")[0]),
|
||||
Integer.parseInt(bungeeconfig.get().getMap("servers").getMap(name).getRawString("address").split(":")[1]), ChatColor.translateAlternateColorCodes('&', bungeeconfig.get().getMap("servers").getMap(name).getString("motd")),
|
||||
bungeeconfig.get().getMap("servers").getMap(name).getBoolean("hidden", false), bungeeconfig.get().getMap("servers").getMap(name).getBoolean("restricted"));
|
||||
server = api.addServer(name, InetAddress.getByName(bungee.get().getMap("servers").getMap(name).getRawString("address").split(":")[0]),
|
||||
Integer.parseInt(bungee.get().getMap("servers").getMap(name).getRawString("address").split(":")[1]), ChatColor.translateAlternateColorCodes('&', bungee.get().getMap("servers").getMap(name).getString("motd")),
|
||||
bungee.get().getMap("servers").getMap(name).getBoolean("hidden", false), bungee.get().getMap("servers").getMap(name).getBoolean("restricted"));
|
||||
} else { // Server wasn't reset, so check for these changes
|
||||
if (!ChatColor.translateAlternateColorCodes('&', bungeeconfig.get().getMap("servers").getMap(name).getString("motd")).equals(server.getMotd()))
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', bungeeconfig.get().getMap("servers").getMap(name).getString("motd")));
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getBoolean("hidden", false) != server.isHidden())
|
||||
server.setHidden(bungeeconfig.get().getMap("servers").getMap(name).getBoolean("hidden", false));
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getBoolean("restricted") != server.isRestricted())
|
||||
server.setRestricted(bungeeconfig.get().getMap("servers").getMap(name).getBoolean("restricted"));
|
||||
if (!ChatColor.translateAlternateColorCodes('&', bungee.get().getMap("servers").getMap(name).getString("motd")).equals(server.getMotd()))
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', bungee.get().getMap("servers").getMap(name).getString("motd")));
|
||||
if (bungee.get().getMap("servers").getMap(name).getBoolean("hidden", false) != server.isHidden())
|
||||
server.setHidden(bungee.get().getMap("servers").getMap(name).getBoolean("hidden", false));
|
||||
if (bungee.get().getMap("servers").getMap(name).getBoolean("restricted") != server.isRestricted())
|
||||
server.setRestricted(bungee.get().getMap("servers").getMap(name).getBoolean("restricted"));
|
||||
} // Check for other changes
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getKeys().contains("display") && ((bungeeconfig.get().getMap("servers").getMap(name).getRawString("display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !bungeeconfig.get().getMap("servers").getMap(name).getRawString("display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(bungeeconfig.get().getMap("servers").getMap(name).getString("display"));
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getKeys().contains("group")) {
|
||||
if (bungee.get().getMap("servers").getMap(name).getKeys().contains("display") && ((bungee.get().getMap("servers").getMap(name).getRawString("display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !bungee.get().getMap("servers").getMap(name).getRawString("display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(bungee.get().getMap("servers").getMap(name).getString("display"));
|
||||
if (bungee.get().getMap("servers").getMap(name).getKeys().contains("group")) {
|
||||
for (String group : server.getGroups()) server.removeGroup(group);
|
||||
for (String group : bungeeconfig.get().getMap("servers").getMap(name).getStringList("group")) server.addGroup(group);
|
||||
for (String group : bungee.get().getMap("servers").getMap(name).getStringList("group")) server.addGroup(group);
|
||||
}
|
||||
if (bungeeconfig.get().getMap("servers").getMap(name).getKeys().contains("extra"))
|
||||
if (bungee.get().getMap("servers").getMap(name).getKeys().contains("extra"))
|
||||
for (String extra : config.get().getMap("servers").getMap(name).getMap("extra").getKeys()) server.addExtra(extra, config.get().getMap("servers").getMap(name).getMap("extra").getObject(extra));
|
||||
if (server.getSubData() != null)
|
||||
((SubDataClient) server.getSubData()).sendPacket(new PacketOutExReload(null));
|
||||
@ -448,9 +456,9 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}, "SubServers.Bungee::System_Shutdown"));
|
||||
running = true;
|
||||
List<String> autorun = new LinkedList<String>();
|
||||
for (String name : config.get().getMap("Servers").getKeys()) {
|
||||
for (String name : this.servers.get().getMap("Servers").getKeys()) {
|
||||
if (!ukeys.contains(name.toLowerCase())) try {
|
||||
if (!this.hosts.keySet().contains(config.get().getMap("Servers").getMap(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + config.get().getMap("Servers").getMap(name).getString("Host"));
|
||||
if (!this.hosts.keySet().contains(this.servers.get().getMap("Servers").getMap(name).getString("Host").toLowerCase())) throw new InvalidServerException("There is no host with this name: " + this.servers.get().getMap("Servers").getMap(name).getString("Host"));
|
||||
if (exServers.keySet().contains(name.toLowerCase())) {
|
||||
exServers.remove(name.toLowerCase());
|
||||
servers--;
|
||||
@ -458,33 +466,33 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
SubServer server = api.getSubServer(name);
|
||||
if (server != null && server.isEditable()) { // Server can edit() (May be reset depending on change severity)
|
||||
ObjectMap<String> edits = new ObjectMap<String>();
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Enabled") != server.isEnabled())
|
||||
edits.set("enabled", config.get().getMap("Servers").getMap(name).getBoolean("Enabled"));
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Display") && ((config.get().getMap("Servers").getMap(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !config.get().getMap("Servers").getMap(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
edits.set("display", config.get().getMap("Servers").getMap(name).getRawString("Display"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getString("Host").equalsIgnoreCase(server.getHost().getName()))
|
||||
edits.set("host", config.get().getMap("Servers").getMap(name).getRawString("Host"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getStringList("Group").equals(server.getGroups()))
|
||||
edits.set("group", config.get().getMap("Servers").getMap(name).getRawStringList("Group"));
|
||||
if (config.get().getMap("Servers").getMap(name).getInt("Port") != server.getAddress().getPort())
|
||||
edits.set("port", config.get().getMap("Servers").getMap(name).getInt("Port"));
|
||||
if (!(ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")).equals(server.getMotd())))
|
||||
edits.set("motd", config.get().getMap("Servers").getMap(name).getRawString("Motd"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Log") != server.isLogging())
|
||||
edits.set("log", config.get().getMap("Servers").getMap(name).getBoolean("Log"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Directory").equals(server.getPath()))
|
||||
edits.set("dir", config.get().getMap("Servers").getMap(name).getRawString("Directory"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable()))
|
||||
edits.set("exec", config.get().getMap("Servers").getMap(name).getRawString("Executable"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
edits.set("stop-cmd", config.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(config.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled") != server.isEnabled())
|
||||
edits.set("enabled", this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled"));
|
||||
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())))
|
||||
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).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())
|
||||
edits.set("port", this.servers.get().getMap("Servers").getMap(name).getInt("Port"));
|
||||
if (!(ChatColor.translateAlternateColorCodes('&', this.servers.get().getMap("Servers").getMap(name).getString("Motd")).equals(server.getMotd())))
|
||||
edits.set("motd", this.servers.get().getMap("Servers").getMap(name).getRawString("Motd"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Log") != server.isLogging())
|
||||
edits.set("log", this.servers.get().getMap("Servers").getMap(name).getBoolean("Log"));
|
||||
if (!this.servers.get().getMap("Servers").getMap(name).getRawString("Directory").equals(server.getPath()))
|
||||
edits.set("dir", this.servers.get().getMap("Servers").getMap(name).getRawString("Directory"));
|
||||
if (!this.servers.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable()))
|
||||
edits.set("exec", this.servers.get().getMap("Servers").getMap(name).getRawString("Executable"));
|
||||
if (!this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
edits.set("stop-cmd", this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null && action != server.getStopAction())
|
||||
edits.set("stop-action", action.toString());
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
|
||||
edits.set("restricted", config.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
|
||||
edits.set("hidden", config.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
|
||||
edits.set("restricted", this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
|
||||
edits.set("hidden", this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
|
||||
|
||||
|
||||
if (edits.getKeys().size() > 0) {
|
||||
@ -493,43 +501,43 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
} else { // Server cannot edit()
|
||||
if (server == null || // Server must be reset
|
||||
!config.get().getMap("Servers").getMap(name).getString("Host").equalsIgnoreCase(server.getHost().getName()) ||
|
||||
config.get().getMap("Servers").getMap(name).getInt("Port") != server.getAddress().getPort() ||
|
||||
!config.get().getMap("Servers").getMap(name).getRawString("Directory").equals(server.getPath()) ||
|
||||
!config.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable())
|
||||
!this.servers.get().getMap("Servers").getMap(name).getString("Host").equalsIgnoreCase(server.getHost().getName()) ||
|
||||
this.servers.get().getMap("Servers").getMap(name).getInt("Port") != server.getAddress().getPort() ||
|
||||
!this.servers.get().getMap("Servers").getMap(name).getRawString("Directory").equals(server.getPath()) ||
|
||||
!this.servers.get().getMap("Servers").getMap(name).getRawString("Executable").equals(server.getExecutable())
|
||||
) {
|
||||
if (server != null) server.getHost().forceRemoveSubServer(name);
|
||||
server = this.hosts.get(config.get().getMap("Servers").getMap(name).getString("Host").toLowerCase()).addSubServer(name, config.get().getMap("Servers").getMap(name).getBoolean("Enabled"),
|
||||
config.get().getMap("Servers").getMap(name).getInt("Port"), ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")), config.get().getMap("Servers").getMap(name).getBoolean("Log"),
|
||||
config.get().getMap("Servers").getMap(name).getRawString("Directory"), config.get().getMap("Servers").getMap(name).getRawString("Executable"), config.get().getMap("Servers").getMap(name).getRawString("Stop-Command"),
|
||||
config.get().getMap("Servers").getMap(name).getBoolean("Hidden"), config.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
server = this.hosts.get(this.servers.get().getMap("Servers").getMap(name).getString("Host").toLowerCase()).addSubServer(name, this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled"),
|
||||
this.servers.get().getMap("Servers").getMap(name).getInt("Port"), ChatColor.translateAlternateColorCodes('&', this.servers.get().getMap("Servers").getMap(name).getString("Motd")), this.servers.get().getMap("Servers").getMap(name).getBoolean("Log"),
|
||||
this.servers.get().getMap("Servers").getMap(name).getRawString("Directory"), this.servers.get().getMap("Servers").getMap(name).getRawString("Executable"), this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command"),
|
||||
this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden"), this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
} else { // Server doesn't need to reset
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Enabled") != server.isEnabled())
|
||||
server.setEnabled(config.get().getMap("Servers").getMap(name).getBoolean("Enabled"));
|
||||
if (!ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")).equals(server.getMotd()))
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', config.get().getMap("Servers").getMap(name).getString("Motd")));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Log") != server.isLogging())
|
||||
server.setLogging(config.get().getMap("Servers").getMap(name).getBoolean("Log"));
|
||||
if (!config.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
server.setStopCommand(config.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
|
||||
server.setRestricted(config.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
if (config.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
|
||||
server.setHidden(config.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled") != server.isEnabled())
|
||||
server.setEnabled(this.servers.get().getMap("Servers").getMap(name).getBoolean("Enabled"));
|
||||
if (!ChatColor.translateAlternateColorCodes('&', this.servers.get().getMap("Servers").getMap(name).getString("Motd")).equals(server.getMotd()))
|
||||
server.setMotd(ChatColor.translateAlternateColorCodes('&', this.servers.get().getMap("Servers").getMap(name).getString("Motd")));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Log") != server.isLogging())
|
||||
server.setLogging(this.servers.get().getMap("Servers").getMap(name).getBoolean("Log"));
|
||||
if (!this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command").equals(server.getStopCommand()))
|
||||
server.setStopCommand(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Command"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted") != server.isRestricted())
|
||||
server.setRestricted(this.servers.get().getMap("Servers").getMap(name).getBoolean("Restricted"));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden") != server.isHidden())
|
||||
server.setHidden(this.servers.get().getMap("Servers").getMap(name).getBoolean("Hidden"));
|
||||
} // Apply these changes regardless of reset
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(config.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
SubServer.StopAction action = Util.getDespiteException(() -> SubServer.StopAction.valueOf(this.servers.get().getMap("Servers").getMap(name).getRawString("Stop-Action", "NONE").toUpperCase().replace('-', '_').replace(' ', '_')), null);
|
||||
if (action != null && action != server.getStopAction())
|
||||
server.setStopAction(action);
|
||||
if (!status && config.get().getMap("Servers").getMap(name).getBoolean("Run-On-Launch"))
|
||||
if (!status && this.servers.get().getMap("Servers").getMap(name).getBoolean("Run-On-Launch"))
|
||||
autorun.add(name.toLowerCase());
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Display") && ((config.get().getMap("Servers").getMap(name).getRawString("Display").length() == 0 && !server.getDisplayName().equals(server.getName())) || !config.get().getMap("Servers").getMap(name).getRawString("Display").equals(server.getDisplayName())))
|
||||
server.setDisplayName(config.get().getMap("Servers").getMap(name).getRawString("Display"));
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Group")) {
|
||||
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("Group")) {
|
||||
for (String group : server.getGroups()) server.removeGroup(group);
|
||||
for (String group : config.get().getMap("Servers").getMap(name).getStringList("Group")) server.addGroup(group);
|
||||
for (String group : this.servers.get().getMap("Servers").getMap(name).getStringList("Group")) server.addGroup(group);
|
||||
}
|
||||
} // Apply these changes regardless of edit/reset
|
||||
if (config.get().getMap("Servers").getMap(name).getKeys().contains("Extra")) for (String extra : config.get().getMap("Servers").getMap(name).getMap("Extra").getKeys()) server.addExtra(extra, config.get().getMap("Servers").getMap(name).getMap("Extra").getObject(extra));
|
||||
if (this.servers.get().getMap("Servers").getMap(name).getKeys().contains("Extra")) for (String extra : this.servers.get().getMap("Servers").getMap(name).getMap("Extra").getKeys()) server.addExtra(extra, this.servers.get().getMap("Servers").getMap(name).getMap("Extra").getObject(extra));
|
||||
ukeys.add(name.toLowerCase());
|
||||
subservers++;
|
||||
} catch (Exception e) {
|
||||
@ -538,7 +546,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
for (String name : ukeys) {
|
||||
SubServer server = api.getSubServer(name);
|
||||
for (String oname : config.get().getMap("Servers").getMap(server.getName()).getRawStringList("Incompatible", new ArrayList<>())) {
|
||||
for (String oname : this.servers.get().getMap("Servers").getMap(server.getName()).getRawStringList("Incompatible", new ArrayList<>())) {
|
||||
SubServer oserver = api.getSubServer(oname);
|
||||
if (oserver != null && server.isCompatible(oserver)) server.toggleCompatibility(oserver);
|
||||
}
|
||||
@ -568,7 +576,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
|
||||
System.out.println("SubServers > " + ((plugins > 0)?plugins+" Plugin"+((plugins == 1)?"":"s")+", ":"") + ((proxies > 1)?proxies+" Proxies, ":"") + hosts + " Host"+((hosts == 1)?"":"s")+", " + servers + " Server"+((servers == 1)?"":"s")+", and " + subservers + " SubServer"+((subservers == 1)?"":"s")+" "+((status)?"re":"")+"loaded in " + new DecimalFormat("0.000").format((Calendar.getInstance().getTime().getTime() - begin) / 1000D) + "s");
|
||||
|
||||
long scd = TimeUnit.SECONDS.toMillis(config.get().getMap("Settings").getLong("Run-On-Launch-Timeout", 0L));
|
||||
long scd = TimeUnit.SECONDS.toMillis(this.servers.get().getMap("Settings").getLong("Run-On-Launch-Timeout", 0L));
|
||||
if (autorun.size() > 0) for (Host host : api.getHosts().values()) {
|
||||
List<String> ar = new LinkedList<String>();
|
||||
for (String name : autorun) if (host.getSubServer(name) != null) ar.add(name);
|
||||
@ -605,6 +613,9 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
getPluginManager().registerCommand(null, SubCommand.BungeeServer.newInstance(this, "server").get());
|
||||
getPluginManager().registerCommand(null, new SubCommand.BungeeList(this, "glist"));
|
||||
}
|
||||
if (config.get().getMap("Settings").getBoolean("Smart-Fallback", true)) {
|
||||
setReconnectHandler(new SmartReconnectHandler());
|
||||
}
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subservers").get());
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "subserver").get());
|
||||
getPluginManager().registerCommand(null, SubCommand.newInstance(this, "sub").get());
|
||||
@ -772,7 +783,8 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
public void ping(ProxyPingEvent e) {
|
||||
int offline = 0;
|
||||
for (String name : e.getConnection().getListener().getServerPriority()) {
|
||||
ServerInfo server = getServerInfo(name);
|
||||
ServerInfo server = api.getServer(name.toLowerCase());
|
||||
if (server == null) server = getServerInfo(name);
|
||||
if (server == null || server instanceof SubServer && !((SubServer) server).isRunning()) offline++;
|
||||
}
|
||||
|
||||
@ -795,46 +807,74 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
if (!e.getTarget().canAccess(e.getPlayer())) {
|
||||
e.setCancelled(true);
|
||||
if (e.getPlayer().getServer() != null) e.getPlayer().sendMessage(getTranslation("no_server_permission"));
|
||||
else e.getPlayer().disconnect(getTranslation("no_server_permission"));
|
||||
} else if (e.getPlayer().getServer() != null && e.getTarget() instanceof SubServer && !((SubServer) e.getTarget()).isRunning()) {
|
||||
e.setCancelled(true);
|
||||
if (e.getPlayer().getServer() == null || fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId()) || fallbackLimbo.get(e.getPlayer().getUniqueId()).contains(e.getTarget())) {
|
||||
ServerKickEvent kick = new ServerKickEvent(e.getPlayer(), e.getTarget(), new BaseComponent[]{
|
||||
new TextComponent(getTranslation("no_server_permission"))
|
||||
}, null, ServerKickEvent.State.CONNECTING);
|
||||
fallback(kick);
|
||||
if (!kick.isCancelled()) e.getPlayer().disconnect(kick.getKickReasonComponent());
|
||||
if (e.getPlayer().getServer() != null) e.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
e.getPlayer().sendMessage(getTranslation("no_server_permission"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else if (e.getPlayer().getServer() != null && !fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId()) && e.getTarget() instanceof SubServer && !((SubServer) e.getTarget()).isRunning()) {
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Server.Offline"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
if (fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
if (fallbackLimbo.get(e.getPlayer().getUniqueId()).contains(e.getTarget())) {
|
||||
fallbackLimbo.get(e.getPlayer().getUniqueId()).remove(e.getTarget());
|
||||
} else if (e.getPlayer().getServer() != null) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallback(ServerKickEvent e) {
|
||||
NamedContainer<Integer, List<ServerInfo>> next = null;
|
||||
for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) {
|
||||
if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) {
|
||||
ServerInfo server = getServerInfo(name);
|
||||
if (server != null && (!(server instanceof SubServer) || ((SubServer) server).isRunning())) {
|
||||
int confidence = 0;
|
||||
if (server instanceof Server) {
|
||||
if (!((Server) server).isHidden()) confidence++;
|
||||
if (!((Server) server).isRestricted()) confidence++;
|
||||
if (((Server) server).getSubData() != null) confidence++;
|
||||
}
|
||||
if (e.getPlayer() instanceof UserConnection && config.get().getMap("Settings").getBoolean("Smart-Fallback", true)) {
|
||||
Map<String, ServerInfo> fallbacks;
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
fallbacks = SmartReconnectHandler.getFallbackServers(e.getPlayer().getPendingConnection().getListener());
|
||||
} else {
|
||||
fallbacks = new LinkedHashMap<String, ServerInfo>();
|
||||
for (ServerInfo server : fallbackLimbo.get(e.getPlayer().getUniqueId())) fallbacks.put(server.getName(), server);
|
||||
}
|
||||
|
||||
if (next == null || confidence > next.name()) {
|
||||
List<ServerInfo> servers = new ArrayList<ServerInfo>();
|
||||
servers.add(server);
|
||||
next = new NamedContainer<Integer, List<ServerInfo>>(confidence, servers);
|
||||
} else if (confidence == next.name()) {
|
||||
next.get().add(server);
|
||||
}
|
||||
}
|
||||
fallbacks.remove(e.getKickedFrom().getName());
|
||||
if (!fallbacks.isEmpty()) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback").replace("$str$", (e.getKickedFrom() instanceof Server)?((Server) e.getKickedFrom()).getDisplayName():e.getKickedFrom().getName()).replace("$msg$", e.getKickReason()));
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) fallbackLimbo.put(e.getPlayer().getUniqueId(), new LinkedList<>(fallbacks.values()));
|
||||
|
||||
ServerInfo next = new LinkedList<Map.Entry<String, ServerInfo>>(fallbacks.entrySet()).getFirst().getValue();
|
||||
e.setCancelServer(next);
|
||||
((UserConnection) e.getPlayer()).setServerJoinQueue(new LinkedBlockingQueue<>(fallbacks.keySet()));
|
||||
((UserConnection) e.getPlayer()).connect(next, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (next != null) {
|
||||
e.setCancelServer(next.get().get(new Random().nextInt(next.get().size())));
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (e.getCancelServer() instanceof Server)?((Server) e.getCancelServer()).getDisplayName():e.getCancelServer().getName()).replace("$msg$", e.getKickReason()));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallbackFound(ServerConnectedEvent e) {
|
||||
if (fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) new Timer("SubServers.Bungee::Fallback_Limbo_Timer(" + e.getPlayer().getUniqueId() + ')').schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (e.getPlayer().getServer() != null && !((UserConnection) e.getPlayer()).isDimensionChange() && e.getPlayer().getServer().getInfo().getAddress().equals(e.getServer().getInfo().getAddress())) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback.Result").replace("$str$", (e.getServer().getInfo() instanceof Server)?((Server) e.getServer().getInfo()).getDisplayName():e.getServer().getInfo().getName()));
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void resetLimbo(PlayerDisconnectEvent e) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
|
@ -54,7 +54,7 @@
|
||||
<dependency>
|
||||
<groupId>net.ME1312.SubData</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>19w16b</version>
|
||||
<version>19w18a</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.ME1312.SubServers.Client.Bukkit.Network;
|
||||
|
||||
import net.ME1312.Galaxi.Library.Callback.Callback;
|
||||
import net.ME1312.Galaxi.Library.Version.Version;
|
||||
import net.ME1312.SubData.Client.SubDataClient;
|
||||
import net.ME1312.SubData.Client.SubDataProtocol;
|
||||
@ -17,14 +18,13 @@ import java.util.logging.Logger;
|
||||
|
||||
public class SubProtocol extends SubDataProtocol {
|
||||
private static SubProtocol instance;
|
||||
private SubProtocol(Logger logger) {
|
||||
super(logger);
|
||||
}
|
||||
private static Logger log;
|
||||
private SubProtocol() {}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static SubProtocol get() {
|
||||
if (instance == null) {
|
||||
Logger log = Logger.getAnonymousLogger();
|
||||
log = Logger.getAnonymousLogger();
|
||||
log.setUseParentHandlers(false);
|
||||
log.addHandler(new Handler() {
|
||||
private boolean open = true;
|
||||
@ -45,11 +45,11 @@ public class SubProtocol extends SubDataProtocol {
|
||||
open = false;
|
||||
}
|
||||
});
|
||||
instance = new SubProtocol(log);
|
||||
instance = new SubProtocol();
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
instance.setName("SubServers 2");
|
||||
instance.addVersion(new Version("2.13.2a+"));
|
||||
instance.addVersion(new Version("2.14a+"));
|
||||
|
||||
|
||||
// 00-09: Object Link Packets
|
||||
@ -114,16 +114,30 @@ public class SubProtocol extends SubDataProtocol {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||
SubDataClient subdata = super.open(address, port);
|
||||
public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubDataClient subdata = super.open(scheduler, logger, address, port);
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
|
||||
subdata.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(plugin)));
|
||||
subdata.on.closed(client -> {
|
||||
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);
|
||||
});
|
||||
|
||||
return subdata;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public SubDataClient open(Logger logger, InetAddress address, int port) throws IOException {
|
||||
SubPlugin plugin = SubAPI.getInstance().getInternals();
|
||||
return open(event -> {
|
||||
if (plugin.isEnabled()) Bukkit.getScheduler().runTask(plugin, event);
|
||||
else event.run();
|
||||
}, logger, address, port);
|
||||
}
|
||||
|
||||
public SubDataClient open(InetAddress address, int port) throws IOException {
|
||||
return open(log, address, port);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -24,16 +25,23 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
|
||||
public final class SubCommand implements CommandExecutor {
|
||||
public final class SubCommand extends BukkitCommand {
|
||||
private SubPlugin plugin;
|
||||
|
||||
public SubCommand(SubPlugin plugin) {
|
||||
public SubCommand(SubPlugin plugin, String name) {
|
||||
super(
|
||||
name,
|
||||
"The SubServers Command",
|
||||
"/" + name + " is currently unavailable",
|
||||
Collections.emptyList()
|
||||
);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||
label = "/" + label;
|
||||
if (plugin.subdata == null) {
|
||||
new IllegalStateException("SubData is not connected").printStackTrace();
|
||||
|
@ -3,8 +3,6 @@ package net.ME1312.SubServers.Client.Bukkit;
|
||||
import net.ME1312.Galaxi.Library.Map.ObjectMap;
|
||||
import net.ME1312.SubData.Client.Encryption.AES;
|
||||
import net.ME1312.SubData.Client.Encryption.RSA;
|
||||
import net.ME1312.SubData.Client.SubDataProtocol;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkDisconnectEvent;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.DefaultUIHandler;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIHandler;
|
||||
import net.ME1312.Galaxi.Library.Config.YAMLConfig;
|
||||
@ -15,9 +13,9 @@ import net.ME1312.Galaxi.Library.UniversalFile;
|
||||
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.PacketLinkServer;
|
||||
import net.ME1312.SubServers.Client.Bukkit.Network.SubProtocol;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
@ -40,7 +38,7 @@ public final class SubPlugin extends JavaPlugin {
|
||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public YAMLConfig config;
|
||||
public SubDataClient subdata = null;
|
||||
public SubDataProtocol subprotocol;
|
||||
public SubProtocol subprotocol;
|
||||
|
||||
public UIHandler gui = null;
|
||||
public final Version version;
|
||||
@ -66,12 +64,12 @@ public final class SubPlugin extends JavaPlugin {
|
||||
}
|
||||
if (!(new UniversalFile(getDataFolder(), "config.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
|
||||
Bukkit.getLogger().info("SubServers > Created ~/plugins/SubServers-Client-Bukkit/config.yml");
|
||||
Bukkit.getLogger().info("SubServers > Created ./plugins/SubServers-Client-Bukkit/config.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getMap("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(getDataFolder(), "config.yml").toPath(), new UniversalFile(getDataFolder(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
|
||||
Bukkit.getLogger().info("SubServers > Updated ~/plugins/SubServers-Client-Bukkit/config.yml");
|
||||
Bukkit.getLogger().info("SubServers > Updated .plugins/SubServers-Client-Bukkit/config.yml");
|
||||
}
|
||||
config = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
|
||||
if (new UniversalFile(new File(System.getProperty("user.dir")), "subdata.json").exists()) {
|
||||
@ -89,11 +87,12 @@ public final class SubPlugin extends JavaPlugin {
|
||||
reload(false);
|
||||
|
||||
if (config.get().getMap("Settings").getBoolean("Ingame-Access", true)) {
|
||||
CommandMap cmd = Util.reflect(Bukkit.getServer().getClass().getDeclaredField("commandMap"), Bukkit.getServer());
|
||||
gui = new DefaultUIHandler(this);
|
||||
SubCommand cmd = new SubCommand(this);
|
||||
getCommand("subservers").setExecutor(cmd);
|
||||
getCommand("subserver").setExecutor(cmd);
|
||||
getCommand("sub").setExecutor(cmd);
|
||||
|
||||
cmd.register("subservers", new SubCommand(this, "subservers"));
|
||||
cmd.register("subservers", new SubCommand(this, "subserver"));
|
||||
cmd.register("subservers", new SubCommand(this, "sub"));
|
||||
}
|
||||
|
||||
new Metrics(this);
|
||||
@ -174,8 +173,10 @@ public final class SubPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (subdata != null) try {
|
||||
setEnabled(false);
|
||||
subdata.close();
|
||||
} catch (IOException e) {
|
||||
subdata.waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,16 @@ version: '2.14a'
|
||||
authors: [ME1312]
|
||||
softdepend: [Vault, TitleManager]
|
||||
website: 'https://github.com/ME1312/SubServers-2'
|
||||
commands:
|
||||
subservers:
|
||||
description: 'The SubServers Command'
|
||||
usage: '/subservers is currently unavailable'
|
||||
subserver:
|
||||
description: 'The SubServers Command'
|
||||
usage: '/subserver is currently unavailable'
|
||||
sub:
|
||||
description: 'The SubServers Command'
|
||||
usage: '/sub is currently unavailable'
|
||||
#commands:
|
||||
# subservers:
|
||||
# description: 'The SubServers Command'
|
||||
# usage: '/subservers is currently unavailable'
|
||||
# subserver:
|
||||
# description: 'The SubServers Command'
|
||||
# usage: '/subserver is currently unavailable'
|
||||
# sub:
|
||||
# description: 'The SubServers Command'
|
||||
# usage: '/sub is currently unavailable'
|
||||
permissions:
|
||||
subservers.*:
|
||||
description: 'Grants Access to to Everything in SubServers.Client'
|
||||
|
@ -84,12 +84,12 @@ public final class SubPlugin {
|
||||
}
|
||||
if (!(new UniversalFile(dir, "config.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(dir, "config.yml").getPath());
|
||||
logger.info("Created ~/config/subservers-client-sponge/config.yml");
|
||||
logger.info("Created ./config/subservers-client-sponge/config.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "config.yml"))).get().getSection("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "config.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(dir, "config.yml").getPath());
|
||||
logger.info("Updated ~/config/subservers-client-sponge/config.yml");
|
||||
logger.info("Updated ./config/subservers-client-sponge/config.yml");
|
||||
}
|
||||
config = new YAMLConfig(new UniversalFile(dir, "config.yml"));
|
||||
if (new UniversalFile(new File(System.getProperty("user.dir")), "subservers.client").exists()) {
|
||||
|
@ -138,18 +138,18 @@ public final class ExHost {
|
||||
log.info.println("Loading SubServers.Host v" + info.getVersion().toString() + " Libraries");
|
||||
if (!(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").exists())) {
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
|
||||
log.info.println("Created ~/config.yml");
|
||||
log.info.println("Created ./config.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"))).get().getSection("Settings").getVersion("Version", new Version(0)).compareTo(new Version("2.11.2a+"))) != 0) {
|
||||
Files.move(new UniversalFile(engine.getRuntimeDirectory(), "config.yml").toPath(), new UniversalFile(engine.getRuntimeDirectory(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/config.yml", new UniversalFile(engine.getRuntimeDirectory(), "config.yml").getPath());
|
||||
log.info.println("Updated ~/config.yml");
|
||||
log.info.println("Updated ./config.yml");
|
||||
}
|
||||
config = new YAMLConfig(new UniversalFile(engine.getRuntimeDirectory(), "config.yml"));
|
||||
|
||||
if (!(new UniversalFile(engine.getRuntimeDirectory(), "Templates").exists())) {
|
||||
new UniversalFile(engine.getRuntimeDirectory(), "Templates").mkdir();
|
||||
log.info.println("Created ~/Templates/");
|
||||
log.info.println("Created ./Templates/");
|
||||
}
|
||||
|
||||
if (new UniversalFile(engine.getRuntimeDirectory(), "Recently Deleted").exists()) {
|
||||
@ -165,22 +165,22 @@ public final class ExHost {
|
||||
if (TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTime().getTime() - json.getLong("Timestamp")) >= 7) {
|
||||
Util.deleteDirectory(file);
|
||||
f--;
|
||||
log.info.println("Removed ~/Recently Deleted/" + file.getName());
|
||||
log.info.println("Removed ./Recently Deleted/" + file.getName());
|
||||
}
|
||||
} else {
|
||||
Util.deleteDirectory(file);
|
||||
f--;
|
||||
log.info.println("Removed ~/Recently Deleted/" + file.getName());
|
||||
log.info.println("Removed ./Recently Deleted/" + file.getName());
|
||||
}
|
||||
} else {
|
||||
Util.deleteDirectory(file);
|
||||
f--;
|
||||
log.info.println("Removed ~/Recently Deleted/" + file.getName());
|
||||
log.info.println("Removed ./Recently Deleted/" + file.getName());
|
||||
}
|
||||
} else {
|
||||
Files.delete(file.toPath());
|
||||
f--;
|
||||
log.info.println("Removed ~/Recently Deleted/" + file.getName());
|
||||
log.info.println("Removed ./Recently Deleted/" + file.getName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error.println(e);
|
||||
|
@ -787,7 +787,7 @@ public class SubCommand {
|
||||
}
|
||||
}).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.",
|
||||
"Templates are downloaded from SubServers.Bungee to ./Templates.",
|
||||
"",
|
||||
"The <Name> argument is required, and should be the name of",
|
||||
"the SubServer you want to create.",
|
||||
|
@ -0,0 +1,17 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Fallback;
|
||||
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
/**
|
||||
* Fallback Server Inspector Layout Class
|
||||
*/
|
||||
public interface FallbackInspector {
|
||||
|
||||
/**
|
||||
* Inspect a fallback server and modify it's confidence score
|
||||
*
|
||||
* @param server Server to inspect
|
||||
* @return A Positive Value to add points, a Negative Value to subtract points, a Null Value to invalidate the server, or a Zero Value to do nothing
|
||||
*/
|
||||
Integer inspect(ServerInfo server);
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package net.ME1312.SubServers.Sync.Library.Fallback;
|
||||
|
||||
import net.ME1312.SubServers.Sync.Library.Util;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.ME1312.SubServers.Sync.SubAPI;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.AbstractReconnectHandler;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.ReconnectHandler;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.PendingConnection;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* Smart Reconnect Handler Class
|
||||
*/
|
||||
public class SmartReconnectHandler implements ReconnectHandler {
|
||||
private static List<FallbackInspector> inspectors = new CopyOnWriteArrayList<FallbackInspector>();
|
||||
|
||||
@Override
|
||||
public ServerInfo getServer(ProxiedPlayer player) {
|
||||
ServerInfo forced = getForcedHost(player.getPendingConnection());
|
||||
if (forced != null) {
|
||||
return forced;
|
||||
} else {
|
||||
Map<String, ServerInfo> fallbacks = getFallbackServers(player.getPendingConnection().getListener());
|
||||
if (fallbacks.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
if (player instanceof UserConnection) ((UserConnection) player).setServerJoinQueue(new LinkedBlockingQueue<>(fallbacks.keySet()));
|
||||
return new LinkedList<Map.Entry<String, ServerInfo>>(fallbacks.entrySet()).getFirst().getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grabs the Forced Host Server for this connection
|
||||
*
|
||||
* @see AbstractReconnectHandler#getForcedHost(PendingConnection) Essentially the same method, but more ambigous
|
||||
* @param connection Connection to check
|
||||
* @return Forced Host Server (or null if there is none)
|
||||
*/
|
||||
public static ServerInfo getForcedHost(PendingConnection connection) {
|
||||
if (connection.getVirtualHost() == null) {
|
||||
return null;
|
||||
} else {
|
||||
String forced = connection.getListener().getForcedHosts().get(connection.getVirtualHost().getHostString());
|
||||
//if (forced == null && con.getListener().isForceDefault()) { // This is the part of the method that made it ambiguous
|
||||
// forced = con.getListener().getDefaultServer(); // Aside from that, everything else was fine
|
||||
//} // :(
|
||||
|
||||
return ProxyServer.getInstance().getServerInfo(forced);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a <i>smart</i> sorted map of fallback servers using a generated confidence score
|
||||
*
|
||||
* @param listener Listener to grab fallback servers from
|
||||
* @return Fallback Server Map (with legacy bungee case-sensitive keys)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Map<String, ServerInfo> getFallbackServers(ListenerInfo listener) {
|
||||
TreeMap<Integer, List<ServerInfo>> score = new TreeMap<Integer, List<ServerInfo>>(Collections.reverseOrder());
|
||||
for (String name : listener.getServerPriority()) {
|
||||
ServerInfo server = SubAPI.getInstance().getInternals().servers.getOrDefault(name.toLowerCase(), null);
|
||||
if (server == null) server = ProxyServer.getInstance().getServerInfo(name);
|
||||
if (server != null) {
|
||||
boolean valid = true;
|
||||
int confidence = 0;
|
||||
if (server instanceof ServerContainer) {
|
||||
if (!((ServerContainer) server).isHidden()) confidence++;
|
||||
if (!((ServerContainer) server).isRestricted()) confidence++;
|
||||
if (((ServerContainer) server).getSubData() != null) confidence++;
|
||||
} if (server instanceof SubServerContainer) {
|
||||
if (!((SubServerContainer) server).isRunning()) valid = false;
|
||||
}
|
||||
|
||||
List<FallbackInspector> inspectors = new ArrayList<FallbackInspector>();
|
||||
inspectors.addAll(SmartReconnectHandler.inspectors);
|
||||
for (FallbackInspector inspector : inspectors) try {
|
||||
Integer response = inspector.inspect(server);
|
||||
if (response == null) {
|
||||
valid = false;
|
||||
} else {
|
||||
confidence += response;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
new InvocationTargetException(e, "Exception while running inspecting fallback server: " + server.getName()).printStackTrace();
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
List<ServerInfo> servers = (score.keySet().contains(confidence))?score.get(confidence):new LinkedList<ServerInfo>();
|
||||
servers.add(server);
|
||||
score.put(confidence, servers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
LinkedHashMap<String, ServerInfo> map = new LinkedHashMap<String, ServerInfo>();
|
||||
for (List<ServerInfo> servers : score.values()) {
|
||||
while (!servers.isEmpty()) {
|
||||
ServerInfo next = servers.get(random.nextInt(servers.size()));
|
||||
map.put(next.getName(), next);
|
||||
servers.remove(next);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Fallback Server Inspector
|
||||
*
|
||||
* @param inspector Inspector
|
||||
*/
|
||||
public static void addInspector(FallbackInspector inspector) {
|
||||
if (Util.isNull(inspector)) throw new NullPointerException();
|
||||
inspectors.add(inspector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Fallback Server Inspector
|
||||
*
|
||||
* @param inspector Inspector
|
||||
*/
|
||||
public static void removeInspector(FallbackInspector inspector) {
|
||||
if (Util.isNull(inspector)) throw new NullPointerException();
|
||||
Util.isException(() -> inspectors.remove(inspector));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServer(ProxiedPlayer player) {
|
||||
// Ignore server switching
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
// Nothing to close
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import com.google.gson.Gson;
|
||||
import net.ME1312.SubServers.Sync.Event.*;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLConfig;
|
||||
import net.ME1312.SubServers.Sync.Library.Config.YAMLSection;
|
||||
import net.ME1312.SubServers.Sync.Library.Fallback.SmartReconnectHandler;
|
||||
import net.ME1312.SubServers.Sync.Library.Metrics;
|
||||
import net.ME1312.SubServers.Sync.Library.NamedContainer;
|
||||
import net.ME1312.SubServers.Sync.Library.UniversalFile;
|
||||
@ -15,13 +16,13 @@ import net.ME1312.SubServers.Sync.Network.SubDataClient;
|
||||
import net.ME1312.SubServers.Sync.Server.ServerContainer;
|
||||
import net.ME1312.SubServers.Sync.Server.SubServerContainer;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ServerPing;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.event.ServerKickEvent;
|
||||
import net.md_5.bungee.api.event.*;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
@ -32,6 +33,7 @@ import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -40,6 +42,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public final class SubPlugin extends BungeeCord implements Listener {
|
||||
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
|
||||
public final Map<String, ServerContainer> servers = new TreeMap<String, ServerContainer>();
|
||||
private final HashMap<UUID, List<ServerInfo>> fallbackLimbo = new HashMap<UUID, List<ServerInfo>>();
|
||||
|
||||
public final PrintStream out;
|
||||
public final UniversalFile dir = new UniversalFile(new File(System.getProperty("user.dir")));
|
||||
@ -63,18 +66,18 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
YAMLConfig tmp = new YAMLConfig(new UniversalFile("config.yml"));
|
||||
tmp.get().set("stats", UUID.randomUUID().toString());
|
||||
tmp.save();
|
||||
System.out.println("SubServers > Created ~/config.yml");
|
||||
System.out.println("SubServers > Created ./config.yml");
|
||||
}
|
||||
UniversalFile dir = new UniversalFile(this.dir, "SubServers");
|
||||
dir.mkdir();
|
||||
if (!(new UniversalFile(dir, "sync.yml").exists())) {
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Sync/Library/Files/config.yml", new UniversalFile(dir, "sync.yml").getPath());
|
||||
System.out.println("SubServers > Created ~/SubServers/sync.yml");
|
||||
System.out.println("SubServers > Created ./SubServers/sync.yml");
|
||||
} else if (((new YAMLConfig(new UniversalFile(dir, "sync.yml"))).get().getSection("Settings").getVersion("Version", new Version(0))).compareTo(new Version("2.11.2a+")) != 0) {
|
||||
Files.move(new UniversalFile(dir, "sync.yml").toPath(), new UniversalFile(dir, "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
|
||||
|
||||
Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Sync/Library/Files/config.yml", new UniversalFile(dir, "sync.yml").getPath());
|
||||
System.out.println("SubServers > Updated ~/SubServers/sync.yml");
|
||||
System.out.println("SubServers > Updated ./SubServers/sync.yml");
|
||||
}
|
||||
config = new YAMLConfig(new UniversalFile(dir, "sync.yml"));
|
||||
|
||||
@ -268,46 +271,74 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
||||
}
|
||||
|
||||
if (!e.getTarget().canAccess(e.getPlayer())) {
|
||||
e.setCancelled(true);
|
||||
if (e.getPlayer().getServer() != null) e.getPlayer().sendMessage(getTranslation("no_server_permission"));
|
||||
else e.getPlayer().disconnect(getTranslation("no_server_permission"));
|
||||
} else if (e.getPlayer().getServer() != null && e.getTarget() instanceof SubServerContainer && !((SubServerContainer) e.getTarget()).isRunning()) {
|
||||
e.setCancelled(true);
|
||||
if (e.getPlayer().getServer() == null || fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId()) || fallbackLimbo.get(e.getPlayer().getUniqueId()).contains(e.getTarget())) {
|
||||
ServerKickEvent kick = new ServerKickEvent(e.getPlayer(), e.getTarget(), new BaseComponent[]{
|
||||
new TextComponent(getTranslation("no_server_permission"))
|
||||
}, null, ServerKickEvent.State.CONNECTING);
|
||||
fallback(kick);
|
||||
if (!kick.isCancelled()) e.getPlayer().disconnect(kick.getKickReasonComponent());
|
||||
if (e.getPlayer().getServer() != null) e.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
e.getPlayer().sendMessage(getTranslation("no_server_permission"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
} else if (e.getPlayer().getServer() != null && !fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId()) && e.getTarget() instanceof SubServerContainer && !((SubServerContainer) e.getTarget()).isRunning()) {
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Server.Offline"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
if (fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
if (fallbackLimbo.get(e.getPlayer().getUniqueId()).contains(e.getTarget())) {
|
||||
fallbackLimbo.get(e.getPlayer().getUniqueId()).remove(e.getTarget());
|
||||
} else if (e.getPlayer().getServer() != null) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallback(ServerKickEvent e) {
|
||||
NamedContainer<Integer, List<ServerInfo>> next = null;
|
||||
for (String name : e.getPlayer().getPendingConnection().getListener().getServerPriority()) {
|
||||
if (!e.getKickedFrom().getName().equalsIgnoreCase(name)) {
|
||||
ServerInfo server = getServerInfo(name);
|
||||
if (server != null && (!(server instanceof SubServerContainer) || ((SubServerContainer) server).isRunning())) {
|
||||
int confidence = 0;
|
||||
if (server instanceof ServerContainer) {
|
||||
if (!((ServerContainer) server).isHidden()) confidence++;
|
||||
if (!((ServerContainer) server).isRestricted()) confidence++;
|
||||
if (((ServerContainer) server).getSubData() != null) confidence++;
|
||||
}
|
||||
if (e.getPlayer() instanceof UserConnection && config.get().getSection("Settings").getBoolean("Smart-Fallback", true)) {
|
||||
Map<String, ServerInfo> fallbacks;
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) {
|
||||
fallbacks = SmartReconnectHandler.getFallbackServers(e.getPlayer().getPendingConnection().getListener());
|
||||
} else {
|
||||
fallbacks = new LinkedHashMap<String, ServerInfo>();
|
||||
for (ServerInfo server : fallbackLimbo.get(e.getPlayer().getUniqueId())) fallbacks.put(server.getName(), server);
|
||||
}
|
||||
|
||||
if (next == null || confidence > next.name()) {
|
||||
List<ServerInfo> servers = new ArrayList<ServerInfo>();
|
||||
servers.add(server);
|
||||
next = new NamedContainer<Integer, List<ServerInfo>>(confidence, servers);
|
||||
} else if (confidence == next.name()) {
|
||||
next.get().add(server);
|
||||
}
|
||||
}
|
||||
fallbacks.remove(e.getKickedFrom().getName());
|
||||
if (!fallbacks.isEmpty()) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback").replace("$str$", (e.getKickedFrom() instanceof ServerContainer)?((ServerContainer) e.getKickedFrom()).getDisplayName():e.getKickedFrom().getName()).replace("$msg$", e.getKickReason()));
|
||||
if (!fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) fallbackLimbo.put(e.getPlayer().getUniqueId(), new LinkedList<>(fallbacks.values()));
|
||||
|
||||
ServerInfo next = new LinkedList<Map.Entry<String, ServerInfo>>(fallbacks.entrySet()).getFirst().getValue();
|
||||
e.setCancelServer(next);
|
||||
((UserConnection) e.getPlayer()).setServerJoinQueue(new LinkedBlockingQueue<>(fallbacks.keySet()));
|
||||
((UserConnection) e.getPlayer()).connect(next, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (next != null) {
|
||||
e.setCancelServer(next.get().get(new Random().nextInt(next.get().size())));
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Return").replace("$str$", (e.getCancelServer() instanceof ServerContainer)?((ServerContainer) e.getCancelServer()).getDisplayName():e.getCancelServer().getName()).replace("$msg$", e.getKickReason()));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = Byte.MAX_VALUE)
|
||||
public void fallbackFound(ServerConnectedEvent e) {
|
||||
if (fallbackLimbo.keySet().contains(e.getPlayer().getUniqueId())) new Timer("SubServers.Sync::Fallback_Limbo_Timer(" + e.getPlayer().getUniqueId() + ')').schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (e.getPlayer().getServer() != null && !((UserConnection) e.getPlayer()).isDimensionChange() && e.getPlayer().getServer().getInfo().getAddress().equals(e.getServer().getInfo().getAddress())) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
e.getPlayer().sendMessage(api.getLang("SubServers", "Bungee.Feature.Smart-Fallback.Result").replace("$str$", (e.getServer().getInfo() instanceof ServerContainer)?((ServerContainer) e.getServer().getInfo()).getDisplayName():e.getServer().getInfo().getName()));
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
public void resetLimbo(PlayerDisconnectEvent e) {
|
||||
fallbackLimbo.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = Byte.MIN_VALUE)
|
||||
|
Loading…
Reference in New Issue
Block a user