From 38eec66a4b50ecf27968245d596c3cedc0f61c03 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sun, 5 Aug 2018 22:07:18 -0400 Subject: [PATCH] Further define proxy status colors The proxies section of the list command now functions like the rest. You can hover over proxies in-game to get more status information on them. The colors shown are as follows: Green (Optimal): Proxy is connected to both Redis and SubData Blue (Available): Proxy is connected to SubData only White (External): Proxy is connected to Redis only Red (Disabled): Proxy is offline --- .../ME1312/SubServers/Bungee/Host/Proxy.java | 12 ++++ .../SubServers/Bungee/Library/Files/lang.yml | 4 ++ .../Packet/PacketDownloadServerList.java | 1 + .../ME1312/SubServers/Bungee/SubCommand.java | 12 +++- .../Library/Compatibility/BungeeChat.java | 67 +++++++++++++++---- .../Client/Bukkit/Network/API/Proxy.java | 10 ++- .../SubServers/Client/Bukkit/SubCommand.java | 12 +++- .../Client/Sponge/Network/API/Proxy.java | 10 ++- .../SubServers/Client/Sponge/SubCommand.java | 46 ++++++++++--- .../SubServers/Host/Network/API/Proxy.java | 10 ++- .../ME1312/SubServers/Host/SubCommand.java | 12 +++- .../SubServers/Sync/Network/API/Proxy.java | 10 ++- .../ME1312/SubServers/Sync/SubCommand.java | 12 +++- 13 files changed, 190 insertions(+), 28 deletions(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Proxy.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Proxy.java index 2c1ab07e..0377b3c8 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Proxy.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Proxy.java @@ -83,6 +83,17 @@ public class Proxy implements ClientHandler, ExtraDataHandler { } } + /** + * Test if the proxy is connected to RedisBungee's server + * + * @return Redis Status + */ + @SuppressWarnings({"deprecation", "unchecked"}) + public boolean isRedis() { + SubPlugin plugin = SubAPI.getInstance().getInternals(); + return plugin.redis && Util.getDespiteException(() -> plugin.redis("getPlayersOnProxy", new NamedContainer<>(String.class, getName())) != null, false); + } + /** * Get the players on this proxy (via RedisBungee) * @@ -152,6 +163,7 @@ public class Proxy implements ClientHandler, ExtraDataHandler { players.set(player.get().toString(), pinfo); } info.set("players", players); + info.set("redis", isRedis()); if (getSubData() != null) info.set("subdata", getSubData().getAddress().toString()); info.set("signature", signature); info.set("extra", getExtra()); 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 75007dd4..be330b14 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 @@ -80,6 +80,10 @@ Lang: 'Interface.Generic.Downloading.Title-Color-Alt': '&3' 'Interface.Generic.Downloading.Response': '&eWaiting for response' 'Interface.Generic.Invalid-Permission': '&4You need &n$str$' + 'Interface.Proxy-Menu.Proxy-Master': '&8Master Proxy' + 'Interface.Proxy-Menu.Proxy-SubData': '&9SubData Only' + 'Interface.Proxy-Menu.Proxy-Redis': '&7Redis Only' + 'Interface.Proxy-Menu.Proxy-Disconnected': '&4Disconnected' 'Interface.Host-Menu.Title': 'Host Menu' 'Interface.Host-Menu.Host-Disabled': '&4Disabled' 'Interface.Host-Menu.Host-Server-Count': '&9$int$ Server(s)' 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 d0d67406..29234898 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 @@ -60,6 +60,7 @@ public class PacketDownloadServerList implements PacketIn, PacketOut { proxies.set(proxy.getName(), new YAMLSection(new Gson().fromJson(proxy.toString(), Map.class))); } data.set("proxies", proxies); + if (plugin.redis) data.set("master-proxy", Util.getDespiteException(() -> plugin.redis("getServerId"), null)); YAMLSection exServers = new YAMLSection(); for (Server server : plugin.exServers.values()) { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java index 5cb0301c..a2b83246 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java @@ -213,7 +213,17 @@ public final class SubCommand extends CommandX { sender.sendMessage("SubServers > Proxy List:"); message = " (master)"; for (Proxy proxy : plugin.api.getProxies().values()) { - message += div + ((proxy.getSubData() != null)?ChatColor.AQUA:ChatColor.WHITE) + proxy.getDisplayName() + ((proxy.getName().equals(proxy.getDisplayName()))?"":" ("+proxy.getName()+')'); + message += div; + if (proxy.getSubData() != null && proxy.isRedis()) { + message += ChatColor.GREEN; + } else if (proxy.getSubData() != null) { + message += ChatColor.AQUA; + } else if (proxy.isRedis()) { + message += ChatColor.WHITE; + } else { + message += ChatColor.RED; + } + message += proxy.getDisplayName() + ((proxy.getName().equals(proxy.getDisplayName()))?"":" ("+proxy.getName()+')'); } sender.sendMessage(message); } diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Compatibility/BungeeChat.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Compatibility/BungeeChat.java index bc09d809..183392fc 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Compatibility/BungeeChat.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Library/Compatibility/BungeeChat.java @@ -289,25 +289,68 @@ public class BungeeChat { else ((Player) sender).spigot().sendMessage(msg); if (data.getSection("proxies").getKeys().size() > 0) { sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Proxy-Header")); - msg = new TextComponent(" (master)"); - msg.setColor(ChatColor.GRAY); + msg = new TextComponent(" "); + List hoverm = new LinkedList(); + TextComponent message = new TextComponent("(master)"); + TextComponent hover = new TextComponent("(master)"); + message.setColor(ChatColor.GRAY); + hover.setColor(ChatColor.GRAY); + hoverm.add(hover); + if (data.getKeys().contains("master-proxy")) { + hover = new TextComponent('\n' + data.getRawString("master-proxy")); + hover.setColor(ChatColor.GRAY); + hoverm.add(hover); + } + hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master")); + hoverm.add(hover); + message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()]))); + msg.addExtra(message); for (String proxy : data.getSection("proxies").getKeys()) { - List hoverm = new LinkedList(); - TextComponent message = new TextComponent(data.getSection("proxies").getSection(proxy).getString("display")); - TextComponent hover = new TextComponent(data.getSection("proxies").getSection(proxy).getString("display")); - if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { + hoverm = new LinkedList(); + message = new TextComponent(data.getSection("proxies").getSection(proxy).getString("display")); + hover = new TextComponent(data.getSection("proxies").getSection(proxy).getString("display")); + if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message.setColor(ChatColor.GREEN); + hover.setColor(ChatColor.GREEN); + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hoverm.add(hover); + hover = new TextComponent('\n' + proxy); + hover.setColor(ChatColor.GRAY); + } + } else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { message.setColor(ChatColor.AQUA); hover.setColor(ChatColor.AQUA); - } else { + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hoverm.add(hover); + hover = new TextComponent('\n' + proxy); + hover.setColor(ChatColor.GRAY); + } + if (data.getKeys().contains("master-proxy")) { + hoverm.add(hover); + hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData")); + } + } else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) { message.setColor(ChatColor.WHITE); hover.setColor(ChatColor.WHITE); + hoverm.add(hover); + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hover = new TextComponent('\n' + proxy); + hover.setColor(ChatColor.GRAY); + hoverm.add(hover); + } + hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis")); + } else { + message.setColor(ChatColor.RED); + hover.setColor(ChatColor.RED); + hoverm.add(hover); + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hover = new TextComponent('\n' + proxy); + hover.setColor(ChatColor.GRAY); + hoverm.add(hover); + } + hover = new TextComponent('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Disconnected")); } hoverm.add(hover); - if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { - hover = new TextComponent('\n' + proxy); - hover.setColor(ChatColor.GRAY); - hoverm.add(hover); - } message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverm.toArray(new TextComponent[hoverm.size()]))); msg.addExtra(div); msg.addExtra(message); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/API/Proxy.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/API/Proxy.java index 2f8e7d15..a8eff724 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/API/Proxy.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/Network/API/Proxy.java @@ -80,12 +80,20 @@ public class Proxy { return raw.getRawString("display"); } + /** + * Test if the proxy is connected to RedisBungee's server + * + * @return Redis Status + */ + public boolean isRedis() { + return raw.getBoolean("redis"); + } + /** * Get the players on this proxy (via RedisBungee) * * @return Player Collection */ - @SuppressWarnings({"deprecation", "unchecked"}) public Collection> getPlayers() { List> players = new ArrayList>(); for (String id : raw.getSection("players").getKeys()) { 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 ebd11a0a..71c93648 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 @@ -156,7 +156,17 @@ public final class SubCommand implements CommandExecutor { sender.sendMessage(plugin.api.getLang("SubServers", "Command.List.Proxy-Header")); message = " (master)"; for (String proxy : data.getSection("proxies").getKeys()) { - message += div + ((data.getSection("proxies").getSection(proxy).getKeys().contains("subdata"))?ChatColor.AQUA:ChatColor.WHITE) + data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')'); + message += div; + if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message += ChatColor.GREEN; + } else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { + message += ChatColor.AQUA; + } else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message += ChatColor.WHITE; + } else { + message += ChatColor.RED; + } + message += data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')'); } sender.sendMessage(message); } diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/API/Proxy.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/API/Proxy.java index 9c378330..0398af1d 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/API/Proxy.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/Network/API/Proxy.java @@ -80,12 +80,20 @@ public class Proxy { return raw.getRawString("display"); } + /** + * Test if the proxy is connected to RedisBungee's server + * + * @return Redis Status + */ + public boolean isRedis() { + return raw.getBoolean("redis"); + } + /** * Get the players on this proxy (via RedisBungee) * * @return Player Collection */ - @SuppressWarnings({"deprecation", "unchecked"}) public Collection> getPlayers() { List> players = new ArrayList>(); for (String id : raw.getSection("players").getKeys()) { diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java index 306c7ccc..9bdbe871 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java @@ -399,23 +399,53 @@ public final class SubCommand implements CommandExecutor { if (data.getSection("proxies").getKeys().size() > 0) { sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.List.Proxy-Header"))); msg = Text.builder(); + Text.Builder message = Text.builder("(master)"); + Text.Builder hover = Text.builder("(master)"); + message.color(TextColors.GRAY); + hover.color(TextColors.GRAY); + if (data.getKeys().contains("master-proxy")) { + hover.append(Text.builder('\n' + data.getRawString("master-proxy")).color(TextColors.GRAY).build()); + } + hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Master"))); + message.onHover(TextActions.showText(hover.build())); + msg.append(message.build()); for (String proxy : data.getSection("proxies").getKeys()) { - Text.Builder message = Text.builder(data.getSection("proxies").getSection(proxy).getString("display")); - Text.Builder hover = Text.builder(data.getSection("proxies").getSection(proxy).getString("display")); - if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { + message = Text.builder(data.getSection("proxies").getSection(proxy).getString("display")); + hover = Text.builder(data.getSection("proxies").getSection(proxy).getString("display")); + if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message.color(TextColors.GREEN); + hover.color(TextColors.GREEN); + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build()); + } + } else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { message.color(TextColors.AQUA); hover.color(TextColors.AQUA); - } else { + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build()); + } + if (data.getKeys().contains("master-proxy")) { + hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-SubData"))); + } + } else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) { message.color(TextColors.WHITE); hover.color(TextColors.WHITE); - } - if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { - hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build()); + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build()); + } + hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Redis"))); + } else { + message.color(TextColors.RED); + hover.color(TextColors.RED); + if (!proxy.equals(data.getSection("proxies").getSection(proxy).getString("display"))) { + hover.append(Text.builder('\n' + proxy).color(TextColors.GRAY).build()); + } + hover.append(Text.of('\n' + plugin.api.getLang("SubServers", "Interface.Proxy-Menu.Proxy-Disconnected"))); } message.onHover(TextActions.showText(hover.build())); msg.append(div, message.build()); } - sender.sendMessage(Text.builder(" (master)").color(TextColors.GRAY).append(msg.build()).build()); + sender.sendMessage(Text.builder(" ").append(msg.build()).build()); } })); return CommandResult.builder().successCount(1).build(); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/API/Proxy.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/API/Proxy.java index 8eb4f60c..271dd3e3 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Network/API/Proxy.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Network/API/Proxy.java @@ -80,12 +80,20 @@ public class Proxy { return raw.getRawString("display"); } + /** + * Test if the proxy is connected to RedisBungee's server + * + * @return Redis Status + */ + public boolean isRedis() { + return raw.getBoolean("redis"); + } + /** * Get the players on this proxy (via RedisBungee) * * @return Player Collection */ - @SuppressWarnings({"deprecation", "unchecked"}) public Collection> getPlayers() { List> players = new ArrayList>(); for (String id : raw.getSection("players").getKeys()) { diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java index aa487ce9..e28368bc 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java @@ -177,7 +177,17 @@ public class SubCommand { host.log.message.println("Proxy List:"); message = " (master)"; for (String proxy : data.getSection("proxies").getKeys()) { - message += div + ((data.getSection("proxies").getSection(proxy).getKeys().contains("subdata"))?TextColor.AQUA:TextColor.WHITE) + data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')'); + message += div; + if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message += TextColor.GREEN; + } else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { + message += TextColor.AQUA; + } else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message += TextColor.WHITE; + } else { + message += TextColor.RED; + } + message += data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')'); } host.log.message.println(message); } diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/API/Proxy.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/API/Proxy.java index 4c3fa155..1c7fd3e6 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/API/Proxy.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/API/Proxy.java @@ -80,12 +80,20 @@ public class Proxy { return raw.getRawString("display"); } + /** + * Test if the proxy is connected to RedisBungee's server + * + * @return Redis Status + */ + public boolean isRedis() { + return raw.getBoolean("redis"); + } + /** * Get the players on this proxy (via RedisBungee) * * @return Player Collection */ - @SuppressWarnings({"deprecation", "unchecked"}) public Collection> getPlayers() { List> players = new ArrayList>(); for (String id : raw.getSection("players").getKeys()) { diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java index ab48f6ce..4583e4a4 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java @@ -166,7 +166,17 @@ public final class SubCommand extends CommandX { sender.sendMessage("SubServers > Proxy List:"); message = " (master)"; for (String proxy : data.getSection("proxies").getKeys()) { - message += div + ((data.getSection("proxies").getSection(proxy).getKeys().contains("subdata"))?ChatColor.AQUA:ChatColor.WHITE) + data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')'); + message += div; + if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata") && data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message += ChatColor.GREEN; + } else if (data.getSection("proxies").getSection(proxy).getKeys().contains("subdata")) { + message += ChatColor.AQUA; + } else if (data.getSection("proxies").getSection(proxy).getBoolean("redis")) { + message += ChatColor.WHITE; + } else { + message += ChatColor.RED; + } + message += data.getSection("proxies").getSection(proxy).getString("display") + ((proxy.equals(data.getSection("proxies").getSection(proxy).getString("display")))?"":" ("+proxy+')'); } sender.sendMessage(message); }