From 6963f6bacf9d9734673a8661aa392ea404e7590f Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sat, 29 Mar 2014 01:32:24 -0400 Subject: [PATCH] Added Player version stat tracking. Added server group stats. --- Plugins/BuildFiles/common.xml | 12 ++-- .../bungee/playerStats/PlayerStats.java | 1 + .../playerStats/PlayerStatsRepository.java | 62 +++++++++++++++++++ .../servermonitor/GroupStatusData.java | 39 +++++++++++- .../mineplex/servermonitor/ServerMonitor.java | 9 +++ 5 files changed, 116 insertions(+), 7 deletions(-) diff --git a/Plugins/BuildFiles/common.xml b/Plugins/BuildFiles/common.xml index 7966c490a..747b164c5 100644 --- a/Plugins/BuildFiles/common.xml +++ b/Plugins/BuildFiles/common.xml @@ -222,9 +222,9 @@ - - - + + + @@ -232,9 +232,9 @@ + value="mineplex.serverstatifier.ServerStatifier"/> - + - \ No newline at end of file + \ No newline at end of file diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStats.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStats.java index 6f1a154b9..8ef242b4e 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStats.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStats.java @@ -24,5 +24,6 @@ public class PlayerStats implements Listener public void playerConnect(PostLoginEvent event) { _repository.addPlayer(event.getPlayer().getName()); + _repository.addPlayerVersion(event.getPlayer().getName(), (event.getPlayer().getPendingConnection().getVersion() == 4 ? "1.7" : "1.6")); } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java index 5711fb8cb..262b4553d 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java @@ -15,6 +15,9 @@ public class PlayerStatsRepository private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS DailyUnique (id INT NOT NULL AUTO_INCREMENT, day VARCHAR(100), playerName VARCHAR(20), PRIMARY KEY (id), UNIQUE KEY unique_player_per_day (day, playerName));"; private static String INSERT_PLAYER = "INSERT INTO DailyUnique (day, playerName) values(curdate(), ?) ON DUPLICATE KEY UPDATE playerName=playerName;"; + + private static String CREATE_VER_TABLE = "CREATE TABLE IF NOT EXISTS PlayerVersion (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), version VARCHAR(40), PRIMARY KEY (id), UNIQUE KEY unique_player (playerName));"; + private static String INSERT_VER_PLAYER = "INSERT INTO PlayerVersion (playerName, version) values(?, ?) ON DUPLICATE KEY UPDATE version=version;"; public void initialize() { @@ -28,6 +31,11 @@ public class PlayerStatsRepository // Create table preparedStatement = _connection.prepareStatement(CREATE_TABLE); preparedStatement.execute(); + + preparedStatement.close(); + + preparedStatement = _connection.prepareStatement(CREATE_VER_TABLE); + preparedStatement.execute(); } catch (Exception exception) { @@ -101,4 +109,58 @@ public class PlayerStatsRepository } } } + + public boolean addPlayerVersion(String playerName, String version) + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(INSERT_VER_PLAYER, Statement.RETURN_GENERATED_KEYS); + + preparedStatement.setString(1, playerName); + preparedStatement.setString(2, version); + + int affectedRows = preparedStatement.executeUpdate(); + + if (affectedRows == 0) + { + throw new SQLException("Adding player version record failed, no rows affected."); + } + + return true; + } + catch (Exception exception) + { + exception.printStackTrace(); + + try + { + Thread.sleep(10); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + + return addPlayer(playerName); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } } diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/GroupStatusData.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/GroupStatusData.java index 3ba6d2aef..609168df9 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/GroupStatusData.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/GroupStatusData.java @@ -15,10 +15,47 @@ public class GroupStatusData public int MaxServerNumber; public List EmptyServers = new ArrayList(); + public List KillServers = new ArrayList(); public HashMap Servers = new HashMap(); public void addServer(ServerStatusData serverStatusData) { + if (Servers.containsKey(Integer.parseInt(serverStatusData.Name.split("-")[1]))) + { + ServerStatusData existingServer = Servers.get(Integer.parseInt(serverStatusData.Name.split("-")[1])); + int existingCount = existingServer.Players; + int newCount = serverStatusData.Players; + + if (newCount == 0 || newCount < existingCount) + { + KillServers.add(serverStatusData); + return; + } + else if (existingCount == 0 || newCount > existingCount) + { + KillServers.add(existingServer); + Players -= existingServer.Players; + MaxPlayers -= existingServer.MaxPlayers; + + if (existingServer.Motd != null && (existingServer.Motd.contains("Starting") || existingServer.Motd.contains("Recruiting") || existingServer.Motd.contains("Waiting") || existingServer.Motd.contains("Cup") || existingServer.Motd.isEmpty() || existingServer.Motd.equals(""))) + { + if (existingServer.Players < existingServer.MaxPlayers) + { + // Lobby joinable checking + if (existingServer.Motd.isEmpty() || existingServer.Motd.equals("")) + { + if (existingServer.Players / existingServer.MaxPlayers < 10) + _joinableCount--; + } + else + { + _joinableCount--; + } + } + } + } + } + Players += serverStatusData.Players; MaxPlayers += serverStatusData.MaxPlayers; @@ -37,7 +74,7 @@ public class GroupStatusData _joinableCount++; } } - } + } _totalCount++; diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index 50184f29b..05eece924 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -58,6 +58,15 @@ public class ServerMonitor Collection serverGroups = _repository.retrieveServerGroups(); HashMap groupStatusList = _repository.retrieveGroupStatusData(); + + for (GroupStatusData groupStatus : groupStatusList.values()) + { + for (ServerStatusData serverToKill : groupStatus.KillServers) + { + System.out.println("----DUPLICATE SERVER----> " + serverToKill.Address + ", " + serverToKill.Name); + killServer(serverToKill); + } + } for (ServerGroupData serverGroup : serverGroups) {