mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-11-25 19:56:24 +01:00
Add options to sync commonly altered BungeeCord values
This commit is contained in:
parent
65b29e666d
commit
b8ee251011
@ -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<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);
|
||||
YAMLSection minecraft = new YAMLSection();
|
||||
minecraft.set("version", Arrays.asList(plugin.api.getGameVersion()));
|
||||
|
@ -5,3 +5,11 @@ Settings:
|
||||
Address: '127.0.0.1:4391'
|
||||
Password: 'default'
|
||||
Encryption: 'AES'
|
||||
|
||||
Sync:
|
||||
Disabled-Commands: false
|
||||
Forced-Hosts: true
|
||||
MOTD: false
|
||||
Player-Limit: false
|
||||
Server-Priorities: true
|
||||
Tab-List: false
|
@ -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<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 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));
|
||||
|
Loading…
Reference in New Issue
Block a user