From d3788e8ddcdf5455896bd8927b8fbb91f07be891 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sat, 11 Oct 2014 04:40:53 -0700 Subject: [PATCH] Fixed redis server time functions. Added kill option for servers with motd Finished in servermonitor --- .../core/status/ServerStatusManager.java | 2 +- .../mineplex/serverdata/MinecraftServer.java | 2 +- .../serverdata/RedisDataRepository.java | 2 +- .../serverdata/RedisServerRepository.java | 6 ++--- .../src/mineplex/serverdata/Utility.java | 23 ++++++++++++++++++- .../mineplex/servermonitor/ServerMonitor.java | 6 +++++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java index 0d45941b0..c8a1abd9b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/status/ServerStatusManager.java @@ -38,7 +38,7 @@ public class ServerStatusManager extends MiniPlugin { super("Server Status Manager", plugin); - _startUpDate = Utility.currentTimeMillis(); + _startUpDate = Utility.currentTimeSeconds(); _lagMeter = lagMeter; if (new File("IgnoreUpdates.dat").exists()) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/MinecraftServer.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/MinecraftServer.java index 2fae68668..aa25b6a81 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/MinecraftServer.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/MinecraftServer.java @@ -103,7 +103,7 @@ public class MinecraftServer public boolean isJoinable() { if (_motd != null && (_motd.contains("Starting") || _motd.contains("Recruiting") - || _motd.contains("Waiting") || _motd.contains("Cup") || _motd.isEmpty())) + || _motd.contains("Waiting") || _motd.contains("Open in") || _motd.isEmpty())) { if (_playerCount < _maxPlayerCount) { diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java index a4787d417..3802afd13 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisDataRepository.java @@ -325,7 +325,7 @@ public class RedisDataRepository implements DataRepository protected Long currentTime() { - return Utility.currentTimeMillis(); + return Utility.currentTimeSeconds(); } /** diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java index 8f3ae9073..7e7ffa669 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/RedisServerRepository.java @@ -151,7 +151,7 @@ public class RedisServerRepository implements ServerRepository String serverName = serverData.getName(); String setKey = concatenate("serverstatus", "minecraft", _region.toString()); String dataKey = concatenate(setKey, serverName); - long expiry = Utility.currentTimeMillis() + timeout; + long expiry = Utility.currentTimeSeconds() + timeout; Transaction transaction = jedis.multi(); transaction.set(dataKey, serializedData); @@ -308,7 +308,7 @@ public class RedisServerRepository implements ServerRepository try { - String min = "(" + Utility.currentTimeMillis(); + String min = "(" + Utility.currentTimeSeconds(); String max = "+inf"; names = jedis.zrangeByScore(key, min, max); } @@ -341,7 +341,7 @@ public class RedisServerRepository implements ServerRepository try { String min = "-inf"; - String max = Utility.currentTimeMillis() + ""; + String max = Utility.currentTimeSeconds() + ""; names = jedis.zrangeByScore(key, min, max); } catch (JedisConnectionException exception) diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java index 875fc1556..1682033ec 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/Utility.java @@ -59,6 +59,27 @@ public class Utility return result; } + /** + * @return the current timestamp (in seconds) fetched from the central jedis repository + * for synced timestamps. + */ + public static long currentTimeSeconds() + { + long currentTime = 0; + Jedis jedis = getPool().getResource(); + + try + { + currentTime = Long.parseLong(jedis.time().get(0)); + } + finally + { + getPool().returnResource(jedis); + } + + return currentTime; + } + /** * @return the current timestamp (in milliseconds) fetched from the central jedis repository * for synced timestamps. @@ -67,7 +88,7 @@ public class Utility { long currentTime = 0; Jedis jedis = getPool().getResource(); - + try { currentTime = Long.parseLong(jedis.time().get(0)); diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index b01f2a25d..35486340a 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -92,6 +92,12 @@ public class ServerMonitor for (MinecraftServer minecraftServer : serverStatuses) { + if (minecraftServer.getMotd().contains("Finished")) + { + killServer(minecraftServer.getName(), minecraftServer.getPublicAddress(), "[KILLED] [FINISHED] " + minecraftServer.getName() + ":" + minecraftServer.getPublicAddress(), true); + continue; + } + for (DedicatedServer server : dedicatedServers) { if (serverGroupMap.containsKey(minecraftServer.getGroup()) && minecraftServer.getPublicAddress().equalsIgnoreCase(server.getPrivateAddress()))