Recommit up-time checking to prevent brand new empty servers from being prematurely killed by ServerMonitor.
This commit is contained in:
parent
c7e0ebefd1
commit
abea4223ab
@ -2,6 +2,7 @@ package mineplex.core.status;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -20,8 +21,8 @@ import mineplex.serverdata.ServerRepository;
|
|||||||
|
|
||||||
public class ServerStatusManager extends MiniPlugin
|
public class ServerStatusManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
// The default timeout (in seconds) before the ServerStatus expires.
|
// The default timeout (in milliseconds) before the ServerStatus expires.
|
||||||
public final int DEFAULT_SERVER_TIMEOUT = 15;
|
public final int DEFAULT_SERVER_TIMEOUT = 15000;
|
||||||
|
|
||||||
private ServerRepository _repository;
|
private ServerRepository _repository;
|
||||||
private LagMeter _lagMeter;
|
private LagMeter _lagMeter;
|
||||||
@ -29,25 +30,35 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
private String _name;
|
private String _name;
|
||||||
private boolean _us;
|
private boolean _us;
|
||||||
|
|
||||||
|
private boolean _alternateSeconds;
|
||||||
private boolean _enabled = true;
|
private boolean _enabled = true;
|
||||||
|
|
||||||
|
private long _startUpDate;
|
||||||
|
|
||||||
public ServerStatusManager(JavaPlugin plugin, LagMeter lagMeter)
|
public ServerStatusManager(JavaPlugin plugin, LagMeter lagMeter)
|
||||||
{
|
{
|
||||||
super("Server Status Manager", plugin);
|
super("Server Status Manager", plugin);
|
||||||
|
|
||||||
|
this._startUpDate = System.currentTimeMillis();
|
||||||
|
|
||||||
_lagMeter = lagMeter;
|
_lagMeter = lagMeter;
|
||||||
|
|
||||||
if (new File("IgnoreUpdates.dat").exists())
|
if (new File("IgnoreUpdates.dat").exists())
|
||||||
_enabled = false;
|
_enabled = false;
|
||||||
|
|
||||||
|
ServerListPingEvent event = new ServerListPingEvent(null, plugin.getServer().getMotd(), plugin.getServer().getOnlinePlayers().length, plugin.getServer().getMaxPlayers());
|
||||||
|
|
||||||
|
GetPluginManager().callEvent(event);
|
||||||
|
|
||||||
setupConfigValues();
|
setupConfigValues();
|
||||||
|
|
||||||
|
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
|
||||||
|
|
||||||
_name = plugin.getConfig().getString("serverstatus.name");
|
_name = plugin.getConfig().getString("serverstatus.name");
|
||||||
_us = plugin.getConfig().getBoolean("serverstatus.us");
|
_us = plugin.getConfig().getBoolean("serverstatus.us");
|
||||||
|
|
||||||
Region region = _us ? Region.US : Region.EU;
|
Region region = _us ? Region.US : Region.EU;
|
||||||
_repository = ServerManager.getServerRepository(region);
|
_repository = ServerManager.getServerRepository(region);
|
||||||
saveServerStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupConfigValues()
|
private void setupConfigValues()
|
||||||
@ -105,6 +116,11 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
|
|
||||||
if (!_enabled)
|
if (!_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
_alternateSeconds = !_alternateSeconds;
|
||||||
|
|
||||||
|
if (!_alternateSeconds)
|
||||||
|
return;
|
||||||
|
|
||||||
saveServerStatus();
|
saveServerStatus();
|
||||||
}
|
}
|
||||||
@ -120,7 +136,7 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
_repository.updataServerStatus(serverSnapshot, DEFAULT_SERVER_TIMEOUT);
|
_repository.updataServerStatus(serverSnapshot, 15000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -131,11 +147,11 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
*/
|
*/
|
||||||
private MinecraftServer generateServerSnapshot()
|
private MinecraftServer generateServerSnapshot()
|
||||||
{
|
{
|
||||||
ServerListPingEvent event = new ServerListPingEvent(null, GetPlugin().getServer().getMotd(), GetPlugin().getServer().getOnlinePlayers().size(), GetPlugin().getServer().getMaxPlayers());
|
ServerListPingEvent event = new ServerListPingEvent(null, GetPlugin().getServer().getMotd(), GetPlugin().getServer().getOnlinePlayers().length, GetPlugin().getServer().getMaxPlayers());
|
||||||
GetPluginManager().callEvent(event);
|
GetPluginManager().callEvent(event);
|
||||||
|
|
||||||
String motd = event.getMotd();
|
String motd = event.getMotd();
|
||||||
int playerCount = Bukkit.getOnlinePlayers().size();
|
int playerCount = Bukkit.getOnlinePlayers().length;
|
||||||
int maxPlayerCount = event.getMaxPlayers();
|
int maxPlayerCount = event.getMaxPlayers();
|
||||||
int tps = (int) _lagMeter.getTicksPerSecond();
|
int tps = (int) _lagMeter.getTicksPerSecond();
|
||||||
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
|
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
|
||||||
@ -145,7 +161,7 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
int maxRam = (int) (Runtime.getRuntime().maxMemory() / 1048576);
|
int maxRam = (int) (Runtime.getRuntime().maxMemory() / 1048576);
|
||||||
|
|
||||||
return new MinecraftServer(_name, group, motd, address, port, playerCount,
|
return new MinecraftServer(_name, group, motd, address, port, playerCount,
|
||||||
maxPlayerCount, tps, ram, maxRam);
|
maxPlayerCount, tps, ram, maxRam, _startUpDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrentServerName()
|
public String getCurrentServerName()
|
||||||
|
@ -29,7 +29,7 @@ public class MinecraftServer
|
|||||||
// The maximum number of players allowed on the server.
|
// The maximum number of players allowed on the server.
|
||||||
private int _maxPlayerCount;
|
private int _maxPlayerCount;
|
||||||
public int getMaxPlayerCount() { return _maxPlayerCount; }
|
public int getMaxPlayerCount() { return _maxPlayerCount; }
|
||||||
|
|
||||||
// The ticks per second (TPS) of the server.
|
// The ticks per second (TPS) of the server.
|
||||||
private int _tps;
|
private int _tps;
|
||||||
public int getTps() { return _tps; }
|
public int getTps() { return _tps; }
|
||||||
@ -50,6 +50,8 @@ public class MinecraftServer
|
|||||||
private int _port;
|
private int _port;
|
||||||
public int getPort() { return _port; }
|
public int getPort() { return _port; }
|
||||||
|
|
||||||
|
private long _startUpDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class constructor
|
* Class constructor
|
||||||
* @param name
|
* @param name
|
||||||
@ -64,7 +66,7 @@ public class MinecraftServer
|
|||||||
* @param maxRam
|
* @param maxRam
|
||||||
*/
|
*/
|
||||||
public MinecraftServer(String name, String group, String motd, String publicAddress, int port,
|
public MinecraftServer(String name, String group, String motd, String publicAddress, int port,
|
||||||
int playerCount, int maxPlayerCount, int tps, int ram, int maxRam)
|
int playerCount, int maxPlayerCount, int tps, int ram, int maxRam, long startUpDate)
|
||||||
{
|
{
|
||||||
this._name = name;
|
this._name = name;
|
||||||
this._group = group;
|
this._group = group;
|
||||||
@ -76,6 +78,7 @@ public class MinecraftServer
|
|||||||
this._maxRam = maxRam;
|
this._maxRam = maxRam;
|
||||||
this._publicAddress = publicAddress;
|
this._publicAddress = publicAddress;
|
||||||
this._port = port;
|
this._port = port;
|
||||||
|
this._startUpDate = startUpDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,6 +89,14 @@ public class MinecraftServer
|
|||||||
return _playerCount == 0;
|
return _playerCount == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the amount of time (in seconds) that this {@link MinecraftServer} has been online for.
|
||||||
|
*/
|
||||||
|
public double getUptime()
|
||||||
|
{
|
||||||
|
return (System.currentTimeMillis() - _startUpDate) / 1000d;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true, if this server is currently joinable by players, false otherwise.
|
* @return true, if this server is currently joinable by players, false otherwise.
|
||||||
*/
|
*/
|
||||||
|
@ -51,13 +51,13 @@ public class ServerGroup
|
|||||||
public boolean getArcadeGroup() { return _arcadeGroup; }
|
public boolean getArcadeGroup() { return _arcadeGroup; }
|
||||||
|
|
||||||
private String _worldZip;
|
private String _worldZip;
|
||||||
public String getWorldZip() { return _worldZip; }
|
public String getWorldZip() { return _serverType; }
|
||||||
|
|
||||||
private String _plugin;
|
private String _plugin;
|
||||||
public String getPlugin() { return _plugin; }
|
public String getPlugin() { return _serverType; }
|
||||||
|
|
||||||
private String _configPath;
|
private String _configPath;
|
||||||
public String getConfigPath() { return _configPath; }
|
public String getConfigPath() { return _serverType; }
|
||||||
|
|
||||||
private int _minPlayers;
|
private int _minPlayers;
|
||||||
public int getMinPlayers() { return _minPlayers; }
|
public int getMinPlayers() { return _minPlayers; }
|
||||||
@ -71,42 +71,6 @@ public class ServerGroup
|
|||||||
private boolean _tournament;
|
private boolean _tournament;
|
||||||
public boolean getTournament() { return _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;
|
private boolean _generateFreeVersions;
|
||||||
public boolean getGenerateFreeVersions() { return _generateFreeVersions; }
|
public boolean getGenerateFreeVersions() { return _generateFreeVersions; }
|
||||||
|
|
||||||
@ -120,8 +84,7 @@ public class ServerGroup
|
|||||||
public boolean getAddNoCheat() { return _addNoCheat; }
|
public boolean getAddNoCheat() { return _addNoCheat; }
|
||||||
|
|
||||||
// The set of active MinecraftServers that belong to this server group
|
// 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
|
* Class constructor
|
||||||
@ -131,38 +94,26 @@ public class ServerGroup
|
|||||||
*/
|
*/
|
||||||
public ServerGroup(Map<String, String> data, Region region)
|
public ServerGroup(Map<String, String> data, Region region)
|
||||||
{
|
{
|
||||||
_name = data.get("name");
|
this._name = data.get("name");
|
||||||
_prefix = data.get("prefix");
|
this._prefix = data.get("prefix");
|
||||||
_scriptName = data.get("scriptName");
|
this._scriptName = data.get("scriptName");
|
||||||
_requiredRam = Integer.valueOf(data.get("ram"));
|
this._requiredRam = Integer.valueOf(data.get("ram"));
|
||||||
_requiredCpu = Integer.valueOf(data.get("cpu"));
|
this._requiredCpu = Integer.valueOf(data.get("cpu"));
|
||||||
_requiredTotalServers = Integer.valueOf(data.get("totalServers"));
|
this._requiredTotalServers = Integer.valueOf(data.get("totalServers"));
|
||||||
_requiredJoinableServers = Integer.valueOf(data.get("joinableServers"));
|
this._requiredJoinableServers = Integer.valueOf(data.get("joinableServers"));
|
||||||
_portSection = Integer.valueOf(data.get("portSection"));
|
this._portSection = Integer.valueOf(data.get("portSection"));
|
||||||
_arcadeGroup = Boolean.valueOf(data.get("arcadeGroup"));
|
this._arcadeGroup = Boolean.valueOf(data.get("arcadeGroup"));
|
||||||
_worldZip = data.get("worldZip");
|
this._worldZip = data.get("worldZip");
|
||||||
_plugin = data.get("plugin");
|
this._plugin = data.get("plugin");
|
||||||
_configPath = data.get("configPath");
|
this._configPath = data.get("configPath");
|
||||||
_minPlayers = Integer.valueOf(data.get("minPlayers"));
|
this._minPlayers = Integer.valueOf(data.get("minPlayers"));
|
||||||
_maxPlayers = Integer.valueOf(data.get("maxPlayers"));
|
this._maxPlayers = Integer.valueOf(data.get("maxPlayers"));
|
||||||
_pvp = Boolean.valueOf(data.get("pvp"));
|
this._pvp = Boolean.valueOf(data.get("pvp"));
|
||||||
_tournament = Boolean.valueOf(data.get("tournament"));
|
this._tournament = Boolean.valueOf(data.get("tournament"));
|
||||||
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
|
this._generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
|
||||||
_games = data.get("games");
|
this._games = data.get("games");
|
||||||
_serverType = data.get("serverType");
|
this._serverType = data.get("serverType");
|
||||||
_addNoCheat = Boolean.valueOf(data.get("addNoCheat"));
|
this._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);
|
fetchServers(region);
|
||||||
}
|
}
|
||||||
@ -173,7 +124,7 @@ public class ServerGroup
|
|||||||
*/
|
*/
|
||||||
public int getServerCount()
|
public int getServerCount()
|
||||||
{
|
{
|
||||||
return _servers.size();
|
return servers.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +135,7 @@ public class ServerGroup
|
|||||||
{
|
{
|
||||||
int joinable = 0;
|
int joinable = 0;
|
||||||
|
|
||||||
for (MinecraftServer server : _servers)
|
for (MinecraftServer server : servers)
|
||||||
{
|
{
|
||||||
if (server.isJoinable())
|
if (server.isJoinable())
|
||||||
{
|
{
|
||||||
@ -203,7 +154,7 @@ public class ServerGroup
|
|||||||
{
|
{
|
||||||
int playerCount = 0;
|
int playerCount = 0;
|
||||||
|
|
||||||
for (MinecraftServer server : _servers)
|
for (MinecraftServer server : servers)
|
||||||
{
|
{
|
||||||
playerCount += server.getPlayerCount();
|
playerCount += server.getPlayerCount();
|
||||||
}
|
}
|
||||||
@ -219,7 +170,7 @@ public class ServerGroup
|
|||||||
{
|
{
|
||||||
int maxPlayerCount = 0;
|
int maxPlayerCount = 0;
|
||||||
|
|
||||||
for (MinecraftServer server : _servers)
|
for (MinecraftServer server : servers)
|
||||||
{
|
{
|
||||||
maxPlayerCount += server.getMaxPlayerCount();
|
maxPlayerCount += server.getMaxPlayerCount();
|
||||||
}
|
}
|
||||||
@ -235,9 +186,9 @@ public class ServerGroup
|
|||||||
{
|
{
|
||||||
Collection<MinecraftServer> emptyServers = new HashSet<MinecraftServer>();
|
Collection<MinecraftServer> emptyServers = new HashSet<MinecraftServer>();
|
||||||
|
|
||||||
for (MinecraftServer server : _servers)
|
for (MinecraftServer server : servers)
|
||||||
{
|
{
|
||||||
if (server.isEmpty())
|
if (server.isEmpty() && server.getUptime() <= 150) // Only return empty servers that have been online for >150 seconds
|
||||||
{
|
{
|
||||||
emptyServers.add(server);
|
emptyServers.add(server);
|
||||||
}
|
}
|
||||||
@ -252,14 +203,14 @@ public class ServerGroup
|
|||||||
*/
|
*/
|
||||||
private void fetchServers(Region region)
|
private void fetchServers(Region region)
|
||||||
{
|
{
|
||||||
this._servers = new HashSet<MinecraftServer>();
|
this.servers = new HashSet<MinecraftServer>();
|
||||||
ServerRepository repository = ServerManager.getServerRepository(region);
|
ServerRepository repository = ServerManager.getServerRepository(region);
|
||||||
|
|
||||||
for (MinecraftServer server : repository.getServerStatuses())
|
for (MinecraftServer server : repository.getServerStatuses())
|
||||||
{
|
{
|
||||||
if (_name.equalsIgnoreCase(server.getGroup()))
|
if (_name.equals(server.getGroup()))
|
||||||
{
|
{
|
||||||
_servers.add(server);
|
servers.add(server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,15 +218,15 @@ public class ServerGroup
|
|||||||
/**
|
/**
|
||||||
* @return a unique server name suffix id, unique to any servers in this ServerGroup.
|
* @return a unique server name suffix id, unique to any servers in this ServerGroup.
|
||||||
*/
|
*/
|
||||||
public int generateUniqueId(int startId)
|
public int generateUniqueId()
|
||||||
{
|
{
|
||||||
int id = startId;
|
int id = 0;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
boolean uniqueId = true;
|
boolean uniqueId = true;
|
||||||
|
|
||||||
for (MinecraftServer server : _servers)
|
for (MinecraftServer server : servers)
|
||||||
{
|
{
|
||||||
String serverName = server.getName();
|
String serverName = server.getName();
|
||||||
try
|
try
|
||||||
@ -304,4 +255,5 @@ public class ServerGroup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user