diff --git a/Artifacts/SubServers.Bungee.jar b/Artifacts/SubServers.Bungee.jar index e1eda683..f25ade88 100644 Binary files a/Artifacts/SubServers.Bungee.jar and b/Artifacts/SubServers.Bungee.jar differ diff --git a/Artifacts/SubServers.Client.Bukkit.jar b/Artifacts/SubServers.Client.Bukkit.jar index 241e65d9..9ed5cb9e 100644 Binary files a/Artifacts/SubServers.Client.Bukkit.jar and b/Artifacts/SubServers.Client.Bukkit.jar differ diff --git a/Artifacts/SubServers.Console.jar b/Artifacts/SubServers.Console.jar index 4aac3134..518193a9 100644 Binary files a/Artifacts/SubServers.Console.jar and b/Artifacts/SubServers.Console.jar differ diff --git a/Artifacts/SubServers.Host.jar b/Artifacts/SubServers.Host.jar index 8404359a..7e936c8a 100644 Binary files a/Artifacts/SubServers.Host.jar and b/Artifacts/SubServers.Host.jar differ diff --git a/Artifacts/SubServers.Sync.jar b/Artifacts/SubServers.Sync.jar index 185adb99..3e52983e 100644 Binary files a/Artifacts/SubServers.Sync.jar and b/Artifacts/SubServers.Sync.jar differ diff --git a/Javadoc/SubServers.Bungee/index-all.html b/Javadoc/SubServers.Bungee/index-all.html index 4a50a72f..4e041b13 100644 --- a/Javadoc/SubServers.Bungee/index-all.html +++ b/Javadoc/SubServers.Bungee/index-all.html @@ -84,6 +84,10 @@
Add an extra value to this Server
+
addGroup(String) - Method in class net.ME1312.SubServers.Bungee.Host.Server
+
+
Add this Server to a Group
+
addHost(String, String, boolean, InetAddress, String, String) - Method in class net.ME1312.SubServers.Bungee.SubAPI
Add a Host to the Network
@@ -924,6 +928,18 @@
Gets the Recommended Minecraft Version
+
getGroup(String) - Method in class net.ME1312.SubServers.Bungee.SubAPI
+
+
Gets a Server Group
+
+
getGroups() - Method in class net.ME1312.SubServers.Bungee.Host.Server
+
+
Get this Server's Groups
+
+
getGroups() - Method in class net.ME1312.SubServers.Bungee.SubAPI
+
+
Gets the Server Groups
+
getHandler() - Method in class net.ME1312.SubServers.Bungee.Host.External.ExternalSubLogger
 
getHandler() - Method in class net.ME1312.SubServers.Bungee.Host.Internal.InternalSubLogger
@@ -1510,6 +1526,8 @@
Gets the SubServers Version
+
groups - Variable in class net.ME1312.SubServers.Bungee.SubPlugin
+
 
@@ -2068,7 +2086,7 @@
New PacketDownloadServerList (In)
-
PacketDownloadServerList(SubPlugin, String, String) - Constructor for class net.ME1312.SubServers.Bungee.Network.Packet.PacketDownloadServerList
+
PacketDownloadServerList(SubPlugin, String, String, String) - Constructor for class net.ME1312.SubServers.Bungee.Network.Packet.PacketDownloadServerList
New PacketDownloadServerList (Out)
@@ -2344,6 +2362,10 @@
Remove an extra value from this Server
+
removeGroup(String) - Method in class net.ME1312.SubServers.Bungee.Host.Server
+
+
Remove this Server from a Group
+
removeHost(String) - Method in class net.ME1312.SubServers.Bungee.SubAPI
Remove a Host from the Network
diff --git a/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.html b/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.html index afd59a1b..c2bba9f0 100644 --- a/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.html +++ b/Javadoc/SubServers.Bungee/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.html @@ -345,7 +345,7 @@ extends Server -addExtra, getDisplayName, getExtra, getExtra, getMotd, getSubData, hasExtra, isHidden, isRestricted, removeExtra, setHidden, setMotd, setRestricted, setSubData +addExtra, addGroup, getDisplayName, getExtra, getExtra, getGroups, getMotd, getSubData, hasExtra, isHidden, isRestricted, removeExtra, removeGroup, setHidden, setMotd, setRestricted, setSubData + + + + diff --git a/Javadoc/SubServers.Client.Bukkit/index-all.html b/Javadoc/SubServers.Client.Bukkit/index-all.html index a6612dc5..722ea770 100644 --- a/Javadoc/SubServers.Client.Bukkit/index-all.html +++ b/Javadoc/SubServers.Client.Bukkit/index-all.html @@ -975,6 +975,12 @@
Get Packet Version
+
groupMenu(int) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.InternalUIRenderer
+
 
+
groupMenu(int) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer
+
+
Opens the Group Menu
+
gui - Variable in class net.ME1312.SubServers.Client.Bukkit.SubPlugin
 
@@ -1349,7 +1355,7 @@
New PacketDownloadServerList (In)
-
PacketDownloadServerList(String, JSONCallback...) - Constructor for class net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList
+
PacketDownloadServerList(String, String, JSONCallback...) - Constructor for class net.ME1312.SubServers.Client.Bukkit.Network.Packet.PacketDownloadServerList
New PacketDownloadServerList (Out)
@@ -1511,6 +1517,12 @@
Attempt to send a Title Message
+
serverMenu(int, String, String) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.InternalUIRenderer
+
 
+
serverMenu(int, String, String) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer
+
+
Opens the SubServer Menu
+
set(YAMLSection) - Method in class net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLConfig
Set Config Contents
@@ -1677,12 +1689,6 @@
Opens SubServer/<name>
-
subserverMenu(int, String) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.InternalUIRenderer
-
 
-
subserverMenu(int, String) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer
-
-
Opens the SubServer Menu
-
subserverPlugin(int, String) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.InternalUIRenderer
 
