From b8ee2510118caa77b020e533529f2a5fb23f2976 Mon Sep 17 00:00:00 2001 From: ME1312 Date: Sat, 4 Aug 2018 23:29:52 -0400 Subject: [PATCH] Add options to sync commonly altered BungeeCord values --- .../Packet/PacketDownloadProxyInfo.java | 16 ++++++++++++ .../SubServers/Sync/Library/Files/config.yml | 10 ++++++- .../Sync/Network/SubDataClient.java | 26 +++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadProxyInfo.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadProxyInfo.java index 93b816f1..7661ace7 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadProxyInfo.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Network/Packet/PacketDownloadProxyInfo.java @@ -6,8 +6,10 @@ import net.ME1312.SubServers.Bungee.Network.Client; 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.config.ListenerInfo; import java.util.Arrays; +import java.util.LinkedList; /** * Download Proxy Info Packet @@ -48,7 +50,21 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut { data.set("subservers", subservers); YAMLSection bungee = new YAMLSection(); bungee.set("version", plugin.api.getProxyVersion()); + bungee.set("disabled-cmds", plugin.getConfig().getDisabledCommands()); + bungee.set("player-limit", plugin.getConfig().getPlayerLimit()); bungee.set("servers", plugin.api.getServers().size()); + LinkedList listeners = new LinkedList(); + for (ListenerInfo info : plugin.getConfig().getListeners()) { + YAMLSection listener = new YAMLSection(); + listener.set("forced-hosts", info.getForcedHosts()); + listener.set("motd", info.getMotd()); + listener.set("priorities", info.getServerPriority()); + listener.set("player-limit", info.getMaxPlayers()); + listener.set("tab-list", info.getTabListType()); + listener.set("tab-list-size", info.getTabListSize()); + listeners.add(listener); + } + bungee.set("listeners", listeners); data.set("bungee", bungee); YAMLSection minecraft = new YAMLSection(); minecraft.set("version", Arrays.asList(plugin.api.getGameVersion())); diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Files/config.yml b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Files/config.yml index a48d3bdc..7bb0e8bc 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Files/config.yml +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Library/Files/config.yml @@ -4,4 +4,12 @@ Settings: SubData: Address: '127.0.0.1:4391' Password: 'default' - Encryption: 'AES' \ No newline at end of file + Encryption: 'AES' + +Sync: + Disabled-Commands: false + Forced-Hosts: true + MOTD: false + Player-Limit: false + Server-Priorities: true + Tab-List: false \ No newline at end of file diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java index eb5ea77f..3a2af1b9 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/Network/SubDataClient.java @@ -12,13 +12,17 @@ import net.ME1312.SubServers.Sync.Library.Version.Version; import net.ME1312.SubServers.Sync.Network.Encryption.AES; import net.ME1312.SubServers.Sync.Network.Packet.*; import net.ME1312.SubServers.Sync.SubPlugin; +import net.md_5.bungee.api.config.ListenerInfo; +import net.md_5.bungee.conf.Configuration; import org.yaml.snakeyaml.error.YAMLException; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; import java.net.InetAddress; import java.net.Socket; import java.net.SocketException; @@ -88,6 +92,24 @@ public final class SubDataClient { plugin.servers.clear(); plugin.lastReload = proxy.getSection("subservers").getLong("last-reload"); } + try { + LinkedList listeners = new LinkedList(plugin.getConfig().getListeners()); + for (int i = 0; i < proxy.getSection("bungee").getSectionList("listeners").size(); i++) if (i < listeners.size()) { + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Forced-Hosts", true)) updateField(ListenerInfo.class.getDeclaredField("forcedHosts"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getSection("forced-hosts").get()); + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("MOTD", false)) updateField(ListenerInfo.class.getDeclaredField("motd"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getRawString("motd")); + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) updateField(ListenerInfo.class.getDeclaredField("maxPlayers"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getInt("player-limit")); + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Server-Priorities", true)) updateField(ListenerInfo.class.getDeclaredField("serverPriority"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getRawStringList("priorities")); + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Tab-List", false)) { + updateField(ListenerInfo.class.getDeclaredField("tabListType"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getRawString("tab-list")); + updateField(ListenerInfo.class.getDeclaredField("tabListSize"), listeners.get(i), proxy.getSection("bungee").getSectionList("listeners").get(i).getInt("tab-list-size")); + } + } + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Disabled-Commands", false)) updateField(Configuration.class.getDeclaredField("disabledCommands"), plugin.getConfig(), proxy.getSection("bungee").getRawStringList("disabled-cmds")); + if (plugin.config.get().getSection("Sync", new YAMLSection()).getBoolean("Player-Limit", false)) updateField(Configuration.class.getDeclaredField("playerLimit"), plugin.getConfig(), proxy.getSection("bungee").getInt("player-limit")); + } catch (Exception e) { + System.out.println("SubServers > Problem syncing BungeeCord config"); + e.printStackTrace(); + } for (String host : data.getSection("hosts").getKeys()) { for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").getKeys()) { plugin.merge(subserver, data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver), true); @@ -104,6 +126,10 @@ public final class SubDataClient { socket.rename(true); plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(this)); } + private void updateField(Field field, Object instance, Object value) throws IllegalAccessException { + field.setAccessible(true); + field.set(instance, value); + } static { addCipher("AES", new AES(128));