diff --git a/Plugins/BuildFiles/EnjinTranslator.xml b/Plugins/BuildFiles/EnjinTranslator.xml index 491280349..bf3c1fb4a 100644 --- a/Plugins/BuildFiles/EnjinTranslator.xml +++ b/Plugins/BuildFiles/EnjinTranslator.xml @@ -18,6 +18,9 @@ + + + diff --git a/Plugins/BuildFiles/common.xml b/Plugins/BuildFiles/common.xml index 59c86a2af..1a95e087b 100644 --- a/Plugins/BuildFiles/common.xml +++ b/Plugins/BuildFiles/common.xml @@ -224,6 +224,10 @@ + + + + @@ -275,11 +279,11 @@ value="mineplex.bungee.BungeeRotator"/> - + diff --git a/Plugins/Libraries/jackson-annotations-2.5.0.jar b/Plugins/Libraries/jackson-annotations-2.5.0.jar new file mode 100644 index 000000000..62521310a Binary files /dev/null and b/Plugins/Libraries/jackson-annotations-2.5.0.jar differ diff --git a/Plugins/Libraries/jackson-core-2.5.1.jar b/Plugins/Libraries/jackson-core-2.5.1.jar new file mode 100644 index 000000000..8c9c4e0e4 Binary files /dev/null and b/Plugins/Libraries/jackson-core-2.5.1.jar differ diff --git a/Plugins/Libraries/jackson-databind-2.5.1.jar b/Plugins/Libraries/jackson-databind-2.5.1.jar new file mode 100644 index 000000000..9b82e3fa5 Binary files /dev/null and b/Plugins/Libraries/jackson-databind-2.5.1.jar differ diff --git a/Plugins/Libraries/jersey-apache-client-1.19.jar b/Plugins/Libraries/jersey-apache-client-1.19.jar new file mode 100644 index 000000000..ac11e75f7 Binary files /dev/null and b/Plugins/Libraries/jersey-apache-client-1.19.jar differ diff --git a/Plugins/Libraries/jersey-bundle-1.17.jar b/Plugins/Libraries/jersey-bundle-1.17.jar new file mode 100644 index 000000000..f25c713ce Binary files /dev/null and b/Plugins/Libraries/jersey-bundle-1.17.jar differ diff --git a/Plugins/Libraries/jersey-multipart-1.19.jar b/Plugins/Libraries/jersey-multipart-1.19.jar new file mode 100644 index 000000000..75d77090a Binary files /dev/null and b/Plugins/Libraries/jersey-multipart-1.19.jar differ diff --git a/Plugins/Libraries/slf4j-api-1.7.10.jar b/Plugins/Libraries/slf4j-api-1.7.10.jar new file mode 100644 index 000000000..ac7da374a Binary files /dev/null and b/Plugins/Libraries/slf4j-api-1.7.10.jar differ diff --git a/Plugins/Mineplex.Bungee.Mineplexer/.classpath b/Plugins/Mineplex.Bungee.Mineplexer/.classpath index dbf2236b6..40645fe06 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/.classpath +++ b/Plugins/Mineplex.Bungee.Mineplexer/.classpath @@ -8,5 +8,6 @@ + diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java index c753a0079..d136dc354 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/motd/MotdManager.java @@ -55,13 +55,18 @@ public class MotdManager implements Listener, Runnable, CustomMotdFactory public void run() { // Add in default MOTD listing to database - if (!_repository.elementExists("MainMotd") || true) + if (!_repository.elementExists("MainMotd")) { + _repository.removeElement("MainMotd"); + List lines = new ArrayList(); - lines.add(" §b§lUltra Sale §a§l50% Off"); // TODO: Implement in-game command to update MOTD? + lines.add(" §e§lSurvival Games §a§lBIG UPDATE!"); // TODO: Implement in-game command to update MOTD? + lines.add(" §d§lHero Sale §a§l33% Off"); + lines.add(" §e§lSurvival Games §a§lBIG UPDATE!"); + updateMainMotd(lines); } - + _motdLines = _repository.getElement("MainMotd").getMotd(); // Update MOTD lines InitialHandler.setCustomMotdFactory(this); } 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 6d09c9d21..63bab7330 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStats.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStats.java @@ -1,25 +1,32 @@ package mineplex.bungee.playerStats; import java.util.HashMap; +import java.util.HashSet; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import mineplex.bungee.playerStats.data.IpInfo; +import mineplex.playerCache.PlayerCache; +import mineplex.playerCache.PlayerInfo; +import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.event.EventHandler; -public class PlayerStats implements Listener +public class PlayerStats implements Listener, Runnable { - private static Object _cacheLock = new Object(); - private Plugin _plugin; private PlayerStatsRepository _repository; - private HashMap _ipCache = new HashMap(); + private PlayerCache _playerCache = new PlayerCache(); + private HashSet _retrievingPlayerInfo = new HashSet(); public PlayerStats(Plugin plugin) { _plugin = plugin; + _plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 5L, TimeUnit.MINUTES); _plugin.getProxy().getPluginManager().registerListener(_plugin, this); _repository = new PlayerStatsRepository(); @@ -33,30 +40,104 @@ public class PlayerStats implements Listener { public void run() { - _repository.addPlayer(event.getPlayer().getName()); - _repository.addPlayerVersion(event.getPlayer().getName(), event.getPlayer().getPendingConnection().getVersion()); - String address = event.getPlayer().getPendingConnection().getAddress().getAddress().getHostAddress(); - /* - boolean addNewIp = false; - int addressId = 0; + UUID uuid = event.getPlayer().getUniqueId(); + String name = event.getPlayer().getName(); + int version = event.getPlayer().getPendingConnection().getVersion(); - synchronized (_cacheLock) + try { - if (_ipCache.containsKey(address)) - addressId = _ipCache.get(address); - else - addNewIp = true; + PlayerInfo playerInfo = null; + IpInfo ipInfo = _repository.getIp(address); + + boolean addOrUpdatePlayer = false; + + playerInfo = _playerCache.getPlayer(uuid); + + if (playerInfo == null) + { + addOrUpdatePlayer = true; + _retrievingPlayerInfo.add(uuid); + } + + if (!addOrUpdatePlayer) + { + if (playerInfo.getVersion() != version) + addOrUpdatePlayer = true; + else if (!playerInfo.getName().equalsIgnoreCase(name)) + addOrUpdatePlayer = true; + } + + if (addOrUpdatePlayer) + { + // Just update? what about other properties? + PlayerInfo updatedPlayerInfo = _repository.getPlayer(uuid, name, version); + + if (playerInfo != null) + { + playerInfo.setName(updatedPlayerInfo.getName()); + playerInfo.setVersion(updatedPlayerInfo.getVersion()); + } + else + playerInfo = updatedPlayerInfo; + + _playerCache.addPlayer(playerInfo); + } + + playerInfo.setSessionId(_repository.updatePlayerStats(playerInfo.getId(), ipInfo.id)); + } + finally + { + _retrievingPlayerInfo.remove(uuid); } - - if (addNewIp) - addressId = _repository.addNewIP(address); - - _repository.addPlayerIP(event.getPlayer().getName(), addressId); - */ - - _repository.addPlayerIP(event.getPlayer().getName(), address); } }); } + + @EventHandler + public void playerDisconnect(final PlayerDisconnectEvent event) + { + _plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable() + { + public void run() + { + UUID uuid = event.getPlayer().getUniqueId(); + + PlayerInfo playerInfo = null; + + playerInfo = _playerCache.getPlayer(uuid); + + int timeout = 5; + + while (playerInfo == null && _retrievingPlayerInfo.contains(uuid) && timeout <= 5) + { + playerInfo = _playerCache.getPlayer(uuid); + + if (playerInfo != null) + break; + + System.out.println("ERROR - Player disconnecting and isn't in cache... sleeping"); + + try + { + Thread.sleep(500); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + + timeout++; + } + + _repository.updatePlayerSession(playerInfo.getSessionId()); + } + }); + } + + @Override + public void run() + { + _playerCache.clean(); + } } 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 c4feab3a3..1e9f765f5 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java @@ -3,142 +3,106 @@ package mineplex.bungee.playerStats; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.UUID; + +import mineplex.bungee.playerStats.data.IpInfo; +import mineplex.playerCache.PlayerInfo; public class PlayerStatsRepository { private Connection _connection = null; - private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; + private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true"; private String _userName = "root"; private String _password = "tAbechAk3wR7tuTh"; - 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 INT, PRIMARY KEY (id), UNIQUE KEY unique_player (playerName));"; - private static String INSERT_VER_PLAYER = "INSERT INTO PlayerVersion (playerName, version) values(?, ?);"; - private static String UPDATE_VER_PLAYER = "UPDATE PlayerVersion SET version = ? WHERE playerName = ?;"; + private static String INSERT_PLAYERINFO = "INSERT INTO playerInfo (uuid, name, version) VALUES (?, ?, ?);"; + private static String SELECT_PLAYERINFO = "SELECT id, name, version FROM playerInfo WHERE uuid = ?;"; + private static String UPDATE_PLAYERINFO = "UPDATE playerInfo SET name = ?, version = ? WHERE id = ?;"; - private static String CREATE_IP_TABLE = "CREATE TABLE IF NOT EXISTS PlayerIP (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), ip VARCHAR(20), PRIMARY KEY (id), UNIQUE INDEX unique_player_ip (playerName, ip));"; - private static String INSERT_IP_PLAYER = "INSERT IGNORE INTO PlayerIP (playerName, ip) values(?, ?);"; - //private static String INSERT_IP_PLAYER = "INSERT IGNORE INTO playerIp (playerName, ip) values(?, ?);"; - //private static String INSERT_IP_PLAYER = "INSERT IGNORE INTO playerIp (playerName, ip) values(?, ?);"; + private static String INSERT_IPINFO = "INSERT INTO ipInfo (ipAddress) VALUES (?);"; + private static String SELECT_IPINFO = "SELECT id FROM ipInfo WHERE ipAddress = ?;"; + + private static String UPDATE_PLAYERSTATS = "INSERT IGNORE INTO playerIps (playerInfoId, ipInfoId, date) VALUES (?, ?, curdate());" + + "INSERT IGNORE INTO playerUniqueLogins (playerInfoId, day) values(?, curdate());" + + "INSERT IGNORE INTO playerLoginSessions (playerInfoId, loginTime) values(?, now());"; + + private static String UPDATE_LOGINSESSION = "UPDATE playerLoginSessions SET timeInGame = TIME_TO_SEC(TIMEDIFF(now(), loginTime)) / 60 WHERE id = ?;"; public void initialize() { - PreparedStatement preparedStatement = null; - try { if (_connection == null || _connection.isClosed()) _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - // Create table - preparedStatement = _connection.prepareStatement(CREATE_TABLE); - preparedStatement.execute(); - - preparedStatement.close(); - - preparedStatement = _connection.prepareStatement(CREATE_VER_TABLE); - preparedStatement.execute(); - - preparedStatement.close(); - - preparedStatement = _connection.prepareStatement(CREATE_IP_TABLE); - preparedStatement.execute(); } catch (Exception exception) { exception.printStackTrace(); } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } System.out.println("Initialized PlayerStats."); } - public boolean addPlayer(String playerName) + public PlayerInfo getPlayer(UUID uuid, String name, int version) { + PlayerInfo playerInfo = null; PreparedStatement preparedStatement = null; + ResultSet resultSet = null; - try + try { if (_connection == null || _connection.isClosed()) _connection = DriverManager.getConnection(_connectionString, _userName, _password); - preparedStatement = _connection.prepareStatement(INSERT_PLAYER, Statement.RETURN_GENERATED_KEYS); + preparedStatement = _connection.prepareStatement(SELECT_PLAYERINFO); - preparedStatement.setString(1, playerName); + preparedStatement.setString(1, uuid.toString()); - int affectedRows = preparedStatement.executeUpdate(); + resultSet = preparedStatement.executeQuery(); - if (affectedRows == 0) + while (resultSet.next()) { - throw new SQLException("Adding unique player record failed, no rows affected."); - } - - return true; - } - catch (Exception exception) - { - exception.printStackTrace(); - - return false; - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + playerInfo = new PlayerInfo(resultSet.getInt(1), uuid, resultSet.getString(2), resultSet.getInt(3)); } - } - } - - public void addPlayerVersion(String playerName, int version) - { - PreparedStatement preparedStatement = null; - - try - { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - preparedStatement = _connection.prepareStatement(UPDATE_VER_PLAYER); + resultSet.close(); + preparedStatement.close(); - preparedStatement.setInt(1, version); - preparedStatement.setString(2, playerName); - - int affectedRows = preparedStatement.executeUpdate(); - - if (affectedRows == 0) + if (playerInfo == null) { - preparedStatement.close(); - preparedStatement = _connection.prepareStatement(INSERT_VER_PLAYER, Statement.RETURN_GENERATED_KEYS); - - preparedStatement.setString(1, playerName); - preparedStatement.setInt(2, version); + preparedStatement = _connection.prepareStatement(INSERT_PLAYERINFO, Statement.RETURN_GENERATED_KEYS); + preparedStatement.setString(1, uuid.toString()); + preparedStatement.setString(2, name); + preparedStatement.setInt(3, version); preparedStatement.executeUpdate(); + + int id = 0; + + resultSet = preparedStatement.getGeneratedKeys(); + + while (resultSet.next()) + { + id = resultSet.getInt(1); + } + + playerInfo = new PlayerInfo(id, uuid, name, version); + + resultSet.close(); + preparedStatement.close(); + } + else if (!playerInfo.getName().equalsIgnoreCase(name) || playerInfo.getVersion() != version) + { + preparedStatement = _connection.prepareStatement(UPDATE_PLAYERINFO); + preparedStatement.setString(1, name); + preparedStatement.setInt(2, version); + preparedStatement.setInt(3, playerInfo.getId()); + + preparedStatement.executeUpdate(); + preparedStatement.close(); } } catch (Exception exception) @@ -158,79 +122,197 @@ public class PlayerStatsRepository e.printStackTrace(); } } + + if (resultSet != null) + { + try + { + resultSet.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } } + + return playerInfo; } - - public void addPlayerIP(String playerName, String address) + + public IpInfo getIp(String ipAddress) { + IpInfo ipInfo = null; PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(SELECT_IPINFO); + preparedStatement.setString(1, ipAddress); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + ipInfo = new IpInfo(); + ipInfo.id = resultSet.getInt(1); + ipInfo.ipAddress = ipAddress; + } + + resultSet.close(); + preparedStatement.close(); + + if (ipInfo == null) + { + preparedStatement = _connection.prepareStatement(INSERT_IPINFO, Statement.RETURN_GENERATED_KEYS); + preparedStatement.setString(1, ipAddress); + + preparedStatement.executeUpdate(); + + int id = 0; + + resultSet = preparedStatement.getGeneratedKeys(); + + while (resultSet.next()) + { + id = resultSet.getInt(1); + } + + ipInfo = new IpInfo(); + ipInfo.id = id; + ipInfo.ipAddress = ipAddress; + + resultSet.close(); + preparedStatement.close(); + } + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + if (resultSet != null) + { + try + { + resultSet.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + return ipInfo; + } + + public int updatePlayerStats(int playerId, int ipId) + { + Statement statement = null; + ResultSet resultSet= null; try { if (_connection == null || _connection.isClosed()) _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + statement = _connection.createStatement(); - preparedStatement = _connection.prepareStatement(INSERT_IP_PLAYER, Statement.RETURN_GENERATED_KEYS); + String queryString = UPDATE_PLAYERSTATS; + queryString = queryString.replaceFirst("\\?", playerId + ""); + queryString = queryString.replaceFirst("\\?", ipId + ""); + queryString = queryString.replaceFirst("\\?", playerId + ""); + queryString = queryString.replaceFirst("\\?", playerId + ""); - preparedStatement.setString(1, playerName); - preparedStatement.setString(2, address); + statement.executeUpdate(queryString, Statement.RETURN_GENERATED_KEYS); - preparedStatement.executeUpdate(); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) + statement.getMoreResults(); + statement.getMoreResults(); + resultSet = statement.getGeneratedKeys(); + + while (resultSet.next()) { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + return resultSet.getInt(1); } } - } - - public int addNewIP(String address) - { - PreparedStatement preparedStatement = null; - - try - { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(INSERT_IP_PLAYER, Statement.RETURN_GENERATED_KEYS); - - preparedStatement.setString(1, address); - - preparedStatement.executeUpdate(); - } catch (Exception exception) { exception.printStackTrace(); } finally { - if (preparedStatement != null) + try { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } + if (statement != null) + statement.close(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + + try + { + if (resultSet != null) + resultSet.close(); + } + catch (Exception exception) + { + exception.printStackTrace(); } } return -1; } + + public void updatePlayerSession(int loginSessionId) + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(UPDATE_LOGINSESSION); + preparedStatement.setInt(1, loginSessionId); + + preparedStatement.executeUpdate(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/data/IpInfo.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/data/IpInfo.java new file mode 100644 index 000000000..ab2c09968 --- /dev/null +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/data/IpInfo.java @@ -0,0 +1,7 @@ +package mineplex.bungee.playerStats.data; + +public class IpInfo +{ + public int id; + public String ipAddress; +} diff --git a/Plugins/Mineplex.BungeeRotator/.classpath b/Plugins/Mineplex.BungeeRotator/.classpath index 7692a6421..e26939c64 100644 --- a/Plugins/Mineplex.BungeeRotator/.classpath +++ b/Plugins/Mineplex.BungeeRotator/.classpath @@ -2,12 +2,12 @@ - - - + + + diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java index 795d23fdf..d08510506 100644 --- a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java @@ -26,11 +26,11 @@ import mineplex.serverdata.data.BungeeServer; import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ServerManager; -import mineplex.serverdata.servers.ServerRepository; public class BungeeRotator { private static DataRepository _repository; + private static PlayerStatsRepository _ipRepository; //private static ServerRepository _repository = null; private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); @@ -39,12 +39,6 @@ public class BungeeRotator public static void main(String args[]) { - /* - IPGeoData recor = new HttpCallBase("http://www.freegeoip.net/json/124.149.22.183").Execute(IPGeoData.class); - - System.out.println(recor.country_name + " " + recor.region_name); - */ - try { Class.forName("com.mysql.jdbc.Driver"); @@ -78,6 +72,8 @@ public class BungeeRotator _repository = new RedisDataRepository(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(), Region.ALL, BungeeServer.class, "bungeeServers"); + _ipRepository = new PlayerStatsRepository(); + BungeeSorter bungeeSorter = new BungeeSorter(); int maxRecordCount = 10; @@ -96,6 +92,9 @@ public class BungeeRotator for (BungeeServer server : bungeeServers) { + if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1")) + continue; + totalPlayers += server.getPlayerCount(); if (server.getRegion() == Region.US) @@ -119,6 +118,9 @@ public class BungeeRotator for (BungeeServer server : bungeeServers) { + if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1")) + continue; + if (usServers.size() < maxRecordCount && server.getRegion() == Region.US) { if (usServers.size() >= 2 && server.getPlayerCount() > 900) @@ -207,7 +209,28 @@ public class BungeeRotator log("Deleted " + recordsToDelete.size() + " records."); } } - + + List updatedAddresses = new ArrayList(1000); + + for (IpInfo ipInfo : _ipRepository.getIpAddresses()) + { + IPGeoData recor = new HttpCallBase("http://www.freegeoip.net/json/" + ipInfo.ipAddress).Execute(IPGeoData.class); + ipInfo.countryCode = recor.country_code; + ipInfo.countryName = recor.country_name; + ipInfo.regionCode = recor.region_code; + ipInfo.regionName = recor.region_name; + ipInfo.city = recor.city; + ipInfo.zipCode = recor.zip_code; + ipInfo.timeZone = recor.time_zone; + ipInfo.latitude = recor.latitude; + ipInfo.longitude = recor.longitude; + ipInfo.metroCode = recor.metro_code; + + updatedAddresses.add(ipInfo); + } + + _ipRepository.updateIps(updatedAddresses); + try { Thread.sleep(15000); @@ -220,6 +243,7 @@ public class BungeeRotator } catch (Exception ex) { + ex.printStackTrace(); log("Error doing something : " + ex.getMessage()); try diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java index c8265c0a2..9988f681c 100644 --- a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java @@ -8,7 +8,7 @@ public class IPGeoData public String region_code; public String region_name; public String city; - public int zip_code; + public String zip_code; public String time_zone; public double latitude; public double longitude; diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IpInfo.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IpInfo.java new file mode 100644 index 000000000..44ad87a97 --- /dev/null +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IpInfo.java @@ -0,0 +1,17 @@ +package mineplex.bungee; + +public class IpInfo +{ + public int id; + public String ipAddress; + public String countryCode; + public String countryName; + public String regionCode; + public String regionName; + public String city; + public String zipCode; + public String timeZone; + public double latitude; + public double longitude; + public int metroCode; +} diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java new file mode 100644 index 000000000..f5b298ae9 --- /dev/null +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java @@ -0,0 +1,146 @@ +package mineplex.bungee; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class PlayerStatsRepository +{ + private Connection _connection = null; + private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true"; + private String _userName = "root"; + private String _password = "tAbechAk3wR7tuTh"; + + private static String SELECT_IPINFO = "SELECT id, ipAddress FROM ipInfo WHERE regionName IS NULL LIMIT 1000;"; + private static String UPDATE_IPINFO = "UPDATE ipInfo SET countryCode = ?, countryName = ?, regionCode = ?, regionName = ?, city = ?, zipCode = ?, timeZone = ?, latitude = ?, longitude = ?, metroCode = ? WHERE id = ?;"; + + public void initialize() + { + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + + System.out.println("Initialized PlayerStats."); + } + + public List getIpAddresses() + { + List ipinfos = new ArrayList(1000); + PreparedStatement preparedStatement = null; + ResultSet resultSet = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(SELECT_IPINFO); + + resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + IpInfo ipInfo = new IpInfo(); + ipInfo.id = resultSet.getInt(1); + ipInfo.ipAddress = resultSet.getString(2); + + ipinfos.add(ipInfo); + } + + resultSet.close(); + preparedStatement.close(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + + if (resultSet != null) + { + try + { + resultSet.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + return ipinfos; + } + + public void updateIps(List ips) + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(UPDATE_IPINFO); + + for (IpInfo ipInfo : ips) + { + preparedStatement.setString(1, ipInfo.countryCode); + preparedStatement.setString(2, ipInfo.countryName); + preparedStatement.setString(3, ipInfo.regionCode); + preparedStatement.setString(4, ipInfo.regionName); + preparedStatement.setString(5, ipInfo.city); + preparedStatement.setString(6, ipInfo.zipCode); + preparedStatement.setString(7, ipInfo.timeZone); + preparedStatement.setDouble(8, ipInfo.latitude); + preparedStatement.setDouble(9, ipInfo.longitude); + preparedStatement.setInt(10, ipInfo.metroCode); + preparedStatement.setInt(11, ipInfo.id); + + preparedStatement.addBatch(); + } + + preparedStatement.executeBatch(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } +} diff --git a/Plugins/Mineplex.ChestConverter/.classpath b/Plugins/Mineplex.ChestConverter/.classpath new file mode 100644 index 000000000..49e473eb4 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.classpath @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Plugins/Mineplex.ChestConverter/.externalToolBuilders/Chest.launch b/Plugins/Mineplex.ChestConverter/.externalToolBuilders/Chest.launch new file mode 100644 index 000000000..ecc42cfd7 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.externalToolBuilders/Chest.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/Plugins/Mineplex.ChestConverter/.externalToolBuilders/New_Builder.launch b/Plugins/Mineplex.ChestConverter/.externalToolBuilders/New_Builder.launch new file mode 100644 index 000000000..0c6e0f696 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.externalToolBuilders/New_Builder.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/Plugins/Mineplex.ChestConverter/.externalToolBuilders/ServerMonitor.launch b/Plugins/Mineplex.ChestConverter/.externalToolBuilders/ServerMonitor.launch new file mode 100644 index 000000000..0c6e0f696 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.externalToolBuilders/ServerMonitor.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/Plugins/Mineplex.ChestConverter/.project b/Plugins/Mineplex.ChestConverter/.project new file mode 100644 index 000000000..d1d373e2c --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.project @@ -0,0 +1,37 @@ + + + Mineplex.ChestConverter + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/ServerMonitor.launch + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + auto,full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/Chest.launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Plugins/Mineplex.ChestConverter/.settings/org.eclipse.core.resources.prefs b/Plugins/Mineplex.ChestConverter/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 000000000..99f26c020 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/Plugins/Mineplex.ChestConverter/.settings/org.eclipse.jdt.core.prefs b/Plugins/Mineplex.ChestConverter/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..7341ab168 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Plugins/Mineplex.ChestConverter/Mineplex.ServerMonitor.iml b/Plugins/Mineplex.ChestConverter/Mineplex.ServerMonitor.iml new file mode 100644 index 000000000..53e69d8e1 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/Mineplex.ServerMonitor.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/ChestConverter.java b/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/ChestConverter.java new file mode 100644 index 000000000..a9ddea664 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/ChestConverter.java @@ -0,0 +1,46 @@ +package mineplex.chestConverter; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.logging.Logger; + +public class ChestConverter +{ + private static ChestConverterRepository _repository = null; + private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); + + public static void main (String args[]) + { + _repository = new ChestConverterRepository(); + int count = 5000; + + while (true) + { + long time = System.currentTimeMillis(); + HashMap playerMap = _repository.retrieveKeyInventoryBatch(count); + + if (playerMap.size() == 0) + return; + + _repository.incrementClient(playerMap, false); + _repository.deleteKeys(count); + try + { + log("Natural sleep. " + count + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds."); + Thread.sleep(250); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + + break; + } + } + + private static void log(String message) + { + System.out.println("[" + _dateFormat.format(new Date()) + "] " + message); + } +} diff --git a/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/ChestConverterRepository.java b/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/ChestConverterRepository.java new file mode 100644 index 000000000..0970b1b4e --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/ChestConverterRepository.java @@ -0,0 +1,316 @@ +package mineplex.chestConverter; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map.Entry; + +public class ChestConverterRepository +{ + private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account"; + private String _userName = "root"; + private String _password = "tAbechAk3wR7tuTh"; + + private static String RETRIEVE_CHESTS = "SELECT A.uuid, count FROM accountInventory INNER JOIN accounts AS A ON A.id = accountInventory.accountId WHERE itemId = 56 AND count > 0 ORDER BY accountInventory.id LIMIT ?;"; + private static String RETRIEVE_KEYS = "SELECT A.uuid, count FROM accountInventory INNER JOIN accounts AS A ON A.id = accountInventory.accountId WHERE itemId = 67 AND count > 0 ORDER BY accountInventory.id LIMIT ?;"; + + private static String DELETE_CHESTS = "DELETE FROM accountInventory WHERE itemId = 56 ORDER BY accountInventory.id LIMIT ?"; + private static String DELETE_KEYS = "DELETE FROM accountInventory WHERE itemId = 67 ORDER BY accountInventory.id LIMIT ?"; + + private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);"; + private static String UPDATE_CLIENT_INVENTORY = "UPDATE accountInventory AS AI INNER JOIN accounts ON AI.accountId = accounts.id SET AI.count = AI.count + ? WHERE accounts.uuid = ? AND AI.itemId = ?;"; + + private static Connection _connection; + + public ChestConverterRepository() + { + PreparedStatement preparedStatement = null; + + try + { + Class.forName("com.mysql.jdbc.Driver"); + + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } + + public HashMap retrieveChestInventoryBatch(int count) + { + HashMap playerList = new HashMap(); + + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(RETRIEVE_CHESTS); + preparedStatement.setInt(1, count); + ResultSet resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + playerList.put(resultSet.getString(1), resultSet.getInt(2)); + } + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + return playerList; + } + + public HashMap retrieveKeyInventoryBatch(int count) + { + HashMap playerList = new HashMap(); + + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(RETRIEVE_KEYS); + preparedStatement.setInt(1, count); + ResultSet resultSet = preparedStatement.executeQuery(); + + while (resultSet.next()) + { + playerList.put(resultSet.getString(1), resultSet.getInt(2)); + } + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + + return playerList; + } + + public void incrementClient(HashMap playerList, boolean chest) + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(UPDATE_CLIENT_INVENTORY); + + for (Entry entry : playerList.entrySet()) + { + preparedStatement.setInt(1, entry.getValue()); + preparedStatement.setString(2, entry.getKey()); + preparedStatement.setInt(3, chest ? 690 : 692); + + preparedStatement.addBatch(); + + if (chest) + { + if (entry.getValue() > 20) + { + preparedStatement.setInt(1, 1); + preparedStatement.setString(2, entry.getKey()); + preparedStatement.setInt(3, 692); + + preparedStatement.addBatch(); + } + + if (entry.getValue() > 50) + { + preparedStatement.setInt(1, 1); + preparedStatement.setString(2, entry.getKey()); + preparedStatement.setInt(3, 691); + + preparedStatement.addBatch(); + } + } + } + + int[] rowsAffected = preparedStatement.executeBatch(); + int i = 0; + + preparedStatement.close(); + preparedStatement = _connection.prepareStatement(INSERT_CLIENT_INVENTORY); + + for (Entry entry : playerList.entrySet()) + { + if (rowsAffected[i] < 1) + { + preparedStatement.setInt(1, chest ? 690 : 692); + preparedStatement.setInt(2, entry.getValue()); + preparedStatement.setString(3, entry.getKey()); + + preparedStatement.addBatch(); + + if (chest) + { + if (entry.getValue() > 20) + { + preparedStatement.setInt(1, 692); + preparedStatement.setInt(2, 1); + preparedStatement.setString(3, entry.getKey()); + + preparedStatement.addBatch(); + } + + if (entry.getValue() > 50) + { + preparedStatement.setInt(1, 691); + preparedStatement.setInt(2, 1); + preparedStatement.setString(3, entry.getKey()); + + preparedStatement.addBatch(); + } + } + } + + i++; + } + + preparedStatement.executeBatch(); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } + + public void deleteChests(int count) + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(DELETE_CHESTS); + preparedStatement.setInt(1, count); + preparedStatement.executeUpdate(); + + System.out.println("Deleting " + count + " inventory records."); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } + + public void deleteKeys(int count) + { + PreparedStatement preparedStatement = null; + + try + { + if (_connection == null || _connection.isClosed()) + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + + preparedStatement = _connection.prepareStatement(DELETE_KEYS); + preparedStatement.setInt(1, count); + preparedStatement.executeUpdate(); + + System.out.println("Deleting " + count + " inventory records."); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + if (preparedStatement != null) + { + try + { + preparedStatement.close(); + } + catch (SQLException e) + { + e.printStackTrace(); + } + } + } + } +} diff --git a/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/GenericRunnable.java b/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/GenericRunnable.java new file mode 100644 index 000000000..987c74db4 --- /dev/null +++ b/Plugins/Mineplex.ChestConverter/src/mineplex/chestConverter/GenericRunnable.java @@ -0,0 +1,6 @@ +package mineplex.chestConverter; + +public interface GenericRunnable +{ + void run(T t); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java index 121ba66d7..92e2ea3cb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniDbClientPlugin.java @@ -22,4 +22,9 @@ public abstract class MiniDbClientPlugin extends MiniCl } public abstract void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException; + + public CoreClientManager getClientManager() + { + return ClientManager; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/AccountCache.java b/Plugins/Mineplex.Core/src/mineplex/core/account/AccountCache.java new file mode 100644 index 000000000..e6ac95b35 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/AccountCache.java @@ -0,0 +1,33 @@ +package mineplex.core.account; + +import java.util.UUID; + +import mineplex.serverdata.data.Data; + +public class AccountCache implements Data +{ + private UUID _uuid; + private Integer _id; + + public AccountCache(UUID uuid, int id) + { + _uuid = uuid; + _id = id; + } + + public UUID getUUID() + { + return _uuid; + } + + public int getId() + { + return _id; + } + + @Override + public String getDataId() + { + return _uuid.toString(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java index 1da48fd9e..ebec4be13 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java @@ -6,7 +6,7 @@ import org.bukkit.entity.Player; public class CoreClient { - private int _accountId; + private int _accountId = -1; private String _name; private Player _player; private Rank _rank; @@ -37,7 +37,7 @@ public class CoreClient _player = player; } - public int GetAccountId() + public int getAccountId() { return _accountId; } @@ -48,7 +48,7 @@ public class CoreClient _player = null; } - public void SetAccountId(int accountId) + public void setAccountId(int accountId) { _accountId = accountId; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index ff0b94dba..f0715f5c7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -21,6 +21,10 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.timing.TimingManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.serverdata.Region; +import mineplex.serverdata.data.BungeeServer; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ServerManager; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -43,6 +47,7 @@ public class CoreClientManager extends MiniPlugin private AccountRepository _repository; private NautHashMap _clientList; private HashSet _duplicateLoginGlitchPreventionList; + private RedisDataRepository _accountCacheRepository; private NautHashMap _loginProcessors = new NautHashMap(); @@ -59,6 +64,9 @@ public class CoreClientManager extends MiniPlugin _repository = new AccountRepository(plugin, webServer); _clientList = new NautHashMap(); _duplicateLoginGlitchPreventionList = new HashSet(); + + _accountCacheRepository = new RedisDataRepository(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(), + Region.ALL, AccountCache.class, "accountCache"); } public AccountRepository getRepository() @@ -155,7 +163,7 @@ public class CoreClientManager extends MiniPlugin catch(Exception exception) { event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute."); - System.out.println(exception.getMessage()); + exception.printStackTrace(); } finally { @@ -189,34 +197,47 @@ public class CoreClientManager extends MiniPlugin { public void run() { - ClientToken token = null; - Gson gson = new Gson(); - - // Fails if not in DB and if duplicate. - UUID uuid = loadUUIDFromDB(playerName); - - if (uuid == null) - uuid = UUIDFetcher.getUUIDOf(playerName); - - String response = _repository.getClientByUUID(uuid); - token = gson.fromJson(response, ClientToken.class); - - client.SetAccountId(token.AccountId); - client.SetRank(Rank.valueOf(token.Rank)); - - _repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName()); - - // JSON sql response - Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); - - Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() + try { - public void run() + ClientToken token = null; + Gson gson = new Gson(); + + // Fails if not in DB and if duplicate. + UUID uuid = loadUUIDFromDB(playerName); + + if (uuid == null) + uuid = UUIDFetcher.getUUIDOf(playerName); + + String response = _repository.getClientByUUID(uuid); + token = gson.fromJson(response, ClientToken.class); + + client.SetRank(Rank.valueOf(token.Rank)); + + client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName())); + + // JSON sql response + Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); + + if (client.getAccountId() > 0) + _accountCacheRepository.addElement(new AccountCache(uuid, client.getAccountId())); + + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() { - if (runnable != null) - runnable.run(); - } - }); + public void run() + { + if (runnable != null) + runnable.run(); + } + }); + } + catch (Exception exception) + { + exception.printStackTrace(); + } + finally + { + runnable.run(); + } } }); } @@ -234,7 +255,7 @@ public class CoreClientManager extends MiniPlugin { public void run() { - _repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName()); + client.setAccountId(_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName())); _clientLoginLock.remove(client.GetPlayerName()); } }); @@ -244,8 +265,7 @@ public class CoreClientManager extends MiniPlugin TimingManager.stop(client.GetPlayerName() + " GetClient."); token = gson.fromJson(response, ClientToken.class); - - client.SetAccountId(token.AccountId); + client.SetRank(Rank.valueOf(token.Rank)); // _repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString()); @@ -272,6 +292,11 @@ public class CoreClientManager extends MiniPlugin TimingManager.stop(client.GetPlayerName() + " LoadClient Total."); + System.out.println(client.GetPlayerName() + "'s account id = " + client.getAccountId()); + + if (client.getAccountId() > 0) + _accountCacheRepository.addElement(new AccountCache(uuid, client.getAccountId())); + return !_clientLoginLock.containsKey(client.GetPlayerName()); } @@ -473,4 +498,9 @@ public class CoreClientManager extends MiniPlugin return client.GetRank().Has(rank); } + + public int getCachedClientAccountId(UUID uuid) + { + return _accountCacheRepository.getElement(uuid.toString()).getId(); + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/ILoginProcessor.java b/Plugins/Mineplex.Core/src/mineplex/core/account/ILoginProcessor.java index 9ac886d69..aca0eb341 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/ILoginProcessor.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/ILoginProcessor.java @@ -9,5 +9,5 @@ public interface ILoginProcessor void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException; - String getQuery(String uuid, String name); + String getQuery(int accountId, String uuid, String name); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index fd1aa01e3..bb8f58163 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -19,7 +19,6 @@ import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UUIDFetcher; import mineplex.core.database.DBPool; import mineplex.core.database.DatabaseRunnable; import mineplex.core.database.RepositoryBase; @@ -32,7 +31,7 @@ import mineplex.core.server.remotecall.JsonWebCall; public class AccountRepository extends RepositoryBase { private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));"; - private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);"; + private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now());"; private static String UPDATE_ACCOUNT_RANK = "UPDATE accounts SET rank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;"; private static String UPDATE_ACCOUNT_RANK_DONOR = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;"; private static String UPDATE_ACCOUNT_RANK_PERM = "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;"; @@ -56,13 +55,41 @@ public class AccountRepository extends RepositoryBase //executeUpdate(CREATE_ACCOUNT_TABLE); } - public void login(NautHashMap loginProcessors, String uuid, String name) + public int login(NautHashMap loginProcessors, String uuid, String name) { + int accountId = -1; try ( Connection connection = getConnection(); Statement statement = connection.createStatement() ) { + statement.execute("SELECT id FROM accounts WHERE accounts.uuid = '" + uuid + "' LIMIT 1;"); + ResultSet resultSet = statement.getResultSet(); + + while (resultSet.next()) + { + accountId = resultSet.getInt(1); + } + + if (accountId == -1) + { + final List tempList = new ArrayList(1); + + executeInsert(ACCOUNT_LOGIN_NEW, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + tempList.add(resultSet.getInt(1)); + } + } + },new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name)); + + accountId = tempList.get(0); + } + /* boolean statementStatus = statement.execute( "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';" @@ -75,10 +102,11 @@ public class AccountRepository extends RepositoryBase ); */ - String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';"; + String loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE id = '" + accountId + "';"; + for (ILoginProcessor loginProcessor : loginProcessors.values()) { - loginString += loginProcessor.getQuery(uuid, name); + loginString += loginProcessor.getQuery(accountId, uuid, name); } statement.execute(loginString); @@ -108,25 +136,22 @@ public class AccountRepository extends RepositoryBase System.out.println("Done"); */ - - boolean accountExists = statement.getUpdateCount() != 0; + statement.getUpdateCount(); statement.getMoreResults(); + for (ILoginProcessor loginProcessor : loginProcessors.values()) { loginProcessor.processLoginResultSet(name, statement.getResultSet()); statement.getMoreResults(); } - - if (!accountExists) - { - executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name)); - } } catch (Exception exception) { exception.printStackTrace(); } + + return accountId; } public String GetClient(String name, UUID uuid, String ipAddress) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java index fd45ee873..fe74c528b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java @@ -78,8 +78,8 @@ public class BenefitManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { - return "SELECT benefit FROM rankBenefits WHERE rankBenefits.uuid = '" + uuid + "';"; + return "SELECT benefit FROM rankBenefits WHERE rankBenefits.accountId = '" + accountId + "';"; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java index 5affc2a0b..54723697b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java @@ -11,7 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin; public class BenefitManagerRepository extends RepositoryBase { - // private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), benefit VARCHAR(100), PRIMARY KEY (id), INDEX rankUuid (uuid));"; + private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, accountId INT, benefit VARCHAR(100), PRIMARY KEY (id), INDEX rankUuid (uuid));"; private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index eab9840f2..ca1a57c4b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -116,7 +116,7 @@ public abstract class RepositoryBase implements Listener } catch (SQLException exception) { - executeInsert(query, callable, columns); + exception.printStackTrace(); } catch (Exception exception) { @@ -142,7 +142,7 @@ public abstract class RepositoryBase implements Listener } catch (SQLException exception) { - executeQuery(statement, callable, columns); + exception.printStackTrace(); } catch (Exception exception) { @@ -162,7 +162,7 @@ public abstract class RepositoryBase implements Listener } catch (SQLException exception) { - executeQuery(query, callable, columns); + exception.printStackTrace(); } catch (Exception exception) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java index 15219684c..3b6620451 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/CoinCommand.java @@ -4,6 +4,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -27,34 +28,39 @@ public class CoinCommand extends CommandBase return; } - String targetName = args[0]; - String coinsString = args[1]; + final String targetName = args[0]; + final String coinsString = args[1]; Player target = UtilPlayer.searchExact(targetName); if (target == null) { - UUID uuid = UUIDFetcher.getUUIDOf(targetName); - if (uuid != null) + Plugin.getClientManager().loadClientByName(targetName, new Runnable() { - rewardCoins(caller, null, targetName, uuid, coinsString); - } - else - { - UtilPlayer.message(caller, F.main("Coin", "Could not find player " + F.name(targetName))); - } + public void run() + { + CoreClient client = Plugin.getClientManager().Get(targetName); + + if (client != null) + rewardCoins(caller, null, targetName, client.getAccountId(), coinsString); + else + { + UtilPlayer.message(caller, F.main("Coin", "Could not find player " + F.name(targetName))); + } + } + }); } else { - rewardCoins(caller, target, target.getName(), target.getUniqueId(), coinsString); + rewardCoins(caller, target, target.getName(), Plugin.getClientManager().Get(target).getAccountId(), coinsString); } } - private void rewardCoins(final Player caller, final Player target, final String targetName, final UUID uuid, String coinsString) + private void rewardCoins(final Player caller, final Player target, final String targetName, final int accountId, String coinsString) { try { int coins = Integer.parseInt(coinsString); - rewardCoins(caller, target, targetName, uuid, coins); + rewardCoins(caller, target, targetName, accountId, coins); } catch (Exception e) { @@ -62,7 +68,7 @@ public class CoinCommand extends CommandBase } } - private void rewardCoins(final Player caller, final Player target, final String targetName, final UUID uuid, final int coins) + private void rewardCoins(final Player caller, final Player target, final String targetName, final int accountId, final int coins) { Plugin.RewardCoins(new Callback() { @@ -75,6 +81,6 @@ public class CoinCommand extends CommandBase UtilPlayer.message(target, F.main("Coin", F.name(caller.getName()) + " gave you " + F.elem(coins + " Coins") + ".")); } } - }, caller.getName(), targetName, uuid, coins); + }, caller.getName(), targetName, accountId, coins); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index cff2bdd9c..c82e72530 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -58,7 +58,7 @@ public class DonationManager extends MiniDbClientPlugin //_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins()); } - public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final UUID uuid, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase) + public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final int accountId, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase) { final Donor donor = Bukkit.getPlayerExact(name) != null ? Get(name) : null; @@ -89,7 +89,7 @@ public class DonationManager extends MiniDbClientPlugin if (callback != null) callback.run(response); } - }, name, uuid.toString(), packageName, coinPurchase, cost); + }, name, accountId, packageName, coinPurchase, cost); } public void PurchaseKnownSalesPackage(final Callback callback, final String name, final UUID uuid, final int cost, final int salesPackageId) @@ -196,12 +196,12 @@ public class DonationManager extends MiniDbClientPlugin _gemQueue.clear(); } - public void RewardCoins(Callback callback, String caller, String name, UUID uuid, int amount) + public void RewardCoins(Callback callback, String caller, String name, int accountId, int amount) { - RewardCoins(callback, caller, name, uuid, amount, true); + RewardCoins(callback, caller, name, accountId, amount, true); } - public void RewardCoins(final Callback callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal) + public void RewardCoins(final Callback callback, final String caller, final String name, final int accountId, final int amount, final boolean updateTotal) { _repository.rewardCoins(new Callback() { @@ -223,7 +223,7 @@ public class DonationManager extends MiniDbClientPlugin callback.run(true); } } - }, caller, name, uuid.toString(), amount); + }, caller, name, accountId, amount); } public void RewardCoinsLater(final String caller, final Player player, final int amount) @@ -266,7 +266,7 @@ public class DonationManager extends MiniDbClientPlugin continue; //Actually Add Gems - RewardCoins(null, caller, player.getName(), player.getUniqueId(), total, false); + RewardCoins(null, caller, player.getName(), ClientManager.Get(player).getAccountId(), total, false); System.out.println("Queue Added [" + player + "] with Coins [" + total + "] for [" + caller + "]"); @@ -278,12 +278,12 @@ public class DonationManager extends MiniDbClientPlugin _coinQueue.clear(); } - public void RewardGold(Callback callback, String caller, String name, UUID uuid, int amount) + public void RewardGold(Callback callback, String caller, String name, int accountId, int amount) { - RewardGold(callback, caller, name, uuid, amount, true); + RewardGold(callback, caller, name, accountId, amount, true); } - public void RewardGold(final Callback callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal) + public void RewardGold(final Callback callback, final String caller, final String name, final int accountId, final int amount, final boolean updateTotal) { _repository.rewardGold(new Callback() { @@ -309,7 +309,7 @@ public class DonationManager extends MiniDbClientPlugin if (callback != null) callback.run(true); } - }, caller, name, uuid.toString(), amount); + }, caller, name, accountId, amount); } public void RewardGoldLater(final String caller, final Player player, final int amount) @@ -352,7 +352,7 @@ public class DonationManager extends MiniDbClientPlugin continue; //Actually Add Gold - RewardGold(null, caller, player.getName(), player.getUniqueId(), total, false); + RewardGold(null, caller, player.getName(), ClientManager.Get(player).getAccountId(), total, false); System.out.println("Queue Added [" + player + "] with Gold [" + total + "] for [" + caller + "]"); @@ -375,15 +375,15 @@ public class DonationManager extends MiniDbClientPlugin Get(playerName).addGold(_repository.retrieveDonorInfo(resultSet).getGold()); } - @Override - public String getQuery(String uuid, String name) - { - return "SELECT gold FROM accounts WHERE uuid = '" + uuid + "';"; - } - @Override protected Donor AddPlayer(String player) { return new Donor(); } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT gold FROM accounts WHERE id = '" + accountId + "';"; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java index 99e12ed0d..384b0b997 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/GoldCommand.java @@ -4,6 +4,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -31,34 +32,39 @@ public class GoldCommand extends CommandBase return; } - String targetName = args[0]; - String goldString = args[1]; + final String targetName = args[0]; + final String goldString = args[1]; Player target = UtilPlayer.searchExact(targetName); if (target == null) { - UUID uuid = UUIDFetcher.getUUIDOf(targetName); - if (uuid != null) + Plugin.getClientManager().loadClientByName(targetName, new Runnable() { - rewardGold(caller, null, targetName, uuid, goldString); - } - else - { - UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName))); - } + public void run() + { + CoreClient client = Plugin.getClientManager().Get(targetName); + + if (client != null) + rewardGold(caller, null, targetName, client.getAccountId(), goldString); + else + { + UtilPlayer.message(caller, F.main("Gold", "Could not find player " + F.name(targetName))); + } + } + }); } else { - rewardGold(caller, target, target.getName(), target.getUniqueId(), goldString); + rewardGold(caller, target, target.getName(), Plugin.getClientManager().Get(target).getAccountId(), goldString); } } - private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, String goldString) + private void rewardGold(final Player caller, final Player target, final String targetName, final int accountId, String goldString) { try { int gold = Integer.parseInt(goldString); - rewardGold(caller, target, targetName, uuid, gold); + rewardGold(caller, target, targetName, accountId, gold); } catch (Exception e) { @@ -66,7 +72,7 @@ public class GoldCommand extends CommandBase } } - private void rewardGold(final Player caller, final Player target, final String targetName, final UUID uuid, final int gold) + private void rewardGold(final Player caller, final Player target, final String targetName, final int accountId, final int gold) { Plugin.RewardGold(new Callback() { @@ -79,6 +85,6 @@ public class GoldCommand extends CommandBase UtilPlayer.message(target, F.main("Gold", F.name(caller.getName()) + " gave you " + F.elem(gold + " Gold") + ".")); } } - }, caller.getName(), targetName, uuid, gold); + }, caller.getName(), targetName, accountId, gold); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java index b7246e8be..bd7a75a7b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -2,7 +2,6 @@ package mineplex.core.donation.repository; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; @@ -23,12 +22,12 @@ import mineplex.core.server.util.TransactionResponse; public class DonationRepository extends RepositoryBase { - private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX coinUuidIndex (accounts_uuid));"; - private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX gemUuidIndex (accounts_uuid));"; - private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accounts_uuid, reason, coins) VALUES(?, ?, ?);"; - private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE uuid = ?;"; - private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE uuid = ?;"; - private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE uuid = ? AND gems IS NULL AND coins IS NULL;"; + private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));"; + private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));"; + private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accountId, reason, coins) VALUES(?, ?, ?);"; + private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE id = ?;"; + private static String UPDATE_ACCOUNT_GOLD = "UPDATE accounts SET gold = gold + ? WHERE id = ?;"; + private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE id = ? AND gems IS NULL AND coins IS NULL;"; private String _webAddress; @@ -70,7 +69,7 @@ public class DonationRepository extends RepositoryBase }), "Error purchasing known sales package in DonationRepository : "); } - public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final String uuid, final String packageName, final boolean coinPurchase, final int cost) + public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final int accountId, final String packageName, final boolean coinPurchase, final int cost) { final UnknownPurchaseToken token = new UnknownPurchaseToken(); token.AccountName = name; @@ -87,8 +86,8 @@ public class DonationRepository extends RepositoryBase { if (coinPurchase) { - executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnVarChar("uuid", 100, uuid)); - executeUpdate(INSERT_COIN_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost)); + executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnInt("id", accountId)); + //executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost)); } } @@ -143,7 +142,7 @@ public class DonationRepository extends RepositoryBase }), "Error updating player gem amount in DonationRepository : "); } - public void rewardCoins(final Callback callback, final String giver, String name, final String uuid, final int coins) + public void rewardCoins(final Callback callback, final String giver, String name, final int accountId, final int coins) { final GemRewardToken token = new GemRewardToken(); token.Source = giver; @@ -156,8 +155,8 @@ public class DonationRepository extends RepositoryBase { if (response) { - executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnVarChar("uuid", 100, uuid)); - executeUpdate(INSERT_COIN_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins)); + executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnInt("id", accountId)); + //executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins)); } Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() @@ -180,13 +179,13 @@ public class DonationRepository extends RepositoryBase }), "Error updating player coin amount in DonationRepository : "); } - public void rewardGold(final Callback callback, final String giver, final String name, final String uuid, final int gold) + public void rewardGold(final Callback callback, final String giver, final String name, final int accountId, final int gold) { handleDatabaseCall(new DatabaseRunnable(new Runnable() { public void run() { - if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnVarChar("uuid", 100, uuid)) < 1) + if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnInt("id", accountId)) < 1) { callback.run(false); } @@ -208,13 +207,13 @@ public class DonationRepository extends RepositoryBase { } - public void updateGemsAndCoins(final UUID uuid, final int gems, final int coins) + public void updateGemsAndCoins(final int accountId, final int gems, final int coins) { handleDatabaseCall(new DatabaseRunnable(new Runnable() { public void run() { - executeUpdate(UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_, new ColumnInt("gems", gems), new ColumnInt("coins", coins), new ColumnVarChar("uuid", 100, uuid.toString())); + executeUpdate(UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_, new ColumnInt("gems", gems), new ColumnInt("coins", coins), new ColumnInt("id", accountId)); } }), "Error updating player's null gems and coins DonationRepository : "); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java index 858e89198..01f927d39 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java @@ -114,7 +114,7 @@ public class EloManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { return "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';"; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java index a78e09161..7289d672f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java @@ -418,7 +418,7 @@ public class FriendManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { return "SELECT tA.Name, status, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget WHERE uuidSource = '" + uuid + "';"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/DeleteFriend.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/DeleteFriend.java new file mode 100644 index 000000000..3f7ff0438 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/DeleteFriend.java @@ -0,0 +1,24 @@ +package mineplex.core.friend.redis; + +import mineplex.serverdata.commands.ServerCommand; + +public class DeleteFriend extends ServerCommand +{ + private String _deleter; + private String _deleted; + + public String getDeleter() { return _deleter; } + public String getDeleted() { return _deleted; } + + public DeleteFriend(String deleter, String deleted) + { + _deleter = deleter; + _deleted = deleted; + } + + @Override + public void run() + { + // Utilitizes a callback functionality to seperate dependencies + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/DeleteFriendHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/DeleteFriendHandler.java new file mode 100644 index 000000000..2cff73b84 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/DeleteFriendHandler.java @@ -0,0 +1,6 @@ +package mineplex.core.friend.redis; + +public class DeleteFriendHandler +{ + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/FriendRequest.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/FriendRequest.java new file mode 100644 index 000000000..3dfd23205 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/FriendRequest.java @@ -0,0 +1,24 @@ +package mineplex.core.friend.redis; + +import mineplex.serverdata.commands.ServerCommand; + +public class FriendRequest extends ServerCommand +{ + private String _requester; + private String _requested; + + public String getRequester() { return _requester; } + public String getRequested() { return _requested; } + + public FriendRequest(String requester, String requested) + { + _requester = requester; + _requested = requested; + } + + @Override + public void run() + { + // Utilitizes a callback functionality to seperate dependencies + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/FriendRequestHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/FriendRequestHandler.java new file mode 100644 index 000000000..7e43e2922 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/redis/FriendRequestHandler.java @@ -0,0 +1,6 @@ +package mineplex.core.friend.redis; + +public class FriendRequestHandler +{ + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java b/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java index 482030f36..7edaa801f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java @@ -236,7 +236,7 @@ public class IgnoreManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { return "SELECT tA.Name FROM accountIgnore INNER Join accounts AS fA ON fA.uuid = uuidIgnorer INNER JOIN accounts AS tA ON tA.uuid = uuidIgnored LEFT JOIN playerMap ON tA.name = playerName WHERE uuidIgnorer = '" + uuid + "';"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java index 577ed05f7..2cb728e5c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java @@ -4,6 +4,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -114,7 +115,7 @@ public class InventoryManager extends MiniDbClientPlugin if (callback != null) callback.run(success); } - }, player.getUniqueId().toString(), category, item, count); + }, player.getUniqueId(), category, item, count); } @@ -149,7 +150,7 @@ public class InventoryManager extends MiniDbClientPlugin return item; } - public void addItemToInventoryForOffline(final Callback callback, final String uuidString, final String category, final String item, final int count) + public void addItemToInventoryForOffline(final Callback callback, final UUID uuid, final String category, final String item, final int count) { Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() { @@ -179,7 +180,7 @@ public class InventoryManager extends MiniDbClientPlugin synchronized (_inventoryLock) { - final boolean success = _repository.incrementClientInventoryItem(uuidString, _items.get(item).Id, count); + final boolean success = _repository.incrementClientInventoryItem(ClientManager.getCachedClientAccountId(uuid), _items.get(item).Id, count); if (callback != null) { @@ -224,7 +225,7 @@ public class InventoryManager extends MiniDbClientPlugin } } } - }, player.getUniqueId().toString(), category, item, count); + }, player.getUniqueId(), category, item, count); } } @@ -256,8 +257,8 @@ public class InventoryManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { - return "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = '" + uuid + "';"; + return "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId WHERE ai.accountId = '" + accountId + "';"; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java index 28c92639e..86254b037 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/command/GiveItemCommand.java @@ -4,6 +4,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -44,7 +45,7 @@ public class GiveItemCommand extends CommandBase final String itemName = itemNameTemp; - Item item = Plugin.getItem(itemName); + final Item item = Plugin.getItem(itemName); Player player = UtilPlayer.searchExact(playerName); if (item == null) @@ -59,21 +60,28 @@ public class GiveItemCommand extends CommandBase } else { - UUID uuid = UUIDFetcher.getUUIDOf(playerName); - if (uuid != null) + Plugin.getClientManager().loadClientByName(playerName, new Runnable() { - Plugin.addItemToInventoryForOffline(new Callback() + public void run() { - public void run (Boolean success) + UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName); + + if (uuid != null) { - UtilPlayer.message(caller, F.main("Item", "You gave " + F.elem(amount + " " + itemName) + " to offline player " + F.name(playerName))); + Plugin.addItemToInventoryForOffline(new Callback() + { + public void run (Boolean success) + { + UtilPlayer.message(caller, F.main("Item", "You gave " + F.elem(amount + " " + itemName) + " to offline player " + F.name(playerName))); + } + }, uuid, item.Category, item.Name, amount); } - }, uuid.toString(), item.Category, item.Name, amount); - } - else - { - UtilPlayer.message(caller, F.main("Item", "Player " + F.name(playerName) + " does not exist!")); - } + else + { + UtilPlayer.message(caller, F.main("Item", "Player " + F.name(playerName) + " does not exist!")); + } + } + }); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java index 444e98bbf..8679dec3e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java @@ -27,8 +27,8 @@ public class InventoryRepository extends RepositoryBase private static String INSERT_CATEGORY = "INSERT INTO itemCategories (name) VALUES (?);"; private static String RETRIEVE_CATEGORIES = "SELECT id, name FROM itemCategories;"; - private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);"; - private static String UPDATE_CLIENT_INVENTORY = "UPDATE accountInventory AS AI INNER JOIN accounts ON AI.accountId = accounts.id SET AI.count = AI.count + ? WHERE accounts.uuid = ? AND AI.itemId = ?;"; + private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE count=count + VALUES(count);"; + private static String UPDATE_CLIENT_INVENTORY = "UPDATE accountInventory SET count = count + ? WHERE accountId = ? AND itemId = ?;"; public InventoryRepository(JavaPlugin plugin) { @@ -96,10 +96,14 @@ public class InventoryRepository extends RepositoryBase return items; } - public boolean incrementClientInventoryItem(String uuid, int itemId, int count) + public boolean incrementClientInventoryItem(int accountId, int itemId, int count) { - if (executeUpdate(UPDATE_CLIENT_INVENTORY, new ColumnInt("count", count), new ColumnVarChar("uuid", 100, uuid), new ColumnInt("itemid", itemId)) < 1) - return executeUpdate(INSERT_CLIENT_INVENTORY, new ColumnInt("itemid", itemId), new ColumnInt("count", count), new ColumnVarChar("uuid", 100, uuid)) > 0; + System.out.println("Updating " + accountId + "'s " + itemId + " with " + count); + if (executeUpdate(UPDATE_CLIENT_INVENTORY, new ColumnInt("count", count), new ColumnInt("id", accountId), new ColumnInt("itemid", itemId)) < 1) + { + System.out.println("Inserting " + accountId + "'s " + itemId + " with " + count); + return executeUpdate(INSERT_CLIENT_INVENTORY, new ColumnInt("id", accountId), new ColumnInt("itemid", itemId), new ColumnInt("count", count)) > 0; + } else return true; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java index fbb331579..b24e700ba 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java @@ -112,7 +112,7 @@ public class PreferencesManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests, friendDisplayInventoryUI FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 33425f5a2..a6f7fd59b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -76,9 +76,9 @@ public class ReportManager { reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database removeActiveReport(reportId); - int closerId = getPlayerAccount(reportCloser).GetAccountId(); + int closerId = getPlayerAccount(reportCloser).getAccountId(); String playerName = getReport(reportId).getPlayerName(); - int playerId = getPlayerAccount(playerName).GetAccountId(); + int playerId = getPlayerAccount(playerName).getAccountId(); String server = null; // TODO: Get current server name reportSqlRepository.logReport(reportId, playerId, server, closerId, result, reason); @@ -86,7 +86,7 @@ public class ReportManager { for (String reporterName : report.getReporters()) { CoreClient reporterAccount = getPlayerAccount(reporterName); - ReportProfile reportProfile = getReportProfile(String.valueOf(reporterAccount.GetAccountId())); + ReportProfile reportProfile = getReportProfile(String.valueOf(reporterAccount.getAccountId())); reportProfile.onReportClose(result); reportProfiles.addElement(reportProfile); } @@ -113,14 +113,14 @@ public class ReportManager { // TODO: Send display message to handler when they arrive on the server // with info about the case/report. - int handlerId = getPlayerAccount(reportHandler).GetAccountId(); + int handlerId = getPlayerAccount(reportHandler).getAccountId(); reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database } } public void reportPlayer(Player reporter, Player reportedPlayer, String reason) { - int reporterId = getPlayerAccount(reporter).GetAccountId(); + int reporterId = getPlayerAccount(reporter).getAccountId(); ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId)); if (reportProfile.canReport()) @@ -232,7 +232,7 @@ public class ReportManager { private int getAccountId(String playerName) { - return getPlayerAccount(playerName).GetAccountId(); + return getPlayerAccount(playerName).getAccountId(); } /** diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java index bcbeddb3a..72bc8f823 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java @@ -53,7 +53,7 @@ public class CoinReward extends Reward { } - }, "Treasure Chest", player.getName(), player.getUniqueId(), gemsToReward); + }, "Treasure Chest", player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), gemsToReward); return new RewardData(getRarity().getColor() + gemsToReward + " Coins", new ItemStack(175)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java index 77e6cff3d..6e041ee9b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java @@ -31,7 +31,7 @@ public class UnknownPackageReward extends Reward @Override protected RewardData giveRewardCustom(Player player) { - _donationManager.PurchaseUnknownSalesPackage(null, player.getName(), player.getUniqueId(), _packageName, true, 0, true); + _donationManager.PurchaseUnknownSalesPackage(null, player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _packageName, true, 0, true); return new RewardData(getRarity().getColor() + _name, _itemStack); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java index fe2dfa558..89b05f239 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java @@ -147,7 +147,7 @@ public class ConfirmationPage } else { - synchronized (_statSync) - { - addToQueue(statName, player, value); - } + addToQueue(statName, player, value); } } private void addToQueue(String statName, Player player, int value) { - if (!_statUploadQueue.containsKey(player)) + synchronized (_statSync) { - _statUploadQueue.put(player, new NautHashMap()); + if (!_statUploadQueue.containsKey(player)) + _statUploadQueue.put(player, new NautHashMap()); + + if (!_statUploadQueue.get(player).containsKey(statName)) + _statUploadQueue.get(player).put(statName, 0); + + _statUploadQueue.get(player).put(statName, _statUploadQueue.get(player).get(statName) + value); } - - if (!_statUploadQueue.get(player).containsKey(statName)) - { - _statUploadQueue.get(player).put(statName, 0); - } - - _statUploadQueue.get(player).put(statName, _statUploadQueue.get(player).get(statName) + value); } protected void saveStats() @@ -121,7 +118,7 @@ public class StatsManager extends MiniDbClientPlugin try { - NautHashMap> uploadQueue = new NautHashMap>(); + NautHashMap> uploadQueue = new NautHashMap>(); synchronized (_statSync) { @@ -132,7 +129,7 @@ public class StatsManager extends MiniDbClientPlugin if (player.isOnline()) continue; - String uploadKey = player.getUniqueId().toString(); + int uploadKey = ClientManager.getCachedClientAccountId(player.getUniqueId()); uploadQueue.put(uploadKey, new NautHashMap()); @@ -155,14 +152,14 @@ public class StatsManager extends MiniDbClientPlugin } } - public boolean incrementStat(final String uuidString, final String statName, final int value) + public boolean incrementStat(final int accountId, final String statName, final int value) { if (_stats.containsKey(statName)) return false; - final NautHashMap> uploadQueue = new NautHashMap>(); - uploadQueue.put(uuidString, new NautHashMap()); - uploadQueue.get(uuidString).put(_stats.get(statName), value); + final NautHashMap> uploadQueue = new NautHashMap>(); + uploadQueue.put(accountId, new NautHashMap()); + uploadQueue.get(accountId).put(_stats.get(statName), value); runAsync(new Runnable() { @@ -200,8 +197,8 @@ public class StatsManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { - return "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';"; + return "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId WHERE accountStats.accountId = '" + accountId + "';"; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java index 58c81c9f8..23d3daa9d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java @@ -77,7 +77,7 @@ public class StatsRepository extends RepositoryBase } @SuppressWarnings("rawtypes") - public void saveStats(NautHashMap> uploadQueue) + public void saveStats(NautHashMap> uploadQueue) { try { @@ -86,23 +86,23 @@ public class StatsRepository extends RepositoryBase List updates = new ArrayList<>(); List inserts = new ArrayList<>(); - for (String uuid : uploadQueue.keySet()) + for (int accountId : uploadQueue.keySet()) { - for (Integer statId : uploadQueue.get(uuid).keySet()) + for (Integer statId : uploadQueue.get(accountId).keySet()) { Update update = context .update(Tables.accountStats) - .set(Tables.accountStats.value, Tables.accountStats.value.plus(uploadQueue.get(uuid).get(statId))) - .where(Tables.accountStats.accountId.eq(context.select(Tables.accounts.id).from(Tables.accounts).where(Tables.accounts.uuid.eq(uuid)))) + .set(Tables.accountStats.value, Tables.accountStats.value.plus(uploadQueue.get(accountId).get(statId))) + .where(Tables.accountStats.accountId.eq(accountId)) .and(Tables.accountStats.statId.eq(statId)); updates.add(update); Insert insert = context .insertInto(Tables.accountStats) - .set(Tables.accountStats.accountId, context.select(Tables.accounts.id).from(Tables.accounts).where(Tables.accounts.uuid.eq(uuid))) + .set(Tables.accountStats.accountId, accountId) .set(Tables.accountStats.statId, statId) - .set(Tables.accountStats.value, uploadQueue.get(uuid).get(statId)); + .set(Tables.accountStats.value, uploadQueue.get(accountId).get(statId)); inserts.add(insert); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/GiveStatCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/GiveStatCommand.java index 3ce6a847b..35293a2b5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/GiveStatCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/GiveStatCommand.java @@ -1,13 +1,11 @@ package mineplex.core.stats.command; -import java.util.UUID; - import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; -import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; import mineplex.core.stats.StatsManager; @@ -31,20 +29,29 @@ public class GiveStatCommand extends CommandBase { Player player = UtilPlayer.searchOnline(caller, args[0], true); - String statName = args[1]; + String tempStatName = args[1]; for (int i = 2; i < args.length - 1; i++) { - statName += " " + args[i]; + tempStatName += " " + args[i]; } + final String statName = tempStatName; + if (player == null) { - UUID uuid = UUIDFetcher.getUUIDOf(args[0]); - if (uuid != null) + Plugin.getClientManager().loadClientByName(args[0], new Runnable() { - Plugin.incrementStat(uuid.toString(), statName, Integer.parseInt(args[args.length - 1])); - } + public void run() + { + final CoreClient client = Plugin.getClientManager().Get(args[0]); + + if (client != null) + Plugin.incrementStat(client.getAccountId(), statName, Integer.parseInt(args[args.length - 1])); + else + caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + args[0] + "'s account!")); + } + }); } else { diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java index 8301f97d5..e663d6e77 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/Enjin.java @@ -17,6 +17,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -144,105 +145,95 @@ public class Enjin extends MiniPlugin implements CommandExecutor if (label.equalsIgnoreCase("enjin_mineplex")) { final String name = args[1]; - UUID uuid = null; - if (_cachedUUIDs.containsKey(name)) - uuid = _cachedUUIDs.get(name).getKey(); - else + _clientManager.loadClientByName(name, new Runnable() { - // Fails if not in DB and if duplicate. - uuid = _clientManager.loadUUIDFromDB(name); - - if (uuid == null) - uuid = UUIDFetcher.getUUIDOf(name); - } - - if (uuid == null) - { - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", no UUID."); - return true; - } - - final UUID playerUUID = uuid; - - _cachedUUIDs.put(name, new AbstractMap.SimpleEntry(playerUUID, System.currentTimeMillis() + 240000)); - - if (args.length == 3 && args[0].equalsIgnoreCase("gem")) - { - final int amount = Integer.parseInt(args[2]); - - _donationManager.RewardGems(new Callback() + public void run() { - public void run (Boolean response) + final CoreClient client = _clientManager.Get(name); + + if (client == null) { - if (response) - { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " gems."); - } + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", isn't in our database."); + } + else + { + UUID uuid = null; + + if (_cachedUUIDs.containsKey(name)) + uuid = _cachedUUIDs.get(name).getKey(); else { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " gems. Queuing for run later."); + // Fails if not in DB and if duplicate. + uuid = _clientManager.loadUUIDFromDB(name); + + if (uuid == null) + uuid = UUIDFetcher.getUUIDOf(name); } - } - }, "purchase", name, playerUUID, amount); - } - else if (args.length == 3 && args[0].equalsIgnoreCase("coin")) - { - final int amount = Integer.parseInt(args[2]); - - _donationManager.RewardCoins(new Callback() - { - public void run (Boolean response) - { - if (response) + + if (uuid == null) { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins."); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + ", no UUID."); + return; } - else - { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later."); - } - } - }, "purchase", name, playerUUID, amount); - } - else if (args.length == 3 && args[0].equalsIgnoreCase("booster")) - { - int amount = Integer.parseInt(args[2]); - - _donationManager.PurchaseUnknownSalesPackage(null, name, playerUUID, "Gem Booster " + amount, false, 0, false); - _repository.addGemBooster(name, amount); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Gem Boosters" + "."); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("key")) - { - final int amount = Integer.parseInt(args[2]); - - if (args.length == 4) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + "."); - else + + final UUID playerUUID = uuid; + + _cachedUUIDs.put(name, new AbstractMap.SimpleEntry(playerUUID, System.currentTimeMillis() + 240000)); + + if (args.length == 3 && args[0].equalsIgnoreCase("gem")) + { + final int amount = Integer.parseInt(args[2]); + + _donationManager.RewardGems(new Callback() { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); - } + public void run (Boolean response) + { + if (response) + { + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " gems."); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " gems. Queuing for run later."); + } + } + }, "purchase", name, playerUUID, amount); + } + else if (args.length == 3 && args[0].equalsIgnoreCase("coin")) + { + final int amount = Integer.parseInt(args[2]); + + _donationManager.RewardCoins(new Callback() + { + public void run (Boolean response) + { + if (response) + { + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " coins."); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " coins. Queuing for run later."); + } + } + }, "purchase", name, client.getAccountId(), amount); } - }, playerUUID.toString(), "Treasure", "Treasure Key", amount); - } - else - { - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) + else if (args.length == 3 && args[0].equalsIgnoreCase("booster")) + { + int amount = Integer.parseInt(args[2]); + + _donationManager.PurchaseUnknownSalesPackage(null, name, client.getAccountId(), "Gem Booster " + amount, false, 0, false); + _repository.addGemBooster(name, amount); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Gem Boosters" + "."); + } + else if (args.length >= 3 && args[0].equalsIgnoreCase("key")) { - if (data == TransactionResponse.Success) + final int amount = Integer.parseInt(args[2]); + + if (args.length == 4) { _inventoryManager.addItemToInventoryForOffline(new Callback() { @@ -257,149 +248,175 @@ public class Enjin extends MiniPlugin implements CommandExecutor System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); } } - }, playerUUID.toString(), "Treasure", "Treasure Key", amount); + }, playerUUID, "Treasure", "Treasure Key", amount); } else { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) + { + if (data == TransactionResponse.Success) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Keys" + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + } + } + }, playerUUID, "Treasure", "Treasure Key", amount); + } + else + { + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + } + } + }, name, client.getAccountId(), "Treasure Key " + amount, false, 0, false); } } - }, name, playerUUID, "Treasure Key " + amount, false, 0, false); - } - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("chest")) - { - final int amount = Integer.parseInt(args[2]); - - if (args.length == 4) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() - { - public void run(Boolean success) - { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + else if (args.length >= 3 && args[0].equalsIgnoreCase("chest")) + { + final int amount = Integer.parseInt(args[2]); + + if (args.length == 4) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + } + } + }, playerUUID, "Utility", "Treasure Chest", amount); + } else { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + } + } + }, playerUUID, "Utility", "Treasure Chest", amount); + } + }, name, client.getAccountId(), "Treasure Chest " + amount, false, 0, false); } } - }, playerUUID.toString(), "Utility", "Treasure Chest", amount); - } - else - { - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) + else if (args.length == 4 && args[0].equalsIgnoreCase("rank")) { - _inventoryManager.addItemToInventoryForOffline(new Callback() + final Rank rank = mineplex.core.common.Rank.valueOf(args[2]); + final boolean perm = Boolean.parseBoolean(args[3]); + + _clientManager.loadClientByName(name, new Runnable() { - public void run(Boolean success) + public void run() { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " Treasure Chests" + "."); + if (_clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().Has(rank) || _clientManager.Get(name).GetRank() == rank) + { + _clientManager.SaveRank(name, playerUUID, rank, perm); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month.")); + } else { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Chests. Queuing for run later."); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " DENIED INFERIOR " + rank + " " + (perm ? "permanently." : "for 1 month.")); } } - }, playerUUID.toString(), "Utility", "Treasure Chest", amount); + }); } - }, name, playerUUID, "Treasure Chest " + amount, false, 0, false); - } - } - else if (args.length == 4 && args[0].equalsIgnoreCase("rank")) - { - final Rank rank = mineplex.core.common.Rank.valueOf(args[2]); - final boolean perm = Boolean.parseBoolean(args[3]); - - _clientManager.loadClientByName(name, new Runnable() - { - public void run() - { - if (_clientManager.Get(name).GetRank() == Rank.ALL || !_clientManager.Get(name).GetRank().Has(rank) || _clientManager.Get(name).GetRank() == rank) + else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase")) { - _clientManager.SaveRank(name, playerUUID, rank, perm); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + rank + " " + (perm ? "permanently." : "for 1 month.")); - } - else - { - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " DENIED INFERIOR " + rank + " " + (perm ? "permanently." : "for 1 month.")); - } - } - }); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("purchase")) - { - final int amount = Integer.parseInt(args[2]); - final String category = args[3]; - String tempName = args[4]; - - for (int i = 5; i < args.length; i++) - { - tempName += " " + args[i]; - } - - final String packageName = tempName; - - _donationManager.PurchaseUnknownSalesPackage(new Callback() - { - public void run(TransactionResponse data) - { - if (data == TransactionResponse.Success) - { - _inventoryManager.addItemToInventoryForOffline(new Callback() + final int amount = Integer.parseInt(args[2]); + final String category = args[3]; + String tempName = args[4]; + + for (int i = 5; i < args.length; i++) { - public void run(Boolean success) + tempName += " " + args[i]; + } + + final String packageName = tempName; + + _donationManager.PurchaseUnknownSalesPackage(new Callback() + { + public void run(TransactionResponse data) { - if (success) - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); + if (data == TransactionResponse.Success) + { + _inventoryManager.addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " received " + amount + " " + packageName + "."); + else + { + // Add arg so we don't add back to windows api call + _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); + } + } + }, playerUUID, category, packageName, amount); + } else { - // Add arg so we don't add back to windows api call - _commandQueue.add(new QueuedCommand(sender, command, label, new String[] { args[0], args[1], args[2], "noaccountchange" })); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + packageName + ". Queuing for run later."); + _commandQueue.add(new QueuedCommand(sender, command, label, args)); + System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); } } - }, playerUUID.toString(), category, packageName, amount); + }, name, client.getAccountId(), packageName, false, 0, false); } - else - { - _commandQueue.add(new QueuedCommand(sender, command, label, args)); - System.out.println("[" + _dateFormat.format(new Date()) + "] ERROR processing " + name + " " + amount + " Treasure Keys. Queuing for run later."); + else if (args.length >= 3 && args[0].equalsIgnoreCase("unban")) + { + String reason = args[2]; + + for (int i = 3; i < args.length; i++) + { + reason += " " + args[i]; + } + + _punish.RemoveBan(name, reason); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " unbanned for " + reason); + } + else if (args.length >= 3 && args[0].equalsIgnoreCase("ban")) + { + String reason = args[2]; + + for (int i = 3; i < args.length; i++) + { + reason += " " + args[i]; + } + + _punish.AddPunishment(name, Category.Other, reason, null, 3, true, -1); + System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " banned for " + reason); } } - }, name, playerUUID, packageName, false, 0, false); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("unban")) - { - String reason = args[2]; - - for (int i = 3; i < args.length; i++) - { - reason += " " + args[i]; } - - _punish.RemoveBan(name, reason); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " unbanned for " + reason); - } - else if (args.length >= 3 && args[0].equalsIgnoreCase("ban")) - { - String reason = args[2]; - - for (int i = 3; i < args.length; i++) - { - reason += " " + args[i]; - } - - _punish.AddPunishment(name, Category.Other, reason, null, 3, true, -1); - System.out.println("[" + _dateFormat.format(new Date()) + "] " + name + " banned for " + reason); - } + }); } } catch (Exception exception) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java index a2e3f6919..727b3c312 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java @@ -76,8 +76,19 @@ public class NewsManager extends MiniPlugin String[] newsStrings = new String[maxPosition]; for (Iterator iterator = newsEntries.keySet().iterator(); iterator.hasNext();) { - String newsPosition = iterator.next(); - newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition); + int newsPos = Integer.parseInt(iterator.next()); + + ChatColor col = ChatColor.RED; + if (newsPos == 1) col = ChatColor.GOLD; + else if (newsPos == 2) col = ChatColor.YELLOW; + else if (newsPos == 3) col = ChatColor.GREEN; + else if (newsPos == 4) col = ChatColor.AQUA; + else if (newsPos == 5) col = ChatColor.LIGHT_PURPLE; + + newsStrings[newsPos - 1] = col + C.Bold + "MINEPLEX" + ChatColor.RESET + " - " + newsEntries.get(newsPos + ""); + + if (newsStrings[newsPos - 1].length() > 64) + newsStrings[newsPos - 1] = newsStrings[newsPos - 1].substring(0, 64); } _news = newsStrings; @@ -230,13 +241,6 @@ public class NewsManager extends MiniPlugin if (event.getType() != UpdateType.FASTEST) return; - //Mineplex Color - ChatColor col = ChatColor.RED; - if (_mineplexIndex == 1) col = ChatColor.GOLD; - else if (_mineplexIndex == 2) col = ChatColor.YELLOW; - else if (_mineplexIndex == 3) col = ChatColor.GREEN; - else if (_mineplexIndex == 4) col = ChatColor.AQUA; - else if (_mineplexIndex == 5) col = ChatColor.LIGHT_PURPLE; _mineplexIndex = (_mineplexIndex + 1)%6; //News Change @@ -250,16 +254,11 @@ public class NewsManager extends MiniPlugin // Resets newsIndex if outside of bounds of news array after RefreshNews but before UtilTime.elapsed above _newsIndex = 0; } - - //Text - String text = col + C.Bold + "MINEPLEX" + ChatColor.RESET + " - " + _news[_newsIndex]; - if (text.length() > 64) - text = text.substring(0, 64); double healthPercent = (double)_newsIndex/(double)(_news.length-1); + String text = _news[_newsIndex]; UtilTextTop.display(text, UtilServer.getPlayers()); - for (Creature pet : Manager.getPetManager().getPets()) { if (pet instanceof Wither) @@ -275,7 +274,7 @@ public class NewsManager extends MiniPlugin ((MountDragon)mount).SetName(text); //((MountDragon)mount).setHealthPercent(healthPercent); } - } + } for (Gadget gadget : Manager.GetGadget().getGadgets(GadgetType.Morph)) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java index 68f88e47f..18f92ae15 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java @@ -216,8 +216,8 @@ public class PollManager extends MiniDbClientPlugin } @Override - public String getQuery(String uuid, String name) + public String getQuery(int accountId, String uuid, String name) { - return "SELECT pollId, value FROM accountPolls INNER JOIN accounts ON accountPolls.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';"; + return "SELECT pollId, value FROM accountPolls WHERE accountPolls.accountId = '" + accountId + "';"; } } diff --git a/Plugins/Mineplex.PlayerCache/.classpath b/Plugins/Mineplex.PlayerCache/.classpath new file mode 100644 index 000000000..7a237e253 --- /dev/null +++ b/Plugins/Mineplex.PlayerCache/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Plugins/Mineplex.PlayerCache/.project b/Plugins/Mineplex.PlayerCache/.project new file mode 100644 index 000000000..0abebe638 --- /dev/null +++ b/Plugins/Mineplex.PlayerCache/.project @@ -0,0 +1,17 @@ + + + Mineplex.PlayerCache + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Plugins/Mineplex.PlayerCache/.settings/org.eclipse.jdt.core.prefs b/Plugins/Mineplex.PlayerCache/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..7341ab168 --- /dev/null +++ b/Plugins/Mineplex.PlayerCache/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/Plugins/Mineplex.PlayerCache/src/mineplex/playerCache/PlayerCache.java b/Plugins/Mineplex.PlayerCache/src/mineplex/playerCache/PlayerCache.java new file mode 100644 index 000000000..15cffb719 --- /dev/null +++ b/Plugins/Mineplex.PlayerCache/src/mineplex/playerCache/PlayerCache.java @@ -0,0 +1,37 @@ +package mineplex.playerCache; + +import java.util.UUID; + +import mineplex.serverdata.Region; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ServerManager; + +public class PlayerCache +{ + private RedisDataRepository _repository; + + public PlayerCache() + { + _repository = new RedisDataRepository( + ServerManager.getMasterConnection(), + ServerManager.getSlaveConnection(), + Region.ALL, + PlayerInfo.class, + "playercache"); + } + + public void addPlayer(PlayerInfo player) + { + _repository.addElement(player, 60 * 60 * 6); // 6 Hours + } + + public PlayerInfo getPlayer(UUID uuid) + { + return _repository.getElement(uuid.toString()); + } + + public void clean() + { + _repository.clean(); + } +} diff --git a/Plugins/Mineplex.PlayerCache/src/mineplex/playerCache/PlayerInfo.java b/Plugins/Mineplex.PlayerCache/src/mineplex/playerCache/PlayerInfo.java new file mode 100644 index 000000000..700839ccb --- /dev/null +++ b/Plugins/Mineplex.PlayerCache/src/mineplex/playerCache/PlayerInfo.java @@ -0,0 +1,86 @@ +package mineplex.playerCache; + +import java.util.UUID; + +import mineplex.serverdata.data.Data; + +public class PlayerInfo implements Data +{ + private int _id; + private UUID _uuid; + private String _name; + private boolean _online; + private long _lastUniqueLogin; + private long _loginTime; + private int _sessionId; + private int _version; + + public PlayerInfo(int id, UUID uuid, String name, int version) + { + _id = id; + _uuid = uuid; + _name = name; + _version = version; + } + + @Override + public String getDataId() + { + return _uuid.toString(); + } + + public int getId() + { + return _id; + } + + public UUID getUUID() + { + return _uuid; + } + + public String getName() + { + return _name; + } + + public boolean getOnline() + { + return _online; + } + + public long getLastUniqueLogin() + { + return _lastUniqueLogin; + } + + public long getLoginTime() + { + return _loginTime; + } + + public int getSessionId() + { + return _sessionId; + } + + public int getVersion() + { + return _version; + } + + public void setSessionId(int sessionId) + { + _sessionId = sessionId; + } + + public void setName(String name) + { + _name = name; + } + + public void setVersion(int version) + { + _version = version; + } +} diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPing.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPing.java new file mode 100644 index 000000000..e101cc0c7 --- /dev/null +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPing.java @@ -0,0 +1,102 @@ +package mineplex.servermonitor; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; +import com.google.gson.Gson; + +public class MinecraftPing { + + /** + * Fetches a {@link MinecraftPingReply} for the supplied hostname. + * Assumed timeout of 2s and port of 25565. + * + * @param hostname - a valid String hostname + * @return {@link MinecraftPingReply} + * @throws IOException + */ + public MinecraftPingReply getPing(final String hostname) throws IOException { + return this.getPing(new MinecraftPingOptions().setHostname(hostname)); + } + + /** + * Fetches a {@link MinecraftPingReply} for the supplied options. + * + * @param options - a filled instance of {@link MinecraftPingOptions} + * @return {@link MinecraftPingReply} + * @throws IOException + */ + public MinecraftPingReply getPing(final MinecraftPingOptions options) throws IOException { + MinecraftPingUtil.validate(options.getHostname(), "Hostname cannot be null."); + MinecraftPingUtil.validate(options.getPort(), "Port cannot be null."); + + final Socket socket = new Socket(); + socket.connect(new InetSocketAddress(options.getHostname(), options.getPort()), options.getTimeout()); + + final DataInputStream in = new DataInputStream(socket.getInputStream()); + final DataOutputStream out = new DataOutputStream(socket.getOutputStream()); + + //> Handshake + + ByteArrayOutputStream handshake_bytes = new ByteArrayOutputStream(); + DataOutputStream handshake = new DataOutputStream(handshake_bytes); + + handshake.writeByte(MinecraftPingUtil.PACKET_HANDSHAKE); + MinecraftPingUtil.writeVarInt(handshake, MinecraftPingUtil.PROTOCOL_VERSION); + MinecraftPingUtil.writeVarInt(handshake, options.getHostname().length()); + handshake.writeBytes(options.getHostname()); + handshake.writeShort(options.getPort()); + MinecraftPingUtil.writeVarInt(handshake, MinecraftPingUtil.STATUS_HANDSHAKE); + + MinecraftPingUtil.writeVarInt(out, handshake_bytes.size()); + out.write(handshake_bytes.toByteArray()); + + //> Status request + + out.writeByte(0x01); // Size of packet + out.writeByte(MinecraftPingUtil.PACKET_STATUSREQUEST); + + //< Status response + + MinecraftPingUtil.readVarInt(in); // Size + int id = MinecraftPingUtil.readVarInt(in); + + MinecraftPingUtil.io(id == -1, "Server prematurely ended stream."); + MinecraftPingUtil.io(id != MinecraftPingUtil.PACKET_STATUSREQUEST, "Server returned invalid packet."); + + int length = MinecraftPingUtil.readVarInt(in); + MinecraftPingUtil.io(length == -1, "Server prematurely ended stream."); + MinecraftPingUtil.io(length == 0, "Server returned unexpected value."); + + byte[] data = new byte[length]; + in.readFully(data); + String json = new String(data, options.getCharset()); + + //> Ping + + out.writeByte(0x09); // Size of packet + out.writeByte(MinecraftPingUtil.PACKET_PING); + out.writeLong(System.currentTimeMillis()); + + //< Ping + + MinecraftPingUtil.readVarInt(in); // Size + id = MinecraftPingUtil.readVarInt(in); + MinecraftPingUtil.io(id == -1, "Server prematurely ended stream."); + //MinecraftPingUtil.io(id != MinecraftPingUtil.PACKET_PING, "Server returned invalid packet."); + + // Close + + handshake.close(); + handshake_bytes.close(); + out.close(); + in.close(); + socket.close(); + + return new Gson().fromJson(json, MinecraftPingReply.class); + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingOptions.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingOptions.java new file mode 100644 index 000000000..1cbe0a4da --- /dev/null +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingOptions.java @@ -0,0 +1,45 @@ +package mineplex.servermonitor; + +public class MinecraftPingOptions +{ + private String hostname; + private int port = 25565; + private int timeout = 2000; + private String charset = "UTF-8"; + + public MinecraftPingOptions setHostname(String hostname) { + this.hostname = hostname; + return this; + } + + public MinecraftPingOptions setPort(int port) { + this.port = port; + return this; + } + + public MinecraftPingOptions setTimeout(int timeout) { + this.timeout = timeout; + return this; + } + + public MinecraftPingOptions setCharset(String charset) { + this.charset = charset; + return this; + } + + public String getHostname() { + return this.hostname; + } + + public int getPort() { + return this.port; + } + + public int getTimeout() { + return this.timeout; + } + + public String getCharset() { + return this.charset; + } +} diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingReply.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingReply.java new file mode 100644 index 000000000..f6aecde32 --- /dev/null +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingReply.java @@ -0,0 +1,103 @@ +package mineplex.servermonitor; + +import java.util.List; + +public class MinecraftPingReply { + + private String description; + private Players players; + private Version version; + private String favicon; + + /** + * @return the MOTD + */ + public String getDescription() { + return this.description; + } + + public Players getPlayers() { + return this.players; + } + + /** + * @return @{link Version} + */ + public Version getVersion() { + return this.version; + } + + /** + * @return Base64 encoded favicon image + */ + public String getFavicon() { + return this.favicon; + } + + public class Players { + private int max; + private int online; + private List sample; + + /** + * @return Maximum player count + */ + public int getMax() { + return this.max; + } + + /** + * @return Online player count + */ + public int getOnline() { + return this.online; + } + + /** + * @return List of some players (if any) specified by server + */ + public List getSample() { + return this.sample; + } + } + + public class Player { + private String name; + private String id; + + /** + * @return Name of player + */ + public String getName() { + return this.name; + } + + /** + * @return Unknown + */ + public String getId() { + return this.id; + } + + } + + public class Version { + private String name; + private int protocol; + + /** + * @return Version name (ex: 13w41a) + */ + public String getName() { + return this.name; + } + + /** + * @return Protocol version + */ + public int getProtocol() { + return this.protocol; + } + } + +} diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingUtil.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingUtil.java new file mode 100644 index 000000000..11a01db51 --- /dev/null +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/MinecraftPingUtil.java @@ -0,0 +1,63 @@ +package mineplex.servermonitor; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class MinecraftPingUtil { + + public static byte PACKET_HANDSHAKE = 0x00, PACKET_STATUSREQUEST = 0x00, PACKET_PING = 0x01; + public static int PROTOCOL_VERSION = 4; + public static int STATUS_HANDSHAKE = 1; + + public static void validate(final Object o, final String m) + { + if (o == null) + { + throw new RuntimeException(m); + } + } + + public static void io(final boolean b, final String m) throws IOException + { + if (b) + { + throw new IOException(m); + } + } + + public static int readVarInt(DataInputStream in) throws IOException + { + int i = 0; + int j = 0; + while (true) { + int k = in.readByte(); + + i |= (k & 0x7F) << j++ * 7; + + if (j > 5) + throw new RuntimeException("VarInt too big"); + + if ((k & 0x80) != 128) + break; + } + + return i; + } + + public static void writeVarInt(DataOutputStream out, int paramInt) throws IOException + { + while (true) + { + if ((paramInt & 0xFFFFFF80) == 0) + { + out.writeByte(paramInt); + return; + } + + out.writeByte(paramInt & 0x7F | 0x80); + paramInt >>>= 7; + } + } + +} diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java index 49d625531..caf70a0ee 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java @@ -152,8 +152,8 @@ public class StatusHistoryRepository for (DedicatedServer dedicatedServer : dedicatedServers) { - double usedCpu = (1d - (double)dedicatedServer.getAvailableCpu() / (double)dedicatedServer.getMaxCpu()) * 100d; - double usedRam = (1d - (double)dedicatedServer.getAvailableRam() / (double)dedicatedServer.getMaxRam()) * 100d; + double usedCpu = dedicatedServer.getMaxCpu() == 0 ? 0 : (1d - (double)dedicatedServer.getAvailableCpu() / (double)dedicatedServer.getMaxCpu()) * 100d; + double usedRam = dedicatedServer.getMaxRam() == 0 ? 0 : (1d - (double)dedicatedServer.getAvailableRam() / (double)dedicatedServer.getMaxRam()) * 100d; preparedStatement.setString(1, dedicatedServer.getName()); preparedStatement.setString(2, dedicatedServer.getPrivateAddress()); diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java index 49f82a18c..bc9c5ca94 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java @@ -103,9 +103,7 @@ public class CustomerSupport extends MiniPlugin caller.sendMessage(C.cBlue + "Coins : " + C.cYellow + donor.getCoins()); caller.sendMessage(C.cBlue + "Gems : " + C.cYellow + donor.GetGems()); - int coinTransactionTotal = 0; int enjinCoinsReceived = 0; - int coinSpentTotal = 0; int oldChestsReceived = 0; int ancientChestsReceived = 0; int mythicalChestsReceived = 0; @@ -114,8 +112,6 @@ public class CustomerSupport extends MiniPlugin { if (transaction.Source.equalsIgnoreCase("Poll") || transaction.Source.equalsIgnoreCase("Halloween Pumpkin") || transaction.Source.equalsIgnoreCase("Treasure Chest") || transaction.Source.equalsIgnoreCase("Coin Party Bomb Pickup") || transaction.Source.contains("Reward") || transaction.Source.contains("purchase")) { - coinTransactionTotal += transaction.Amount; - if (transaction.Source.contains("purchase")) enjinCoinsReceived += transaction.Amount; } @@ -123,8 +119,6 @@ public class CustomerSupport extends MiniPlugin for (TransactionToken transaction : donor.getTransactions()) { - coinSpentTotal += transaction.Coins; - if (transaction.SalesPackageName.startsWith("Old Chest")) { if (transaction.Coins == 0 && transaction.Gems == 0) @@ -165,15 +159,6 @@ public class CustomerSupport extends MiniPlugin caller.sendMessage(C.cBlue + "Ancient Chests Received : " + C.cYellow + ancientChestsReceived); caller.sendMessage(C.cBlue + "Mythical Chests Received : " + C.cYellow + mythicalChestsReceived); - int coinsMissing = coinTransactionTotal - (donor.getCoins() + coinSpentTotal); - - if (coinsMissing > 0) - { - caller.sendMessage(C.cRed + "Coins missing!"); - new JsonMessage("[").color("blue").extra(C.cGreen + "Apply Missing Coins").color("green").click("run_command", "/sales coin " + playerName + " " + coinsMissing) - .add("] ").color("blue").add("Missing Coins.").color("yellow").sendToPlayer(caller); - } - caller.sendMessage(C.cDGreen + C.Strike + "============================================="); _salesPackageManager.displaySalesPackages(caller, playerName); caller.sendMessage(C.cDGreen + C.Strike + "============================================="); diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java index 6d9d2087f..cd977bf80 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java @@ -4,6 +4,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; @@ -18,20 +19,28 @@ public class CoinCommand extends CommandBase } @Override - public void Execute(Player caller, String[] args) + public void Execute(final Player caller, String[] args) { if (args == null || args.length != 2) return; - String playerName = args[0]; - int amount = Integer.parseInt(args[1]); + final String playerName = args[0]; + final int amount = Integer.parseInt(args[1]); - UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName); - - if (uuid == null) - UUIDFetcher.getUUIDOf(playerName); - - Plugin.getDonationManager().RewardCoins(null, caller.getName(), playerName, uuid, amount); - caller.sendMessage(F.main(Plugin.getName(), "Added " + amount + " coins to " + playerName + "'s account!")); + Plugin.getClientManager().loadClientByName(playerName, new Runnable() + { + public void run() + { + CoreClient client = Plugin.getClientManager().Get(playerName); + + if (client != null) + { + Plugin.getDonationManager().RewardCoins(null, caller.getName(), playerName, client.getAccountId(), amount); + caller.sendMessage(F.main(Plugin.getName(), "Added " + amount + " coins to " + playerName + "'s account!")); + } + else + caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + playerName + "'s account!")); + } + }); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java index d5c2bb514..87d3749a7 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java @@ -4,6 +4,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; @@ -18,26 +19,37 @@ public class GemHunterCommand extends CommandBase } @Override - public void Execute(Player caller, String[] args) + public void Execute(final Player caller, String[] args) { if (args == null || args.length != 2) return; - String playerName = args[0]; - int amount = Integer.parseInt(args[1]); - int experience = 0; - UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName); + final String playerName = args[0]; + final int amount = Integer.parseInt(args[1]); + int tempExp = 0; - if (uuid == null) - UUIDFetcher.getUUIDOf(playerName); - if (amount == 4) - experience = 70000; + tempExp = 70000; else if (amount == 8) - experience = 220000; + tempExp = 220000; - Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, uuid, "Gem Hunter Level " + amount, false, 0, false); - Plugin.getStatsManager().incrementStat(uuid.toString(), "Global.GemsEarned", experience); - caller.sendMessage(F.main(Plugin.getName(), "Added Level " + amount + " Gem Hunter to " + playerName + "'s account!")); + final int experience = tempExp; + + Plugin.getClientManager().loadClientByName(playerName, new Runnable() + { + public void run() + { + CoreClient client = Plugin.getClientManager().Get(playerName); + + if (client != null) + { + Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, client.getAccountId(), "Gem Hunter Level " + amount, false, 0, false); + Plugin.getStatsManager().incrementStat(client.getAccountId(), "Global.GemsEarned", experience); + caller.sendMessage(F.main(Plugin.getName(), "Added Level " + amount + " Gem Hunter to " + playerName + "'s account!")); + } + else + caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + playerName + "'s account!")); + } + }); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/ItemCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/ItemCommand.java index ff97c0786..336fd3c46 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/ItemCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/ItemCommand.java @@ -4,6 +4,7 @@ import java.util.UUID; import org.bukkit.entity.Player; +import mineplex.core.account.CoreClient; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -37,12 +38,6 @@ public class ItemCommand extends CommandBase } final String itemName = tempName; - UUID uuidLookup = Plugin.getClientManager().loadUUIDFromDB(playerName); - - if (uuidLookup == null) - uuidLookup = UUIDFetcher.getUUIDOf(playerName); - - final UUID uuid = uuidLookup; final int amount = amountSpecified; if (!Plugin.getInventoryManager().validCategory(category)) @@ -57,23 +52,37 @@ public class ItemCommand extends CommandBase return; } - Plugin.getDonationManager().PurchaseUnknownSalesPackage(new Callback() + Plugin.getClientManager().loadClientByName(playerName, new Runnable() { - public void run(TransactionResponse data) + public void run() { - Plugin.getInventoryManager().addItemToInventoryForOffline(new Callback() + final UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName); + final CoreClient client = Plugin.getClientManager().Get(playerName); + + if (uuid != null) { - public void run(Boolean success) + Plugin.getDonationManager().PurchaseUnknownSalesPackage(new Callback() { - if (success) - UtilPlayer.message(caller, F.main(Plugin.getName(), playerName + " received " + amount + " " + itemName + ".")); - else + public void run(TransactionResponse data) { - UtilPlayer.message(caller, F.main(Plugin.getName(), "ERROR processing " + playerName + " " + amount + " " + itemName + ".")); + Plugin.getInventoryManager().addItemToInventoryForOffline(new Callback() + { + public void run(Boolean success) + { + if (success) + UtilPlayer.message(caller, F.main(Plugin.getName(), playerName + " received " + amount + " " + itemName + ".")); + else + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "ERROR processing " + playerName + " " + amount + " " + itemName + ".")); + } + } + }, uuid, category, itemName, amount); } - } - }, uuid.toString(), category, itemName, amount); + }, playerName, client.getAccountId(), (amount == 1 ? itemName : itemName + " " + amount), false, 0, false); + } + else + caller.sendMessage(F.main(Plugin.getName(), "Couldn't find " + playerName + "'s account!")); } - }, playerName, uuid, (amount == 1 ? itemName : itemName + " " + amount), false, 0, false); + }); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java index 5d3dcab91..3858e54c8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java @@ -399,7 +399,7 @@ public class Halloween extends SoloGame { for (Player player : GetPlayers(false)) { - Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), player.getUniqueId(), "Pumpling", false, 0, true); + Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), Manager.GetClients().Get(player).getAccountId(), "Pumpling", false, 0, true); Manager.GetGame().AddGems(player, 30, "Killing the Pumpkin King", false, false); Manager.GetGame().AddGems(player, 10, "Participation", false, false); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/HalloweenManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/HalloweenManager.java index 0bdb338d8..fd45a05a8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/HalloweenManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/HalloweenManager.java @@ -217,7 +217,7 @@ public class HalloweenManager implements Listener event.setCancelled(true); event.getItem().remove(); - Manager.GetDonation().RewardCoins(null, "Halloween Pumpkin", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 4 * event.getItem().getItemStack().getAmount()); + Manager.GetDonation().RewardCoins(null, "Halloween Pumpkin", event.getPlayer().getName(), Manager.GetClients().Get(event.getPlayer()).getAccountId(), 4 * event.getItem().getItemStack().getAmount()); event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f); }