subserverPlugin(int, String) - Method in class net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer
diff --git a/Javadoc/SubServers.Client.Bukkit/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.html b/Javadoc/SubServers.Client.Bukkit/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.html index 761652ff..f33490e8 100644 --- a/Javadoc/SubServers.Client.Bukkit/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.html +++ b/Javadoc/SubServers.Client.Bukkit/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.html @@ -17,7 +17,7 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -161,67 +161,74 @@ extends +void +groupMenu(int page) +
Opens the Group Menu
+ + + boolean hasHistory()
If there is any Window History
- + void hostAdmin(java.lang.String host)
Opens Host/<name>
- + void hostCreator(UIRenderer.CreatorOptions options)
Opens Host/<name>/Create
- + void hostCreatorTemplates(int page, UIRenderer.CreatorOptions options)  - + void hostMenu(int page)
Opens the Host Menu
- + void hostPlugin(int page, java.lang.String host)
Opens Host/<name>/Plugins
- + void newUI()
Opens a new window
- + void reopen()
Reopens the current window
- + +void +serverMenu(int page, + java.lang.String host, + java.lang.String group) +
Opens the SubServer Menu
+ + + void subserverAdmin(java.lang.String subserver)
Opens SubServer/<name>
- -void -subserverMenu(int page, - java.lang.String host) -
Opens the SubServer Menu
- - - + void subserverPlugin(int page, java.lang.String subserver) @@ -412,19 +419,37 @@ extends + + + + + - + + + + + - +
  • PacketDownloadServerList

    public PacketDownloadServerList(java.lang.String host,
    +                                java.lang.String group,
                                     JSONCallback... callback)
    New PacketDownloadServerList (Out)
    Parameters:
    host - Host name (or null for all)
    +
    group - Group name (or null for all)
    callback - Callbacks
  • diff --git a/SubServers.Bungee/META-INF/MANIFEST.MF b/SubServers.Bungee/META-INF/MANIFEST.MF index d9a41a05..48d5effa 100644 --- a/SubServers.Bungee/META-INF/MANIFEST.MF +++ b/SubServers.Bungee/META-INF/MANIFEST.MF @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Class-Path: BungeeCord.jar Main-Class: net.ME1312.SubServers.Bungee.Launch -Implementation-Version: 2.12.1d -Specification-Version: 0 +Implementation-Version: 2.12.1e +Specification-Version: 1 diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java index 0bdf1441..f2186dff 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalHost.java @@ -171,7 +171,10 @@ public class ExternalHost extends Host implements ClientHandler { getSubServer(name).waitFor(); } queue(new PacketExRemoveServer(name, json -> { - if (json.getInt("r") == 0) servers.remove(name.toLowerCase()); + if (json.getInt("r") == 0) { + for (String group : getSubServer(name).getGroups()) getSubServer(name).removeGroup(group); + servers.remove(name.toLowerCase()); + } })); return true; } else return false; @@ -186,7 +189,10 @@ public class ExternalHost extends Host implements ClientHandler { getSubServer(name).terminate(); } queue(new PacketExRemoveServer(name, json -> { - if (json.getInt("r") == 0) servers.remove(name.toLowerCase()); + if (json.getInt("r") == 0) { + for (String group : getSubServer(name).getGroups()) getSubServer(name).removeGroup(group); + servers.remove(name.toLowerCase()); + } })); return true; } @@ -220,6 +226,7 @@ public class ExternalHost extends Host implements ClientHandler { System.out.println("SubServers > Removing Files..."); queue(new PacketExDeleteServer(server, info, json -> { if (json.getInt("r") == 0) { + for (String group : getSubServer(name).getGroups()) getSubServer(name).removeGroup(group); servers.remove(server.toLowerCase()); System.out.println("SubServers > Done!"); } else { @@ -257,6 +264,7 @@ public class ExternalHost extends Host implements ClientHandler { System.out.println("SubServers > Removing Files..."); queue(new PacketExDeleteServer(server, info, json -> { if (json.getInt("r") == 0) { + for (String group : getSubServer(name).getGroups()) getSubServer(name).removeGroup(group); servers.remove(server.toLowerCase()); System.out.println("SubServers > Done!"); } else { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java index 8016bfaf..f0e1c4f9 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubCreator.java @@ -84,7 +84,9 @@ public class ExternalSubCreator extends SubCreator { } if (!server.contains("Enabled")) server.set("Enabled", true); + if (!server.contains("Display")) server.set("Display", ""); if (!server.contains("Host")) server.set("Host", host.getName()); + if (!server.contains("Group")) server.set("Group", ""); if (!server.contains("Port")) server.set("Port", port); if (!server.contains("Motd")) server.set("Motd", "Some SubServer"); if (!server.contains("Log")) server.set("Log", true); @@ -93,10 +95,11 @@ public class ExternalSubCreator extends SubCreator { if (!server.contains("Stop-Command")) server.set("Stop-Command", "stop"); if (!server.contains("Run-On-Launch")) server.set("Run-On-Launch", false); if (!server.contains("Auto-Restart")) server.set("Auto-Restart", false); - if (!server.contains("Hidden")) server.set("Hidden", false); if (!server.contains("Restricted")) server.set("Restricted", false); + if (!server.contains("Incompatible")) server.set("Incompatible", new ArrayList()); + if (!server.contains("Hidden")) server.set("Hidden", false); - SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"), + host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"), new Executable(server.getRawString("Executable")), server.getRawString("Stop-Command"), true, server.getBoolean("Auto-Restart"), server.getBoolean("Hidden"), server.getBoolean("Restricted"), false); host.plugin.config.get().getSection("Servers").set(name, server); host.plugin.config.save(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java index beb92c93..56e8563b 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/External/ExternalSubServer.java @@ -9,10 +9,13 @@ import net.ME1312.SubServers.Bungee.Library.Exception.InvalidServerException; import net.ME1312.SubServers.Bungee.Library.NamedContainer; import net.ME1312.SubServers.Bungee.Library.Util; import net.ME1312.SubServers.Bungee.Network.Packet.PacketExUpdateServer; +import net.ME1312.SubServers.Bungee.SubAPI; import java.io.File; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.UUID; /** @@ -157,6 +160,7 @@ public class ExternalSubServer extends SubServer { + @SuppressWarnings("deprecation") public int edit(UUID player, YAMLSection edit) { int c = 0; boolean state = isRunning(); @@ -175,6 +179,10 @@ public class ExternalSubServer extends SubServer { SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { YAMLSection config = this.host.plugin.config.get().getSection("Servers").getSection(getName()); @@ -220,11 +228,26 @@ public class ExternalSubServer extends SubServer { c++; } break; + case "group": + if (value.isList()) { + for (String group : getGroups()) removeGroup(group); + for (String group : value.asStringList()) addGroup(group); + if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { + this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Group", value.asStringList()); + this.host.plugin.config.save(); + } + c++; + } + break; case "host": if (value.isString() && host.removeSubServer(player, getName())) { SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Host", server.getHost().getName()); @@ -240,6 +263,10 @@ public class ExternalSubServer extends SubServer { SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Port", server.getAddress().getPort()); @@ -279,6 +306,10 @@ public class ExternalSubServer extends SubServer { SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), value.asRawString(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Directory", server.getPath()); @@ -294,6 +325,10 @@ public class ExternalSubServer extends SubServer { SubServer server = host.addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), new Executable(value.asRawString()), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Executable", value.asRawString()); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java index 7f93c1f2..b5059462 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalHost.java @@ -122,6 +122,7 @@ public class InternalHost extends Host { getSubServer(name).stop(); getSubServer(name).waitFor(); } + for (String group : getSubServer(name).getGroups()) getSubServer(name).removeGroup(group); servers.remove(name.toLowerCase()); return true; } else return false; @@ -135,6 +136,7 @@ public class InternalHost extends Host { if (getSubServer(name).isRunning()) { getSubServer(name).terminate(); } + for (String group : getSubServer(name).getGroups()) getSubServer(name).removeGroup(group); servers.remove(name.toLowerCase()); return true; } diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java index 85507515..840ac268 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubCreator.java @@ -198,9 +198,10 @@ public class InternalSubCreator extends SubCreator { .replace("$version$", version.toString().replace(" ", "@")).replace("$port$", Integer.toString(port))); } } - if (!server.contains("Enabled")) server.set("Enabled", true); + if (!server.contains("Display")) server.set("Display", ""); if (!server.contains("Host")) server.set("Host", host.getName()); + if (!server.contains("Group")) server.set("Group", ""); if (!server.contains("Port")) server.set("Port", port); if (!server.contains("Motd")) server.set("Motd", "Some SubServer"); if (!server.contains("Log")) server.set("Log", true); @@ -209,10 +210,11 @@ public class InternalSubCreator extends SubCreator { if (!server.contains("Stop-Command")) server.set("Stop-Command", "stop"); if (!server.contains("Run-On-Launch")) server.set("Run-On-Launch", false); if (!server.contains("Auto-Restart")) server.set("Auto-Restart", false); - if (!server.contains("Hidden")) server.set("Hidden", false); if (!server.contains("Restricted")) server.set("Restricted", false); + if (!server.contains("Incompatible")) server.set("Incompatible", new ArrayList()); + if (!server.contains("Hidden")) server.set("Hidden", false); - SubServer subserver = host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"), + host.addSubServer(player, name, server.getBoolean("Enabled"), port, server.getColoredString("Motd", '&'), server.getBoolean("Log"), server.getRawString("Directory"), new Executable(server.getRawString("Executable")), server.getRawString("Stop-Command"), true, server.getBoolean("Auto-Restart"), server.getBoolean("Hidden"), server.getBoolean("Restricted"), false); host.plugin.config.get().getSection("Servers").set(name, server); host.plugin.config.save(); @@ -340,7 +342,7 @@ public class InternalSubCreator extends SubCreator { private void generateProperties(File dir, int port) throws IOException { File file = new File(dir, "server.properties"); if (!file.exists()) file.createNewFile(); - String content = Util.readAll(new BufferedReader(new InputStreamReader(new FileInputStream(file)))).replace("server-port=", "server-port=" + port).replace("server-ip=", "server-ip=" + host.getAddress().getHostAddress().substring(1)); + String content = Util.readAll(new BufferedReader(new InputStreamReader(new FileInputStream(file)))).replace("server-port=", "server-port=" + port).replace("server-ip=", "server-ip=" + host.getAddress().getHostAddress()); file.delete(); PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.write(content); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java index 6a678b9b..97912670 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java @@ -10,6 +10,7 @@ import net.ME1312.SubServers.Bungee.Library.NamedContainer; import net.ME1312.SubServers.Bungee.Library.UniversalFile; import net.ME1312.SubServers.Bungee.Library.Util; import net.ME1312.SubServers.Bungee.Library.Version.Version; +import net.ME1312.SubServers.Bungee.SubAPI; import net.ME1312.SubServers.Bungee.SubPlugin; import org.json.JSONObject; @@ -215,6 +216,7 @@ public class InternalSubServer extends SubServer { } else return false; } + @SuppressWarnings("deprecation") public int edit(UUID player, YAMLSection edit) { int c = 0; boolean state = isRunning(); @@ -233,6 +235,10 @@ public class InternalSubServer extends SubServer { SubServer server = host.addSubServer(player, value.asRawString(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { YAMLSection config = this.host.plugin.config.get().getSection("Servers").getSection(getName()); @@ -277,11 +283,26 @@ public class InternalSubServer extends SubServer { c++; } break; + case "group": + if (value.isList()) { + for (String group : getGroups()) removeGroup(group); + for (String group : value.asStringList()) addGroup(group); + if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { + this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Group", value.asStringList()); + this.host.plugin.config.save(); + } + c++; + } + break; case "host": if (value.isString() && host.removeSubServer(player, getName())) { SubServer server = this.host.plugin.api.getHost(value.asRawString()).addSubServer(player, getName(), isEnabled(), getAddress().getPort(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Host", server.getHost().getName()); @@ -297,6 +318,10 @@ public class InternalSubServer extends SubServer { SubServer server = host.addSubServer(player, getName(), isEnabled(), value.asInt(), getMotd(), isLogging(), getPath(), getExecutable(), getStopCommand(), false, willAutoRestart(), isHidden(), isRestricted(), isTemporary()); if (server != null) { if (!getName().equals(getDisplayName())) server.setDisplayName(getDisplayName()); + for (String group : getGroups()) { + removeGroup(group); + server.addGroup(group); + } for (String extra : getExtra().getKeys()) server.addExtra(extra, getExtra(extra)); if (this.host.plugin.config.get().getSection("Servers").getKeys().contains(getName())) { this.host.plugin.config.get().getSection("Servers").getSection(getName()).set("Port", server.getAddress().getPort()); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java index 9351f528..bc8828bb 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Server.java @@ -10,12 +10,17 @@ import net.ME1312.SubServers.Bungee.Library.Util; import net.ME1312.SubServers.Bungee.Network.Client; import net.ME1312.SubServers.Bungee.Network.ClientHandler; import net.ME1312.SubServers.Bungee.Network.SubDataServer; +import net.ME1312.SubServers.Bungee.SubAPI; import net.md_5.bungee.BungeeServerInfo; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.connection.ProxiedPlayer; import org.json.JSONObject; import java.net.InetSocketAddress; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; /** * Server Class @@ -23,6 +28,7 @@ import java.net.InetSocketAddress; public class Server extends BungeeServerInfo implements ClientHandler, ExtraDataHandler { private YAMLSection extra = new YAMLSection(); private Client client = null; + private List groups = new ArrayList(); private String nick = null; private String motd; private boolean restricted; @@ -124,6 +130,45 @@ public class Server extends BungeeServerInfo implements ClientHandler, ExtraData return restricted; } + /** + * Get this Server's Groups + * + * @return Group names + */ + public List getGroups() { + return groups; + } + + /** + * Add this Server to a Group + * + * @param value Group name + */ + @SuppressWarnings("deprecation") + public void addGroup(String value) { + if (Util.isNull(value)) throw new NullPointerException(); + if (value.length() > 0 && !groups.contains(value)) { + List list = (SubAPI.getInstance().getInternals().groups.keySet().contains(value))?SubAPI.getInstance().getInternals().groups.get(value):new ArrayList(); + list.add(this); + SubAPI.getInstance().getInternals().groups.put(value, list); + groups.add(value); + } + } + + /** + * Remove this Server from a Group + * + * @param value value Group name + */ + @SuppressWarnings("deprecation") + public void removeGroup(String value) { + if (Util.isNull(value)) throw new NullPointerException(); + List list = SubAPI.getInstance().getInternals().groups.get(value); + list.remove(this); + SubAPI.getInstance().getInternals().groups.put(value, list); + groups.remove(value); + } + /** * Sets if the Server is Restricted * @@ -169,6 +214,7 @@ public class Server extends BungeeServerInfo implements ClientHandler, ExtraData JSONObject info = new JSONObject(); info.put("type", "Server"); info.put("name", getName()); + info.put("group", getGroups()); info.put("display", getDisplayName()); info.put("address", getAddress().getAddress().getHostAddress() + ':' + getAddress().getPort()); info.put("motd", getMotd()); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java index 713c90cc..372d0686 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/SubServer.java @@ -391,6 +391,7 @@ public abstract class SubServer extends Server { JSONObject sinfo = new JSONObject(super.toString()); sinfo.put("type", "SubServer"); sinfo.put("enabled", getHost().isEnabled() && isEnabled()); + sinfo.put("host", getHost().getName()); sinfo.put("running", isRunning()); sinfo.put("log", isLogging()); List incompatible = new ArrayList(); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Config/YAMLSection.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Config/YAMLSection.java index e86cbd2a..46ad5ca3 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Config/YAMLSection.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Config/YAMLSection.java @@ -172,8 +172,10 @@ public class YAMLSection { * @param value Value */ public void set(String handle, Object value) { - if (Util.isNull(handle, value)) throw new NullPointerException(); - if (value instanceof Collection) { + if (Util.isNull(handle)) throw new NullPointerException(); + if (value == null) { + remove(handle); + } else if (value instanceof Collection) { set(handle, (Collection) value); } else { map.put(handle, convert(value)); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/bungee.yml b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/bungee.yml index 46c8fe4d..7f9f664f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/bungee.yml +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/bungee.yml @@ -15,9 +15,12 @@ permissions: groups: {} servers: Lobby: + display: '' + group: [] motd: '&1Just another BungeeCord - Forced Host' address: 127.0.0.1:25566 restricted: false + hidden: false timeout: 30000 listeners: - query_port: 25564 diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/config.yml b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/config.yml index fd2d853b..b9c94861 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/config.yml +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/config.yml @@ -10,6 +10,7 @@ Settings: Hosts: '~': Enabled: true + Display: '' Driver: 'BUILT-IN' Address: '127.0.0.1' Directory: './' @@ -18,7 +19,9 @@ Hosts: Servers: 'Example': Enabled: false + Display: '' Host: '~' + Group: [] Port: 25567 Motd: '&aThis is a SubServer' Log: true diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/lang.yml b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/lang.yml index 8606376a..246b1973 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/lang.yml +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Library/Files/lang.yml @@ -1,4 +1,4 @@ -Version: '2.12.1c+' +Version: '2.12.1e+' Lang: 'Bungee.Server.Current': '&6You are currently connected to $str$' 'Bungee.Server.Available': '&6You may connect to the following servers at this time:' @@ -30,9 +30,12 @@ Lang: 'Command.Version': '&7SubServers \u00BB $name$ is running version &f$str$' 'Command.Version.Outdated': '&7You are $int$ version(s) behind.' 'Command.Version.Latest': '&7You are on the latest version.' + 'Command.List.Group-Header': '&7SubServers \u00BB Group/Server List:' 'Command.List.Host-Header': '&7SubServers \u00BB Host/SubServer List:' 'Command.List.Server-Header': '&7SubServers \u00BB Server List:' + 'Command.List.Header': '&7: ' 'Command.List.Divider': '&7, ' + 'Command.List.Empty': '&7(none)' 'Command.Info': '&7SubServers \u00BB Info on &f$str$&7:' 'Command.Info.Unknown': '&cSubServers \u00BB There is no server with that name' 'Command.Info.Invalid': '&cSubServers \u00BB That Server is not a SubServer' @@ -80,7 +83,7 @@ Lang: 'Interface.Host-Menu.Host-Disabled': '&4Disabled' 'Interface.Host-Menu.Host-Server-Count': '&9$int$ Server(s)' 'Interface.Host-Menu.No-Hosts': '&c&oThere are No Hosts' - 'Interface.Host-Menu.SubServer-Menu': '&a&lSubServer Menu' + 'Interface.Host-Menu.Group-Menu': '&6&lView Servers by Group' 'Interface.Host-Admin.Title': 'Host/$str$' 'Interface.Host-Admin.Creator': '&eCreate a SubServer' 'Interface.Host-Admin.SubServers': '&aView SubServers' @@ -111,15 +114,21 @@ Lang: 'Interface.Host-Plugin.Title': 'Host/$str$/Plugins' 'Interface.Host-Plugin.No-Plugins': '&c&oThere are No Plugins Available' 'Interface.Host-SubServer.Title': 'Host/$str$/SubServers' - 'Interface.SubServer-Menu.Title': 'SubServer Menu' - 'Interface.SubServer-Menu.SubServer-Player-Count': '&2$int$ Player(s) Online' - 'Interface.SubServer-Menu.SubServer-External': '&7External Server' - 'Interface.SubServer-Menu.SubServer-Temporary': '&9Temporary' - 'Interface.SubServer-Menu.SubServer-Offline': '&6Offline' - 'Interface.SubServer-Menu.SubServer-Incompatible': '&4Incompatible with $str$' - 'Interface.SubServer-Menu.SubServer-Disabled': '&4Disabled' - 'Interface.SubServer-Menu.No-SubServers': '&c&oThere are No SubServers' - 'Interface.SubServer-Menu.Host-Menu': '&b&lHost Menu' + 'Interface.Group-Menu.Title': 'Group Menu' + 'Interface.Group-Menu.Group-Server-Count': '&9$int$ Server(s)' + 'Interface.Group-Menu.No-Groups': '&c&oThere are No Groups' + 'Interface.Group-Menu.Server-Menu': '&a&lView All Servers' + 'Interface.Group-SubServer.Title': 'Group/$str$/Servers' + 'Interface.Server-Menu.Title': 'Server Menu' + 'Interface.Server-Menu.Server-Player-Count': '&2$int$ Player(s) Online' + 'Interface.Server-Menu.Server-External': '&7External Server' + 'Interface.Server-Menu.SubServer-Temporary': '&9Temporary' + 'Interface.Server-Menu.SubServer-Offline': '&6Offline' + 'Interface.Server-Menu.SubServer-Incompatible': '&4Incompatible with $str$' + 'Interface.Server-Menu.SubServer-Disabled': '&4Disabled' + 'Interface.Server-Menu.SubServer-Invalid': '&4Cannot be managed by SubServers' + 'Interface.Server-Menu.No-Servers': '&c&oThere are No Servers' + 'Interface.Server-Menu.Host-Menu': '&b&lView Hosts' 'Interface.SubServer-Admin.Title': 'SubServer/$str$' 'Interface.SubServer-Admin.Start': '&aStart SubServer' 'Interface.SubServer-Admin.Start.Title': '&aStarting SubServer' diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerInfo.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerInfo.java index 9346d986..1f557525 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerInfo.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerInfo.java @@ -73,6 +73,7 @@ public class PacketDownloadServerInfo implements PacketIn, PacketOut { } if (server != null) { info.put("name", server.getName()); info.put("display", server.getDisplayName()); + info.put("group", server.getGroups()); info.put("address", server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort()); info.put("restricted", server.isRestricted()); info.put("hidden", server.isHidden()); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerList.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerList.java index ad15d36c..d9a5063f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerList.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadServerList.java @@ -11,14 +11,19 @@ import net.ME1312.SubServers.Bungee.Network.PacketIn; import net.ME1312.SubServers.Bungee.Network.PacketOut; import net.ME1312.SubServers.Bungee.SubPlugin; import net.md_5.bungee.api.connection.ProxiedPlayer; +import org.json.JSONArray; import org.json.JSONObject; +import java.util.ArrayList; +import java.util.List; + /** * Download Server List Packet */ public class PacketDownloadServerList implements PacketIn, PacketOut { private SubPlugin plugin; private String host; + private String group; private String id; /** @@ -36,12 +41,14 @@ public class PacketDownloadServerList implements PacketIn, PacketOut { * * @param plugin SubPlugin * @param host Host (or null for all) + * @param group Group (or null for all) * @param id Receiver ID */ - public PacketDownloadServerList(SubPlugin plugin, String host, String id) { + public PacketDownloadServerList(SubPlugin plugin, String host, String group, String id) { if (Util.isNull(plugin)) throw new NullPointerException(); this.plugin = plugin; this.host = host; + this.group = group; this.id = id; } @@ -49,13 +56,12 @@ public class PacketDownloadServerList implements PacketIn, PacketOut { public JSONObject generate() { JSONObject json = new JSONObject(); json.put("id", id); - if (host == null || host.equals("")) { - JSONObject exServers = new JSONObject(); - for (Server server : plugin.exServers.values()) { - exServers.put(server.getName(), new JSONObject(server.toString())); - } - json.put("servers", exServers); + + JSONObject exServers = new JSONObject(); + for (Server server : plugin.exServers.values()) { + exServers.put(server.getName(), new JSONObject(server.toString())); } + json.put("servers", exServers); if (this.host == null || !this.host.equals("")) { JSONObject hosts = new JSONObject(); @@ -67,12 +73,25 @@ public class PacketDownloadServerList implements PacketIn, PacketOut { json.put("hosts", hosts); } + if (this.group == null || !this.group.equals("")) { + JSONObject groups = new JSONObject(); + for (String group : plugin.api.getGroups().keySet()) { + if (this.group == null || this.group.equalsIgnoreCase(group)) { + JSONObject servers = new JSONObject(); + for (Server server : plugin.api.getGroup(group)) { + servers.put(server.getName(), new JSONObject(server.toString())); + } + groups.put(group, servers); + } + } + json.put("groups", groups); + } return json; } @Override public void execute(Client client, JSONObject data) { - client.sendPacket(new PacketDownloadServerList(plugin, (data.keySet().contains("host"))?data.getString("host"):null, (data.keySet().contains("id"))?data.getString("id"):null)); + client.sendPacket(new PacketDownloadServerList(plugin, (data.keySet().contains("host"))?data.getString("host"):null, (data.keySet().contains("group"))?data.getString("group"):null, (data.keySet().contains("id"))?data.getString("id"):null)); } @Override diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java index 4c882507..3c6f26c1 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubAPI.java @@ -213,6 +213,25 @@ public final class SubAPI { return true; } + /** + * Gets the Server Groups + * + * @return Group Map + */ + public Map> getGroups() { + return new TreeMap>(plugin.groups); + } + + /** + * Gets a Server Group + * + * @param name Group name + * @return a Server Group + */ + public List getGroup(String name) { + return getGroups().get(name); + } + /** * Gets the Servers (including SubServers) * diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java index a14316e9..92e64002 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java @@ -107,9 +107,37 @@ public final class SubCommand extends Command implements TabExecutor { plugin.getPluginManager().dispatchCommand(ConsoleCommandSender.getInstance(), "greload"); } } else if (args[0].equalsIgnoreCase("list")) { - sender.sendMessage("SubServers > Host/SubServer List:"); String div = ChatColor.RESET + ", "; int i = 0; + sender.sendMessage("SubServers > Group/Server List:"); + for (String group : plugin.api.getGroups().keySet()) { + String message = ""; + message += ChatColor.GOLD + group + ChatColor.RESET + ": "; + List names = new ArrayList(); + Map servers = plugin.api.getServers(); + for (Server server : plugin.api.getGroup(group)) names.add(server.getName()); + Collections.sort(names); + for (String name : names) { + if (i != 0) message += div; + Server server = servers.get(name.toLowerCase()); + if (!(servers.get(name.toLowerCase()) instanceof SubServer)) { + message += ChatColor.WHITE; + } else if (((SubServer) server).isTemporary()) { + message += ChatColor.AQUA; + } else if (((SubServer) server).isRunning()) { + message += ChatColor.GREEN; + } else if (((SubServer) server).isEnabled() && ((SubServer) server).getCurrentIncompatibilities().size() == 0) { + message += ChatColor.YELLOW; + } else { + message += ChatColor.RED; + } + message += server.getDisplayName() + " (" + server.getAddress().getAddress().getHostAddress() + ':' + server.getAddress().getPort() + ((server.getName().equals(server.getDisplayName()))?"":ChatColor.stripColor(div)+server.getName()) + ")"; + i++; + } + sender.sendMessage(message); + i = 0; + } + sender.sendMessage("SubServers > Host/SubServer List:"); for (Host host : plugin.api.getHosts().values()) { String message = ""; if (host.isEnabled()) { @@ -158,6 +186,10 @@ public final class SubCommand extends Command implements TabExecutor { if (!server.getName().equals(server.getDisplayName())) sender.sendMessage(" - Real Name: " + server.getName()); sender.sendMessage(" - Host: " + server.getHost().getDisplayName() + ((!server.getHost().getName().equals(server.getHost().getDisplayName()))?" ("+server.getHost().getName()+')':"")); sender.sendMessage(" - Enabled: " + ((server.isEnabled())?"yes":"no")); + if (server.getGroups().size() > 0) { + sender.sendMessage(" - Groups:"); + for (String group : server.getGroups()) sender.sendMessage(" - " + group); + } if (server.isTemporary()) sender.sendMessage(" - Temporary: yes"); sender.sendMessage(" - Running: " + ((server.isRunning())?"yes":"no")); sender.sendMessage(" - Logging: " + ((server.isLogging())?"yes":"no")); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java index f5bd23ca..dfcf9d0c 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java @@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit; public final class SubPlugin extends BungeeCord implements Listener { protected final HashMap> hostDrivers = new HashMap>(); public final HashMap hosts = new HashMap(); + public final HashMap> groups = new HashMap>(); public final HashMap exServers = new HashMap(); private final HashMap legServers = new HashMap(); @@ -93,7 +94,7 @@ public final class SubPlugin extends BungeeCord implements Listener { 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"); - } else if ((new Version((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getString("Version", "0")).compareTo(new Version("2.12.1c+"))) != 0) { + } else if ((new Version((new YAMLConfig(new UniversalFile(dir, "lang.yml"))).get().getString("Version", "0")).compareTo(new Version("2.12.1e+"))) != 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"); @@ -222,7 +223,7 @@ public final class SubPlugin extends BungeeCord implements Listener { if (!hostDrivers.keySet().contains(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toLowerCase())) throw new InvalidHostException("Invalid Driver for host: " + name); Host host = api.addHost(config.get().getSection("Hosts").getSection(name).getRawString("Driver").toLowerCase(), name, config.get().getSection("Hosts").getSection(name).getBoolean("Enabled"), InetAddress.getByName(config.get().getSection("Hosts").getSection(name).getRawString("Address")), config.get().getSection("Hosts").getSection(name).getRawString("Directory"), config.get().getSection("Hosts").getSection(name).getRawString("Git-Bash")); - if (config.get().getSection("Hosts").getSection(name).getKeys().contains("Display")) host.setDisplayName(config.get().getSection("Hosts").getSection(name).getString("Display")); + if (config.get().getSection("Hosts").getSection(name).getKeys().contains("Display") && config.get().getSection("Hosts").getSection(name).getString("Display").length() > 0) host.setDisplayName(config.get().getSection("Hosts").getSection(name).getString("Display")); if (config.get().getSection("Hosts").getSection(name).getKeys().contains("Extra")) for (String extra : config.get().getSection("Hosts").getSection(name).getSection("Extra").getKeys()) host.addExtra(extra, config.get().getSection("Hosts").getSection(name).getSection("Extra").getObject(extra)); hosts++; } catch (Exception e) { @@ -238,7 +239,8 @@ public final class SubPlugin extends BungeeCord implements Listener { Server server = api.addServer(name, InetAddress.getByName(bungee.get().getSection("servers").getSection(name).getRawString("address").split(":")[0]), Integer.parseInt(bungee.get().getSection("servers").getSection(name).getRawString("address").split(":")[1]), bungee.get().getSection("servers").getSection(name).getColoredString("motd", '&'), bungee.get().getSection("servers").getSection(name).getBoolean("hidden", false), bungee.get().getSection("servers").getSection(name).getBoolean("restricted")); - if (bungee.get().getSection("servers").getSection(name).getKeys().contains("display")) server.setDisplayName(bungee.get().getSection("servers").getSection(name).getString("display")); + if (bungee.get().getSection("servers").getSection(name).getKeys().contains("display") && bungee.get().getSection("servers").getSection(name).getString("display").length() > 0) server.setDisplayName(bungee.get().getSection("servers").getSection(name).getString("display")); + if (bungee.get().getSection("servers").getSection(name).getKeys().contains("group")) for (String group : bungee.get().getSection("servers").getSection(name).getStringList("group")) server.addGroup(group); if (bungee.get().getSection("servers").getSection(name).getKeys().contains("extra")) for (String extra : config.get().getSection("servers").getSection(name).getSection("extra").getKeys()) server.addExtra(extra, config.get().getSection("servers").getSection(name).getSection("extra").getObject(extra)); servers++; } catch (Exception e) { @@ -259,7 +261,8 @@ public final class SubPlugin extends BungeeCord implements Listener { config.get().getSection("Servers").getSection(name).getInt("Port"), config.get().getSection("Servers").getSection(name).getColoredString("Motd", '&'), config.get().getSection("Servers").getSection(name).getBoolean("Log"), config.get().getSection("Servers").getSection(name).getRawString("Directory"), new Executable(config.get().getSection("Servers").getSection(name).getRawString("Executable")), config.get().getSection("Servers").getSection(name).getRawString("Stop-Command"), config.get().getSection("Servers").getSection(name).getBoolean("Run-On-Launch"), config.get().getSection("Servers").getSection(name).getBoolean("Auto-Restart"), config.get().getSection("Servers").getSection(name).getBoolean("Hidden"), config.get().getSection("Servers").getSection(name).getBoolean("Restricted"), false); - if (config.get().getSection("Servers").getSection(name).getKeys().contains("Display")) server.setDisplayName(config.get().getSection("Servers").getSection(name).getString("Display")); + if (config.get().getSection("Servers").getSection(name).getKeys().contains("Display") && config.get().getSection("Servers").getSection(name).getString("Display").length() > 0) server.setDisplayName(config.get().getSection("Servers").getSection(name).getString("Display")); + if (config.get().getSection("Servers").getSection(name).getKeys().contains("Group")) for (String group : config.get().getSection("Servers").getSection(name).getStringList("Group")) server.addGroup(group); if (config.get().getSection("Servers").getSection(name).getKeys().contains("Extra")) for (String extra : config.get().getSection("Servers").getSection(name).getSection("Extra").getKeys()) server.addExtra(extra, config.get().getSection("Servers").getSection(name).getSection("Extra").getObject(extra)); subservers++; } catch (Exception e) { diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Event/SubEditServerEvent.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Event/SubEditServerEvent.java index 30ed3c0f..d31c593a 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Event/SubEditServerEvent.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Event/SubEditServerEvent.java @@ -33,7 +33,7 @@ public class SubEditServerEvent extends Event implements SubEvent { section.set(".", edit.get()); this.player = player; this.server = server; - this.edit = new NamedContainer(edit.name(), section.get(".")); + this.edit = new NamedContainer(edit.name(), section.contains(".")?section.get("."):null); this.perm = permanent; } diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java index c18be605..be8aae6f 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIHandler.java @@ -51,6 +51,7 @@ public class InternalUIHandler implements UIHandler, Listener { enabled = false; } + @SuppressWarnings("ConstantConditions") @EventHandler(priority = EventPriority.HIGHEST) public void click(InventoryClickEvent event) { Player player = (Player) event.getWhoClicked(); @@ -71,9 +72,9 @@ public class InternalUIHandler implements UIHandler, Listener { } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) { player.closeInventory(); gui.hostMenu(gui.lastPage + 1); - } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.SubServer-Menu", '&'))) { + } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Group-Menu", '&'))) { player.closeInventory(); - gui.subserverMenu(1, null); + gui.groupMenu(1); } else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.No-Hosts", '&'))) { player.closeInventory(); String obj; @@ -98,7 +99,7 @@ public class InternalUIHandler implements UIHandler, Listener { gui.lastUsedOptions.undo(); gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Submit", '&'))) { - if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + gui.lastVistedObject.toLowerCase())) { + if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + gui.lastVisitedObject.toLowerCase())) { player.closeInventory(); gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&')); plugin.subdata.sendPacket(new PacketCreateServer(player.getUniqueId(), (UIRenderer.CreatorOptions) gui.lastUsedOptions, json -> { @@ -118,7 +119,7 @@ public class InternalUIHandler implements UIHandler, Listener { Bukkit.getScheduler().runTaskLater(plugin, () -> gui.hostCreator((UIRenderer.CreatorOptions) gui.lastUsedOptions), 4 * 20); } else { gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&')); - plugin.subdata.sendPacket(new PacketDownloadServerList(null, json -> { + plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, json -> { boolean match = false; for (String tmphost : json.getJSONObject("hosts").keySet()) { for (String tmpsubserver : json.getJSONObject("hosts").getJSONObject(tmphost).getJSONObject("servers").keySet()) { @@ -203,10 +204,10 @@ public class InternalUIHandler implements UIHandler, Listener { String item = event.getCurrentItem().getItemMeta().getDisplayName(); if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) { player.closeInventory(); - gui.hostPlugin(gui.lastPage - 1, gui.lastVistedObject); + gui.hostPlugin(gui.lastPage - 1, gui.lastVisitedObject); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) { player.closeInventory(); - gui.hostPlugin(gui.lastPage + 1, gui.lastVistedObject); + gui.hostPlugin(gui.lastPage + 1, gui.lastVisitedObject); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) { player.closeInventory(); gui.back(); @@ -219,8 +220,8 @@ public class InternalUIHandler implements UIHandler, Listener { if (plugin.get() == null) { gui.reopen(); } else { - gui.setDownloading(ChatColor.stripColor(this.plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", gui.lastVistedObject))); - this.plugin.subdata.sendPacket(new PacketDownloadHostInfo(gui.lastVistedObject, (json) -> { + gui.setDownloading(ChatColor.stripColor(this.plugin.lang.getSection("Lang").getColoredString("Interface.Host-Plugin.Title", '&').replace("$str$", gui.lastVisitedObject))); + this.plugin.subdata.sendPacket(new PacketDownloadHostInfo(gui.lastVisitedObject, (json) -> { if (json.getBoolean("valid")) { gui.setDownloading(null); plugin.get().open(player, json.getJSONObject("host")); @@ -231,26 +232,56 @@ public class InternalUIHandler implements UIHandler, Listener { } } } - } else if (event.getClickedInventory().getTitle().equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&')) || // SubServer Menu - event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$")[0]) && - (plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$").length == 1 || - event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$")[1]))) { + + } else if (event.getClickedInventory().getTitle().equals(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Title", '&'))) { // Host Menu if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) { String item = event.getCurrentItem().getItemMeta().getDisplayName(); if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) { player.closeInventory(); - gui.subserverMenu(gui.lastPage - 1, gui.lastVistedObject); + gui.groupMenu(gui.lastPage - 1); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) { player.closeInventory(); - gui.subserverMenu(gui.lastPage + 1, gui.lastVistedObject); - } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Host-Menu", '&'))) { + gui.groupMenu(gui.lastPage + 1); + } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Server-Menu", '&'))) { + player.closeInventory(); + gui.serverMenu(1, null, null); + } else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.No-Groups", '&'))) { + player.closeInventory(); + gui.serverMenu(1, null, ChatColor.stripColor(item)); + } + } + } else if (event.getClickedInventory().getTitle().equals(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Title", '&')) || // SubServer Menu + event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$")[0]) && + (plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$").length == 1 || + event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').split("\\$str\\$")[1])) || + event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Group-SubServer.Title", '&').split("\\$str\\$")[0]) && + (plugin.lang.getSection("Lang").getColoredString("Interface.Group-SubServer.Title", '&').split("\\$str\\$").length == 1 || + event.getClickedInventory().getTitle().endsWith(plugin.lang.getSection("Lang").getColoredString("Interface.Group-SubServer.Title", '&').split("\\$str\\$")[1]))) { + if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR && event.getCurrentItem().hasItemMeta()) { + String item = event.getCurrentItem().getItemMeta().getDisplayName(); + + if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) { + player.closeInventory(); + if (gui.lastVisitedObjectPosition > 1) { + gui.serverMenu(gui.lastPage - 1, null, gui.lastVisitedObject); + } else { + gui.serverMenu(gui.lastPage - 1, gui.lastVisitedObject, null); + } + } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) { + player.closeInventory(); + if (gui.lastVisitedObjectPosition > 1) { + gui.serverMenu(gui.lastPage + 1, null, gui.lastVisitedObject); + } else { + gui.serverMenu(gui.lastPage + 1, gui.lastVisitedObject, null); + } + } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Host-Menu", '&'))) { player.closeInventory(); gui.hostMenu(1); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) { player.closeInventory(); gui.back(); - } else if (!item.equals(ChatColor.RESET.toString()) && !item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.No-SubServers", '&'))) { + } else if (!item.equals(ChatColor.RESET.toString()) && event.getCurrentItem().getDurability() != 0 && event.getCurrentItem().getDurability() != 8 && !item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.No-Servers", '&'))) { player.closeInventory(); String obj; if (event.getCurrentItem().getItemMeta().getLore() != null && event.getCurrentItem().getItemMeta().getLore().size() > 0 && event.getCurrentItem().getItemMeta().getLore().get(0).startsWith(ChatColor.GRAY.toString())) { @@ -272,15 +303,15 @@ public class InternalUIHandler implements UIHandler, Listener { gui.back(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Creator", '&'))) { player.closeInventory(); - if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + gui.lastVistedObject.toLowerCase())) { - gui.hostCreator(new UIRenderer.CreatorOptions(gui.lastVistedObject)); + if (player.hasPermission("subservers.host.create.*") || player.hasPermission("subservers.host.create." + gui.lastVisitedObject.toLowerCase())) { + gui.hostCreator(new UIRenderer.CreatorOptions(gui.lastVisitedObject)); } else gui.reopen(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.SubServers", '&'))) { player.closeInventory(); - gui.subserverMenu(1, gui.lastVistedObject); + gui.serverMenu(1, gui.lastVisitedObject, null); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Admin.Plugins", '&'))) { player.closeInventory(); - gui.hostPlugin(1, gui.lastVistedObject); + gui.hostPlugin(1, gui.lastVisitedObject); } } } else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Title", '&').split("\\$str\\$")[0]) && // SubServer Admin @@ -294,23 +325,23 @@ public class InternalUIHandler implements UIHandler, Listener { gui.back(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start", '&'))) { player.closeInventory(); - if (player.hasPermission("subservers.subserver.start.*") || player.hasPermission("subservers.subserver.start." + gui.lastVistedObject.toLowerCase())) { + if (player.hasPermission("subservers.subserver.start.*") || player.hasPermission("subservers.subserver.start." + gui.lastVisitedObject.toLowerCase())) { gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&')); - plugin.subdata.sendPacket(new PacketStartServer(player.getUniqueId(), gui.lastVistedObject, json -> { + plugin.subdata.sendPacket(new PacketStartServer(player.getUniqueId(), gui.lastVisitedObject, json -> { gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Start.Title", '&')); Bukkit.getScheduler().runTaskLater(plugin, gui::reopen, 30); })); } else gui.reopen(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop", '&'))) { player.closeInventory(); - if (player.hasPermission("subservers.subserver.stop.*") || player.hasPermission("subservers.subserver.stop." + gui.lastVistedObject.toLowerCase())) { + if (player.hasPermission("subservers.subserver.stop.*") || player.hasPermission("subservers.subserver.stop." + gui.lastVisitedObject.toLowerCase())) { gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&')); final Container listening = new Container(true); PacketInRunEvent.callback("SubStoppedEvent", new JSONCallback() { @Override public void run(JSONObject json) { try { - if (listening.get()) if (!json.getString("server").equalsIgnoreCase(gui.lastVistedObject)) { + if (listening.get()) if (!json.getString("server").equalsIgnoreCase(gui.lastVisitedObject)) { PacketInRunEvent.callback("SubStoppedEvent", this); } else { gui.reopen(); @@ -318,23 +349,23 @@ public class InternalUIHandler implements UIHandler, Listener { } catch (Exception e) {} } }); - plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), gui.lastVistedObject, false, json -> { + plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), gui.lastVisitedObject, false, json -> { if (json.getInt("r") != 0) { gui.reopen(); listening.set(false); - } else gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop.Title", '&').replace("$str$", gui.lastVistedObject)); + } else gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Stop.Title", '&').replace("$str$", gui.lastVisitedObject)); })); } else gui.reopen(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate", '&'))) { player.closeInventory(); - if (player.hasPermission("subservers.subserver.terminate.*") || player.hasPermission("subservers.subserver.terminate." + gui.lastVistedObject.toLowerCase())) { + if (player.hasPermission("subservers.subserver.terminate.*") || player.hasPermission("subservers.subserver.terminate." + gui.lastVisitedObject.toLowerCase())) { gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&')); final Container listening = new Container(true); PacketInRunEvent.callback("SubStoppedEvent", new JSONCallback() { @Override public void run(JSONObject json) { try { - if (listening.get()) if (!json.getString("server").equalsIgnoreCase(gui.lastVistedObject)) { + if (listening.get()) if (!json.getString("server").equalsIgnoreCase(gui.lastVisitedObject)) { PacketInRunEvent.callback("SubStoppedEvent", this); } else { gui.reopen(); @@ -342,28 +373,28 @@ public class InternalUIHandler implements UIHandler, Listener { } catch (Exception e) {} } }); - plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), gui.lastVistedObject, false, json -> { + plugin.subdata.sendPacket(new PacketStopServer(player.getUniqueId(), gui.lastVisitedObject, false, json -> { if (json.getInt("r") != 0) { gui.reopen(); listening.set(false); - } else gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate.Title", '&').replace("$str$", gui.lastVistedObject)); + } else gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Terminate.Title", '&').replace("$str$", gui.lastVisitedObject)); })); } else gui.reopen(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command", '&'))) { player.closeInventory(); - if (player.hasPermission("subservers.subserver.command.*") || player.hasPermission("subservers.subserver.command." + gui.lastVistedObject.toLowerCase())) { + if (player.hasPermission("subservers.subserver.command.*") || player.hasPermission("subservers.subserver.command." + gui.lastVisitedObject.toLowerCase())) { if (!gui.sendTitle(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command.Title", '&'), 4 * 20)) player.sendMessage(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Command.Message", '&')); input.put(player.getUniqueId(), m -> { gui.setDownloading(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Downloading.Response", '&')); - plugin.subdata.sendPacket(new PacketCommandServer(player.getUniqueId(), gui.lastVistedObject, (m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message"), json -> { + plugin.subdata.sendPacket(new PacketCommandServer(player.getUniqueId(), gui.lastVisitedObject, (m.getString("message").startsWith("/"))?m.getString("message").substring(1):m.getString("message"), json -> { gui.reopen(); })); }); } else gui.reopen(); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Admin.Plugins", '&'))) { player.closeInventory(); - gui.subserverPlugin(1, gui.lastVistedObject); + gui.subserverPlugin(1, gui.lastVisitedObject); } } } else if (event.getClickedInventory().getTitle().startsWith(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').split("\\$str\\$")[0]) && // SubServer Plugin @@ -373,10 +404,10 @@ public class InternalUIHandler implements UIHandler, Listener { String item = event.getCurrentItem().getItemMeta().getDisplayName(); if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&'))) { player.closeInventory(); - gui.subserverPlugin(gui.lastPage - 1, gui.lastVistedObject); + gui.subserverPlugin(gui.lastPage - 1, gui.lastVisitedObject); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&'))) { player.closeInventory(); - gui.subserverPlugin(gui.lastPage + 1, gui.lastVistedObject); + gui.subserverPlugin(gui.lastPage + 1, gui.lastVisitedObject); } else if (item.equals(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&'))) { player.closeInventory(); gui.back(); @@ -389,8 +420,8 @@ public class InternalUIHandler implements UIHandler, Listener { if (plugin.get() == null) { gui.reopen(); } else { - gui.setDownloading(ChatColor.stripColor(this.plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", gui.lastVistedObject))); - this.plugin.subdata.sendPacket(new PacketDownloadServerInfo(gui.lastVistedObject, json -> { + gui.setDownloading(ChatColor.stripColor(this.plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Plugin.Title", '&').replace("$str$", gui.lastVisitedObject))); + this.plugin.subdata.sendPacket(new PacketDownloadServerInfo(gui.lastVisitedObject, json -> { if (json.getString("type").equals("subserver")) { gui.setDownloading(null); plugin.get().open(player, json.getJSONObject("server")); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java index 58edf234..d5fa80d6 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/InternalUIRenderer.java @@ -12,7 +12,6 @@ import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; import java.text.DecimalFormat; import java.util.*; @@ -25,7 +24,8 @@ import java.util.regex.Pattern; public class InternalUIRenderer extends UIRenderer { private List windowHistory = new LinkedList(); protected Options lastUsedOptions = null; - protected String lastVistedObject = null; + protected int lastVisitedObjectPosition = 0; + protected String lastVisitedObject = null; protected int lastPage = 1; protected Runnable lastMenu = null; protected boolean open = false; @@ -101,9 +101,9 @@ public class InternalUIRenderer extends UIRenderer { public void hostMenu(final int page) { setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Title", '&'))); - plugin.subdata.sendPacket(new PacketDownloadServerList(null, (json) -> { + plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, (json) -> { setDownloading(null); - lastVistedObject = null; + lastVisitedObject = null; lastPage = page; lastMenu = () -> hostMenu(1); windowHistory.add(() -> hostMenu(page)); @@ -202,9 +202,9 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); } else i += 2; i++; - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 1); blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.SubServer-Menu", '&')); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Menu.Group-Menu", '&')); block.setItemMeta(blockMeta); inv.setItem(i++, block); inv.setItem(i++, block); @@ -232,7 +232,7 @@ public class InternalUIRenderer extends UIRenderer { if (hasHistory()) back(); } else { setDownloading(null); - lastVistedObject = host; + lastVisitedObject = host; ItemStack block; ItemMeta blockMeta; @@ -342,7 +342,7 @@ public class InternalUIRenderer extends UIRenderer { lastUsedOptions = options; if (!options.init()) { windowHistory.add(() -> hostCreator(options)); - lastVistedObject = options.getHost(); + lastVisitedObject = options.getHost(); } plugin.subdata.sendPacket(new PacketDownloadHostInfo(options.getHost(), json -> { @@ -476,7 +476,7 @@ public class InternalUIRenderer extends UIRenderer { public void hostCreatorTemplates(final int page, final CreatorOptions options) { setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Host-Creator.Edit-Template.Title", '&').replace("$str$", options.getHost()))); lastUsedOptions = options; - if (!options.init()) lastVistedObject = options.getHost(); + if (!options.init()) lastVisitedObject = options.getHost(); plugin.subdata.sendPacket(new PacketDownloadHostInfo(options.getHost(), (json) -> { if (!json.getBoolean("valid")|| !json.getJSONObject("host").getBoolean("enabled")) { lastUsedOptions = null; @@ -595,7 +595,7 @@ public class InternalUIRenderer extends UIRenderer { if (hasHistory()) back(); } else { setDownloading(null); - lastVistedObject = host; + lastVisitedObject = host; lastPage = page; List renderers = new ArrayList(); for (String renderer : renderers) { @@ -695,32 +695,16 @@ public class InternalUIRenderer extends UIRenderer { })); } - public void subserverMenu(final int page, final String host) { - setDownloading(ChatColor.stripColor((host == null)?plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", host))); - plugin.subdata.sendPacket(new PacketDownloadServerList(host, json -> { + public void groupMenu(final int page) { + setDownloading(ChatColor.stripColor(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Title", '&'))); + plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, (json) -> { setDownloading(null); + lastVisitedObject = null; lastPage = page; - - HashMap hosts = new HashMap(); - List subservers = new ArrayList(); - if (host != null && json.getJSONObject("hosts").keySet().contains(host)) { - lastVistedObject = host; - for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) { - hosts.put(subserver, host); - subservers.add(subserver); - } - } else { - lastVistedObject = null; - lastMenu = () -> subserverMenu(1, null); - for (String tmphost : json.getJSONObject("hosts").keySet()) { - for (String tmpsubserver : json.getJSONObject("hosts").getJSONObject(tmphost).getJSONObject("servers").keySet()) { - hosts.put(tmpsubserver, tmphost); - subservers.add(tmpsubserver); - } - } - } - Collections.sort(subservers); - windowHistory.add(() -> subserverMenu(page, host)); + lastMenu = () -> groupMenu(1); + windowHistory.add(() -> groupMenu(page)); + List groups = new ArrayList(); + groups.addAll(json.getJSONObject("groups").keySet()); ItemStack block; ItemMeta blockMeta; @@ -732,10 +716,10 @@ public class InternalUIRenderer extends UIRenderer { int i = 0; int min = ((page - 1) * 36); int max = (min + 35); - int count = (subservers.size() == 0)?27:((subservers.size() - min >= max)?36:subservers.size() - min); + int count = (groups.size() == 0)?27:((groups.size() - min >= max)?36:groups.size() - min); int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; - Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", json.getJSONObject("hosts").getJSONObject(host).getString("display"))); + Inventory inv = Bukkit.createInventory(null, 18 + area, plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Title", '&')); block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); block.setItemMeta(divMeta); while (i < area) { @@ -746,66 +730,19 @@ public class InternalUIRenderer extends UIRenderer { i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); boolean even = (count & 1) == 0 && count < 9; - short online, temp, offline, disabled; + short color; - for (String subserver : subservers) { - if (subservers.indexOf(subserver) >= min && subservers.indexOf(subserver) <= max) { + for (String group : groups) { + if (groups.indexOf(group) >= min && groups.indexOf(group) <= max) { if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); - online = (short) (((i & 1) == 0) ? 5 : 13); - temp = (short) (((i & 1) == 0) ? 3 : 11); - offline = (short) (((i & 1) == 0) ? 4 : 1); - disabled = (short) (((i & 1) == 0) ? 2 : 14); + color = (short) (((i & 1) == 0) ? 1 : 4); - if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("temp")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, temp); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display")); - LinkedList lore = new LinkedList(); - if (!subserver.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display"))) - lore.add(ChatColor.GRAY + subserver); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size()))); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&')); - lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1])); - blockMeta.setLore(lore); - } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("running")) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, online); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.GREEN + json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display")); - LinkedList lore = new LinkedList(); - if (!subserver.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display"))) - lore.add(ChatColor.GRAY + subserver); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size()))); - lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1])); - blockMeta.setLore(lore); - } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("enabled") && json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONArray("incompatible").length() == 0) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, offline); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.YELLOW + json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display")); - LinkedList lore = new LinkedList(); - if (!subserver.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display"))) - lore.add(ChatColor.GRAY + subserver); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&')); - lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1])); - blockMeta.setLore(lore); - } else { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); - blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(ChatColor.RED + json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display")); - LinkedList lore = new LinkedList(); - if (!subserver.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("display"))) - lore.add(ChatColor.GRAY + subserver); - if (json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONArray("incompatible").length() != 0) { - String list = ""; - for (int ii = 0; ii < json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONArray("incompatible").length(); ii++) { - if (list.length() != 0) list += ", "; - list += json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getJSONArray("incompatible").getString(ii); - } - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Incompatible", '&').replace("$str$", list)); - } - if (!json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getBoolean("enabled")) lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&')); - lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(subserver)).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1])); - blockMeta.setLore(lore); - } + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, color); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GOLD + group); + LinkedList lore = new LinkedList(); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Group-Server-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("groups").getJSONObject(group).keySet().size()))); + blockMeta.setLore(lore); block.setItemMeta(blockMeta); inv.setItem(i, block); @@ -819,10 +756,10 @@ public class InternalUIRenderer extends UIRenderer { } } - if (subservers.size() == 0) { + if (groups.size() == 0) { block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); blockMeta = block.getItemMeta(); - blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.No-SubServers", '&')); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.No-Groups", '&')); block.setItemMeta(blockMeta); inv.setItem(12, block); inv.setItem(13, block); @@ -845,17 +782,215 @@ public class InternalUIRenderer extends UIRenderer { inv.setItem(i++, block); } else i += 2; i++; - if (host == null || hasHistory()) { - block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) ((host == null) ? 11 : 14)); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 5); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Server-Menu", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + inv.setItem(i++, block); + i++; + if (groups.size() - 1 > max) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); blockMeta = block.getItemMeta(); - blockMeta.setDisplayName((host == null) ? plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.Host-Menu", '&') : plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i, block); + } + + Bukkit.getPlayer(player).openInventory(inv); + open = true; + })); + } + + public void serverMenu(final int page, final String host, final String group) { + setDownloading(ChatColor.stripColor((host == null)?((group == null)?plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Group-SubServer.Title", '&').replace("$str$", group)):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", host))); + plugin.subdata.sendPacket(new PacketDownloadServerList(host, (host != null)?null:group, json -> { + setDownloading(null); + lastPage = page; + + HashMap hosts = new HashMap(); + List servers = new ArrayList(); + if (host != null && json.getJSONObject("hosts").keySet().contains(host)) { + lastVisitedObject = host; + lastVisitedObjectPosition = 1; + for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) { + hosts.put(subserver, host); + servers.add(subserver); + } + } else if (group != null && json.getJSONObject("groups").keySet().contains(group)) { + lastVisitedObject = group; + lastVisitedObjectPosition = 2; + for (String server : json.getJSONObject("groups").getJSONObject(group).keySet()) { + hosts.put(server, (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).keySet().contains("host") && json.getJSONObject("hosts").keySet().contains(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("host")))?json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("host"):null); + servers.add(server); + } + } else { + lastVisitedObject = null; + lastVisitedObjectPosition = 0; + lastMenu = () -> serverMenu(1, null, null); + for (String s : json.getJSONObject("servers").keySet()) { + hosts.put(s, null); + servers.add(s); + } + for (String h : json.getJSONObject("hosts").keySet()) { + for (String ss : json.getJSONObject("hosts").getJSONObject(h).getJSONObject("servers").keySet()) { + hosts.put(ss, h); + servers.add(ss); + } + } + } + Collections.sort(servers); + windowHistory.add(() -> serverMenu(page, host, group)); + + ItemStack block; + ItemMeta blockMeta; + ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); + ItemMeta divMeta = div.getItemMeta(); + divMeta.setDisplayName(ChatColor.RESET.toString()); + div.setItemMeta(divMeta); + + int i = 0; + int min = ((page - 1) * 36); + int max = (min + 35); + int count = (servers.size() == 0)?27:((servers.size() - min >= max)?36:servers.size() - min); + int area = (count % 9 == 0) ? count : (int) (Math.floor(count / 9) + 1) * 9; + + Inventory inv = Bukkit.createInventory(null, 18 + area, (host == null)?((group == null)?plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Title", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Group-SubServer.Title", '&').replace("$str$", group)):plugin.lang.getSection("Lang").getColoredString("Interface.Host-SubServer.Title", '&').replace("$str$", json.getJSONObject("hosts").getJSONObject(host).getString("display"))); + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 7); + block.setItemMeta(divMeta); + while (i < area) { + inv.setItem(i, block); + i++; + } + ItemStack adiv = block; + i = (int) ((count < 9) ? Math.floor((9 - count) / 2) : 0); + + boolean even = (count & 1) == 0 && count < 9; + short external, online, temp, offline, disabled; + + for (String server : servers) { + if (servers.indexOf(server) >= min && servers.indexOf(server) <= max) { + if (even && (i == 4 || i == 13 || i == 22 || i == 31)) inv.setItem(i++, adiv); + external = (short) (((i & 1) == 0) ? 0 : 8); + online = (short) (((i & 1) == 0) ? 5 : 13); + temp = (short) (((i & 1) == 0) ? 3 : 11); + offline = (short) (((i & 1) == 0) ? 4 : 1); + disabled = (short) (((i & 1) == 0) ? 2 : 14); + + if (hosts.get(server) == null) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, external); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("servers").getJSONObject(server).getString("display")); + LinkedList lore = new LinkedList(); + if (!server.equals(json.getJSONObject("servers").getJSONObject(server).getString("display"))) + lore.add(ChatColor.GRAY + server); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("servers").getJSONObject(server).getJSONObject("players").keySet().size()))); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-External", '&')); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Invalid", '&')); + lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); + blockMeta.setLore(lore); + } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("temp")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, temp); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.AQUA + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); + LinkedList lore = new LinkedList(); + if (!server.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display"))) + lore.add(ChatColor.GRAY + server); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONObject("players").keySet().size()))); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Temporary", '&')); + lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); + blockMeta.setLore(lore); + } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("running")) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, online); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.GREEN + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); + LinkedList lore = new LinkedList(); + if (!server.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display"))) + lore.add(ChatColor.GRAY + server); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONObject("players").keySet().size()))); + lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); + blockMeta.setLore(lore); + } else if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("enabled") && json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONArray("incompatible").length() == 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, offline); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.YELLOW + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); + LinkedList lore = new LinkedList(); + if (!server.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display"))) + lore.add(ChatColor.GRAY + server); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Offline", '&')); + lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); + blockMeta.setLore(lore); + } else { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, disabled); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(ChatColor.RED + json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display")); + LinkedList lore = new LinkedList(); + if (!server.equals(json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("display"))) + lore.add(ChatColor.GRAY + server); + if (json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONArray("incompatible").length() != 0) { + String list = ""; + for (int ii = 0; ii < json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONArray("incompatible").length(); ii++) { + if (list.length() != 0) list += ", "; + list += json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getJSONArray("incompatible").getString(ii); + } + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Incompatible", '&').replace("$str$", list)); + } + if (!json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getBoolean("enabled")) lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Disabled", '&')); + lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(hosts.get(server)).getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1])); + blockMeta.setLore(lore); + } + block.setItemMeta(blockMeta); + inv.setItem(i, block); + + count--; + if (count < 9 && (i == 8 || i == 17 || i == 26)) { + i += (int) Math.floor((9 - count) / 2) + 1; + even = (count & 1) == 0; + } else { + i++; + } + } + } + + if (servers.size() == 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 14); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.No-Servers", '&')); + block.setItemMeta(blockMeta); + inv.setItem(12, block); + inv.setItem(13, block); + inv.setItem(14, block); + } + + i = inv.getSize() - 18; + while (i < inv.getSize()) { + inv.setItem(i, div); + i++; + } + i = inv.getSize() - 9; + + if (min != 0) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back-Arrow", '&')); + block.setItemMeta(blockMeta); + inv.setItem(i++, block); + inv.setItem(i++, block); + } else i += 2; + i++; + if (host == null || group == null || hasHistory()) { + block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) ((host == null && group == null)?11:14)); + blockMeta = block.getItemMeta(); + blockMeta.setDisplayName((host == null && group == null)?plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Host-Menu", '&'):plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Back", '&')); block.setItemMeta(blockMeta); inv.setItem(i++, block); inv.setItem(i++, block); inv.setItem(i++, block); i++; } - if (subservers.size() - 1 > max) { + if (servers.size() - 1 > max) { block = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 4); blockMeta = block.getItemMeta(); blockMeta.setDisplayName(plugin.lang.getSection("Lang").getColoredString("Interface.Generic.Next-Arrow", '&')); @@ -877,7 +1012,7 @@ public class InternalUIRenderer extends UIRenderer { if (hasHistory()) back(); } else { setDownloading(null); - lastVistedObject = subserver; + lastVisitedObject = subserver; ItemStack block; ItemMeta blockMeta; ItemStack div = new ItemStack(Material.STAINED_GLASS_PANE, 1, (short) 15); @@ -987,8 +1122,8 @@ public class InternalUIRenderer extends UIRenderer { LinkedList lore = new LinkedList(); if (!subserver.equals(json.getJSONObject("server").getString("display"))) lore.add(ChatColor.GRAY + subserver); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size()))); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&')); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size()))); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Temporary", '&')); lore.add(ChatColor.WHITE + json.getJSONObject("server").getString("address")); blockMeta.setLore(lore); } else if (json.getJSONObject("server").getBoolean("running")) { @@ -998,7 +1133,7 @@ public class InternalUIRenderer extends UIRenderer { LinkedList lore = new LinkedList(); if (!subserver.equals(json.getJSONObject("server").getString("display"))) lore.add(ChatColor.GRAY + subserver); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size()))); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("server").getJSONObject("players").keySet().size()))); lore.add(ChatColor.WHITE + json.getJSONObject("server").getString("address")); blockMeta.setLore(lore); } else if (json.getJSONObject("server").getBoolean("enabled") && json.getJSONObject("server").getJSONArray("incompatible").length() == 0) { @@ -1008,7 +1143,7 @@ public class InternalUIRenderer extends UIRenderer { LinkedList lore = new LinkedList(); if (!subserver.equals(json.getJSONObject("server").getString("display"))) lore.add(ChatColor.GRAY + subserver); - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&')); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Offline", '&')); lore.add(ChatColor.WHITE + json.getJSONObject("server").getString("address")); blockMeta.setLore(lore); } else { @@ -1024,9 +1159,9 @@ public class InternalUIRenderer extends UIRenderer { if (list.length() != 0) list += ", "; list += json.getJSONObject("server").getJSONArray("incompatible").getString(ii); } - lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Incompatible", '&').replace("$str$", list)); + lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Incompatible", '&').replace("$str$", list)); } - if (!json.getJSONObject("server").getBoolean("enabled")) lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&')); + if (!json.getJSONObject("server").getBoolean("enabled")) lore.add(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Disabled", '&')); lore.add(ChatColor.WHITE + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("server").getString("address"):json.getJSONObject("server").getString("address").split(":")[json.getJSONObject("server").getString("address").split(":").length - 1])); blockMeta.setLore(lore); } @@ -1059,7 +1194,7 @@ public class InternalUIRenderer extends UIRenderer { if (hasHistory()) back(); } else { setDownloading(null); - lastVistedObject = subserver; + lastVisitedObject = subserver; lastPage = page; List renderers = new ArrayList(); for (String renderer : renderers) { diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java index ed82765d..84f99695 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Graphic/UIRenderer.java @@ -264,13 +264,20 @@ public abstract class UIRenderer { */ public abstract void hostPlugin(int page, String host); + /** + * Opens the Group Menu + * + * @param page Page Number (starting from page 1) + */ + public abstract void groupMenu(int page); + /** * Opens the SubServer Menu * * @param page Page Number (starting from page 1) * @param host Host Name (or null to scan all hosts) */ - public abstract void subserverMenu(int page, String host); + public abstract void serverMenu(int page, String host, String group); /** * Opens SubServer/<name> diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Config/YAMLSection.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Config/YAMLSection.java index 45dad405..344da149 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Config/YAMLSection.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Config/YAMLSection.java @@ -172,8 +172,10 @@ public class YAMLSection { * @param value Value */ public void set(String handle, Object value) { - if (Util.isNull(handle, value)) throw new NullPointerException(); - if (value instanceof Collection) { + if (Util.isNull(handle)) throw new NullPointerException(); + if (value == null) { + remove(handle); + } else if (value instanceof Collection) { set(handle, (Collection) value); } else { map.put(handle, convert(value)); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketDownloadServerList.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketDownloadServerList.java index 759e4d8d..6b493536 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketDownloadServerList.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/Packet/PacketDownloadServerList.java @@ -27,9 +27,10 @@ public class PacketDownloadServerList implements PacketIn, PacketOut { * New PacketDownloadServerList (Out) * * @param host Host name (or null for all) + * @param group Group name (or null for all) * @param callback Callbacks */ - public PacketDownloadServerList(String host, JSONCallback... callback) { + public PacketDownloadServerList(String host, String group, JSONCallback... callback) { if (Util.isNull((Object) callback)) throw new NullPointerException(); this.host = host; this.id = Util.getNew(callbacks.keySet(), UUID::randomUUID).toString(); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java index 6c3cfa7d..31a49fc4 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java @@ -11,7 +11,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -21,6 +20,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.StringReader; +import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.nio.charset.Charset; import java.text.DecimalFormat; @@ -76,14 +76,126 @@ public final class SubCommand implements CommandExecutor { } } else if (args[0].equalsIgnoreCase("list")) { final String fLabel = label; - plugin.subdata.sendPacket(new PacketDownloadServerList(null, json -> { + plugin.subdata.sendPacket(new PacketDownloadServerList(null, null, json -> { int i = 0; + boolean sent = false; Container spigot = new Container(false); if (!Util.isException(() -> { if (Class.forName("org.spigotmc.SpigotConfig") != null) spigot.set(true); }) && spigot.get() && sender instanceof Player) { - sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Host-Header", '&')); net.md_5.bungee.api.chat.TextComponent div = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Command.List.Divider", '&')); + sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Group-Header", '&')); + for (String group : json.getJSONObject("groups").keySet()) { + List hoverm = new LinkedList(); + net.md_5.bungee.api.chat.TextComponent msg = new net.md_5.bungee.api.chat.TextComponent(ChatColor.RESET.toString()); + net.md_5.bungee.api.chat.TextComponent message = new net.md_5.bungee.api.chat.TextComponent(group); + net.md_5.bungee.api.chat.TextComponent hover = new net.md_5.bungee.api.chat.TextComponent(group + '\n'); + message.setColor(net.md_5.bungee.api.ChatColor.GOLD); + hover.setColor(net.md_5.bungee.api.ChatColor.GOLD); + hoverm.add(hover); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Group-Menu.Group-Server-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("groups").getJSONObject(group).keySet().size()))); + hoverm.add(hover); + message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open Server 1 " + group)); + message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()]))); + msg.addExtra(message); + msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Command.List.Header", '&'))); + + for (String server : json.getJSONObject("groups").getJSONObject(group).keySet()) { + hoverm = new LinkedList(); + message = new net.md_5.bungee.api.chat.TextComponent(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display")); + hover = new net.md_5.bungee.api.chat.TextComponent(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display") + '\n'); + if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).keySet().contains("enabled")) { + message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + server)); + if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("temp")) { + message.setColor(net.md_5.bungee.api.ChatColor.AQUA); + hover.setColor(net.md_5.bungee.api.ChatColor.AQUA); + hoverm.add(hover); + if (!server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display"))) { + hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n'); + hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); + hoverm.add(hover); + } + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONObject("players").keySet().size())) + '\n'); + hoverm.add(hover); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Temporary", '&')); + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("running")) { + message.setColor(net.md_5.bungee.api.ChatColor.GREEN); + hover.setColor(net.md_5.bungee.api.ChatColor.GREEN); + hoverm.add(hover); + if (!server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display"))) { + hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n'); + hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); + hoverm.add(hover); + } + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONObject("players").keySet().size()))); + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("enabled") && json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").length() == 0) { + message.setColor(net.md_5.bungee.api.ChatColor.YELLOW); + hover.setColor(net.md_5.bungee.api.ChatColor.YELLOW); + hoverm.add(hover); + if (!server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display"))) { + hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n'); + hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); + hoverm.add(hover); + } + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Offline", '&')); + } else { + message.setColor(net.md_5.bungee.api.ChatColor.RED); + hover.setColor(net.md_5.bungee.api.ChatColor.RED); + if (!server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display"))) { + hoverm.add(hover); + hover = new net.md_5.bungee.api.chat.TextComponent(server + '\n'); + hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); + } + if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").length() != 0) { + hoverm.add(hover); + String list = ""; + for (int ii = 0; ii < json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").length(); ii++) { + if (list.length() != 0) list += ", "; + list += json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").getString(ii); + } + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Incompatible", '&').replace("$str$", list)); + } + if (!json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("enabled")) { + hoverm.add(hover); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Disabled", '&')); + } + } + hoverm.add(hover); + if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) { + hover = new net.md_5.bungee.api.chat.TextComponent('\n' + json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address")); + } else { + hover = new net.md_5.bungee.api.chat.TextComponent('\n' + json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address").split(":")[json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address").split(":").length - 1]); + } + hover.setColor(net.md_5.bungee.api.ChatColor.WHITE); + hoverm.add(hover); + message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open SubServer/ " + server)); + } else { + message.setColor(net.md_5.bungee.api.ChatColor.WHITE); + hover.setColor(net.md_5.bungee.api.ChatColor.WHITE); + hoverm.add(hover); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-External", '&')); + hoverm.add(hover); + if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) { + hover = new net.md_5.bungee.api.chat.TextComponent('\n' + json.getJSONObject("servers").getJSONObject(server).getString("address")); + } else { + hover = new net.md_5.bungee.api.chat.TextComponent('\n' + json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1]); + } + hover.setColor(net.md_5.bungee.api.ChatColor.WHITE); + hoverm.add(hover); + } + message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()]))); + if (i != 0) msg.addExtra(div); + msg.addExtra(message); + i++; + } + if (i == 0) msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&'))); + ((Player) sender).spigot().sendMessage(msg); + i = 0; + sent = true; + } + if (!sent) sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&')); + sent = false; + sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Host-Header", '&')); for (String host : json.getJSONObject("hosts").keySet()) { List hoverm = new LinkedList(); net.md_5.bungee.api.chat.TextComponent msg = new net.md_5.bungee.api.chat.TextComponent(ChatColor.RESET.toString()); @@ -119,7 +231,7 @@ public final class SubCommand implements CommandExecutor { message.setClickEvent(new net.md_5.bungee.api.chat.ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.RUN_COMMAND, fLabel + " open Host/ " + host)); message.setHoverEvent(new net.md_5.bungee.api.chat.HoverEvent(net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new net.md_5.bungee.api.chat.TextComponent[hoverm.size()]))); msg.addExtra(message); - msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(ChatColor.GRAY + ": ")); + msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Command.List.Header", '&'))); for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) { hoverm = new LinkedList(); @@ -135,9 +247,9 @@ public final class SubCommand implements CommandExecutor { hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); hoverm.add(hover); } - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size())) + '\n'); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size())) + '\n'); hoverm.add(hover); - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Temporary", '&')); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Temporary", '&')); } else if (json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("running")) { message.setColor(net.md_5.bungee.api.ChatColor.GREEN); hover.setColor(net.md_5.bungee.api.ChatColor.GREEN); @@ -147,7 +259,7 @@ public final class SubCommand implements CommandExecutor { hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); hoverm.add(hover); } - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size()))); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-Player-Count", '&').replace("$int$", new DecimalFormat("#,###").format(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getJSONObject("players").keySet().size()))); } else if (json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("enabled") && json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getJSONArray("incompatible").length() == 0) { message.setColor(net.md_5.bungee.api.ChatColor.YELLOW); hover.setColor(net.md_5.bungee.api.ChatColor.YELLOW); @@ -157,7 +269,7 @@ public final class SubCommand implements CommandExecutor { hover.setColor(net.md_5.bungee.api.ChatColor.GRAY); hoverm.add(hover); } - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Offline", '&')); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Offline", '&')); } else { message.setColor(net.md_5.bungee.api.ChatColor.RED); hover.setColor(net.md_5.bungee.api.ChatColor.RED); @@ -173,11 +285,11 @@ public final class SubCommand implements CommandExecutor { if (list.length() != 0) list += ", "; list += json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getJSONArray("incompatible").getString(ii); } - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Incompatible", '&').replace("$str$", list)); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Incompatible", '&').replace("$str$", list)); } if (!json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("enabled")) { hoverm.add(hover); - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-Disabled", '&')); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.SubServer-Disabled", '&')); } } hoverm.add(hover); @@ -194,9 +306,12 @@ public final class SubCommand implements CommandExecutor { msg.addExtra(message); i++; } + if (i == 0) msg.addExtra(new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&'))); ((Player) sender).spigot().sendMessage(msg); i = 0; + sent = true; } + if (!sent) sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&')); sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Server-Header", '&')); net.md_5.bungee.api.chat.TextComponent msg = new net.md_5.bungee.api.chat.TextComponent(ChatColor.RESET.toString()); for (String server : json.getJSONObject("servers").keySet()) { @@ -206,7 +321,7 @@ public final class SubCommand implements CommandExecutor { message.setColor(net.md_5.bungee.api.ChatColor.WHITE); hover.setColor(net.md_5.bungee.api.ChatColor.WHITE); hoverm.add(hover); - hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.SubServer-Menu.SubServer-External", '&')); + hover = new net.md_5.bungee.api.chat.TextComponent(plugin.lang.getSection("Lang").getColoredString("Interface.Server-Menu.Server-External", '&')); hoverm.add(hover); if (plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false)) { hover = new net.md_5.bungee.api.chat.TextComponent('\n' + json.getJSONObject("servers").getJSONObject(server).getString("address")); @@ -220,11 +335,39 @@ public final class SubCommand implements CommandExecutor { msg.addExtra(message); i++; } + if (i == 0) sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&')); ((Player) sender).spigot().sendMessage(msg); } else { - sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Host-Header", '&')); + sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Group-Header", '&')); String div = plugin.lang.getSection("Lang").getColoredString("Command.List.Divider", '&'); + for (String group : json.getJSONObject("groups").keySet()) { + String message = ""; + message += ChatColor.GOLD + group + plugin.lang.getSection("Lang").getColoredString("Command.List.Header", '&'); + for (String server : json.getJSONObject("groups").getJSONObject(group).keySet()) { + if (i != 0) message += div; + if (!json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).keySet().contains("enabled")) { + message += ChatColor.WHITE; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("temp")) { + message += ChatColor.AQUA; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("running")) { + message += ChatColor.GREEN; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("enabled") && json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").length() == 0) { + message += ChatColor.YELLOW; + } else { + message += ChatColor.RED; + } + message += json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display") + " (" + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address"):json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address").split(":")[json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address").split(":").length - 1]) + ((server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display")))?"":ChatColor.stripColor(div)+server) + ")"; + i++; + } + if (i == 0) message += plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&'); + sender.sendMessage(message); + i = 0; + sent = true; + } + if (!sent) sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&')); + sent = false; + sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Host-Header", '&')); for (String host : json.getJSONObject("hosts").keySet()) { String message = ""; if (json.getJSONObject("hosts").getJSONObject(host).getBoolean("enabled")) { @@ -238,7 +381,7 @@ public final class SubCommand implements CommandExecutor { } else if (!host.equals(json.getJSONObject("hosts").getJSONObject(host).getString("display"))) { message += " (" + host + ")"; } - message += ChatColor.GRAY + ": "; + message += plugin.lang.getSection("Lang").getColoredString("Command.List.Header", '&'); for (String subserver : json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").keySet()) { if (i != 0) message += div; if (json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getBoolean("temp")) { @@ -253,9 +396,12 @@ public final class SubCommand implements CommandExecutor { message += json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display") + " (" + json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1] + ((subserver.equals(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display")))?"":ChatColor.stripColor(div)+subserver) + ")"; i++; } + if (i == 0) message += plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&'); sender.sendMessage(message); i = 0; + sent = true; } + if (!sent) sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&')); sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Server-Header", '&')); String message = ""; for (String server : json.getJSONObject("servers").keySet()) { @@ -263,6 +409,7 @@ public final class SubCommand implements CommandExecutor { message += ChatColor.WHITE + json.getJSONObject("servers").getJSONObject(server).getString("display") + " (" + ((plugin.config.get().getSection("Settings").getBoolean("Show-Addresses", false))?json.getJSONObject("servers").getJSONObject(server).getString("address"):json.getJSONObject("servers").getJSONObject(server).getString("address").split(":")[json.getJSONObject("servers").getJSONObject(server).getString("address").split(":").length - 1]) + ((server.equals(json.getJSONObject("servers").getJSONObject(server).getString("display")))?"":ChatColor.stripColor(div)+server) + ")"; i++; } + if (i == 0) sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.List.Empty", '&')); sender.sendMessage(message); } })); @@ -279,6 +426,11 @@ public final class SubCommand implements CommandExecutor { sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Real Name") + ChatColor.AQUA + json.getJSONObject("server").getString("name")); sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Host") + ChatColor.AQUA + json.getJSONObject("server").getString("host")); sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Enabled") + ((json.getJSONObject("server").getBoolean("enabled"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no")); + if (json.getJSONObject("server").getJSONArray("group").length() > 0) { + sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Group")); + for (int i = 0; i < json.getJSONObject("server").getJSONArray("group").length(); i++) + sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.List", '&').replace("$str$", ChatColor.GOLD + json.getJSONObject("server").getJSONArray("group").getString(i))); + } if (json.getJSONObject("server").getBoolean("temp")) sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Temporary") + ChatColor.GREEN+"yes"); sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Running") + ((json.getJSONObject("server").getBoolean("running"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no")); sender.sendMessage(" " + plugin.lang.getSection("Lang").getColoredString("Command.Info.Format", '&').replace("$str$", "Logging") + ((json.getJSONObject("server").getBoolean("log"))?ChatColor.GREEN+"yes":ChatColor.DARK_RED+"no")); @@ -498,25 +650,36 @@ public final class SubCommand implements CommandExecutor { break; case "host/creator": if (sender.hasPermission("subservers.host.create.*") || sender.hasPermission("subservers.host.create." + args[2].toLowerCase())) plugin.gui.getRenderer((Player) sender).hostCreator(new UIRenderer.CreatorOptions(args[2])); + else throw new IllegalStateException("Player does not meet the requirements to render this page"); break; - case "host/plugins": + case "host/plugin": if (args.length > 3) plugin.gui.getRenderer((Player) sender).hostPlugin(Integer.parseInt(args[3]), args[2]); else plugin.gui.getRenderer((Player) sender).hostPlugin(1, args[2]); break; - case "subserver": - if (args.length > 3) plugin.gui.getRenderer((Player) sender).subserverMenu(Integer.parseInt(args[2]), args[3]); - else if (args.length > 2) plugin.gui.getRenderer((Player) sender).subserverMenu(Integer.parseInt(args[2]), null); - else plugin.gui.getRenderer((Player) sender).subserverMenu(1, null); + case "group": + if (args.length > 2) plugin.gui.getRenderer((Player) sender).groupMenu(Integer.parseInt(args[2])); + else plugin.gui.getRenderer((Player) sender).groupMenu(1); + break; + case "server": + if (args.length > 4) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), args[4], null); + else if (args.length > 3) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), null, args[3]); + else if (args.length > 2) plugin.gui.getRenderer((Player) sender).serverMenu(Integer.parseInt(args[2]), null, null); + else plugin.gui.getRenderer((Player) sender).serverMenu(1, null, null); break; case "subserver/": plugin.gui.getRenderer((Player) sender).subserverAdmin(args[2]); break; - case "subserver/plugins": + case "subserver/plugin": if (args.length > 3) plugin.gui.getRenderer((Player) sender).subserverPlugin(Integer.parseInt(args[3]), args[2]); else plugin.gui.getRenderer((Player) sender).subserverPlugin(1, args[2]); break; } - } catch (Throwable e) {} + } catch (Throwable e) { + List list = new LinkedList(); + list.addAll(Arrays.asList(args)); + list.remove(0); + new InvocationTargetException(e, "Could not render page with arguments: " + list.toString()).printStackTrace(); + } } else { sender.sendMessage(plugin.lang.getSection("Lang").getColoredString("Command.Generic.Invalid-Permission", '&').replace("$str$", "subservers.interface")); } diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java index 147c3dcd..d568c938 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java @@ -27,7 +27,7 @@ public final class SubPlugin extends JavaPlugin { public UIHandler gui = null; public final Version version; - public final Version bversion = null; + public final Version bversion = new Version(1); public final SubAPI api = new SubAPI(this); public SubPlugin() { diff --git a/SubServers.Client/Bukkit/src/plugin.yml b/SubServers.Client/Bukkit/src/plugin.yml index 5615f287..7c0bd334 100644 --- a/SubServers.Client/Bukkit/src/plugin.yml +++ b/SubServers.Client/Bukkit/src/plugin.yml @@ -1,6 +1,6 @@ name: 'SubServers-Client-Bukkit' main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin' -version: '2.12.1d' +version: '2.12.1e' authors: [ME1312] softdepend: [Vault, TitleManager] website: 'http://www.ME1312.net/' diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java b/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java index 93acadcc..ed31bef1 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java @@ -53,8 +53,8 @@ public final class ExHost { public YAMLSection lang = null; public SubDataClient subdata = null; - public final Version version = new Version("2.12.1c"); - public final Version bversion = null; + public final Version version = new Version("2.12.1d"); + public final Version bversion = new Version(1); public final SubAPI api = new SubAPI(this); private boolean running; diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Config/YAMLSection.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Config/YAMLSection.java index a0769bf6..2a063b76 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Config/YAMLSection.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Config/YAMLSection.java @@ -172,8 +172,10 @@ public class YAMLSection { * @param value Value */ public void set(String handle, Object value) { - if (Util.isNull(handle, value)) throw new NullPointerException(); - if (value instanceof Collection) { + if (Util.isNull(handle)) throw new NullPointerException(); + if (value == null) { + remove(handle); + } else if (value instanceof Collection) { set(handle, (Collection) value); } else { map.put(handle, convert(value)); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java index 6db259d8..27cf7448 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java @@ -83,10 +83,38 @@ public class SubCommand { @Override public void command(String handle, String[] args) { host.subdata.sendPacket(new PacketDownloadServerList(null, json -> { - host.log.message.println("Host/SubServer List:"); - ExHost h = host; - String div = TextColor.RESET + ", "; int i = 0; + boolean sent = false; + String div = TextColor.RESET + ", "; + host.log.message.println("Group/Server List:"); + for (String group : json.getJSONObject("groups").keySet()) { + String message = ""; + message += TextColor.GOLD + group + TextColor.RESET + ": "; + for (String server : json.getJSONObject("groups").getJSONObject(group).keySet()) { + if (i != 0) message += div; + if (!json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).keySet().contains("enabled")) { + message += TextColor.WHITE; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("temp")) { + message += TextColor.AQUA; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("running")) { + message += TextColor.GREEN; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("enabled") && json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").length() == 0) { + message += TextColor.YELLOW; + } else { + message += TextColor.RED; + } + message += json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display") + " (" + json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address") + ((server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display")))?"":TextColor.stripColor(div)+server) + ")"; + i++; + } + if (i == 0) message += TextColor.RESET + "(none)"; + host.log.message.println(message); + i = 0; + sent = true; + } + if (!sent) host.log.message.println(TextColor.RESET + "(none)"); + sent = false; + ExHost h = host; + host.log.message.println("Host/SubServer List:"); for (String host : json.getJSONObject("hosts").keySet()) { String message = ""; if (json.getJSONObject("hosts").getJSONObject(host).getBoolean("enabled")) { @@ -109,9 +137,12 @@ public class SubCommand { message += json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display") + " (" + json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1] + ((subserver.equals(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display")))?"":TextColor.stripColor(div)+subserver) + ")"; i++; } + if (i == 0) message += TextColor.RESET + "(none)"; h.log.message.println(message); i = 0; + sent = true; } + if (!sent) host.log.message.println(TextColor.RESET + "(none)"); host.log.message.println("Server List:"); String message = ""; for (String server : json.getJSONObject("servers").keySet()) { @@ -119,6 +150,7 @@ public class SubCommand { message += TextColor.WHITE + json.getJSONObject("servers").getJSONObject(server).getString("display") + " (" + json.getJSONObject("servers").getJSONObject(server).getString("address") + ((server.equals(json.getJSONObject("servers").getJSONObject(server).getString("display")))?"":TextColor.stripColor(div)+server) + ")"; i++; } + if (i == 0) message += TextColor.RESET + "(none)"; host.log.message.println(message); })); } @@ -143,6 +175,12 @@ public class SubCommand { if (!json.getJSONObject("server").getString("name").equals(json.getJSONObject("server").getString("display"))) host.log.message.println(" - Real Name: " + json.getJSONObject("server").getString("name")); host.log.message.println(" - Host: " + json.getJSONObject("server").getString("host")); host.log.message.println(" - Enabled: " + ((json.getJSONObject("server").getBoolean("enabled"))?"yes":"no")); + host.log.message.println(" - Group: " + ((json.getJSONObject("server").getString("group").length() > 0)?json.getJSONObject("server").getString("group"):"(none)")); + if (json.getJSONObject("server").getJSONArray("group").length() > 0) { + host.log.message.println(" - Group:"); + for (int i = 0; i < json.getJSONObject("server").getJSONArray("group").length(); i++) + host.log.message.println(" - " + json.getJSONObject("server").getJSONArray("group").getString(i)); + } if (json.getJSONObject("server").getBoolean("temp")) host.log.message.println(" - Temporary: yes"); host.log.message.println(" - Running: " + ((json.getJSONObject("server").getBoolean("running"))?"yes":"no")); host.log.message.println(" - Logging: " + ((json.getJSONObject("server").getBoolean("log"))?"yes":"no")); diff --git a/SubServers.Sync/META-INF/MANIFEST.MF b/SubServers.Sync/META-INF/MANIFEST.MF index 2286dbef..39f5ca0b 100644 --- a/SubServers.Sync/META-INF/MANIFEST.MF +++ b/SubServers.Sync/META-INF/MANIFEST.MF @@ -1,5 +1,5 @@ Manifest-Version: 1.0 Class-Path: BungeeCord.jar Main-Class: net.ME1312.SubServers.Sync.Launch -Implementation-Version: 2.12.1a -Specification-Version: 0 +Implementation-Version: 2.12.1b +Specification-Version: 1 diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Config/YAMLSection.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Config/YAMLSection.java index 7ea184e0..383b77f3 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Config/YAMLSection.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Config/YAMLSection.java @@ -172,8 +172,10 @@ public class YAMLSection { * @param value Value */ public void set(String handle, Object value) { - if (Util.isNull(handle, value)) throw new NullPointerException(); - if (value instanceof Collection) { + if (Util.isNull(handle)) throw new NullPointerException(); + if (value == null) { + remove(handle); + } else if (value instanceof Collection) { set(handle, (Collection) value); } else { map.put(handle, convert(value)); diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java index cafdd8a4..4a6c5507 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java @@ -80,9 +80,37 @@ public final class SubCommand extends Command { } } else if (args[0].equalsIgnoreCase("list")) { plugin.subdata.sendPacket(new PacketDownloadServerList(null, json -> { - sender.sendMessage("SubServers > Host/SubServer List:"); - String div = ChatColor.RESET + ", "; int i = 0; + boolean sent = false; + String div = ChatColor.RESET + ", "; + sender.sendMessage("SubServers > Group/Server List:"); + for (String group : json.getJSONObject("groups").keySet()) { + String message = ""; + message += ChatColor.GOLD + group + ChatColor.RESET + ": "; + for (String server : json.getJSONObject("groups").getJSONObject(group).keySet()) { + if (i != 0) message += div; + if (!json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).keySet().contains("enabled")) { + message += ChatColor.WHITE; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("temp")) { + message += ChatColor.AQUA; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("running")) { + message += ChatColor.GREEN; + } else if (json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getBoolean("enabled") && json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getJSONArray("incompatible").length() == 0) { + message += ChatColor.YELLOW; + } else { + message += ChatColor.RED; + } + message += json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display") + " (" + json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("address") + ((server.equals(json.getJSONObject("groups").getJSONObject(group).getJSONObject(server).getString("display")))?"":ChatColor.stripColor(div)+server) + ")"; + i++; + } + if (i == 0) message += ChatColor.RESET + "(none)"; + sender.sendMessage(message); + i = 0; + sent = true; + } + if (!sent) sender.sendMessage(ChatColor.RESET + "(none)"); + sent = false; + sender.sendMessage("SubServers > Host/SubServer List:"); for (String host : json.getJSONObject("hosts").keySet()) { String message = ""; if (json.getJSONObject("hosts").getJSONObject(host).getBoolean("enabled")) { @@ -105,9 +133,12 @@ public final class SubCommand extends Command { message += json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display") + " (" + json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":")[json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("address").split(":").length - 1] + ((subserver.equals(json.getJSONObject("hosts").getJSONObject(host).getJSONObject("servers").getJSONObject(subserver).getString("display"))) ? "" : ChatColor.stripColor(div) + subserver) + ")"; i++; } + if (i == 0) message += ChatColor.RESET + "(none)"; sender.sendMessage(message); i = 0; + sent = true; } + if (!sent) sender.sendMessage(ChatColor.RESET + "(none)"); sender.sendMessage("SubServers > Server List:"); String message = ""; for (String server : json.getJSONObject("servers").keySet()) { @@ -115,6 +146,7 @@ public final class SubCommand extends Command { message += ChatColor.WHITE + json.getJSONObject("servers").getJSONObject(server).getString("display") + " (" + json.getJSONObject("servers").getJSONObject(server).getString("address") + ((server.equals(json.getJSONObject("servers").getJSONObject(server).getString("display"))) ? "" : ChatColor.stripColor(div) + server) + ")"; i++; } + if (i == 0) message += ChatColor.RESET + "(none)"; sender.sendMessage(message); })); } else if (args[0].equalsIgnoreCase("info") || args[0].equalsIgnoreCase("status")) { @@ -129,6 +161,11 @@ public final class SubCommand extends Command { if (!json.getJSONObject("server").getString("name").equals(json.getJSONObject("server").getString("display"))) sender.sendMessage(" - Real Name: " + json.getJSONObject("server").getString("name")); sender.sendMessage(" - Host: " + json.getJSONObject("server").getString("host")); sender.sendMessage(" - Enabled: " + ((json.getJSONObject("server").getBoolean("enabled"))?"yes":"no")); + if (json.getJSONObject("server").getJSONArray("group").length() > 0) { + sender.sendMessage(" - Group:"); + for (int i = 0; i < json.getJSONObject("server").getJSONArray("group").length(); i++) + sender.sendMessage(" - " + json.getJSONObject("server").getJSONArray("group").getString(i)); + } if (json.getJSONObject("server").getBoolean("temp")) sender.sendMessage(" - Temporary: yes"); sender.sendMessage(" - Running: " + ((json.getJSONObject("server").getBoolean("running"))?"yes":"no")); sender.sendMessage(" - Logging: " + ((json.getJSONObject("server").getBoolean("log"))?"yes":"no"));