Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Cheese 2015-03-16 13:39:54 +11:00
commit 4581f49948
95 changed files with 739 additions and 1266 deletions

View File

@ -264,6 +264,9 @@
<fileset dir="../Mineplex.BungeeRotator/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/mysql.zip" />
@ -272,14 +275,18 @@
value="mineplex.bungee.BungeeRotator"/>
</manifest>
<zipfileset src="../Libraries/jooq-3.5.2.jar" />
<zipfileset src="../Libraries/httpclient-4.2.jar" />
<zipfileset src="../Libraries/httpcore-4.2.jar" />
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
<zipfileset src="../Libraries/httpmime-4.2.jar" />
<zipfileset src="../Libraries/gson-2.2.1.jar" />
<zipfileset src="../Libraries/javax.mail.jar" />
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
<zipfileset src="../Libraries/commons-dbcp2-2.0.1.jar" />
<zipfileset src="../Libraries/jedis-2.4.2.jar" />
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
<zipfileset src="../Libraries/commons-dbcp2-2.0.1.jar" />
</jar>
<copy file="../bin/BungeeRotator.jar" todir="../../Testing/BungeeRotator/"/>
</target>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/BungeeCord.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-io-2.4.jar"/>

View File

@ -19,7 +19,7 @@ public class Mineplexer extends Plugin
PlayerCount playerCount = new PlayerCount(this);
new FileUpdater(this);
new PlayerStats(this);
new InternetStatus(this);
//new InternetStatus(this);
new PlayerTracker(this);
new AccountManager(this, playerCount);
}

View File

@ -8,10 +8,11 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;

View File

@ -2,7 +2,7 @@ package mineplex.bungee.lobbyBalancer;
import java.util.Comparator;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.data.MinecraftServer;
public class LobbySorter implements Comparator<MinecraftServer>
{

View File

@ -0,0 +1,40 @@
package mineplex.bungee.motd;
import java.util.List;
import mineplex.serverdata.data.Data;
/**
* A GlobalMotd represents a set of MOTD packaged lines.
* @author MrTwiggy
*
*/
public class GlobalMotd implements Data
{
// The unique name representing this MOTD set
private String _name;
// List of lines describing the MOTD
private List<String> _motd;
public List<String> getMotd() { return _motd; }
/**
* Constructor
* @param name
* @param motd
*/
public GlobalMotd(String name, List<String> motd)
{
_name = name;
_motd = motd;
}
/**
* Unique identifying ID associated with this {@link GlobalMotd}.
*/
public String getDataId()
{
return _name;
}
}

View File

@ -106,7 +106,7 @@ public class Motd implements CustomMotd
List<String> lines = _manager.getMotdLines();
if (lines != null && lines.size() > 0)
{
int index = _ticks / (MAX_TICKS / (lines.size()-1));
int index = _ticks / (MAX_TICKS / (lines.size()));
String currentLine = index >= lines.size() ? lines.get(lines.size() - 1) : lines.get(index);
desc += "\n" + currentLine;
}

View File

@ -1,8 +1,14 @@
package mineplex.bungee.motd;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.BungeeServer;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
@ -14,7 +20,8 @@ import net.md_5.bungee.event.EventHandler;
public class MotdManager implements Listener, Runnable, CustomMotdFactory
{
private Plugin _plugin;
private MotdRepository _repository;
private DataRepository<GlobalMotd> _repository;
private String firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
private List<String> _motdLines;
@ -26,8 +33,8 @@ public class MotdManager implements Listener, Runnable, CustomMotdFactory
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 30L, TimeUnit.SECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
_repository = new MotdRepository();
_repository.initialize();
_repository = new RedisDataRepository<GlobalMotd>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.ALL, GlobalMotd.class, "globalMotd");
}
@EventHandler
@ -37,24 +44,35 @@ public class MotdManager implements Listener, Runnable, CustomMotdFactory
String motd = firstLine;
if (_motdLines != null && _motdLines.size() > 0)
{
motd += "\n" + _motdLines.get(0);
}
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
}
@Override
public void run()
{
_motdLines = _repository.retrieveMotd();
if (_repository.retrieveMotdAnimated())
// Add in default MOTD listing to database
if (!_repository.elementExists("MainMotd") || true)
{
InitialHandler.setCustomMotdFactory(this);
}
else
{
InitialHandler.setCustomMotdFactory(null);
List<String> lines = new ArrayList<String>();
lines.add(" §b§lUltra Sale §a§l50% Off"); // TODO: Implement in-game command to update MOTD?
updateMainMotd(lines);
}
_motdLines = _repository.getElement("MainMotd").getMotd(); // Update MOTD lines
InitialHandler.setCustomMotdFactory(this);
}
/**
* Update the main {@link GlobalMotd} determining the MOTD for Bungee instances.
* @param motdLines - the lines to update the MOTD to.
*/
public void updateMainMotd(List<String> motdLines)
{
_repository.addElement(new GlobalMotd("MainMotd", motdLines));
}
public List<String> getMotdLines()

View File

@ -1,171 +0,0 @@
package mineplex.bungee.motd;
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;
import net.md_5.bungee.api.ChatColor;
public class MotdRepository
{
private Connection _connection = null;
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeMotd (id INT NOT NULL AUTO_INCREMENT, motd VARCHAR(256), PRIMARY KEY (id));";
private static String RETRIEVE_MOTD = "SELECT motd FROM BungeeMotd;";
private static String RETRIEVE_ANIMATED = "SELECT value FROM bungeeSettings WHERE id='animatedMotd'";
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();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
System.out.println("Initialized MOTD.");
}
public List<String> retrieveMotd()
{
// String motd = "§b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r §c§l§m§kZ§6§l§m§kZ§e§l§m§kZ§a§l§m§kZ§b§l§m§kZ§r §f§lPLAY NOW§r §b§l§m§kZ§a§l§m§kZ§e§l§m§kZ§6§l§m§kZ§c§l§m§kZ";
ArrayList<String> lines = new ArrayList<String>();
// lines.add(" " + ChatColor.WHITE + ChatColor.BOLD + "New Game" + ChatColor.RED + ChatColor.BOLD + " Christmas Chaos");
// lines.add(" " + ChatColor.WHITE + ChatColor.BOLD + "Winter Sale" + ChatColor.BLUE + ChatColor.BOLD + " 33% Off Everything");
// lines.add(" " + ChatColor.WHITE + ChatColor.BOLD + "New Game" + ChatColor.RED + ChatColor.BOLD + " Christmas Chaos");
// return lines;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(RETRIEVE_MOTD);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
lines.add(resultSet.getString(1));
}
}
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 lines;
}
public boolean retrieveMotdAnimated()
{
boolean enabled = false;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(RETRIEVE_ANIMATED);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
enabled = resultSet.getBoolean(1);
}
}
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 enabled;
}
}

View File

@ -1,7 +1,16 @@
package mineplex.bungee.playerCount;
import java.io.File;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import mineplex.bungee.status.InternetStatus;
import mineplex.serverdata.Region;
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;
import net.md_5.bungee.api.ServerPing.Players;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.event.ProxyPingEvent;
@ -11,31 +20,64 @@ import net.md_5.bungee.event.EventHandler;
public class PlayerCount implements Listener, Runnable
{
private DataRepository<BungeeServer> _repository;
private UUID _uuid;
private Region _region;
private ListenerInfo _listenerInfo;
private Plugin _plugin;
private PlayerCountRepository _repository;
private int _totalPlayers = -1;
public PlayerCount(Plugin plugin)
{
_uuid = UUID.randomUUID();
_region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_plugin = plugin;
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS);
_plugin.getProxy().getScheduler().schedule(_plugin, this, 500L, 500L, TimeUnit.MILLISECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
_repository = new PlayerCountRepository(listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort(), listenerInfo.getMaxPlayers());
_repository.initialize();
_listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.ALL, BungeeServer.class, "bungeeServers");
}
public void run()
{
_repository.updatePlayerCountInDatabase(_plugin.getProxy().getOnlineCount());
BungeeServer snapshot = generateSnapshot();
_repository.addElement(snapshot, 15); // Update with a 15 second expiry on session
PlayerTotalData playerTotalData = _repository.retrievePlayerCount();
_totalPlayers = playerTotalData.CurrentPlayers;
_totalPlayers = fetchPlayerCount();
}
/**
* @return an up-to-date total player count across all active Bungee Servers.
*/
private int fetchPlayerCount()
{
int totalPlayers = 0;
for (BungeeServer server : _repository.getElements())
{
totalPlayers += server.getPlayerCount();
}
return totalPlayers;
}
/**
* @return a newly instantiated {@link BungeeServer} snapshot of the current state of this server.
*/
private BungeeServer generateSnapshot()
{
String name = _uuid.toString(); // Use random UUID for unique id name.
String host = _listenerInfo.getHost().getAddress().getHostAddress();
int port = _listenerInfo.getHost().getPort();
boolean connected = InternetStatus.isConnected();
int playerCount = _plugin.getProxy().getOnlineCount();
return new BungeeServer(name, _region, host, port, playerCount, connected);
}
@EventHandler

