Added ServerConfiguration.

Added support to enable whitelist, alter max players and pvp value.
This commit is contained in:
Jonathan Williams 2014-11-05 14:44:56 -08:00
parent 4722062a36
commit 44ccd452a3
2 changed files with 71 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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<MinecraftServer> _servers;
public Set<MinecraftServer> 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);
}