diff --git a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStats.java b/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStats.java deleted file mode 100644 index f2ea158bf..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStats.java +++ /dev/null @@ -1,87 +0,0 @@ -package mineplex.core.simpleStats; - -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; - -public class SimpleStats extends MiniPlugin -{ - private static Object _transferLock = new Object(); - - private SimpleStatsRepository _repository = new SimpleStatsRepository(); - private NautHashMap _entries = new NautHashMap(); - - public SimpleStats(JavaPlugin plugin) - { - super("SimpleStats", plugin); - - _repository.initialize(); - } - - /* - public NautHashMap getEntries() - { - synchronized (_transferLock) - { - return _entries; - } - }*/ - - @EventHandler - public void storeStatsUpdate(final UpdateEvent updateEvent) - { - if (updateEvent.getType() != UpdateType.SLOW) - return; - - Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() - { - public void run() - { - synchronized (_transferLock) - { - _entries = (_repository.retrieveStatRecords()); - } - } - }); - } - - public void store(String statName, String statValue) - { - final String statNameFinal = statName; - final String statValueFinal = statValue; - - Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() - { - public void run() - { - synchronized (_transferLock) - { - _repository.storeStatValue(statNameFinal, statValueFinal); - } - } - }); - } - - public NautHashMap getStat(String statName) - { - final String statNameFinal = statName; - - Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() - { - public void run() - { - synchronized (_transferLock) - { - _entries = _repository.retrieveStat(statNameFinal); - } - } - }); - - return _entries; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java deleted file mode 100644 index ff39bce61..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java +++ /dev/null @@ -1,220 +0,0 @@ -package mineplex.core.simpleStats; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import mineplex.core.common.util.NautHashMap; - -public class SimpleStatsRepository -{ - private static Object _connectionLock = new Object(); - - private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10"; - private String _userName = "root"; - private String _password = "tAbechAk3wR7tuTh"; //try to obfuscate this in the future! - - private static String CREATE_STATS_TABLE = "CREATE TABLE IF NOT EXISTS simpleStats (id INT NOT NULL AUTO_INCREMENT, statName VARCHAR(64), statValue VARCHAR(64), PRIMARY KEY (id));"; - private static String RETRIEVE_STATS_RECORDS = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats;"; - private static String STORE_STATS_RECORD = "INSERT INTO simpleStats (statName,statValue) VALUES(?,?);"; - private static String RETRIEVE_STAT_RECORD = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats WHERE statName = '?';"; - - private Connection _connection = null; - - public void initialize() - { - /* - PreparedStatement preparedStatement = null; - - try - { - Class.forName("com.mysql.jdbc.Driver"); - - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - // Create table - preparedStatement = _connection.prepareStatement(CREATE_STATS_TABLE); - preparedStatement.execute(); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - */ - } - - public NautHashMap retrieveStatRecords() - { - ResultSet resultSet = null; - PreparedStatement preparedStatement = null; - NautHashMap statRecords = new NautHashMap(); - - try - { - synchronized (_connectionLock) - { - if (_connection.isClosed()) - { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - - preparedStatement = _connection.prepareStatement(RETRIEVE_STATS_RECORDS); - - resultSet = preparedStatement.executeQuery(); - - while (resultSet.next()) - { - statRecords.put(resultSet.getString(1), resultSet.getString(2)); - } - } - } - 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 statRecords; - } - - public void storeStatValue(String statName, String statValue) - { - PreparedStatement preparedStatement = null; - - try - { - synchronized (_connectionLock) - { - if (_connection.isClosed()) - { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - - preparedStatement = _connection.prepareStatement(STORE_STATS_RECORD); - preparedStatement.setString(1, statName); - preparedStatement.setString(2, statValue); - - preparedStatement.executeUpdate(); - } - } - catch (Exception exception) - { - exception.printStackTrace(); - } - finally - { - if (preparedStatement != null) - { - try - { - preparedStatement.close(); - } - catch (SQLException e) - { - e.printStackTrace(); - } - } - } - } - - public NautHashMap retrieveStat(String statName) - { - ResultSet resultSet = null; - PreparedStatement preparedStatement = null; - NautHashMap statRecords = new NautHashMap(); - - try - { - synchronized (_connectionLock) - { - if (_connection.isClosed()) - { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - - preparedStatement = _connection.prepareStatement(RETRIEVE_STAT_RECORD); - preparedStatement.setString(1, statName); - - resultSet = preparedStatement.executeQuery(); - - while (resultSet.next()) - { - statRecords.put(resultSet.getString(1), resultSet.getString(2)); - } - } - } - 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 statRecords; - } -}