View File

@ -1,257 +0,0 @@
package mineplex.bungee.playerCount;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PlayerCountRepository
{
private Connection _connection = null;
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeServers (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(256), updated LONG, players INT, maxPlayers INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String INSERT_PLAYER_COUNT = "INSERT INTO BungeeServers(address, updated, players, maxPlayers, ram, maxRam) values(?, now(), ?, ?, ?, ?);";
private static String UPDATE_PLAYER_COUNT = "UPDATE BungeeServers SET updated = now(), players = ?, maxPlayers = ?, ram = ?, maxRam = ? WHERE id = ?;";
private static String RETRIEVE_ID = "SELECT id FROM BungeeServers WHERE address = ?;";
private static String RETRIEVE_PLAYER_COUNT = "SELECT SUM(players) AS playerCount, SUM(maxPlayers) AS maxPlayerCount FROM BungeeServers WHERE TIME_TO_SEC(TIMEDIFF(now(), BungeeServers.updated)) < 10;";
private int _id = -1;
private String _address;
private int _maxPlayers = 0;
public PlayerCountRepository(String address, int maxPlayers)
{
_address = address;
_maxPlayers = maxPlayers;
}
public void initialize()
{
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
preparedStatementRetrieve = _connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery();
while (resultSet.next())
{
_id = resultSet.getInt("id");
}
// Insert if not there
if (_id == -1)
{
preparedStatementInsert = _connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _address);
preparedStatementInsert.setInt(2, 0);
preparedStatementInsert.setInt(3, _maxPlayers);
preparedStatementInsert.setInt(4, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatementInsert.setInt(5, (int) (Runtime.getRuntime().maxMemory() / 1048576));
int affectedRows = preparedStatementInsert.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Creating bungee server failed, no rows affected.");
}
resultSet.close();
resultSet = preparedStatementInsert.getGeneratedKeys();
if (resultSet.next())
{
_id = resultSet.getInt(1);
System.out.println("id = " + _id);
}
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementRetrieve != null)
{
try
{
preparedStatementRetrieve.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (preparedStatementInsert != null)
{
try
{
preparedStatementInsert.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
System.out.println("Initialized PlayerCount.");
}
public boolean updatePlayerCountInDatabase(int players)
{
PreparedStatement preparedStatement = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, players);
preparedStatement.setInt(2, _maxPlayers);
preparedStatement.setInt(3, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatement.setInt(4, (int) (Runtime.getRuntime().maxMemory() / 1048576));
preparedStatement.setInt(5, _id);
int affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Updating bungee server player count failed, no rows affected.");
}
return true;
}
catch (Exception exception)
{
exception.printStackTrace();
try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
return updatePlayerCountInDatabase(players);
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public PlayerTotalData retrievePlayerCount()
{
PlayerTotalData playerData = new PlayerTotalData();
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
playerData.CurrentPlayers = resultSet.getInt(1);
playerData.MaxPlayers = resultSet.getInt(2);
return playerData;
}
}
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 playerData;
}
}

View File

@ -1,7 +0,0 @@
package mineplex.bungee.playerCount;
public class PlayerTotalData
{
public int CurrentPlayers;
public int MaxPlayers;
}

View File

@ -2,6 +2,11 @@ package mineplex.bungee.playerTracker;
import java.io.File;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.data.PlayerStatus;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.plugin.Listener;
@ -10,8 +15,13 @@ import net.md_5.bungee.event.EventHandler;
public class PlayerTracker implements Listener
{
// Default period before status expiry (8 hours)
private static final int DEFAULT_STATUS_TIMEOUT = 60 * 60 * 8;
// Repository storing player status' across network.
private DataRepository<PlayerStatus> _repository;
private Plugin _plugin;
private PlayerTrackerRepository _repository = null;
public PlayerTracker(Plugin plugin)
{
@ -19,8 +29,9 @@ public class PlayerTracker implements Listener
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
_repository = new PlayerTrackerRepository();
_repository.initialize(!new File("eu.dat").exists());
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
region, PlayerStatus.class, "playerStatus");
System.out.println("Initialized PlayerTracker.");
}
@ -32,7 +43,8 @@ public class PlayerTracker implements Listener
{
public void run()
{
_repository.updatePlayerServer(event.getPlayer().getName(), event.getServer().getInfo().getName());
PlayerStatus snapshot = new PlayerStatus(event.getPlayer().getName(), event.getServer().getInfo().getName());
_repository.addElement(snapshot, DEFAULT_STATUS_TIMEOUT);
}
});
}
@ -44,7 +56,7 @@ public class PlayerTracker implements Listener
{
public void run()
{
_repository.deleteServerTransfers(event.getPlayer().getName());
_repository.removeElement(event.getPlayer().getName());
}
});
}

View File

