Add options to sync commonly altered BungeeCord values

This commit is contained in:
ME1312 2018-08-04 23:29:52 -04:00
parent 65b29e666d
commit b8ee251011
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
3 changed files with 51 additions and 1 deletions

View File

@ -6,8 +6,10 @@ import net.ME1312.SubServers.Bungee.Network.Client;
import net.ME1312.SubServers.Bungee.Network.PacketIn; import net.ME1312.SubServers.Bungee.Network.PacketIn;
import net.ME1312.SubServers.Bungee.Network.PacketOut; import net.ME1312.SubServers.Bungee.Network.PacketOut;
import net.ME1312.SubServers.Bungee.SubPlugin; import net.ME1312.SubServers.Bungee.SubPlugin;
import net.md_5.bungee.api.config.ListenerInfo;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList;
/** /**
* Download Proxy Info Packet * Download Proxy Info Packet
@ -48,7 +50,21 @@ public class PacketDownloadProxyInfo implements PacketIn, PacketOut {
data.set("subservers", subservers); data.set("subservers", subservers);
YAMLSection bungee = new YAMLSection(); YAMLSection bungee = new YAMLSection();
bungee.set("version", plugin.api.getProxyVersion()); 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()); bungee.set("servers", plugin.api.getServers().size());
LinkedList<YAMLSection> listeners = new LinkedList<YAMLSection>();
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); data.set("bungee", bungee);
YAMLSection minecraft = new YAMLSection(); YAMLSection minecraft = new YAMLSection();
minecraft.set("version", Arrays.asList(plugin.api.getGameVersion())); minecraft.set("version", Arrays.asList(plugin.api.getGameVersion()));

View File

@ -5,3 +5,11 @@ Settings:
Address: '127.0.0.1:4391' Address: '127.0.0.1:4391'
Password: 'default' Password: 'default'
Encryption: 'AES' Encryption: 'AES'
Sync:
Disabled-Commands: false
Forced-Hosts: true
MOTD: false
Player-Limit: false
Server-Priorities: true
Tab-List: false

View File

@ -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.Encryption.AES;
import net.ME1312.SubServers.Sync.Network.Packet.*; import net.ME1312.SubServers.Sync.Network.Packet.*;
import net.ME1312.SubServers.Sync.SubPlugin; 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 org.yaml.snakeyaml.error.YAMLException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
@ -88,6 +92,24 @@ public final class SubDataClient {
plugin.servers.clear(); plugin.servers.clear();
plugin.lastReload = proxy.getSection("subservers").getLong("last-reload"); plugin.lastReload = proxy.getSection("subservers").getLong("last-reload");
} }
try {
LinkedList<ListenerInfo> listeners = new LinkedList<ListenerInfo>(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 host : data.getSection("hosts").getKeys()) {
for (String subserver : data.getSection("hosts").getSection(host).getSection("servers").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); plugin.merge(subserver, data.getSection("hosts").getSection(host).getSection("servers").getSection(subserver), true);
@ -104,6 +126,10 @@ public final class SubDataClient {
socket.rename(true); socket.rename(true);
plugin.getPluginManager().callEvent(new SubNetworkConnectEvent(this)); 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 { static {
addCipher("AES", new AES(128)); addCipher("AES", new AES(128));