Reverted and merged twigs status update. (Needs fix on startDate.)

This commit is contained in:
Jonathan Williams 2014-09-18 22:22:01 -10:00
parent 239b021b0d
commit c8e755fe5f
3 changed files with 90 additions and 59 deletions

View File

@ -2,7 +2,6 @@ package mineplex.core.status;
import java.io.File;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
@ -21,8 +20,8 @@ import mineplex.serverdata.ServerRepository;
public class ServerStatusManager extends MiniPlugin
{
// The default timeout (in milliseconds) before the ServerStatus expires.
public final int DEFAULT_SERVER_TIMEOUT = 15000;
// The default timeout (in seconds) before the ServerStatus expires.
public final int DEFAULT_SERVER_TIMEOUT = 15;
private ServerRepository _repository;
private LagMeter _lagMeter;
@ -30,35 +29,25 @@ public class ServerStatusManager extends MiniPlugin
private String _name;
private boolean _us;
private boolean _alternateSeconds;
private boolean _enabled = true;
private long _startUpDate;
public ServerStatusManager(JavaPlugin plugin, LagMeter lagMeter)
{
super("Server Status Manager", plugin);
this._startUpDate = System.currentTimeMillis();
_lagMeter = lagMeter;
if (new File("IgnoreUpdates.dat").exists())
_enabled = false;
ServerListPingEvent event = new ServerListPingEvent(null, plugin.getServer().getMotd(), plugin.getServer().getOnlinePlayers().size(), plugin.getServer().getMaxPlayers());
GetPluginManager().callEvent(event);
setupConfigValues();
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
_name = plugin.getConfig().getString("serverstatus.name");
_us = plugin.getConfig().getBoolean("serverstatus.us");
Region region = _us ? Region.US : Region.EU;
_repository = ServerManager.getServerRepository(region);
saveServerStatus();
}
private void setupConfigValues()
@ -116,11 +105,6 @@ public class ServerStatusManager extends MiniPlugin
if (!_enabled)
return;
_alternateSeconds = !_alternateSeconds;
if (!_alternateSeconds)
return;
saveServerStatus();
}
@ -136,7 +120,7 @@ public class ServerStatusManager extends MiniPlugin
{
public void run()
{
_repository.updataServerStatus(serverSnapshot, 15000);
_repository.updataServerStatus(serverSnapshot, DEFAULT_SERVER_TIMEOUT);
}
});
}
@ -161,7 +145,7 @@ public class ServerStatusManager extends MiniPlugin
int maxRam = (int) (Runtime.getRuntime().maxMemory() / 1048576);
return new MinecraftServer(_name, group, motd, address, port, playerCount,
maxPlayerCount, tps, ram, maxRam, _startUpDate);
maxPlayerCount, tps, ram, maxRam, 0L);
}
public String getCurrentServerName()

View File