@ -1,203 +0,0 @@
package mineplex.bungee.playerTracker;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class PlayerTrackerRepository
{
private static Object _connectionLock = new Object();
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private boolean _us = true;
private static String CREATE_PLAYERMAP_TABLE = "CREATE TABLE IF NOT EXISTS playerMap (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(256), serverName VARCHAR(256), us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX playerIndex (playerName));";
private static String RETRIEVE_PLAYERMAP = "SELECT playerName, serverName FROM playerMap WHERE playerName = ? AND us = ?;";
private static String INSERT_PLAYERMAP = "INSERT INTO playerMap (playerName, serverName, us) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE serverName = VALUES(serverName), us = VALUES(us);";
private static String DELETE_PLAYERMAP = "DELETE FROM playerMap WHERE playerName = ? AND us = ?;";
private Connection _connection = null;
public void initialize(boolean us)
{
_us = us;
PreparedStatement preparedStatement = null;
try
{
Class.forName("com.mysql.jdbc.Driver");
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = _connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public String retrievePlayerServer(String playerName)
{
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
String server = "N/A";
try
{
synchronized (_connectionLock)
{
if (_connection.isClosed())
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERMAP);
preparedStatement.setString(1, playerName);
preparedStatement.setBoolean(2, _us);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
server = resultSet.getString(1);
}
}
}
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 server;
}
public void deleteServerTransfers(String playerName)
{
PreparedStatement preparedStatement = null;
try
{
synchronized (_connectionLock)
{
if (_connection.isClosed())
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
preparedStatement = _connection.prepareStatement(DELETE_PLAYERMAP);
preparedStatement.setString(1, playerName);
preparedStatement.setBoolean(2, _us);
preparedStatement.executeUpdate();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public void updatePlayerServer(String playerName, String serverName)
{
PreparedStatement preparedStatement = null;
try
{
synchronized (_connectionLock)
{
if (_connection.isClosed())
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
preparedStatement = _connection.prepareStatement(INSERT_PLAYERMAP);
preparedStatement.setString(1, playerName);
preparedStatement.setString(2, serverName);
preparedStatement.setBoolean(3, _us);
preparedStatement.executeUpdate();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -10,20 +10,15 @@ import net.md_5.bungee.api.plugin.Plugin;
public class InternetStatus implements Runnable
{
// Current internet connectivity status
private static boolean _connected = true;
public static boolean isConnected() { return _connected; }
private Plugin _plugin;
private StatusRepository _repository;
public InternetStatus(Plugin plugin)
{
_plugin = plugin;
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
boolean us = !new File("eu.dat").exists();
String address = listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort();
_repository = new StatusRepository(address, us);
_repository.initialize();
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES);
System.out.println("Initialized InternetStatus.");
@ -32,48 +27,28 @@ public class InternetStatus implements Runnable
@Override
public void run()
{
_repository.updateOnlineStatus(isOnline());
_connected = isOnline(); // Update _connected flag.
}
private boolean isOnline()
{
if (testUrl("www.google.com"))
return true;
else if (testUrl("www.espn.com"))
return true;
else if (testUrl("www.bing.com"))
return true;
return false;
return testUrl("www.google.com")
|| testUrl("www.espn.com")
|| testUrl("www.bing.com");
}
private boolean testUrl(String url)
{
Socket socket = null;
boolean reachable = false;
try
try (Socket socket = new Socket(url, 80))
{
socket = new Socket(url, 80);
reachable = true;
}
catch (Exception e)
{
// Meh i don't care
}
finally
{
if (socket != null)
{
try
{
socket.close();
}
catch (IOException e)
{
}
}
}
return reachable;
}

View File

@ -1,120 +0,0 @@
package mineplex.bungee.status;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class StatusRepository
{
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private String _address;
private boolean _us;
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));";
private static String INSERT_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated) values(?, ?, ?, now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated);";
private static String INSERT_ONLINE_SERVER = "INSERT INTO bungeeOnlineStatus (address, online, us, updated, lastOnline) values(?, ?, ?, now(), now()) ON DUPLICATE KEY UPDATE online = VALUES(online), updated = VALUES(updated), lastOnline = VALUES(lastOnline);";
public StatusRepository(String address, boolean us)
{
_address = address;
_us = us;
}
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public void updateOnlineStatus(boolean online)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(online ? INSERT_ONLINE_SERVER : INSERT_SERVER);
preparedStatement.setString(1, _address);
preparedStatement.setBoolean(2, online);
preparedStatement.setBoolean(3, _us);
preparedStatement.executeUpdate();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/javax.mail.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -1,142 +0,0 @@
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.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class BungeeRepository
{
// Yip Yip actual IP because if null route happens we can't resolve the HOSTNAME DERP FACE DEFEK7!!! -defek7
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_ONLINE_TABLE = "CREATE TABLE IF NOT EXISTS bungeeOnlineStatus (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(40), online BOOLEAN NOT NULL DEFAULT 0, updated LONG, us BOOLEAN NOT NULL DEFAULT 1, lastOnline LONG, PRIMARY KEY (id), UNIQUE INDEX addressIndex(address));";
private static String CREATE_PLAYER_TABLE = "CREATE TABLE IF NOT EXISTS BungeeServers (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(256), updated LONG, players INT, maxPlayers INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String RETRIEVE_SERVERS_PLAYERCOUNTS = "SELECT bos.address, players, maxPlayers, BungeeServers.updated, bos.lastOnline, BungeeServers.US, now() FROM BungeeServers INNER JOIN bungeeOnlineStatus AS bos ON bos.address = BungeeServers.address WHERE TIME_TO_SEC(TIMEDIFF(now(), BungeeServers.updated)) < 15;";
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = connection.prepareStatement(CREATE_ONLINE_TABLE);
preparedStatement.execute();
preparedStatement.close();
preparedStatement = connection.prepareStatement(CREATE_PLAYER_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public List<BungeeServer> getBungeeServers()
{
List<BungeeServer> bungeeServers = new ArrayList<BungeeServer>();
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVERS_PLAYERCOUNTS);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
long current = dateFormat.parse(resultSet.getString(7)).getTime();
long updated = dateFormat.parse(resultSet.getString(4)).getTime();
long lastOnline = dateFormat.parse(resultSet.getString(5)).getTime();
if (current - updated <= 15000 && current - lastOnline <= 300000)
{
BungeeServer server = new BungeeServer();
server.Address = resultSet.getString(1).split(":")[0];
server.Players = resultSet.getInt(2);
server.MaxPlayers = resultSet.getInt(3);
server.US = resultSet.getBoolean(6);
bungeeServers.add(server);
}
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return bungeeServers;
}
}

View File

@ -1,8 +1,10 @@
package mineplex.bungee;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
@ -18,16 +20,24 @@ import mineplex.bungee.api.ApiPostCall;
import mineplex.bungee.api.token.ARecord;
import mineplex.bungee.api.token.DnsRecord;
import mineplex.bungee.api.token.DomainRecords;
import mineplex.serverdata.Region;
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 BungeeRepository _repository = null;
private static DataRepository<BungeeServer> _repository;
//private static ServerRepository _repository = null;
private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
private static Logger _logger = Logger.getLogger("BungeeRotator");
private static boolean _debug = false;
public static void main(String args[])
{
{
try
{
Class.forName("com.mysql.jdbc.Driver");
@ -56,7 +66,11 @@ public class BungeeRotator
e1.printStackTrace();
}
_repository = new BungeeRepository();
_debug = new File("debug.dat").exists();
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.ALL, BungeeServer.class, "bungeeServers");
BungeeSorter bungeeSorter = new BungeeSorter();
int maxRecordCount = 10;
@ -64,100 +78,127 @@ public class BungeeRotator
{
try
{
List<BungeeServer> bungeeServers = _repository.getBungeeServers();
HashSet<String> usServers = new HashSet<String>();
HashSet<String> euServers = new HashSet<String>();
List<BungeeServer> bungeeServers = new ArrayList<BungeeServer>(_repository.getElements());
Collections.sort(bungeeServers, bungeeSorter);
for (BungeeServer server : bungeeServers)
if (_debug)
{
if (usServers.size() < maxRecordCount && server.US)
int totalPlayers = 0;
int usPlayers = 0;
int euPlayers = 0;
for (BungeeServer server : bungeeServers)
{
if (usServers.size() >= 2 && server.Players > 900)
continue;
totalPlayers += server.getPlayerCount();
log("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
usServers.add(server.Address);
}
else if (euServers.size() < maxRecordCount && !server.US)
{
if (euServers.size() >= 2 && server.Players > 900)
continue;
if (server.getRegion() == Region.US)
usPlayers += server.getPlayerCount();
else
euPlayers += server.getPlayerCount();
log("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
euServers.add(server.Address);
System.out.println(server.getRegion().toString() + " " + server.getPublicAddress() + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
}
System.out.println("US Players : " + usPlayers);
System.out.println("EU Players : " + euPlayers);
System.out.println("Total Players : " + totalPlayers);
System.out.println("Count : " + bungeeServers.size());
}
DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728,
"/records", "").Execute(DomainRecords.class);
List<DnsRecord> recordsToDelete = new ArrayList<DnsRecord>();
List<DnsRecord> recordsToAdd = new ArrayList<DnsRecord>();
for (DnsRecord record : records.data)
else
{
if (record.type.equalsIgnoreCase("A"))
HashSet<String> usServers = new HashSet<String>();
HashSet<String> euServers = new HashSet<String>();
for (BungeeServer server : bungeeServers)
{
if (record.name.equalsIgnoreCase("us"))
if (usServers.size() < maxRecordCount && server.getRegion() == Region.US)
{
if (usServers.contains(record.value))
usServers.remove(record.value);
else
recordsToDelete.add(record);
if (usServers.size() >= 2 && server.getPlayerCount() > 900)
continue;
log("SELECTED " + server.getPublicAddress() + " " + (server.getRegion() == Region.US ? "us" : "eu") + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
usServers.add(server.getPublicAddress());
}
else if (record.name.equalsIgnoreCase("eu"))
else if (euServers.size() < maxRecordCount && server.getRegion() != Region.US)
{
if (euServers.contains(record.value))
euServers.remove(record.value);
else
recordsToDelete.add(record);
if (euServers.size() >= 2 && server.getPlayerCount() > 900)
continue;
log("SELECTED " + server.getPublicAddress() + " " + (server.getRegion() == Region.US ? "us" : "eu") + " " + server.getPlayerCount() + "/" + server.getPlayerCount());
euServers.add(server.getPublicAddress());
}
}
}
for (String address : usServers)
{
recordsToAdd.add(new ARecord("us", address, 300));
log("Adding server address in DNS : " + "us " + address);
}
if (recordsToAdd.size() > 0)
{
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
log("Created " + recordsToAdd.size() + " records.");
}
recordsToAdd.clear();
for (String address : euServers)
{
recordsToAdd.add(new ARecord("eu", address, 300));
log("Adding server address in DNS : " + "eu " + address);
}
if (recordsToAdd.size() > 0)
{
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
log("Created " + recordsToAdd.size() + " records.");
}
recordsToAdd.clear();
if (recordsToDelete.size() > 0)
{
StringBuilder idBuilder = new StringBuilder();
for (DnsRecord record : recordsToDelete)
DomainRecords records = new ApiGetCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728,
"/records", "").Execute(DomainRecords.class);
List<DnsRecord> recordsToDelete = new ArrayList<DnsRecord>();
List<DnsRecord> recordsToAdd = new ArrayList<DnsRecord>();
for (DnsRecord record : records.data)
{
if (idBuilder.length() != 0)
idBuilder.append("&");
idBuilder.append("ids=" + record.id);
if (record.type.equalsIgnoreCase("A"))
{
if (record.name.equalsIgnoreCase("us"))
{
if (usServers.contains(record.value))
usServers.remove(record.value);
else
recordsToDelete.add(record);
}
else if (record.name.equalsIgnoreCase("eu"))
{
if (euServers.contains(record.value))
euServers.remove(record.value);
else
recordsToDelete.add(record);
}
}
}
for (String address : usServers)
{
recordsToAdd.add(new ARecord("us", address, 300));
log("Adding server address in DNS : " + "us " + address);
}
if (recordsToAdd.size() > 0)
{
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
log("Created " + recordsToAdd.size() + " records.");
}
recordsToAdd.clear();
for (String address : euServers)
{
recordsToAdd.add(new ARecord("eu", address, 300));
log("Adding server address in DNS : " + "eu " + address);
}
if (recordsToAdd.size() > 0)
{
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
log("Created " + recordsToAdd.size() + " records.");
}
recordsToAdd.clear();
new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?" + idBuilder.toString()).Execute();
log("Deleted " + recordsToDelete.size() + " records.");
if (recordsToDelete.size() > 0)
{
StringBuilder idBuilder = new StringBuilder();
for (DnsRecord record : recordsToDelete)
{
if (idBuilder.length() != 0)
idBuilder.append("&");
idBuilder.append("ids=" + record.id);
}
new ApiDeleteCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records?" + idBuilder.toString()).Execute();
log("Deleted " + recordsToDelete.size() + " records.");
}
}
try

View File

@ -1,9 +0,0 @@
package mineplex.bungee;
public class BungeeServer
{
public String Address;
public int Players;
public int MaxPlayers;
public boolean US;
}

View File

@ -2,14 +2,16 @@ package mineplex.bungee;
import java.util.Comparator;
import mineplex.serverdata.data.BungeeServer;
public class BungeeSorter implements Comparator<BungeeServer>
{
public int compare(BungeeServer a, BungeeServer b)
{
if (a.Players < b.Players)
if (a.getPlayerCount() < b.getPlayerCount())
return -1;
if (b.Players < a.Players)
if (b.getPlayerCount() < a.getPlayerCount())
return 1;
return 0;

View File

@ -337,7 +337,7 @@ public class CoreClientManager extends MiniPlugin
}
}
public void SaveRank(final String name, Rank rank, boolean perm)
public void SaveRank(final String name, final UUID uuid, Rank rank, boolean perm)
{
_repository.saveRank(new Callback<Rank>()
{
@ -350,7 +350,7 @@ public class CoreClientManager extends MiniPlugin
client.SetRank(newRank);
}
}
}, name, rank, perm);
}, name, uuid, rank, perm);
}
public void checkPlayerNameExact(final Callback<Boolean> callback, final String playerName)

View File

@ -2,6 +2,7 @@ package mineplex.core.account.command;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -11,6 +12,7 @@ import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.common.util.UtilPlayer;
public class UpdateRank extends CommandBase<CoreClientManager>
@ -86,13 +88,18 @@ public class UpdateRank extends CommandBase<CoreClientManager>
return;
}
UUID uuid = Plugin.loadUUIDFromDB(playerName);
if (uuid == null)
uuid = UUIDFetcher.getUUIDOf(playerName);
Plugin.getRepository().saveRank(new Callback<Rank>()
{
public void run(Rank rank)
{
caller.sendMessage(F.main(Plugin.getName(), target + "'s rank has been updated to " + rank.Name + "!"));
}
}, target, rank, true);
}, target, uuid, rank, true);
}
}, caller, playerName, true);

View File

@ -166,7 +166,7 @@ public class AccountRepository extends RepositoryBase
return uuids.size() == 1 ? uuids.get(0) : null;
}
public void saveRank(final Callback<Rank> callback, final String name, final Rank rank, final boolean perm)
public void saveRank(final Callback<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm)
{
final RankUpdateToken token = new RankUpdateToken();
token.Name = name;
@ -180,16 +180,16 @@ public class AccountRepository extends RepositoryBase
if (rank == Rank.ULTRA || rank == Rank.HERO || rank == Rank.LEGEND)
{
if (perm)
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
else
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("donorRank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
}
else
{
if (perm)
executeUpdate(UPDATE_ACCOUNT_RANK_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
executeUpdate(UPDATE_ACCOUNT_RANK_PERM, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
else
executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString()));
executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
}
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()

View File

@ -17,15 +17,13 @@ public final class DBPool
BasicDataSource source = new BasicDataSource();
source.addConnectionProperty("autoReconnect", "true");
source.addConnectionProperty("allowMultiQueries", "true");
source.setDefaultAutoCommit(true);
source.setEnableAutoCommitOnReturn(true);
source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
source.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
source.setDriverClassName("com.mysql.jdbc.Driver");
source.setUrl(url);
source.setUsername(username);
source.setPassword(password);
source.setMaxTotal(3);
source.setMaxIdle(3);
source.setMaxTotal(4);
source.setMaxIdle(4);
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);

View File

@ -81,6 +81,7 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
if (event.getType() != UpdateType.SLOW || Bukkit.getOnlinePlayers().size() == 0)
return;
/*
final Player[] onlinePlayers = UtilServer.getPlayers();
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
@ -108,10 +109,13 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
});
}
});
*/
}
public void addFriend(final Player caller, final String name)
{
caller.sendMessage(F.main(getName(), ChatColor.RED + "Friend is currently disabled."));
/*
if (caller.getName().equalsIgnoreCase(name))
{
caller.sendMessage(F.main(getName(), ChatColor.GRAY + "You cannot add yourself as a friend"));
@ -214,10 +218,13 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
});
}
});
*/
}
public void removeFriend(final Player caller, final String name)
{
caller.sendMessage(F.main(getName(), ChatColor.RED + "Friend is currently disabled."));
/*
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
@ -247,10 +254,13 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
});
}
});
*/
}
public void showFriends(Player caller)
{
caller.sendMessage(F.main(getName(), ChatColor.RED + "Friend is currently disabled."));
/*
boolean isStaff = ClientManager.Get(caller).GetRank().Has(Rank.HELPER);
boolean gotAFriend = false;
List<FriendStatus> friendStatuses = Get(caller).getFriends();
@ -383,6 +393,7 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
message.add(C.cAqua + C.Strike + "======================");
message.sendToPlayer(caller);
*/
}
public boolean isFriends(Player player, String friend)
@ -409,7 +420,7 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
@Override
public String getQuery(String uuid, String name)
{
return "SELECT tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = '"
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 + "';";
}
}

