Merge branch 'master' of ssh://dev.mineplex.com:7999/min/mineplex

This commit is contained in:
Chiss 2013-10-18 09:12:19 +11:00
commit 02258b9fd3
13 changed files with 355 additions and 51 deletions

View File

@ -16,13 +16,14 @@ public class GlobalServerRepository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -31,6 +32,18 @@ public class GlobalServerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try

View File

@ -20,13 +20,14 @@ public class LobbyBalancerRepository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -35,6 +36,18 @@ public class LobbyBalancerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -53,13 +66,14 @@ public class LobbyBalancerRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -84,6 +98,18 @@ public class LobbyBalancerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -33,18 +33,21 @@ public class PlayerCountRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery();
@ -56,7 +59,7 @@ public class PlayerCountRepository
// Insert if not there
if (_id == -1)
{
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _address);
preparedStatementInsert.setInt(2, 0);
@ -86,6 +89,42 @@ public class PlayerCountRepository
}
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
@ -115,12 +154,13 @@ public class PlayerCountRepository
public boolean updatePlayerCountInDatabase(int players)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, players);
preparedStatement.setInt(2, _maxPlayers);
@ -144,6 +184,18 @@ public class PlayerCountRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -163,12 +215,13 @@ public class PlayerCountRepository
Connection connection = null;
PlayerTotalData playerData = new PlayerTotalData();
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -184,6 +237,18 @@ public class PlayerCountRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -21,13 +21,14 @@ public class PlayerTrackerRepository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -36,6 +37,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -53,12 +66,13 @@ public class PlayerTrackerRepository
public boolean updatePlayerServer(String name, String server)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_SERVER);
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_SERVER);
preparedStatement.setString(1, server);
preparedStatement.setString(2, name);
@ -89,6 +103,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -107,12 +133,13 @@ public class PlayerTrackerRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_SERVER);
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_SERVER);
preparedStatement.setString(1, name);
resultSet = preparedStatement.executeQuery();
@ -127,6 +154,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
@ -158,12 +197,13 @@ public class PlayerTrackerRepository
public boolean removePlayer(String name)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(DELETE_PLAYER);
preparedStatement = connection.prepareStatement(DELETE_PLAYER);
preparedStatement.setString(1, name);
@ -183,6 +223,18 @@ public class PlayerTrackerRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try

View File

@ -1,8 +1,6 @@
package mineplex.core.account;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import mineplex.core.account.event.AsyncClientLoadEvent;
import mineplex.core.account.event.ClientUnloadEvent;
@ -12,8 +10,6 @@ import mineplex.core.account.repository.token.ClientToken;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
@ -34,7 +30,6 @@ public class CoreClientManager implements Listener
private JavaPlugin _plugin;
private AccountRepository _repository;
private HashSet<String> _allClients;
private NautHashMap<String, CoreClient> _clientList;
private HashSet<String> _dontRemoveList;
@ -46,15 +41,9 @@ public class CoreClientManager implements Listener
_plugin = plugin;
_repository = new AccountRepository(webServer);
_allClients = new HashSet<String>();
_clientList = new NautHashMap<String, CoreClient>();
_dontRemoveList = new HashSet<String>();
for (String clientName : _repository.GetAllClientNames())
{
_allClients.add(clientName);
}
_plugin.getServer().getPluginManager().registerEvents(this, _plugin);
}
@ -117,11 +106,6 @@ public class CoreClientManager implements Listener
return _clientList.get(player.getName());
}
}
public HashSet<String> GetAll()
{
return _allClients;
}
@EventHandler(priority = EventPriority.LOWEST)
public void AsyncLogin(AsyncPlayerPreLoginEvent event)

View File

