Added Player mapping.

Removed joining full servers for ultra.
This commit is contained in:
Jonathan Williams 2014-07-01 18:31:17 -07:00
parent b627e8fdf5
commit 6fd889d8fc
5 changed files with 253 additions and 5 deletions

View File

@ -196,14 +196,14 @@ public class CoreClientManager extends MiniPlugin
// Reserved Slot Check // Reserved Slot Check
if (Bukkit.getOnlinePlayers().length >= Bukkit.getServer().getMaxPlayers()) if (Bukkit.getOnlinePlayers().length >= Bukkit.getServer().getMaxPlayers())
{ {
if (client.GetRank().Has(event.getPlayer(), Rank.ULTRA, false)) if (client.GetRank().Has(event.getPlayer(), Rank.MODERATOR, false))
{ {
event.allow(); event.allow();
event.setResult(PlayerLoginEvent.Result.ALLOWED); event.setResult(PlayerLoginEvent.Result.ALLOWED);
return; return;
} }
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Full > Purchase Ultra at www.mineplex.com/shop"); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "This server is full and no longer accepts players.");
} }
} }

View File

@ -0,0 +1,33 @@
package mineplex.core.playerTracker;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.event.ClientUnloadEvent;
public class PlayerTracker extends MiniPlugin
{
private PlayerTrackerRepository _repository = null;
public PlayerTracker(JavaPlugin plugin, String serverName, boolean us)
{
super("Player Tracker", plugin);
_repository = new PlayerTrackerRepository();
_repository.initialize(serverName, us);
}
@EventHandler
public void trackPlayer(PlayerJoinEvent event)
{
_repository.updatePlayerServer(event.getPlayer().getName());
}
@EventHandler
public void untrackPlayer(ClientUnloadEvent event)
{
_repository.deleteServerTransfers(event.GetName());
}
}

View File

@ -0,0 +1,206 @@
package mineplex.core.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 String _serverName = "";
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 serverName = ? AND us = ?;";
private Connection _connection = null;
public void initialize(String serverName, boolean us)
{
_serverName = serverName;
_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.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();
}
}
}
}
public void updatePlayerServer(String playerName)
{
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

@ -20,6 +20,7 @@ public class ServerStatusManager extends MiniPlugin
private LagMeter _lagMeter; private LagMeter _lagMeter;
private String _name; private String _name;
private boolean _us;
private boolean _alternateSeconds; private boolean _alternateSeconds;
private boolean _enabled = true; private boolean _enabled = true;
@ -42,6 +43,7 @@ public class ServerStatusManager extends MiniPlugin
String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp(); String address = Bukkit.getServer().getIp().isEmpty() ? "localhost" : Bukkit.getServer().getIp();
_name = plugin.getConfig().getString("serverstatus.name"); _name = plugin.getConfig().getString("serverstatus.name");
_us = plugin.getConfig().getBoolean("serverstatus.us");
try try
{ {
@ -49,7 +51,7 @@ public class ServerStatusManager extends MiniPlugin
plugin.getConfig().getString("serverstatus.connectionurl"), plugin.getConfig().getString("serverstatus.connectionurl"),
plugin.getConfig().getString("serverstatus.username"), plugin.getConfig().getString("serverstatus.username"),
plugin.getConfig().getString("serverstatus.password"), plugin.getConfig().getString("serverstatus.password"),
plugin.getConfig().getBoolean("serverstatus.us"), _us,
_name, _name,
plugin.getConfig().getString("serverstatus.group"), plugin.getConfig().getString("serverstatus.group"),
address, address,
@ -144,4 +146,9 @@ public class ServerStatusManager extends MiniPlugin
{ {
return _name; return _name;
} }
public boolean getUs()
{
return _us;
}
} }

View File

@ -19,6 +19,7 @@ import mineplex.core.monitor.LagMeter;
import mineplex.core.movement.Movement; import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager; import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketHandler;
import mineplex.core.playerTracker.PlayerTracker;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager; import mineplex.core.preferences.PreferencesManager;
import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileManager;
@ -92,6 +93,7 @@ public class Hub extends JavaPlugin implements IRelation
PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager); PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager);
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), new DisguiseManager(this, packetHandler), new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager); HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), new DisguiseManager(this, packetHandler), new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager)); ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));
PlayerTracker tracker = new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);