View File

@ -18,7 +18,7 @@ public class AddFriend extends CommandBase<FriendManager>
@Override
public void Execute(final Player caller, final String[] args)
{
if (args == null)
if (args == null || args.length < 1)
{
if (Plugin.getPreferenceManager().Get(caller).friendDisplayInventoryUI)
{

View File

@ -2,6 +2,12 @@ package mineplex.core.friend.data;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -12,18 +18,29 @@ import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.friend.FriendStatusType;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.data.PlayerStatus;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
public class FriendRepository extends RepositoryBase
{
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, 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 IN ";
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget, status, created) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget, ?, now() FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;";
private static String UPDATE_MUTUAL_RECORD = "UPDATE accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid SET aF.status = ? WHERE tA.name = ? AND fA.name = ?;";
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid WHERE fA.name = ? AND tA.name = ?;";
// Repository holding active PlayerStatus data.
private DataRepository<PlayerStatus> _repository;
public FriendRepository(JavaPlugin plugin)
{
super(plugin, DBPool.ACCOUNT);
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.currentRegion(), PlayerStatus.class, "playerStatus");
}
@Override
@ -81,29 +98,35 @@ public class FriendRepository extends RepositoryBase
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
Set<FriendData> friendDatas = new HashSet<FriendData>();
while (resultSet.next())
{
FriendStatus friend = new FriendStatus();
String uuidSource = resultSet.getString(1);
friend.Name = resultSet.getString(2);
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(3));
friend.ServerName = resultSet.getString(4);
friend.Online = !(friend.ServerName == null || friend.ServerName.isEmpty());
friend.LastSeenOnline = resultSet.getTimestamp(6).getTime() - resultSet.getTimestamp(5).getTime();
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(3));
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime() - resultSet.getTimestamp(4).getTime();
if (!friends.containsKey(uuidSource))
friends.put(uuidSource, new FriendData());
friends.get(uuidSource).getFriends().add(friend);
friendDatas.add(friends.get(uuidSource));
}
// Load the server status of friends for all sources.
for(FriendData friendData : friendDatas)
{
loadFriendStatuses(friendData);
}
}
});
return friends;
}
public FriendData loadClientInformation(ResultSet resultSet) throws SQLException
{
FriendData friendData = new FriendData();
@ -114,12 +137,59 @@ public class FriendRepository extends RepositoryBase
friend.Name = resultSet.getString(1);
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(2));
friend.ServerName = resultSet.getString(3);
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime() - resultSet.getTimestamp(4).getTime();
friend.LastSeenOnline = resultSet.getTimestamp(4).getTime() - resultSet.getTimestamp(3).getTime();
friend.ServerName = null;
friend.Online = (friend.ServerName != null);
friendData.getFriends().add(friend);
}
loadFriendStatuses(friendData);
return friendData;
}
/**
* Load the server status information for a list of {@link FriendStatus}.
* @param friendData - the {@link FriendStatus} object friends server status' are to be updated
* @param statuses - the fetched {@link PlayerStatus} associated with all online {@code friends}.
*/
public void loadFriendStatuses(FriendData friendData)
{
// Generate a set of all friend names
Set<String> friendNames = new HashSet<String>();
for(FriendStatus status : friendData.getFriends())
{
friendNames.add(status.Name);
}
// Load PlayerStatus' for friends
Collection<PlayerStatus> statuses = _repository.getElements(friendNames);
// Load player statuses into a mapping
Map<String, PlayerStatus> playerStatuses = new HashMap<String, PlayerStatus>();
for(PlayerStatus status : statuses)
{
playerStatuses.put(status.getName(), status);
}
// Load status information into friend data.
for (FriendStatus friend : friendData.getFriends())
{
PlayerStatus status = playerStatuses.get(friend.Name);
friend.Online = (status != null);
friend.ServerName = (friend.Online) ? status.getServer() : null;
}
}
/**
* @param playerName - the name of the player whose current server status is being fetched
* @return the {@link MinecraftServer} name that the player matching {@code playerName}
* is currently online on, if they are online, null otherwise.
*/
public String fetchPlayerServer(String playerName)
{
PlayerStatus status = _repository.getElement(playerName);
return (status == null) ? null : status.getServer();
}
}