@ -32,6 +32,9 @@ import org.bukkit.util.Vector;
public class AntiHack extends MiniPlugin
{
public static AntiHack Instance;
private static Object _offensesSynch = new Object();
private AntiHackRepository _repository;
//Record Offesnes
private HashMap<Player, HashMap<String, Integer>> _offenses = new HashMap<Player, HashMap<String, Integer>>();
@ -60,6 +63,9 @@ public class AntiHack extends MiniPlugin
protected AntiHack(JavaPlugin plugin)
{
super("AntiHack", plugin);
_repository = new AntiHackRepository(this, plugin.getConfig().getString("serverstatus.name"));
_repository.initialize();
}
public static void Initialize(JavaPlugin plugin)
@ -172,6 +178,25 @@ public class AntiHack extends MiniPlugin
UpdateSpeed(player, event);
}
public HashMap<Player, HashMap<String, Integer>> getOffenses()
{
return _offenses;
}
public Object getOffensesSynch()
{
return _offensesSynch;
}
@EventHandler
public void updateDatabase(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
return;
_repository.saveOffenses();
}
private void UpdateFloat(Player player)
{
int count = 0;
@ -286,6 +311,7 @@ public class AntiHack extends MiniPlugin
limit = 0.32;
for (PotionEffect effect : player.getActivePotionEffects())
{
if (effect.getType().equals(PotionEffectType.SPEED))
{
if (UtilEnt.isGrounded(player))
@ -293,7 +319,8 @@ public class AntiHack extends MiniPlugin
else
limit += 0.04 * (effect.getAmplifier() + 1);
}
}
//Check
if (offset > limit && !UtilTime.elapsed(_speedTicks.get(player).getValue(), 150))//Counters Lag
{
@ -316,14 +343,17 @@ public class AntiHack extends MiniPlugin
private void AddOffense(Player player, String type)
{
if (!_offenses.containsKey(player))
_offenses.put(player, new HashMap<String, Integer>());
int previous = 0;
if (_offenses.get(player).containsKey(type))
previous = _offenses.get(player).get(type);
_offenses.get(player).put(type, previous + 1);
synchronized (getOffensesSynch())
{
if (!_offenses.containsKey(player))
_offenses.put(player, new HashMap<String, Integer>());
int previous = 0;
if (_offenses.get(player).containsKey(type))
previous = _offenses.get(player).get(type);
_offenses.get(player).put(type, previous + 1);
}
//Staff
for (Player other : UtilServer.getPlayers())
@ -352,6 +382,10 @@ public class AntiHack extends MiniPlugin
_ignore.remove(player);
_ignoreSecondary.remove(player);
_offenses.remove(player);
synchronized (getOffensesSynch())
{
_offenses.remove(player);
}
}
}

View File

@ -42,18 +42,21 @@ public class ServerStatusRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
PreparedStatement preparedStatementRetrieve = null;
PreparedStatement preparedStatementInsert = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
resultSet = preparedStatementRetrieve.executeQuery();
@ -65,7 +68,7 @@ public class ServerStatusRepository
// Insert if not there
if (_id == -1)
{
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _serverName);
preparedStatementInsert.setString(2, _serverGroup);
@ -99,6 +102,42 @@ public class ServerStatusRepository
}
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
@ -128,12 +167,13 @@ public class ServerStatusRepository
public boolean updatePlayerCountInDatabase(String motd, int players, int maxPlayers, int tps)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, _serverName);
preparedStatement.setString(2, _serverGroup);
@ -161,6 +201,18 @@ public class ServerStatusRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -179,13 +231,14 @@ public class ServerStatusRepository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -206,6 +259,18 @@ public class ServerStatusRepository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -2,6 +2,7 @@ package mineplex.hub;
import me.chiss.Core.MemoryFix.MemoryFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat;
import mineplex.core.command.CommandCenter;
@ -66,6 +67,7 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
CommandCenter.Initialize(this, clientManager);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
AntiHack.Initialize(this);
DonationManager donationManager = new DonationManager(this, GetWebServerAddress());

View File

@ -319,9 +319,15 @@ public class HubManager extends MiniClientPlugin<HubClient>
Rank rank = GetClients().Get(player).GetRank();
boolean ownsUltra = _donationManager.Get(player.getName()).OwnsUltraPackage();
//Rank Prefix
String rankStr = "";
if (rank != Rank.ALL)
rankStr = rank.Color + C.Bold + GetClients().Get(player).GetRank().Name.toUpperCase() + " ";
rankStr = rank.Color + C.Bold + rank.Name.toUpperCase() + " ";
if (ownsUltra && !rank.Has(Rank.ULTRA))
rankStr = Rank.ULTRA.Color + C.Bold + Rank.ULTRA.Name.toUpperCase() + " ";
//Party Chat
if (event.getMessage().charAt(0) == '@')

View File

@ -0,0 +1,6 @@
package mineplex.servermonitor;
public class DynamicMonitor
{
}

View File

@ -0,0 +1,13 @@
package mineplex.servermonitor;
import java.util.ArrayList;
import java.util.List;
public class GroupStatusData
{
public String Name;
public int Players;
public int MaxPlayers;
public List<ServerStatusData> Servers = new ArrayList<ServerStatusData>();
}

View File

@ -20,8 +20,8 @@ public class Repository
public void initialize()
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
@ -30,7 +30,7 @@ public class Repository
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@ -39,6 +39,18 @@ public class Repository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (connection != null)
{
try
@ -57,13 +69,14 @@ public class Repository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_OLD_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -88,6 +101,18 @@ public class Repository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
@ -120,13 +145,14 @@ public class Repository
{
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
List<GroupStatusData> groupData = new ArrayList<GroupStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
@ -151,6 +177,18 @@ public class Repository
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try

View File

@ -75,7 +75,7 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
private Logger _logger;
private LootFactory _lootFactory;
private Observer _observer;
private PetManager _petManager;
private PetManager _petManager;
private me.chiss.Core.Server.Server _serverModule;
private Spawn _spawn;
private Teleport _teleport;
@ -279,7 +279,7 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
}
@Override
public JavaPlugin GetPlugin()
public JavaPlugin GetPlugin()
{
return this;
}
@ -429,7 +429,7 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
}
@Override
public Teleport GetTeleport()
public Teleport GetTeleport()
{
if (_teleport == null)
_teleport = new Teleport(this, _clientManager, GetSpawn());