From 44ccd452a3c04963b18032f4712ac8e7de4574f2 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Wed, 5 Nov 2014 14:44:56 -0800 Subject: [PATCH] Added ServerConfiguration. Added support to enable whitelist, alter max players and pvp value. --- .../serverConfig/ServerConfiguration.java | 63 +++++++++++++++++++ .../src/mineplex/serverdata/ServerGroup.java | 8 +++ 2 files changed, 71 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java new file mode 100644 index 000000000..3b9f18cab --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/serverConfig/ServerConfiguration.java @@ -0,0 +1,63 @@ +package mineplex.core.serverConfig; + +import java.lang.reflect.Field; +import java.util.LinkedList; +import java.util.Map.Entry; + +import net.minecraft.server.v1_7_R4.PlayerList; + +import org.bukkit.craftbukkit.v1_7_R4.CraftServer; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.serverdata.Region; +import mineplex.serverdata.ServerGroup; +import mineplex.serverdata.ServerManager; + +public class ServerConfiguration extends MiniPlugin +{ + private Field _playerListMaxPlayers; + private ServerGroup _serverGroup; + + public ServerConfiguration(JavaPlugin plugin) + { + super("Server Configuration", plugin); + + Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU; + + for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups()) + { + System.out.println(serverGroup.getName()); + + if (serverGroup.getName().equalsIgnoreCase(plugin.getConfig().getString("serverstatus.group"))) + { + _serverGroup = serverGroup; + break; + } + } + + if (_serverGroup == null) + return; + + if (_serverGroup.getWhitelist()) + _plugin.getServer().setWhitelist(true); + + try + { + _playerListMaxPlayers = PlayerList.class.getDeclaredField("maxPlayers"); + _playerListMaxPlayers.setAccessible(true); + _playerListMaxPlayers.setInt(((CraftServer)_plugin.getServer()).getHandle(), _serverGroup.getMaxPlayers()); + } + catch (Exception e) + { + e.printStackTrace(); + } + + ((CraftServer)_plugin.getServer()).getServer().setPvP(_serverGroup.getPvp()); + } + + public ServerGroup getServerGroup() + { + return _serverGroup; + } +} diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java index dfebd6849..d5549917e 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/ServerGroup.java @@ -116,6 +116,12 @@ public class ServerGroup private boolean _addNoCheat; public boolean getAddNoCheat() { return _addNoCheat; } + private boolean _whitelist; + public boolean getWhitelist() { return _whitelist; } + + private boolean _staffOnly; + public boolean getStaffOnly() { return _staffOnly; } + // The set of active MinecraftServers that belong to this server group private Set _servers; public Set getServers() { return _servers; } @@ -160,6 +166,8 @@ public class ServerGroup _hotbarInventory = Boolean.valueOf(data.get("hotbarInventory")); _hotbarHubClock = Boolean.valueOf(data.get("hotbarHubClock")); _playerKickIdle = Boolean.valueOf(data.get("playerKickIdle")); + _staffOnly = Boolean.valueOf(data.get("staffOnly")); + _whitelist = Boolean.valueOf(data.get("whitelist")); fetchServers(region); }