View File

@ -61,6 +61,7 @@ public class LeaderboardManager extends MiniPlugin
*/
public boolean onStatEvent(final Player player, final StatType type, final int gamemode, final int value)
{
/*
// Asynchronously make DB call to insert stat event.
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
@ -69,6 +70,7 @@ public class LeaderboardManager extends MiniPlugin
_statEvents.insertStatEvent(player.getName(), gamemode, _serverGroup, type.getTypeId(), value);
}
});
*/
return true;
}

View File

@ -35,8 +35,8 @@ import mineplex.core.punish.Punish;
import mineplex.core.punish.PunishClient;
import mineplex.core.punish.Punishment;
import mineplex.core.punish.PunishmentSentence;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.transfers.AnnouncementCommand;
import mineplex.serverdata.commands.AnnouncementCommand;
import mineplex.serverdata.commands.ServerCommandManager;
public class MessageManager extends MiniClientPlugin<ClientMessage>
{

View File

@ -7,7 +7,7 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.message.MessageManager;
import mineplex.serverdata.transfers.AnnouncementCommand;
import mineplex.serverdata.commands.AnnouncementCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -5,7 +5,7 @@ import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.message.MessageManager;
import mineplex.serverdata.transfers.AnnouncementCommand;
import mineplex.serverdata.commands.AnnouncementCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -4,9 +4,9 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.transfers.AnnouncementCommand;
import mineplex.serverdata.commands.AnnouncementCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -4,8 +4,8 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.message.MessageManager;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class MessageHandler implements CommandCallback
{

View File

@ -2,7 +2,7 @@ package mineplex.core.message.redis;
import java.util.UUID;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.ServerCommand;
/**
* Used to send a admin or normal message between servers

View File

@ -2,7 +2,7 @@ package mineplex.core.message.redis;
import java.util.UUID;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.ServerCommand;
/**
* Used as a response in return to a admin or normal message between servers.

View File

@ -16,10 +16,10 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.party.redis.RedisPartyData;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.transfers.ServerTransfer;
import mineplex.serverdata.transfers.TransferCommand;
import mineplex.serverdata.commands.ServerTransfer;
import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -5,6 +5,7 @@ import java.util.Iterator;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.party.commands.PartyCommand;
import mineplex.core.party.redis.RedisPartyData;
import mineplex.core.party.redis.RedisPartyHandler;
@ -13,7 +14,7 @@ import mineplex.core.portal.ServerTransferEvent;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -29,7 +30,7 @@ public class PartyManager extends MiniPlugin
private Portal _portal;
private String _serverName;
public HashSet<Party> _parties = new HashSet<Party>();
public NautHashMap<String, Party> _partyLeaderMap = new NautHashMap<String, Party>();
public PartyManager(JavaPlugin plugin, Portal portal, CoreClientManager clientManager, PreferencesManager preferenceManager)
{
@ -64,7 +65,7 @@ public class PartyManager extends MiniPlugin
{
Party party = new Party(this);
party.JoinParty(player);
_parties.add(party);
_partyLeaderMap.put(player.getName(), party);
return party;
}
@ -76,51 +77,31 @@ public class PartyManager extends MiniPlugin
public void addParty(Party party)
{
for (Party parties : _parties)
{
if (parties.GetLeader().equalsIgnoreCase(party.GetLeader()))
{
parties.resetWaitingTime();
return;
}
}
_parties.add(party);
if (_partyLeaderMap.containsKey(party.GetLeader()))
_partyLeaderMap.get(party.GetLeader()).resetWaitingTime();
else
_partyLeaderMap.put(party.GetLeader(), party);
}
@EventHandler
public void serverTransfer(ServerTransferEvent event)
{
for (Party party : _parties)
Party party = _partyLeaderMap.get(event.getPlayer().getName());
if (party != null)
{
if (party.GetLeader().equals(event.getPlayer().getName()))
party.switchedServer();
RedisPartyData data = new RedisPartyData(party, _serverName);
data.setTargetServers(event.getServer());
data.publish();
for (Player player : party.GetPlayersOnline())
{
party.switchedServer();
boolean destLobby = event.getServer().equalsIgnoreCase("lobby");
RedisPartyData data = new RedisPartyData(party, destLobby ? _serverName : null);
if (!destLobby)
if (player != event.getPlayer())
{
data.setTargetServers(event.getServer());
_portal.sendPlayerToServer(player, event.getServer(), false);
}
data.publish();
if (!destLobby)
{
for (Player player : party.GetPlayersOnline())
{
if (player != event.getPlayer())
{
_portal.sendPlayerToServer(player, event.getServer(), false);
}
}
}
break;
}
}
}
@ -130,7 +111,7 @@ public class PartyManager extends MiniPlugin
{
try
{
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
party.PlayerJoin(event.getPlayer());
}
@ -144,7 +125,7 @@ public class PartyManager extends MiniPlugin
@EventHandler
public void PlayerQuit(PlayerQuitEvent event)
{
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
party.PlayerQuit(event.getPlayer());
}
@ -158,7 +139,7 @@ public class PartyManager extends MiniPlugin
ExpireParties();
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
party.ExpireInvitees();
party.UpdateScoreboard();
@ -167,7 +148,7 @@ public class PartyManager extends MiniPlugin
public void ExpireParties()
{
Iterator<Party> partyIterator = _parties.iterator();
Iterator<Party> partyIterator = _partyLeaderMap.values().iterator();
while (partyIterator.hasNext())
{
@ -184,7 +165,7 @@ public class PartyManager extends MiniPlugin
public Party GetParty(Player player)
{
for (Party party : _parties)
for (Party party : _partyLeaderMap.values())
{
if (party.GetPlayers().contains(player.getName()))
{

View File

@ -1,11 +1,10 @@
package mineplex.core.party.redis;
import mineplex.core.party.Party;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.ServerCommand;
public class RedisPartyData extends ServerCommand
{
private String[] _players;
private String _leader;
private String _previousServer;

View File

@ -2,8 +2,8 @@ package mineplex.core.party.redis;
import mineplex.core.party.Party;
import mineplex.core.party.PartyManager;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class RedisPartyHandler implements CommandCallback
{

View File

@ -23,9 +23,9 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
public class PersonalServerManager extends MiniPlugin
{

View File

@ -23,13 +23,13 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTabTitle;
import mineplex.core.portal.Commands.SendCommand;
import mineplex.core.portal.Commands.ServerCommand;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.transfers.ServerTransfer;
import mineplex.serverdata.transfers.TransferCommand;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.commands.ServerTransfer;
import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
public class Portal extends MiniPlugin
{

View File

@ -1,9 +1,9 @@
package mineplex.core.portal;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.transfers.ServerTransfer;
import mineplex.serverdata.transfers.TransferCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
import mineplex.serverdata.commands.ServerTransfer;
import mineplex.serverdata.commands.TransferCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -16,7 +16,7 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.punish.Command.PunishCommand;
import mineplex.core.punish.Tokens.PunishClientToken;
import mineplex.core.punish.Tokens.PunishmentToken;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
@ -44,7 +44,7 @@ public class Punish extends MiniPlugin
_clientManager = clientManager;
_repository = new PunishRepository(webServerAddress);
ServerCommandManager.getInstance().registerCommandType("PunishCommand", mineplex.serverdata.transfers.PunishCommand.class, new PunishmentHandler(this));
ServerCommandManager.getInstance().registerCommandType("PunishCommand", mineplex.serverdata.commands.PunishCommand.class, new PunishmentHandler(this));
}
public PunishRepository GetRepository()
@ -167,7 +167,7 @@ public class Punish extends MiniPlugin
if (target != null)
target.kickPlayer(kickReason);
else
new mineplex.serverdata.transfers.PunishCommand(playerName, true, false, kickReason).publish();
new mineplex.serverdata.commands.PunishCommand(playerName, true, false, kickReason).publish();
}
});
@ -193,7 +193,7 @@ public class Punish extends MiniPlugin
target.playSound(target.getLocation(), Sound.CAT_MEOW, 1f, 1f);
}
else
new mineplex.serverdata.transfers.PunishCommand(playerName, false, finalDuration != 0, F.main("Punish", F.elem(C.cGray + C.Bold + (finalDuration != 0 ? "Mute" : "Warning") + " Reason: ") + reason)).publish();
new mineplex.serverdata.commands.PunishCommand(playerName, false, finalDuration != 0, F.main("Punish", F.elem(C.cGray + C.Bold + (finalDuration != 0 ? "Mute" : "Warning") + " Reason: ") + reason)).publish();
_repository.LoadPunishClient(playerName, new Callback<PunishClientToken>()
{

View File

@ -3,9 +3,9 @@ package mineplex.core.punish;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.punish.Tokens.PunishClientToken;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.transfers.PunishCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.PunishCommand;
import mineplex.serverdata.commands.ServerCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -3,7 +3,7 @@ package mineplex.core.report;
import java.util.HashSet;
import java.util.Set;
import mineplex.serverdata.Data;
import mineplex.serverdata.data.Data;
public class Report implements Data
{

View File

@ -9,10 +9,10 @@ import mineplex.core.command.CommandCenter;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Portal;
import mineplex.core.report.command.ReportNotification;
import mineplex.serverdata.DataRepository;
import mineplex.serverdata.RedisDataRepository;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

View File

@ -1,6 +1,6 @@
package mineplex.core.report;
import mineplex.serverdata.Data;
import mineplex.serverdata.data.Data;
public class ReportProfile implements Data
{

View File

@ -4,7 +4,7 @@ import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilServer;
import mineplex.core.report.ReportManager;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.ServerCommand;
public class ReportNotification extends ServerCommand
{

View File

@ -1,11 +1,14 @@
package mineplex.core.reward.rewards;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.reward.Reward;
import mineplex.core.reward.RewardData;
import mineplex.core.reward.RewardRarity;
@ -21,7 +24,6 @@ public class RankReward extends Reward
_clientManager = clientManager;
}
@Override
public RewardData giveRewardCustom(Player player)
{
@ -34,7 +36,7 @@ public class RankReward extends Reward
return new RewardData(getRarity().getColor() + "Rank Upgrade Error", new ItemStack(Material.PAPER));
_clientManager.Get(player).SetRank(rank);
_clientManager.getRepository().saveRank(null, player.getName(), rank, true);
_clientManager.getRepository().saveRank(null, player.getName(), player.getUniqueId(), rank, true);
return new RewardData(getRarity().getColor() + rank.Name + " Rank", new ItemStack(Material.NETHER_STAR));
}

View File

@ -14,8 +14,8 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.servers.ServerManager;
public class ServerConfiguration extends MiniPlugin
{

View File

@ -14,14 +14,14 @@ import mineplex.core.common.util.Callback;
import mineplex.core.monitor.LagMeter;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.Utility;
import mineplex.serverdata.transfers.SuicideCommand;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.commands.SuicideCommand;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
public class ServerStatusManager extends MiniPlugin
{

View File

@ -2,10 +2,10 @@ package mineplex.core.status;
import mineplex.core.common.util.F;
import mineplex.core.portal.Portal;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.transfers.SuicideCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
import mineplex.serverdata.commands.SuicideCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -23,7 +23,7 @@ import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;

View File

@ -2,7 +2,7 @@ package mineplex.core.teleport.redis;
import java.util.UUID;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.ServerCommand;
public class RedisLocate extends ServerCommand
{

View File

@ -2,7 +2,7 @@ package mineplex.core.teleport.redis;
import java.util.UUID;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.ServerCommand;
public class RedisLocateCallback extends ServerCommand
{

View File

@ -2,9 +2,10 @@ package mineplex.core.teleport.redis;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.teleport.Teleport;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class RedisLocateHandler implements CommandCallback
{

View File

@ -21,8 +21,8 @@ import mineplex.core.portal.Portal;
import mineplex.core.updater.event.RestartServerEvent;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommandManager;
import mineplex.serverdata.transfers.RestartCommand;
import mineplex.serverdata.commands.RestartCommand;
import mineplex.serverdata.commands.ServerCommandManager;
public class FileUpdater extends MiniPlugin
{

View File

@ -2,10 +2,10 @@ package mineplex.core.updater;
import mineplex.core.common.util.F;
import mineplex.core.portal.Portal;
import mineplex.serverdata.CommandCallback;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommand;
import mineplex.serverdata.transfers.RestartCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.RestartCommand;
import mineplex.serverdata.commands.ServerCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

View File

@ -9,7 +9,7 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Portal;
import mineplex.serverdata.transfers.RestartCommand;
import mineplex.serverdata.commands.RestartCommand;
public class RestartServerCommand extends CommandBase<FileUpdater>
{

View File

@ -57,8 +57,8 @@ import mineplex.hub.queue.ui.QueueShop;
import mineplex.hub.server.ui.LobbyShop;
import mineplex.hub.server.ui.QuickShop;
import mineplex.hub.server.ui.ServerNpcShop;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.data.ServerGroup;
public class ServerManager extends MiniPlugin
{

View File

@ -4,8 +4,8 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import mineplex.serverdata.Data;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.Data;
public class QueueParty implements Data
{

View File

@ -9,16 +9,16 @@ import java.util.Set;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import mineplex.serverdata.ConnectionData;
import mineplex.serverdata.DataRepository;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.RedisDataRepository;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.Utility;
import mineplex.serverdata.transfers.ServerTransfer;
import mineplex.serverdata.transfers.TransferCommand;
import mineplex.serverdata.commands.ServerTransfer;
import mineplex.serverdata.commands.TransferCommand;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
public class QueueRepository
{

View File

@ -1,5 +1,7 @@
package mineplex.serverdata;
import java.io.File;
/**
* Region enumerates the various geographical regions where Mineplex servers are
* hosted.
@ -11,4 +13,12 @@ public enum Region
US,
EU,
ALL;
/**
* @return the geographical {@link Region} of the current running process.
*/
public static Region currentRegion()
{
return !new File("eu.dat").exists() ? Region.US : Region.EU;
}
}

View File

@ -1,5 +1,7 @@
package mineplex.serverdata;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

View File

@ -1,6 +1,5 @@
package mineplex.serverdata.transfers;
package mineplex.serverdata.commands;
import mineplex.serverdata.ServerCommand;
public class AnnouncementCommand extends ServerCommand
{

View File

@ -1,4 +1,5 @@
package mineplex.serverdata;
package mineplex.serverdata.commands;
public interface CommandCallback
{

View File

@ -1,4 +1,5 @@
package mineplex.serverdata;
package mineplex.serverdata.commands;
public class CommandType
{

View File

@ -1,6 +1,5 @@
package mineplex.serverdata.transfers;
package mineplex.serverdata.commands;
import mineplex.serverdata.ServerCommand;
public class PunishCommand extends ServerCommand
{

View File

@ -1,7 +1,6 @@
package mineplex.serverdata.transfers;
package mineplex.serverdata.commands;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommand;
public class RestartCommand extends ServerCommand
{

View File

@ -1,4 +1,5 @@
package mineplex.serverdata;
package mineplex.serverdata.commands;
public abstract class ServerCommand
{

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.commands;
import redis.clients.jedis.JedisPubSub;

View File

@ -1,8 +1,10 @@
package mineplex.serverdata;
package mineplex.serverdata.commands;
import java.util.HashMap;
import java.util.Map;
import mineplex.serverdata.Utility;
import mineplex.serverdata.servers.ServerManager;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@ -115,13 +117,16 @@ public class ServerCommandManager
Class<? extends ServerCommand> commandClazz = _commandTypes.get(commandType).getCommandType();
final ServerCommand serverCommand = Utility.deserialize(serializedCommand, commandClazz);
// TODO: Run synchronously?
CommandCallback callback = _commandTypes.get(commandType).getCallback();
serverCommand.run(); // Run server command without callback
if (callback != null)
if (serverCommand.isTargetServer(_localServerName))
{
callback.run(serverCommand); // Run callback
// TODO: Run synchronously?
CommandCallback callback = _commandTypes.get(commandType).getCallback();
serverCommand.run(); // Run server command without callback
if (callback != null)
{
callback.run(serverCommand); // Run callback
}
}
}
}

View File

@ -1,4 +1,4 @@
package mineplex.serverdata.transfers;
package mineplex.serverdata.commands;
public class ServerTransfer
{

View File

@ -1,7 +1,6 @@
package mineplex.serverdata.transfers;
package mineplex.serverdata.commands;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerCommand;
public class SuicideCommand extends ServerCommand
{

View File

@ -1,6 +1,5 @@
package mineplex.serverdata.transfers;
package mineplex.serverdata.commands;
import mineplex.serverdata.ServerCommand;
/**
* The TransferCommand is sent across the server network to notify

View File

@ -0,0 +1,57 @@
package mineplex.serverdata.data;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.Data;
public class BungeeServer implements Data
{
// The name of this server.
private String _name;
public String getName() { return _name; }
// The geographical region of this Bungee Server.
private Region _region;
public Region getRegion() { return _region; }
// The number of players currently online.
private int _playerCount;
public int getPlayerCount() { return _playerCount; }
// The public I.P address used by players to connect to the server.
private String _publicAddress;
public String getPublicAddress() { return _publicAddress; }
// The port the server is currently running/listening on.
private int _port;
public int getPort() { return _port; }
// Whether the Bungee server can connect to the internet.
private boolean _connected;
public boolean isConnected() { return _connected; }
/**
* Class constructor
* @param name
* @param publicAddress
* @param port
* @param playerCount
* @param connected
*/
public BungeeServer(String name, Region region, String publicAddress, int port, int playerCount, boolean connected)
{
_name = name;
_region = region;
_playerCount = playerCount;
_publicAddress = publicAddress;
_port = port;
_connected = connected;
}
/**
* Unique identifying ID for this Bungee Server.
*/
public String getDataId()
{
return _name;
}
}

View File

@ -1,4 +1,5 @@
package mineplex.serverdata;
package mineplex.serverdata.data;
public interface Data
{

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.data;
import java.util.Collection;
@ -15,6 +15,8 @@ public interface DataRepository<T extends Data>
public Collection<T> getElements();
public T getElement(String dataId);
public Collection<T> getElements(Collection<String> dataIds);
public void addElement(T element, int timeout);

View File

@ -1,8 +1,10 @@
package mineplex.serverdata;
package mineplex.serverdata.data;
import java.util.HashMap;
import java.util.Map;
import mineplex.serverdata.Region;
public class DedicatedServer
{

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.data;
public class MinecraftServer
{

View File

@ -0,0 +1,33 @@
package mineplex.serverdata.data;
import mineplex.serverdata.data.Data;
public class PlayerStatus implements Data
{
// The name of this server.
private String _name;
public String getName() { return _name; }
// The current message of the day (MOTD) of the server.
private String _server;
public String getServer() { return _server; }
/**
* Class constructor
* @param name
* @param server
*/
public PlayerStatus(String name, String server)
{
_name = name;
_server = server;
}
/**
* Unique identifying String ID associated with this {@link PlayerStatus}.
*/
public String getDataId()
{
return _name;
}
}

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.data;
import java.util.Collection;
import java.util.HashMap;
@ -6,6 +6,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import mineplex.serverdata.Region;
public class ServerGroup
{
private HashMap<String, String> _dataMap = null;

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.redis;
import java.util.ArrayList;
import java.util.Collection;
@ -6,6 +6,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.data.Data;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@ -20,15 +26,17 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
// The delimiter character used for redis key paths
public final char KEY_DELIMITER = '.';
// The pool used to retrieve jedis instances.
// The pools used to retrieve jedis instances.
private JedisPool _writePool;
private JedisPool _readPool;
// The geographical region of the servers stored by this ServerRepository
private Region _region;
// The class type of the elements stored in this repository
private Class<T> _elementType;
// A unique label designating the elements and this repository.
private String _elementLabel;
/**
@ -77,6 +85,12 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
@Override
public Collection<T> getElements()
{
return getElements(getActiveElements());
}
@Override
public Collection<T> getElements(Collection<String> dataIds)
{
Collection<T> elements = new HashSet<T>();
Jedis jedis = _readPool.getResource();
@ -86,11 +100,12 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
Pipeline pipeline = jedis.pipelined();
List<Response<String>> responses = new ArrayList<Response<String>>();
for (String dataId : getActiveElements())
for (String dataId : dataIds)
{
responses.add(pipeline.get(generateKey(dataId)));
}
// Block until all requests have received pipelined responses
pipeline.sync();
for (Response<String> response : responses)
@ -120,7 +135,7 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
return elements;
}
@Override
public T getElement(String dataId)
{
@ -186,7 +201,7 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
@Override
public void addElement(T element)
{
addElement(element, 1000 * 60 * 60 * 24 * 7 * 4 * 12 * 10); // Set the timeout to 10 years
addElement(element, 60 * 60 * 24 * 7 * 4 * 12 * 10); // Set the timeout to 10 years
}
@Override
@ -206,7 +221,7 @@ public class RedisDataRepository<T extends Data> implements DataRepository<T>
String dataKey = generateKey(dataId);
Transaction transaction = jedis.multi();
transaction.set(dataKey, null);
transaction.del(dataKey);
transaction.zrem(setKey, dataId);
transaction.exec();
}

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.redis;
import java.util.ArrayList;
import java.util.Collection;
@ -9,9 +9,15 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.data.DedicatedServer;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerRepository;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
@ -551,7 +557,7 @@ public class RedisServerRepository implements ServerRepository
return server;
}
/*
* <region> = "US" or "EU"
* serverstatus.minecraft.<region>.<name> stores the JSON encoded information of an active MinecraftServer instance.

View File

@ -1,4 +1,4 @@
package mineplex.serverdata;
package mineplex.serverdata.servers;
/**
* ConnectionData stores information relevant for initiating a connection to a repository.
@ -25,3 +25,4 @@ public class ConnectionData
_port = port;
}
}

View File

@ -1,7 +1,9 @@
package mineplex.serverdata;
package mineplex.serverdata.servers;
import java.util.Comparator;
import mineplex.serverdata.data.DedicatedServer;
public class DedicatedServerSorter implements Comparator<DedicatedServer>
{
@Override

View File

@ -1,9 +1,12 @@
package mineplex.serverdata;
package mineplex.serverdata.servers;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import mineplex.serverdata.Region;
import mineplex.serverdata.redis.RedisServerRepository;
/**
* ServerManager handles the creation/management of {@link ServerRepository}s for use.
* @author Ty

View File

@ -1,6 +1,11 @@
package mineplex.serverdata;
package mineplex.serverdata.servers;
import java.util.Collection;
import java.util.List;
import mineplex.serverdata.data.DedicatedServer;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.data.ServerGroup;
/**
* The ServerRepository is used for storing/retrieving active sessions
@ -72,5 +77,4 @@ public interface ServerRepository
void updateServerGroup(ServerGroup serverGroup);
public void removeServerGroup(ServerGroup serverGroup);
}

View File

@ -20,15 +20,15 @@ import java.util.logging.FileHandler;
import java.util.logging.Logger;
import mineplex.core.common.util.NautHashMap;
import mineplex.serverdata.DedicatedServer;
import mineplex.serverdata.DedicatedServerSorter;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.transfers.RestartCommand;
import mineplex.serverdata.transfers.SuicideCommand;
import mineplex.serverdata.commands.RestartCommand;
import mineplex.serverdata.commands.SuicideCommand;
import mineplex.serverdata.data.DedicatedServer;
import mineplex.serverdata.data.MinecraftServer;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.servers.DedicatedServerSorter;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ServerRepository;
public class ServerMonitor
{
@ -54,6 +54,18 @@ public class ServerMonitor
public static void main (String args[])
{
/*
MinecraftPingReply data = null;
try
{
data = new MinecraftPing().getPing(new MinecraftPingOptions().setHostname("127.0.0.1").setPort(25565));
}
catch (IOException e2)
{
e2.printStackTrace();
}
System.out.println(data.getDescription() + " " + data.getPlayers().getOnline());
*/
_region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_debug = new File("debug.dat").exists();
_repository = ServerManager.getServerRepository(_region); // Fetches and connects to server repo
@ -169,7 +181,7 @@ public class ServerMonitor
log("Saved Dedicated Server Stats.");
_historyRepository.saveServerGroupStats((int)totalCPU, (int)totalRAM, _serverGroupMap.values());
log("Saved ServerGroup Stats.");
_historyRepository.saveNetworkStats(usedCpuPercent, usedRamPercent, availableCPU, availableRAM, _region);
//_historyRepository.saveNetworkStats(usedCpuPercent, usedRamPercent, availableCPU, availableRAM, _region);
log("Saved Network Stats.");
for (ServerGroup groupStatus : _serverGroups)
@ -452,6 +464,10 @@ public class ServerMonitor
if (joinableServers > maxUHC)
serversToKill = maxUHC - joinableServers;
}
else if (serverGroup.getName().equalsIgnoreCase("Testing"))
{
return;
}
// KILL, CLEAN, THEN ADD
while (serversToKill > 0)

View File

@ -2,7 +2,7 @@ package mineplex.servermonitor;
import java.util.Comparator;
import mineplex.serverdata.MinecraftServer;
import mineplex.serverdata.data.MinecraftServer;
public class ServerSorter implements Comparator<MinecraftServer>
{

View File

@ -9,9 +9,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import mineplex.serverdata.DedicatedServer;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerGroup;
import mineplex.serverdata.data.DedicatedServer;
import mineplex.serverdata.data.ServerGroup;
import mineplex.servermonitor.data.BungeeStatusData;
public class StatusHistoryRepository

View File

@ -82,5 +82,9 @@ public class StaffServer extends JavaPlugin
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("04a484d0-93e0-4777-a70c-808046917e3a"), "EvilEsther"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("adaa7613-6683-400f-baf8-7272c04b2cb4"), "Timmy48081_"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("2d5fd31b-0aa5-41db-a62d-a4611a24349a"), "ishh"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("1def99f1-ae43-4917-a5dc-138dc73aaf36"), "FireStar891"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("a133d8bf-128c-47e1-b63c-33c278371593"), "blondebug"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("52eb645e-58e8-4a3f-a7dc-5c7a5e382232"), "blackfiend"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("0c4dd677-8e84-4755-8e66-f426a16b55bd"), "axegirl"));
}
}

View File

@ -37,11 +37,12 @@ public class ItemCommand extends CommandBase<SalesPackageManager>
}
final String itemName = tempName;
final UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName);
UUID uuidLookup = Plugin.getClientManager().loadUUIDFromDB(playerName);
if (uuid == null)
UUIDFetcher.getUUIDOf(playerName);
if (uuidLookup == null)
uuidLookup = UUIDFetcher.getUUIDOf(playerName);
final UUID uuid = uuidLookup;
final int amount = amountSpecified;
if (!Plugin.getInventoryManager().validCategory(category))

View File

@ -1,10 +1,13 @@
package mineplex.staffServer.salespackage.command;
import java.util.UUID;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.staffServer.salespackage.SalesPackageManager;
public class RankCommand extends CommandBase<SalesPackageManager>
@ -24,11 +27,16 @@ public class RankCommand extends CommandBase<SalesPackageManager>
String rank = args[1];
boolean perm = Boolean.parseBoolean(args[2]);
UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName);
if (uuid == null)
uuid = UUIDFetcher.getUUIDOf(playerName);
final Rank rankEnum = Rank.valueOf(rank);
if (rankEnum == Rank.HERO || rankEnum == Rank.ULTRA || rankEnum == Rank.LEGEND || rankEnum == Rank.ALL)
{
Plugin.getClientManager().SaveRank(playerName, mineplex.core.common.Rank.valueOf(rank), perm);
Plugin.getClientManager().SaveRank(playerName, uuid, mineplex.core.common.Rank.valueOf(rank), perm);
caller.sendMessage(F.main(Plugin.getName(), playerName + "'s rank has been updated to " + rank + "!"));
}
}