@ -51,13 +51,13 @@ public class ServerGroup
public boolean getArcadeGroup() { return _arcadeGroup; }
private String _worldZip;
public String getWorldZip() { return _serverType; }
public String getWorldZip() { return _worldZip; }
private String _plugin;
public String getPlugin() { return _serverType; }
public String getPlugin() { return _plugin; }
private String _configPath;
public String getConfigPath() { return _serverType; }
public String getConfigPath() { return _configPath; }
private int _minPlayers;
public int getMinPlayers() { return _minPlayers; }
@ -71,6 +71,42 @@ public class ServerGroup
private boolean _tournament;
public boolean getTournament() { return _tournament; }
private boolean _teamRejoin;
public boolean getTeamRejoin() { return _teamRejoin; }
private boolean _teamAutoJoin;
public boolean getTeamAutoJoin() { return _teamAutoJoin; }
private boolean _teamForceBalance;
public boolean getTeamForceBalance() { return _teamForceBalance; }
private boolean _gameAutoStart;
public boolean getGameAutoStart() { return _gameAutoStart; }
private boolean _gameTimeout;
public boolean getGameTimeout() { return _gameTimeout; }
private boolean _rewardGems;
public boolean getRewardGems() { return _rewardGems; }
private boolean _rewardItems;
public boolean getRewardItems() { return _rewardItems; }
private boolean _rewardStats;
public boolean getRewardStats() { return _rewardStats; }
private boolean _rewardAchievements;
public boolean getRewardAchievements() { return _rewardAchievements; }
private boolean _hotbarInventory;
public boolean getHotbarInventory() { return _hotbarInventory; }
private boolean _hotbarHubClock;
public boolean getHotbarHubClock() { return _hotbarHubClock; }
private boolean _playerKickIdle;
public boolean getPlayerKickIdle() { return _playerKickIdle; }
private boolean _generateFreeVersions;
public boolean getGenerateFreeVersions() { return _generateFreeVersions; }
@ -84,7 +120,8 @@ public class ServerGroup
public boolean getAddNoCheat() { return _addNoCheat; }
// The set of active MinecraftServers that belong to this server group
private Set<MinecraftServer> servers;
private Set<MinecraftServer> _servers;
public Set<MinecraftServer> getServers() { return _servers; }
/**
* Class constructor
@ -94,26 +131,38 @@ public class ServerGroup
*/
public ServerGroup(Map<String, String> data, Region region)
{
this._name = data.get("name");
this._prefix = data.get("prefix");
this._scriptName = data.get("scriptName");
this._requiredRam = Integer.valueOf(data.get("ram"));
this._requiredCpu = Integer.valueOf(data.get("cpu"));
this._requiredTotalServers = Integer.valueOf(data.get("totalServers"));
this._requiredJoinableServers = Integer.valueOf(data.get("joinableServers"));
this._portSection = Integer.valueOf(data.get("portSection"));
this._arcadeGroup = Boolean.valueOf(data.get("arcadeGroup"));
this._worldZip = data.get("worldZip");
this._plugin = data.get("plugin");
this._configPath = data.get("configPath");
this._minPlayers = Integer.valueOf(data.get("minPlayers"));
this._maxPlayers = Integer.valueOf(data.get("maxPlayers"));
this._pvp = Boolean.valueOf(data.get("pvp"));
this._tournament = Boolean.valueOf(data.get("tournament"));
this._generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
this._games = data.get("games");
this._serverType = data.get("serverType");
this._addNoCheat = Boolean.valueOf(data.get("addNoCheat"));
_name = data.get("name");
_prefix = data.get("prefix");
_scriptName = data.get("scriptName");
_requiredRam = Integer.valueOf(data.get("ram"));
_requiredCpu = Integer.valueOf(data.get("cpu"));
_requiredTotalServers = Integer.valueOf(data.get("totalServers"));
_requiredJoinableServers = Integer.valueOf(data.get("joinableServers"));
_portSection = Integer.valueOf(data.get("portSection"));
_arcadeGroup = Boolean.valueOf(data.get("arcadeGroup"));
_worldZip = data.get("worldZip");
_plugin = data.get("plugin");
_configPath = data.get("configPath");
_minPlayers = Integer.valueOf(data.get("minPlayers"));
_maxPlayers = Integer.valueOf(data.get("maxPlayers"));
_pvp = Boolean.valueOf(data.get("pvp"));
_tournament = Boolean.valueOf(data.get("tournament"));
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
_games = data.get("games");
_serverType = data.get("serverType");
_addNoCheat = Boolean.valueOf(data.get("addNoCheat"));
_teamRejoin = Boolean.valueOf(data.get("teamRejoin"));
_teamAutoJoin = Boolean.valueOf(data.get("teamAutoJoin"));
_teamForceBalance = Boolean.valueOf(data.get("teamForceBalance"));
_gameAutoStart = Boolean.valueOf(data.get("gameAutoStart"));
_gameTimeout = Boolean.valueOf(data.get("gameTimeout"));
_rewardGems = Boolean.valueOf(data.get("rewardGems"));
_rewardItems = Boolean.valueOf(data.get("rewardItems"));
_rewardStats = Boolean.valueOf(data.get("rewardStats"));
_rewardAchievements = Boolean.valueOf(data.get("rewardAchievements"));
_hotbarInventory = Boolean.valueOf(data.get("hotbarInventory"));
_hotbarHubClock = Boolean.valueOf(data.get("hotbarHubClock"));
_playerKickIdle = Boolean.valueOf(data.get("playerKickIdle"));
fetchServers(region);
}
@ -124,7 +173,7 @@ public class ServerGroup
*/
public int getServerCount()
{
return servers.size();
return _servers.size();
}
/**
@ -135,7 +184,7 @@ public class ServerGroup
{
int joinable = 0;
for (MinecraftServer server : servers)
for (MinecraftServer server : _servers)
{
if (server.isJoinable())
{
@ -154,7 +203,7 @@ public class ServerGroup
{
int playerCount = 0;
for (MinecraftServer server : servers)
for (MinecraftServer server : _servers)
{
playerCount += server.getPlayerCount();
}
@ -170,7 +219,7 @@ public class ServerGroup
{
int maxPlayerCount = 0;
for (MinecraftServer server : servers)
for (MinecraftServer server : _servers)
{
maxPlayerCount += server.getMaxPlayerCount();
}
@ -186,7 +235,7 @@ public class ServerGroup
{
Collection<MinecraftServer> emptyServers = new HashSet<MinecraftServer>();
for (MinecraftServer server : servers)
for (MinecraftServer server : _servers)
{
if (server.isEmpty() && server.getUptime() <= 150) // Only return empty servers that have been online for >150 seconds
{
@ -203,14 +252,14 @@ public class ServerGroup
*/
private void fetchServers(Region region)
{
this.servers = new HashSet<MinecraftServer>();
this._servers = new HashSet<MinecraftServer>();
ServerRepository repository = ServerManager.getServerRepository(region);
for (MinecraftServer server : repository.getServerStatuses())
{
if (_name.equals(server.getGroup()))
if (_name.equalsIgnoreCase(server.getGroup()))
{
servers.add(server);
_servers.add(server);
}
}
}
@ -218,15 +267,15 @@ public class ServerGroup
/**
* @return a unique server name suffix id, unique to any servers in this ServerGroup.
*/
public int generateUniqueId()
public int generateUniqueId(int startId)
{
int id = 0;
int id = startId;
while (true)
{
boolean uniqueId = true;
for (MinecraftServer server : servers)
for (MinecraftServer server : _servers)
{
String serverName = server.getName();
try
@ -255,5 +304,4 @@ public class ServerGroup
}
}
}
}

View File

@ -6,7 +6,6 @@ import mineplex.core.command.CommandCenter;
import mineplex.core.creature.Creature;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.join.JoinQuit;
import mineplex.core.memory.MemoryFix;
import mineplex.core.monitor.LagMeter;
import mineplex.core.npc.NpcManager;