diff --git a/Plugins/BuildFiles/EnjinTranslator.xml b/Plugins/BuildFiles/EnjinTranslator.xml
index 6207ea3d4..2e82ee910 100644
--- a/Plugins/BuildFiles/EnjinTranslator.xml
+++ b/Plugins/BuildFiles/EnjinTranslator.xml
@@ -8,6 +8,9 @@
+
+
+
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/RankBenefitsGiver9000Repository.java b/Plugins/Mineplex.Core/src/mineplex/core/RankBenefitsGiver9000Repository.java
index 83ac3e5fa..2dbe2b6f8 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/RankBenefitsGiver9000Repository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/RankBenefitsGiver9000Repository.java
@@ -5,10 +5,12 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class RankBenefitsGiver9000Repository extends RepositoryBase
@@ -18,9 +20,9 @@ public class RankBenefitsGiver9000Repository extends RepositoryBase
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
private static String RETRIEVE_BENEFITS = "SELECT benefit FROM rankBenefits WHERE uuid = ?;";
- public RankBenefitsGiver9000Repository(JavaPlugin plugin)
+ public RankBenefitsGiver9000Repository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java
index a562aad6a..e817b653e 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java
@@ -5,6 +5,7 @@ import java.util.List;
import java.util.UUID;
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.repository.token.LoginToken;
@@ -12,6 +13,7 @@ import mineplex.core.account.repository.token.RankUpdateToken;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher;
+import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnBoolean;
@@ -32,9 +34,9 @@ public class AccountRepository extends RepositoryBase
private String _webAddress;
- public AccountRepository(JavaPlugin plugin, String webAddress)
+ public AccountRepository(Plugin plugin, String webAddress)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
_webAddress = webAddress;
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java
index ec67315dd..515c10081 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java
@@ -5,6 +5,7 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import mineplex.core.database.DBPool;
import mineplex.core.logger.Logger;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
@@ -12,15 +13,8 @@ import org.bukkit.entity.Player;
public class AntiHackRepository
{
- private static Object _connectionLock = new Object();
-
private String _serverName;
-
- private static Connection _connection;
- private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
- private String _userName = "root";
- private String _password = "tAbechAk3wR7tuTh";
-
+
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS AntiHack_Kick_Log (id INT NOT NULL AUTO_INCREMENT, updated LONG, playerName VARCHAR(256), motd VARCHAR(56), gameType VARCHAR(56), map VARCHAR(256), serverName VARCHAR(256), report VARCHAR(256), ping VARCHAR(25), PRIMARY KEY (id));";
private static String UPDATE_PLAYER_OFFENSES = "INSERT INTO AntiHack_Kick_Log (updated, playerName, motd, gameType, map, serverName, report, ping) VALUES (now(), ?, ?, ?, ?, ?, ?, ?);";
@@ -33,13 +27,10 @@ public class AntiHackRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -70,47 +61,40 @@ public class AntiHackRepository
public void run()
{
PreparedStatement preparedStatement = null;
-
- synchronized (_connectionLock)
- {
- try
- {
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- preparedStatement = _connection.prepareStatement(UPDATE_PLAYER_OFFENSES);
-
-
- preparedStatement.setString(1, player.getName());
- preparedStatement.setString(2, motd);
- preparedStatement.setString(3, game);
- preparedStatement.setString(4, map);
- preparedStatement.setString(5, _serverName);
- preparedStatement.setString(6, report);
- preparedStatement.setString(7, ((CraftPlayer)player).getHandle().ping + "ms");
-
- preparedStatement.execute();
- }
- catch (Exception exception)
- {
- exception.printStackTrace();
- Logger.Instance.log(exception);
- }
- finally
- {
- if (preparedStatement != null)
- {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
+
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
+ {
+ preparedStatement = connection.prepareStatement(UPDATE_PLAYER_OFFENSES);
+
+ preparedStatement.setString(1, player.getName());
+ preparedStatement.setString(2, motd);
+ preparedStatement.setString(3, game);
+ preparedStatement.setString(4, map);
+ preparedStatement.setString(5, _serverName);
+ preparedStatement.setString(6, report);
+ preparedStatement.setString(7, ((CraftPlayer)player).getHandle().ping + "ms");
+
+ preparedStatement.execute();
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace();
+ Logger.Instance.log(exception);
+ }
+ finally
+ {
+ if (preparedStatement != null)
+ {
+ try
+ {
+ preparedStatement.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
}
}).start();
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java b/Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java
index 47825a4f4..93274675e 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java
@@ -1,51 +1,33 @@
package mineplex.core.database;
+import javax.sql.DataSource;
import java.sql.Connection;
-import java.sql.SQLException;
import org.apache.commons.dbcp2.BasicDataSource;
public class DBPool
{
- private static final DBPool _instance = new DBPool();
+ public static final DataSource ACCOUNT = openDataSource("jdbc:mysql://db.mineplex.com/Account", "root", "tAbechAk3wR7tuTh");
+ public static final DataSource QUEUE = openDataSource("jdbc:mysql://db.mineplex.com/Queue", "root", "tAbechAk3wR7tuTh");
+ public static final DataSource MINEPLEX = openDataSource("jdbc:mysql://db.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
+ public static final DataSource STATS_MINEPLEX = openDataSource("jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
- public static DBPool getInstance()
+ private static DataSource openDataSource(String url, String username, String password)
{
- return _instance;
- }
+ BasicDataSource source = new BasicDataSource();
+ source.addConnectionProperty("autoReconnect", "true");
+ source.setDefaultAutoCommit(true);
+ source.setEnableAutoCommitOnReturn(true);
+ source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
+ source.setDriverClassName("com.mysql.jdbc.Driver");
+ source.setUrl(url);
+ source.setUsername(username);
+ source.setPassword(password);
+ source.setMaxTotal(-1);
+ source.setMaxIdle(3);
+ source.setTimeBetweenEvictionRunsMillis(180 * 1000);
+ source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
- private BasicDataSource _source = null;
-
- public synchronized BasicDataSource source()
- {
- if (_source == null || _source.isClosed())
- {
- _source = new BasicDataSource();
- _source.addConnectionProperty("autoReconnect", "true");
- _source.setDefaultAutoCommit(true);
- _source.setEnableAutoCommitOnReturn(true);
- _source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
- _source.setDriverClassName("com.mysql.jdbc.Driver");
- _source.setUrl("jdbc:mysql://db.mineplex.com/Account");
- _source.setUsername("root");
- _source.setPassword("tAbechAk3wR7tuTh");
- }
-
- return _source;
- }
-
-
- public synchronized Connection getConnection() throws SQLException
- {
- return source().getConnection();
- }
-
- public synchronized void close() throws SQLException
- {
- if (_source != null)
- {
- _source.close();
- _source = null;
- }
+ return source;
}
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java
index 9b6cf846a..f2f2e7002 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java
@@ -1,99 +1,73 @@
package mineplex.core.database;
+import javax.sql.DataSource;
import java.sql.Connection;
-import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
+import org.bukkit.Bukkit;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.plugin.Plugin;
+
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.column.Column;
import mineplex.core.logger.Logger;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
-import org.bukkit.Bukkit;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.Listener;
-import org.bukkit.plugin.java.JavaPlugin;
-
public abstract class RepositoryBase implements Listener
{
- protected static Object _connectionLock = new Object();
-
- private Connection _connection = null;
-
private static Object _queueLock = new Object();
-
+
private NautHashMap _failedQueue = new NautHashMap();
-
- private String _connectionString;
- private String _userName;
- private String _password;
-
- protected JavaPlugin Plugin;
-
- public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
+
+ private final Plugin _plugin;
+ private final DataSource _dataSource;
+
+ public RepositoryBase(Plugin plugin, DataSource dataSource)
{
- Plugin = plugin;
-
- _connectionString = connectionString;
- _userName = username;
- _password = password;
-
+ _plugin = plugin;
+ _dataSource = dataSource;
+
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
public void run()
{
- synchronized (_connectionLock)
- {
- initialize();
- update();
- }
+ initialize();
+ update();
}
});
-
+
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
-
+
protected abstract void initialize();
-
+
protected abstract void update();
-
- protected Connection getConnection()
+
+ protected Connection getConnection() throws SQLException
{
- try
- {
- if (_connection == null || !_connection.isValid(1))
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
-
- return _connection;
+ return getDataSource().getConnection();
}
-
- protected int executeUpdate(String query, Column>...columns)
+
+ protected int executeUpdate(String query, Column>... columns)
{
PreparedStatement preparedStatement = null;
-
+
int affectedRows = 0;
-
- try
+
+ try (Connection connection = getConnection())
{
- if (_connection == null || !_connection.isValid(1))
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- preparedStatement = _connection.prepareStatement(query);
-
- for (int i=0; i < columns.length; i++)
+ preparedStatement = connection.prepareStatement(query);
+
+ for (int i = 0; i < columns.length; i++)
{
- columns[i].setValue(preparedStatement, i+1);
+ columns[i].setValue(preparedStatement, i + 1);
}
-
+
affectedRows = preparedStatement.executeUpdate();
}
catch (Exception exception)
@@ -107,30 +81,30 @@ public abstract class RepositoryBase implements Listener
try
{
preparedStatement.close();
- }
+ }
catch (SQLException e)
{
e.printStackTrace();
}
}
}
-
+
return affectedRows;
}
-
- protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column>...columns)
+
+ protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column>... columns)
{
ResultSet resultSet = null;
-
+
try
{
- for (int i=0; i < columns.length; i++)
+ for (int i = 0; i < columns.length; i++)
{
- columns[i].setValue(statement, i+1);
+ columns[i].setValue(statement, i + 1);
}
-
+
resultSet = statement.executeQuery();
-
+
callable.processResultSet(resultSet);
}
catch (Exception exception)
@@ -138,13 +112,13 @@ public abstract class RepositoryBase implements Listener
exception.printStackTrace();
}
finally
- {
+ {
if (resultSet != null)
{
try
{
resultSet.close();
- }
+ }
catch (SQLException e)
{
e.printStackTrace();
@@ -152,18 +126,15 @@ public abstract class RepositoryBase implements Listener
}
}
}
-
- protected void executeQuery(String query, ResultSetCallable callable, Column>...columns)
+
+ protected void executeQuery(String query, ResultSetCallable callable, Column>... columns)
{
PreparedStatement preparedStatement = null;
-
- try
+
+ try (Connection connection = getConnection())
{
- if (_connection == null || !_connection.isValid(1))
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- preparedStatement = _connection.prepareStatement(query);
-
+ preparedStatement = connection.prepareStatement(query);
+
executeQuery(preparedStatement, callable, columns);
}
catch (Exception exception)
@@ -177,7 +148,7 @@ public abstract class RepositoryBase implements Listener
try
{
preparedStatement.close();
- }
+ }
catch (SQLException e)
{
e.printStackTrace();
@@ -185,102 +156,112 @@ public abstract class RepositoryBase implements Listener
}
}
}
-
- protected int executeUpdate(PreparedStatement preparedStatement, Column>...columns)
+
+ protected int executeUpdate(PreparedStatement preparedStatement, Column>... columns)
{
int affectedRows = 0;
-
+
try
{
- for (int i=0; i < columns.length; i++)
+ for (int i = 0; i < columns.length; i++)
{
- columns[i].setValue(preparedStatement, i+1);
+ columns[i].setValue(preparedStatement, i + 1);
}
-
+
affectedRows = preparedStatement.executeUpdate();
}
catch (Exception exception)
{
exception.printStackTrace();
}
-
+
return affectedRows;
}
-
+
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
{
- Thread asyncThread = new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- databaseRunnable.run();
- }
- catch (Exception exception)
- {
- Logger.Instance.log(errorMessage + exception.getMessage());
-
- databaseRunnable.incrementFailCount();
-
- synchronized (_queueLock)
- {
- _failedQueue.put(databaseRunnable, errorMessage);
- }
- }
- }
- });
+ Thread asyncThread = new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ databaseRunnable.run();
+ }
+ catch (Exception exception)
+ {
+ Logger.Instance.log(errorMessage + exception.getMessage());
+
+ databaseRunnable.incrementFailCount();
+
+ synchronized (_queueLock)
+ {
+ _failedQueue.put(databaseRunnable, errorMessage);
+ }
+ }
+ }
+ });
asyncThread.start();
}
-
+
@EventHandler
public void processDatabaseQueue(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_01)
return;
-
+
processFailedQueue();
}
-
+
private void processFailedQueue()
{
synchronized (_queueLock)
{
- for (Iterator runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();)
+ for (Iterator runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext(); )
{
final DatabaseRunnable databaseRunnable = runnablesIterator.next();
-
- Thread asyncThread = new Thread(new Runnable()
- {
- public void run()
- {
- try
- {
- databaseRunnable.run();
- }
- catch (Exception exception)
- {
- Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
-
- if (databaseRunnable.getFailedCounts() < 4)
- {
- synchronized (_queueLock)
- {
- _failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
- }
- }
- else
- {
- Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
- }
- }
- }
- });
-
- runnablesIterator.remove();
+
+ Thread asyncThread = new Thread(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ databaseRunnable.run();
+ }
+ catch (Exception exception)
+ {
+ Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
+
+ if (databaseRunnable.getFailedCounts() < 4)
+ {
+ synchronized (_queueLock)
+ {
+ _failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
+ }
+ }
+ else
+ {
+ Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
+ }
+ }
+ }
+ });
+
+ runnablesIterator.remove();
asyncThread.start();
}
}
}
+
+ public Plugin getPlugin()
+ {
+ return _plugin;
+ }
+
+ public DataSource getDataSource()
+ {
+ return _dataSource;
+ }
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/Table.java b/Plugins/Mineplex.Core/src/mineplex/core/database/Table.java
deleted file mode 100644
index 57c362892..000000000
--- a/Plugins/Mineplex.Core/src/mineplex/core/database/Table.java
+++ /dev/null
@@ -1,417 +0,0 @@
-package mineplex.core.database;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import mineplex.core.common.util.NautHashMap;
-import mineplex.core.database.column.Column;
-
-public class Table
-{
- private static Connection _connection;
-
- private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
- private String _userName = "root";
- private String _password = "tAbechAk3wR7tuTh";
-
- private String _name;
- private List> _primaryKeys;
- private NautHashMap> _columns = new NautHashMap>();
- private Column> _index;
-
- public Table(String name, List> primaryKeys, List> columns, Column> index)
- {
- _name = name;
- _primaryKeys = primaryKeys;
-
- for (Column> column : columns)
- {
- _columns.put(column.Name, column);
- }
-
- _index = index;
- }
-
- public void initialize()
- {
- if (!doesTableExist())
- {
- create();
- }
- }
-/*
- private void updateSchema()
- {
- PreparedStatement getTableColumns = null;
- ResultSet resultSet = null;
-
- try
- {
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- getTableColumns = _connection.prepareStatement("SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '`" + _name + "`' AND table_schema = 'Mineplex';");
-
- resultSet = getTableColumns.executeQuery();
-
- HashSet columnExists = new HashSet();
-
- while (resultSet.next())
- {
- columnExists.add(resultSet.getString("COLUMN_NAME"));
- }
- }
- catch (Exception exception)
- {
- System.out.println("Error updating table `" + _name + "`.");
- exception.printStackTrace();
- }
- finally
- {
- if (getTableColumns != null)
- {
- try
- {
- getTableColumns.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
-
- if (resultSet != null)
- {
- try
- {
- resultSet.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
-*/
- private void create()
- {
- PreparedStatement createStatement = null;
-
- try
- {
- StringBuilder columnBuilder = new StringBuilder();
-
- for (Iterator> columnIterator = _columns.values().iterator(); columnIterator.hasNext();)
- {
- Column> column = columnIterator.next();
-
- columnBuilder.append(column.getCreateString());
-
- if (columnIterator.hasNext())
- {
- columnBuilder.append(", ");
- }
- }
-
- StringBuilder primaryKey = new StringBuilder();
-
- for (Column> column : _primaryKeys)
- {
- primaryKey.append(column.Name);
-
- if (!column.equals(_primaryKeys.get(_primaryKeys.size() - 1)))
- {
- primaryKey.append(", ");
- }
- }
-
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- createStatement = _connection.prepareStatement("CREATE TABLE IF NOT EXISTS `" + _name + "` (" + columnBuilder.toString() + ", PRIMARY KEY (" + primaryKey.toString() + "), INDEX (" + _index.Name + "));");
-
- createStatement.execute();
- }
- catch (Exception exception)
- {
- System.out.println("Error creating table `" + _name + "`.");
- exception.printStackTrace();
- }
- finally
- {
- if (createStatement != null)
- {
- try
- {
- createStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- }
-
- private boolean doesTableExist()
- {
- PreparedStatement checkIfTableExistsStatement = null;
-
- try
- {
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- checkIfTableExistsStatement = _connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'Mineplex' AND table_name LIKE '`" + _name + "`'");
-
- if (checkIfTableExistsStatement.executeQuery().next())
- return true;
- }
- catch (Exception exception)
- {
- System.out.println("Error updating table `" + _name + "`.");
- exception.printStackTrace();
- }
- finally
- {
- if (checkIfTableExistsStatement != null)
- {
- try
- {
- checkIfTableExistsStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- return false;
- }
-
- public void insert(List> columns)
- {
- StringBuilder temporaryBuilder = new StringBuilder();
- StringBuilder questionBuilder = new StringBuilder();
- StringBuilder updateBuilder = new StringBuilder();
-
- for (Column> column : columns)
- {
- temporaryBuilder.append(column.Name);
- questionBuilder.append("'" + column.Value + "'");
- updateBuilder.append(column.Name + " = VALUES(" + column.Name + ")");
-
- if (!column.equals(columns.get(columns.size() - 1)))
- {
- temporaryBuilder.append(", ");
- questionBuilder.append(", ");
- updateBuilder.append(", ");
- }
- }
-
- PreparedStatement preparedStatement = null;
-
- try
- {
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- preparedStatement = _connection.prepareStatement("INSERT INTO `" + _name + "` (" + temporaryBuilder.toString() + ") VALUES (" + questionBuilder.toString() + ") ON DUPLICATE KEY UPDATE " + updateBuilder.toString() + ";", Statement.RETURN_GENERATED_KEYS);
-
- preparedStatement.execute();
- }
- catch (Exception exception)
- {
- System.out.println("Error updating table `" + _name + "`.");
- exception.printStackTrace();
- }
- finally
- {
- if (preparedStatement != null)
- {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
-
- public boolean update(List> columns, Column> whereColumn)
- {
- List> whereColumnList = new ArrayList>();
- whereColumnList.add(whereColumn);
-
- return update(columns, whereColumnList);
- }
-
- public boolean update(List> columns, List> whereColumns)
- {
- String updateStatement = buildUpdateStatement(columns, whereColumns);
-
- PreparedStatement preparedStatement = null;
-
- try
- {
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- preparedStatement = _connection.prepareStatement(updateStatement);
-
- if (preparedStatement.executeUpdate() != 0)
- return true;
- }
- catch (Exception exception)
- {
- System.out.println("Error updating table `" + _name + "`.");
- exception.printStackTrace();
- }
- finally
- {
- if (preparedStatement != null)
- {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- return false;
- }
-
- public List retrieve(List> columns)
- {
- StringBuilder temporaryBuilder = new StringBuilder();
-
- for (Iterator> columnIterator = _columns.values().iterator(); columnIterator.hasNext();)
- {
- Column> column = columnIterator.next();
- temporaryBuilder.append(column.Name);
-
- if (columnIterator.hasNext())
- temporaryBuilder.append(", ");
- }
-
- PreparedStatement preparedStatement = null;
- ResultSet resultSet = null;
- List rows = new ArrayList();
-
- try
- {
- if (_connection == null || _connection.isClosed())
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
- preparedStatement = _connection.prepareStatement("Select " + temporaryBuilder.toString() + " FROM `" + _name + "` " + buildWhereString(columns) + ";");
-
- resultSet = preparedStatement.executeQuery();
-
- while (resultSet.next())
- {
- Row row = new Row();
-
- for (Column> column : columns)
- {
- column.getValue(resultSet);
- row.Columns.put(column.Name, column);
- }
-
- rows.add(row);
- }
- }
- catch (Exception exception)
- {
- System.out.println("Error updating table `" + _name + "`.");
- exception.printStackTrace();
- }
- finally
- {
- if (preparedStatement != null)
- {
- try
- {
- preparedStatement.close();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
-
- return rows;
- }
-
- private String buildUpdateStatement(List> columns, List> whereColumns)
- {
- StringBuilder setBuilder = new StringBuilder();
-
- if (columns.size() > 0)
- setBuilder.append("SET ");
-
- for (Column> column : columns)
- {
- setBuilder.append(column.Name + " = '" + column.Value + "'");
-
- if (!column.equals(columns.get(columns.size() - 1)))
- setBuilder.append(", ");
- }
-
- return "UPDATE `" + _name + "` " + setBuilder.toString() + " " + buildWhereString(whereColumns) + ";";
- }
-
- private String buildWhereString(List> columns)
- {
- StringBuilder whereBuilder = new StringBuilder();
-
- if (columns.size() > 0)
- {
- whereBuilder.append("WHERE ");
- }
-
- for (Column> column : columns)
- {
- whereBuilder.append(column.Name + " = '" + column.Value + "'");
-
- if (!column.equals(columns.get(columns.size() - 1)))
- whereBuilder.append(" AND ");
- }
-
- return whereBuilder.toString();
- }
-
- public Column> getColumn(String columnName)
- {
- return _columns.get(columnName);
- }
-
- public Row createRow()
- {
- Row row = new Row();
-
- for (Column> column : _columns.values())
- {
- row.Columns.put(column.Name, column);
- }
-
- return row;
- }
-}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java
index 9523c2e06..b8f4f95fc 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java
@@ -2,10 +2,12 @@ package mineplex.core.donation.repository;
import java.util.UUID;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher;
+import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
@@ -28,9 +30,9 @@ public class DonationRepository extends RepositoryBase
private String _webAddress;
- public DonationRepository(JavaPlugin plugin, String webAddress)
+ public DonationRepository(Plugin plugin, String webAddress)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
_webAddress = webAddress;
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java
index 0aaac6e85..a8cbe5c0b 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java
@@ -22,27 +22,11 @@ public class EloManager extends MiniPlugin
{
super("Elo Rating", plugin);
- setupConfigValues(plugin);
-
- _repository = new EloRepository(plugin.getConfig().getString("elo.connectionurl"));
+ _repository = new EloRepository();
_ratingSystem = new EloRatingSystem(new KFactor(0, 1200, 25), new KFactor(1201, 1600, 20), new KFactor(1601, 2000, 15), new KFactor(2001, 2500, 10));
_playerElos = new NautHashMap>();
}
- private void setupConfigValues(JavaPlugin plugin)
- {
- try
- {
- plugin.getConfig().addDefault("elo.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
- plugin.getConfig().set("elo.connectionurl", plugin.getConfig().getString("elo.connectionurl"));
- plugin.saveConfig();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
@EventHandler
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
{
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java
index c3aab6735..fc30a882d 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java
@@ -7,24 +7,18 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
+import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
+import mineplex.core.database.DBPool;
public class EloRepository
{
- private String _connectionString;
- private String _userName = "root";
- private String _password = "tAbechAk3wR7tuTh";
-
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), gameType VARCHAR(256), elo INT, PRIMARY KEY (id), UNIQUE INDEX uuid_gameType_index (uuid, gameType));";
private static String INSERT_ELO = "INSERT INTO eloRating (uuid, gameType, elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE elo=VALUES(elo);";
private static String RETRIEVE_ELO = "SELECT gameType, elo FROM eloRating WHERE uuid = ?;";
- private Connection _connection = null;
-
- public EloRepository(String connectionUrl)
+ public EloRepository()
{
- _connectionString = connectionUrl;
-
initialize();
}
@@ -32,12 +26,10 @@ public class EloRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_ELO_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_ELO_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -66,14 +58,9 @@ public class EloRepository
int affectedRows = 0;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(INSERT_ELO);
+ preparedStatement = connection.prepareStatement(INSERT_ELO);
preparedStatement.setString(1, uuid);
preparedStatement.setString(2, gameType);
@@ -118,14 +105,9 @@ public class EloRepository
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(RETRIEVE_ELO);
+ preparedStatement = connection.prepareStatement(RETRIEVE_ELO);
preparedStatement.setString(1, uuid.toString());
resultSet = preparedStatement.executeQuery();
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java
index f5282e269..7e460416a 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java
@@ -5,9 +5,11 @@ import java.sql.SQLException;
import java.util.UUID;
import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
@@ -26,9 +28,9 @@ public class FriendRepository extends RepositoryBase
// Not mutual, need to drop accountFriend to recreate with constraint.
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
- public FriendRepository(JavaPlugin plugin)
+ public FriendRepository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java
index 37d1c186e..5ec50c578 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java
@@ -5,8 +5,10 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
@@ -29,9 +31,9 @@ public class InventoryRepository extends RepositoryBase
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
private static String RETRIEVE_CLIENT_INVENTORY = "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = ?;";
- public InventoryRepository(JavaPlugin plugin)
+ public InventoryRepository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java b/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java
index 25108a02c..e584f2913 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java
@@ -21,9 +21,7 @@ public class Logger
public Logger(JavaPlugin plugin)
{
- setupConfigValues(plugin);
-
- _repository = new LoggerRepository(plugin.getConfig().getString("log.connectionurl"), plugin.getConfig().getString("serverstatus.name"));
+ _repository = new LoggerRepository(plugin.getConfig().getString("serverstatus.name"));
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
{
@@ -36,20 +34,6 @@ public class Logger
});
}
- private void setupConfigValues(JavaPlugin plugin)
- {
- try
- {
- plugin.getConfig().addDefault("log.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
- plugin.getConfig().set("log.connectionurl", plugin.getConfig().getString("log.connectionurl"));
- plugin.saveConfig();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
public void log(final String message)
{
System.out.println(message);
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java
index 0ba4d99ce..3dce0186d 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/logger/LoggerRepository.java
@@ -5,23 +5,17 @@ import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import mineplex.core.database.DBPool;
+
public class LoggerRepository
{
- private static Object _connectionLock = new Object();
-
- private String _connectionString;
- private String _userName = "root";
- private String _password = "tAbechAk3wR7tuTh";
-
private static String CREATE_LOG_TABLE = "CREATE TABLE IF NOT EXISTS errorLog (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(256), message VARCHAR(256), date LONG, PRIMARY KEY (id));";
private static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());";
-
- private Connection _connection = null;
+
private String _serverName;
- public LoggerRepository(String connectionUrl, String serverName)
+ public LoggerRepository(String serverName)
{
- _connectionString = connectionUrl;
_serverName = serverName;
initialize();
@@ -31,12 +25,10 @@ public class LoggerRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_LOG_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_LOG_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -63,26 +55,18 @@ public class LoggerRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(INSERT_LOG);
+
+ for (String msg : message)
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(INSERT_LOG);
-
- for (String msg : message)
- {
- preparedStatement.setString(1, _serverName);
- preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
- preparedStatement.addBatch();
- }
-
- preparedStatement.executeBatch();
+ preparedStatement.setString(1, _serverName);
+ preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
+ preparedStatement.addBatch();
}
+
+ preparedStatement.executeBatch();
}
catch (Exception exception)
{
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java
index e818920a7..6d7718266 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java
@@ -106,21 +106,6 @@ public class NpcManager extends MiniPlugin
private final Set _npcDeletingPlayers = new HashSet<>();
private Connection _connection;
- protected Connection getConnection()
- {
- try
- {
- if (_connection == null || !_connection.isValid(1))
- _connection = DriverManager.getConnection("jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
-
- return _connection;
- }
-
public NpcManager(JavaPlugin plugin, Creature creature)
{
super("NpcManager", plugin);
@@ -276,9 +261,7 @@ public class NpcManager extends MiniPlugin
public Entity addNpc(Player player, EntityType entityType, double radius, boolean adult, String name, String entityMeta) throws SQLException
{
- Connection connection = getConnection();
-
- //try (Connection connection = DBPool.getInstance().getConnection())
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
String helmet = itemStackToYaml(player.getInventory().getHelmet());
String chestplate = itemStackToYaml(player.getInventory().getChestplate());
@@ -393,9 +376,7 @@ public class NpcManager extends MiniPlugin
if (npc != null)
{
- Connection connection = getConnection();
-
- try// (Connection connection = DBPool.getInstance().getConnection())
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
npc.getDatabaseRecord().attach(DSL.using(connection).configuration());
npc.getDatabaseRecord().delete();
@@ -502,9 +483,7 @@ public class NpcManager extends MiniPlugin
{
String serverType = getServerName();
- Connection connection = getConnection();
-
- //try (Connection connection = DBPool.getInstance().getConnection())
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
Result result = DSL.using(connection)
.selectFrom(Tables.npcs)
@@ -530,9 +509,7 @@ public class NpcManager extends MiniPlugin
{
String serverType = getServerName();
- Connection connection = getConnection();
-
- //try (Connection connection = DBPool.getInstance().getConnection())
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
DSL.using(connection)
.delete(Tables.npcs)
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/playerTracker/PlayerTrackerRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/playerTracker/PlayerTrackerRepository.java
index 2ffdc3d5a..b1f7e83a7 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/playerTracker/PlayerTrackerRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/playerTracker/PlayerTrackerRepository.java
@@ -6,14 +6,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import mineplex.core.database.DBPool;
+
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;
@@ -22,8 +18,6 @@ public class PlayerTrackerRepository
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;
@@ -31,14 +25,10 @@ public class PlayerTrackerRepository
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
- Class.forName("com.mysql.jdbc.Driver");
-
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -67,25 +57,17 @@ public class PlayerTrackerRepository
PreparedStatement preparedStatement = null;
String server = "N/A";
- try
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
- synchronized (_connectionLock)
- {
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERMAP);
- preparedStatement.setString(1, playerName);
- preparedStatement.setBoolean(2, _us);
+ preparedStatement = connection.prepareStatement(RETRIEVE_PLAYERMAP);
+ preparedStatement.setString(1, playerName);
+ preparedStatement.setBoolean(2, _us);
- resultSet = preparedStatement.executeQuery();
-
- while (resultSet.next())
- {
- server = resultSet.getString(1);
- }
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next())
+ {
+ server = resultSet.getString(1);
}
}
catch (Exception exception)
@@ -126,22 +108,14 @@ public class PlayerTrackerRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
- 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 = _connection.prepareStatement(DELETE_PLAYERMAP);
- preparedStatement.setString(1, playerName);
- preparedStatement.setString(2, _serverName);
- preparedStatement.setBoolean(3, _us);
-
- preparedStatement.executeUpdate();
- }
+ preparedStatement.executeUpdate();
}
catch (Exception exception)
{
@@ -167,22 +141,14 @@ public class PlayerTrackerRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.ACCOUNT.getConnection())
{
- 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 = _connection.prepareStatement(INSERT_PLAYERMAP);
- preparedStatement.setString(1, playerName);
- preparedStatement.setString(2, _serverName);
- preparedStatement.setBoolean(3, _us);
-
- preparedStatement.executeUpdate();
- }
+ preparedStatement.executeUpdate();
}
catch (Exception exception)
{
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java
index defec6261..fb2ed6a71 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java
@@ -36,28 +36,13 @@ public class PreferencesManager extends MiniClientPlugin
{
super("Preferences", plugin);
- setupConfigValues();
-
- _repository = new PreferencesRepository(plugin, plugin.getConfig().getString("preferences.connectionurl"));
+ _repository = new PreferencesRepository(plugin);
+
_shop = new PreferencesShop(this, clientManager, donationManager);
AddCommand(new PreferencesCommand(this));
}
- private void setupConfigValues()
- {
- try
- {
- GetPlugin().getConfig().addDefault("preferences.connectionurl", "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
- GetPlugin().getConfig().set("preferences.connectionurl", GetPlugin().getConfig().getString("preferences.connectionurl"));
- GetPlugin().saveConfig();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
-
@Override
protected UserPreferences AddPlayer(String player)
{
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java
index 767ecbad2..61d5e931b 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java
@@ -1,14 +1,17 @@
package mineplex.core.preferences;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map.Entry;
import java.util.UUID;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
@@ -20,9 +23,9 @@ public class PreferencesRepository extends RepositoryBase
private static String RETRIEVE_ACCOUNT_PREFERENCES = "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;";
- public PreferencesRepository(JavaPlugin plugin, String connectionString)
+ public PreferencesRepository(Plugin plugin)
{
- super(plugin, connectionString, "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
@@ -40,9 +43,9 @@ public class PreferencesRepository extends RepositoryBase
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = getConnection())
{
- preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
+ preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
for (Entry entry : preferences.entrySet())
{
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRepository.java
index b9e40ca3a..1e257dbfa 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardRepository.java
@@ -1,8 +1,13 @@
package mineplex.core.reward;
+import java.sql.Connection;
+import java.sql.SQLException;
+
import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.database.Tables;
import org.jooq.DSLContext;
@@ -13,9 +18,9 @@ import org.jooq.impl.DSL;
*/
public class RewardRepository extends RepositoryBase
{
- public RewardRepository(JavaPlugin plugin)
+ public RewardRepository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
@@ -32,21 +37,26 @@ public class RewardRepository extends RepositoryBase
public void logReward(Player player, String type, String rarity, String reward)
{
- DSLContext context;
-
- synchronized (this)
+ try
{
- context = DSL.using(getConnection());
- }
+ try (Connection connection = getConnection())
+ {
+ DSLContext context = DSL.using(connection);
- context.insertInto(Tables.rewardLog)
- .set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
- .from(Tables.accounts)
- .where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
- .set(Tables.rewardLog.date, DSL.currentTimestamp())
- .set(Tables.rewardLog.type, type)
- .set(Tables.rewardLog.rarity, rarity)
- .set(Tables.rewardLog.reward, reward)
- .execute();
+ context.insertInto(Tables.rewardLog)
+ .set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
+ .from(Tables.accounts)
+ .where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
+ .set(Tables.rewardLog.date, DSL.currentTimestamp())
+ .set(Tables.rewardLog.type, type)
+ .set(Tables.rewardLog.rarity, rarity)
+ .set(Tables.rewardLog.reward, reward)
+ .execute();
+ }
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
}
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java
index a5001c3fd..a1daa52cb 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/simpleStats/SimpleStatsRepository.java
@@ -6,35 +6,25 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
+import mineplex.core.database.DBPool;
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
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- Class.forName("com.mysql.jdbc.Driver");
-
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_STATS_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_STATS_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -63,23 +53,15 @@ public class SimpleStatsRepository
PreparedStatement preparedStatement = null;
NautHashMap statRecords = new NautHashMap();
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(RETRIEVE_STATS_RECORDS);
+
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next())
{
- 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));
- }
+ statRecords.put(resultSet.getString(1), resultSet.getString(2));
}
}
catch (Exception exception)
@@ -120,21 +102,13 @@ public class SimpleStatsRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- 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();
- }
+ preparedStatement = connection.prepareStatement(STORE_STATS_RECORD);
+ preparedStatement.setString(1, statName);
+ preparedStatement.setString(2, statValue);
+
+ preparedStatement.executeUpdate();
}
catch (Exception exception)
{
@@ -162,24 +136,16 @@ public class SimpleStatsRepository
PreparedStatement preparedStatement = null;
NautHashMap statRecords = new NautHashMap();
- try
+ try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(RETRIEVE_STAT_RECORD);
+ preparedStatement.setString(1, statName);
+
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next())
{
- 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));
- }
+ statRecords.put(resultSet.getString(1), resultSet.getString(2));
}
}
catch (Exception exception)
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java
index 296c4ee66..69c521373 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java
@@ -130,7 +130,7 @@ public class StatsManager extends MiniClientPlugin
});
}
- public PlayerStats getOfflinePlayerStats(String playerName)
+ public PlayerStats getOfflinePlayerStats(String playerName) throws SQLException
{
return _repository.loadOfflinePlayerStats(playerName);
}
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java
index d00079f1a..0d3bcf904 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java
@@ -1,5 +1,6 @@
package mineplex.core.stats;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -7,9 +8,11 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
@@ -36,9 +39,9 @@ public class StatsRepository extends RepositoryBase
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
- public StatsRepository(JavaPlugin plugin)
+ public StatsRepository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
@@ -85,9 +88,9 @@ public class StatsRepository extends RepositoryBase
{
System.out.println("saving stats.");
- try
+ try (Connection connection = getConnection())
{
- DSLContext context = DSL.using(getConnection());
+ DSLContext context = DSL.using(connection);
List updates = new ArrayList<>();
List inserts = new ArrayList<>();
@@ -134,36 +137,33 @@ public class StatsRepository extends RepositoryBase
}
}
- public PlayerStats loadOfflinePlayerStats(String playerName)
+ public PlayerStats loadOfflinePlayerStats(String playerName) throws SQLException
{
- PlayerStats playerStats = null;
-
- DSLContext context;
-
- synchronized (this)
+ try (Connection connection = getConnection())
{
- context = DSL.using(getConnection());
- }
+ PlayerStats playerStats = null;
- Result> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
- .join(Tables.stats)
- .on(Tables.stats.id.eq(Tables.accountStats.statId))
- .where(Tables.accountStats.accountId.eq(DSL.select(Tables.accounts.id)
- .from(Tables.accounts)
- .where(Tables.accounts.name.eq(playerName)))
- ).fetch();
+ DSLContext context = DSL.using(connection);
+ Result> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
+ .join(Tables.stats)
+ .on(Tables.stats.id.eq(Tables.accountStats.statId))
+ .where(Tables.accountStats.accountId.eq(DSL.select(Tables.accounts.id)
+ .from(Tables.accounts)
+ .where(Tables.accounts.name.eq(playerName)))
+ ).fetch();
- if (result.isNotEmpty())
- {
- playerStats = new PlayerStats();
- for (Record2 record : result)
+ if (result.isNotEmpty())
{
- playerStats.addStat(record.value1(), record.value2());
+ playerStats = new PlayerStats();
+ for (Record2 record : result)
+ {
+ playerStats.addStat(record.value1(), record.value2());
+ }
}
- }
- return playerStats;
+ return playerStats;
+ }
}
public PlayerStats loadClientInformation(String uuid)
diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/TimeCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/TimeCommand.java
index a9399c4a3..dcc12bf24 100644
--- a/Plugins/Mineplex.Core/src/mineplex/core/stats/command/TimeCommand.java
+++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/command/TimeCommand.java
@@ -1,5 +1,7 @@
package mineplex.core.stats.command;
+import java.sql.SQLException;
+
import org.bukkit.entity.Player;
import mineplex.core.achievement.AchievementManager;
@@ -39,25 +41,31 @@ public class TimeCommand extends CommandBase
@Override
public void run()
{
- final PlayerStats stats = Plugin.getOfflinePlayerStats(args[0]);
-
- Plugin.GetPlugin().getServer().getScheduler().runTask(Plugin.GetPlugin(), new Runnable()
+ try
{
- @Override
- public void run()
- {
- if (stats == null)
- {
- UtilPlayer.message(caller, F.main("Time", "Player " + F.elem(args[0]) + " not found!"));
- }
- else
- {
- int time = stats.getStat("Global.TimeInGame");
- UtilPlayer.message(caller, F.main("Time", F.name(args[0]) + " has spent " + F.elem(UtilTime.convertString(time * 1000L, 1, UtilTime.TimeUnit.FIT)) + " in game"));
- }
- }
- });
+ final PlayerStats stats = Plugin.getOfflinePlayerStats(args[0]);
+ Plugin.GetPlugin().getServer().getScheduler().runTask(Plugin.GetPlugin(), new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ if (stats == null)
+ {
+ UtilPlayer.message(caller, F.main("Time", "Player " + F.elem(args[0]) + " not found!"));
+ }
+ else
+ {
+ int time = stats.getStat("Global.TimeInGame");
+ UtilPlayer.message(caller, F.main("Time", F.name(args[0]) + " has spent " + F.elem(UtilTime.convertString(time * 1000L, 1, UtilTime.TimeUnit.FIT)) + " in game"));
+ }
+ }
+ });
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
}
});
}
diff --git a/Plugins/Mineplex.EnjinTranslator/.classpath b/Plugins/Mineplex.EnjinTranslator/.classpath
index a0ee58bf4..76585c180 100644
--- a/Plugins/Mineplex.EnjinTranslator/.classpath
+++ b/Plugins/Mineplex.EnjinTranslator/.classpath
@@ -5,5 +5,6 @@
+
diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java
index e052ee72e..ac9055bb8 100644
--- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java
+++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java
@@ -1,7 +1,9 @@
package mineplex.enjinTranslator;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
@@ -10,9 +12,9 @@ public class TempRepository extends RepositoryBase
{
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, 5, ? FROM accounts WHERE accounts.name = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
- public TempRepository(JavaPlugin plugin)
+ public TempRepository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
public void addGemBooster(String name, int amount)
diff --git a/Plugins/Mineplex.Hub/Mineplex.Hub.iml b/Plugins/Mineplex.Hub/Mineplex.Hub.iml
index dfc217d28..fa16dfadc 100644
--- a/Plugins/Mineplex.Hub/Mineplex.Hub.iml
+++ b/Plugins/Mineplex.Hub/Mineplex.Hub.iml
@@ -15,6 +15,8 @@
+
+
diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java
index 6a1f30702..a8216b3fe 100644
--- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java
+++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java
@@ -11,17 +11,13 @@ import java.util.HashMap;
import java.util.List;
import mineplex.core.common.util.NautHashMap;
+import mineplex.core.database.DBPool;
+
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class HubRepository
{
- private static Object _connectionLock = new Object();
-
- private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
- private String _userName = "root";
- private String _password = "tAbechAk3wR7tuTh";
-
private boolean _us = true;
private static String CREATE_NEWS_TABLE = "CREATE TABLE IF NOT EXISTS newsList (id INT NOT NULL AUTO_INCREMENT, newsString VARCHAR(256), newsPosition INT, PRIMARY KEY (id));";
@@ -34,22 +30,16 @@ public class HubRepository
private static String RECALC_NEWS_POSITIONS = "UPDATE newsList SET newsPosition = newsPosition - 1 WHERE newsPosition > ?;";
//private static String DELETE_RECALC_NEWS_ENTRY = "SET @pos = ?;SET @max = (SELECT MAX(newsPosition) AS newsPosition FROM newsList);DELETE FROM newsList WHERE newsPosition = @pos;UPDATE newsList SET newsPosition = IF(@max <> @pos, newsPosition - 1, newsPosition) WHERE newsPosition > @pos;";
- private Connection _connection = null;
-
public void initialize(boolean us)
{
_us = us;
PreparedStatement preparedStatement = null;
-
- try
+
+ try (Connection connection = DBPool.MINEPLEX.getConnection())
{
- Class.forName("com.mysql.jdbc.Driver");
-
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_NEWS_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_NEWS_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -78,23 +68,15 @@ public class HubRepository
PreparedStatement preparedStatement = null;
HashMap newsEntries = new HashMap();
- try
+ try (Connection connection = DBPool.MINEPLEX.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(RETRIEVE_NEWS_ENTRIES);
+
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next())
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(RETRIEVE_NEWS_ENTRIES);
-
- resultSet = preparedStatement.executeQuery();
-
- while (resultSet.next())
- {
- newsEntries.put(resultSet.getString(2), resultSet.getString(1));
- }
+ newsEntries.put(resultSet.getString(2), resultSet.getString(1));
}
}
catch (Exception exception)
@@ -135,22 +117,14 @@ public class HubRepository
{
int result = 0;
PreparedStatement preparedStatement = null;
-
- try
+
+ try (Connection connection = DBPool.MINEPLEX.getConnection())
{
- synchronized (_connectionLock)
- {
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(SET_NEWS_ENTRY);
- preparedStatement.setString(1, newsEntry);
- preparedStatement.setInt(2, newsPosition);
-
- result = preparedStatement.executeUpdate();
- }
+ preparedStatement = connection.prepareStatement(SET_NEWS_ENTRY);
+ preparedStatement.setString(1, newsEntry);
+ preparedStatement.setInt(2, newsPosition);
+
+ result = preparedStatement.executeUpdate();
}
catch (Exception exception)
{
@@ -179,23 +153,15 @@ public class HubRepository
int result = 0;
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
-
- try
+
+ try (Connection connection = DBPool.MINEPLEX.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(RETRIEVE_MAX_NEWS_POSITION);
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next())
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(RETRIEVE_MAX_NEWS_POSITION);
- resultSet = preparedStatement.executeQuery();
-
- while (resultSet.next())
- {
- result = Integer.parseInt(resultSet.getString(1));
- }
+ result = Integer.parseInt(resultSet.getString(1));
}
}
catch (Exception exception)
@@ -225,22 +191,14 @@ public class HubRepository
int result = 0;
int maxPos = retrieveMaxNewsPosition();
PreparedStatement preparedStatement = null;
-
- try
- {
- synchronized (_connectionLock)
- {
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
- preparedStatement = _connection.prepareStatement(ADD_NEWS_ENTRY);
- preparedStatement.setString(1, newsEntry);
- preparedStatement.setInt(2, maxPos + 1);
-
- result = preparedStatement.executeUpdate();
- }
+ try (Connection connection = DBPool.MINEPLEX.getConnection())
+ {
+ preparedStatement = connection.prepareStatement(ADD_NEWS_ENTRY);
+ preparedStatement.setString(1, newsEntry);
+ preparedStatement.setInt(2, maxPos + 1);
+
+ result = preparedStatement.executeUpdate();
}
catch (Exception exception)
{
@@ -269,30 +227,22 @@ public class HubRepository
int result = 0;
int maxPos = retrieveMaxNewsPosition();
PreparedStatement preparedStatement = null;
-
- try
- {
- synchronized (_connectionLock)
- {
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- //preparedStatement = _connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY);
- preparedStatement = _connection.prepareStatement(DELETE_NEWS_ENTRY);
- preparedStatement.setInt(1, newsPosition);
- result = preparedStatement.executeUpdate();
-
- if (result != 0 && maxPos != newsPosition)
- {
- preparedStatement.close();
- preparedStatement = _connection.prepareStatement(RECALC_NEWS_POSITIONS);
- preparedStatement.setInt(1, newsPosition);
-
- result = preparedStatement.executeUpdate();
- }
+ try (Connection connection = DBPool.MINEPLEX.getConnection())
+ {
+ //preparedStatement = connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY);
+ preparedStatement = connection.prepareStatement(DELETE_NEWS_ENTRY);
+ preparedStatement.setInt(1, newsPosition);
+ result = preparedStatement.executeUpdate();
+
+ if (result != 0 && maxPos != newsPosition)
+ {
+ preparedStatement.close();
+
+ preparedStatement = connection.prepareStatement(RECALC_NEWS_POSITIONS);
+ preparedStatement.setInt(1, newsPosition);
+
+ result = preparedStatement.executeUpdate();
}
}
catch (Exception exception)
diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java
index f96c2a875..11c634add 100644
--- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java
+++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollRepository.java
@@ -8,6 +8,7 @@ import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
@@ -28,7 +29,7 @@ public class PollRepository extends RepositoryBase
public PollRepository(JavaPlugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
}
@Override
diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java
index 14d5a7224..628c7c0fe 100644
--- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java
+++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueManager.java
@@ -41,16 +41,13 @@ public class QueueManager extends MiniPlugin
_eloManager = eloManager;
_partyManager = partyManager;
- _repository = new QueueRepository(plugin.getConfig().getString("queue.connectionurl"), plugin.getConfig().getBoolean("queue.us"));
+ _repository = new QueueRepository(plugin.getConfig().getBoolean("queue.us"));
}
private void setupConfigValues()
{
try
{
- GetPlugin().getConfig().addDefault("queue.connectionurl", "jdbc:mysql://db.mineplex.com:3306/Queue?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
- GetPlugin().getConfig().set("queue.connectionurl", GetPlugin().getConfig().getString("queue.connectionurl"));
-
GetPlugin().getConfig().addDefault("queue.us", true);
GetPlugin().getConfig().set("queue.us", GetPlugin().getConfig().getBoolean("queue.us"));
}
diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java
index 59e9249b9..3e66c7a84 100644
--- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java
+++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java
@@ -7,14 +7,11 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import mineplex.core.common.util.C;
+import mineplex.core.database.DBPool;
+
public class QueueRepository
{
- private static Object _connectionLock = new Object();
-
- private String _connectionString;
- private String _userName = "root";
- private String _password = "tAbechAk3wR7tuTh";
-
private boolean _us = true;
private static String CREATE_ELO_QUEUE_TABLE = "CREATE TABLE IF NOT EXISTS playerQueue (id INT NOT NULL AUTO_INCREMENT, playerList VARCHAR(256), gameType VARCHAR(256), playerCount INT, elo INT, state VARCHAR(256), time LONG, assignedMatch INT, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id), UNIQUE INDEX name_gametype (playerList, gameType));";
@@ -24,11 +21,8 @@ public class QueueRepository
private static String RETRIEVE_MATCH_STATUS = "SELECT state, assignedMatch FROM playerQueue WHERE id = ?;";
private static String RETRIEVE_OTHER_MATCH_STATUS = "SELECT state, playerCount FROM playerQueue WHERE assignedMatch = ? AND id != ? ORDER BY id DESC;";
- private Connection _connection = null;
-
- public QueueRepository(String connectionUrl, boolean us)
+ public QueueRepository(boolean us)
{
- _connectionString = connectionUrl;
_us = us;
initialize();
@@ -38,12 +32,10 @@ public class QueueRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.QUEUE.getConnection())
{
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
-
// Create table
- preparedStatement = _connection.prepareStatement(CREATE_ELO_QUEUE_TABLE);
+ preparedStatement = connection.prepareStatement(CREATE_ELO_QUEUE_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
@@ -70,23 +62,15 @@ public class QueueRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.QUEUE.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(DELETE_QUEUE_RECORD);
+
+ preparedStatement.setInt(1, matchStatus.Id);
+
+ if (preparedStatement.executeUpdate() == 0)
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(DELETE_QUEUE_RECORD);
-
- preparedStatement.setInt(1, matchStatus.Id);
-
- if (preparedStatement.executeUpdate() == 0)
- {
- System.out.println("Error deleting queue record.");
- }
+ System.out.println("Error deleting queue record.");
}
}
catch (Exception exception)
@@ -113,23 +97,15 @@ public class QueueRepository
{
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.QUEUE.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(SAVE_STATE_VALUE);
+ preparedStatement.setString(1, matchStatus.State);
+ preparedStatement.setInt(2, matchStatus.Id);
+
+ if (preparedStatement.executeUpdate() == 0)
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(SAVE_STATE_VALUE);
- preparedStatement.setString(1, matchStatus.State);
- preparedStatement.setInt(2, matchStatus.Id);
-
- if (preparedStatement.executeUpdate() == 0)
- {
- System.out.println("Error updating state.");
- }
+ System.out.println("Error updating state.");
}
}
catch (Exception exception)
@@ -158,29 +134,21 @@ public class QueueRepository
PreparedStatement preparedStatement = null;
PlayerMatchStatus matchStatus = new PlayerMatchStatus();
- try
+ try (Connection connection = DBPool.QUEUE.getConnection())
{
- synchronized (_connectionLock)
- {
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(INSERT_ACCOUNT, Statement.RETURN_GENERATED_KEYS);
- preparedStatement.setString(1, playerList);
- preparedStatement.setString(2, gameType);
- preparedStatement.setInt(3, elo);
- //preparedStatement.setBoolean(4, _us);
- preparedStatement.setInt(4, playerCount);
-
- preparedStatement.executeUpdate();
- resultSet = preparedStatement.getGeneratedKeys();
+ preparedStatement = connection.prepareStatement(INSERT_ACCOUNT, Statement.RETURN_GENERATED_KEYS);
+ preparedStatement.setString(1, playerList);
+ preparedStatement.setString(2, gameType);
+ preparedStatement.setInt(3, elo);
+ //preparedStatement.setBoolean(4, _us);
+ preparedStatement.setInt(4, playerCount);
- while (resultSet.next())
- {
- matchStatus.Id = resultSet.getInt(1);
- }
+ preparedStatement.executeUpdate();
+ resultSet = preparedStatement.getGeneratedKeys();
+
+ while (resultSet.next())
+ {
+ matchStatus.Id = resultSet.getInt(1);
}
}
catch (Exception exception)
@@ -223,28 +191,20 @@ public class QueueRepository
PreparedStatement preparedStatement = null;
PlayerMatchStatus matchStatus = null;
- try
+ try (Connection connection = DBPool.QUEUE.getConnection())
{
- synchronized (_connectionLock)
- {
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(RETRIEVE_MATCH_STATUS);
- preparedStatement.setInt(1, id);
-
- resultSet = preparedStatement.executeQuery();
+ preparedStatement = connection.prepareStatement(RETRIEVE_MATCH_STATUS);
+ preparedStatement.setInt(1, id);
- while (resultSet.next())
- {
- matchStatus = new PlayerMatchStatus();
-
- matchStatus.Id = id;
- matchStatus.State = resultSet.getString(1);
- matchStatus.AssignedMatch = resultSet.getInt(2);
- }
+ resultSet = preparedStatement.executeQuery();
+
+ while (resultSet.next())
+ {
+ matchStatus = new PlayerMatchStatus();
+
+ matchStatus.Id = id;
+ matchStatus.State = resultSet.getString(1);
+ matchStatus.AssignedMatch = resultSet.getInt(2);
}
}
catch (Exception exception)
@@ -286,29 +246,21 @@ public class QueueRepository
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
- try
+ try (Connection connection = DBPool.QUEUE.getConnection())
{
- synchronized (_connectionLock)
+ preparedStatement = connection.prepareStatement(RETRIEVE_OTHER_MATCH_STATUS);
+ preparedStatement.setInt(1, matchStatus.AssignedMatch);
+ preparedStatement.setInt(2, matchStatus.Id);
+
+ resultSet = preparedStatement.executeQuery();
+ matchStatus.OtherStatuses.clear();
+
+ while (resultSet.next())
{
- if (_connection.isClosed())
- {
- _connection = DriverManager.getConnection(_connectionString, _userName, _password);
- }
-
- preparedStatement = _connection.prepareStatement(RETRIEVE_OTHER_MATCH_STATUS);
- preparedStatement.setInt(1, matchStatus.AssignedMatch);
- preparedStatement.setInt(2, matchStatus.Id);
-
- resultSet = preparedStatement.executeQuery();
- matchStatus.OtherStatuses.clear();
-
- while (resultSet.next())
- {
- int playerCount = resultSet.getInt(2);
-
- for (int i = 0; i < playerCount; i++)
- matchStatus.OtherStatuses.add(resultSet.getString(1));
- }
+ int playerCount = resultSet.getInt(2);
+
+ for (int i = 0; i < playerCount; i++)
+ matchStatus.OtherStatuses.add(resultSet.getString(1));
}
}
catch (Exception exception)
diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/NullBlade.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/NullBlade.java
index e45918159..eb66125f8 100644
--- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/NullBlade.java
+++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Mage/NullBlade.java
@@ -52,7 +52,7 @@ public class NullBlade extends Skill
Factory.Energy().ModifyEnergy(damager, 2 + 2 * level);
//Damage
- event.AddMod(damager.getName(), GetName(), 0, true);
+ event.AddMod(damager.getName(), GetName(), 0, false);
//Effect
damager.getWorld().playSound(damager.getLocation(), Sound.BLAZE_BREATH, 0.6f, 0.6f);
diff --git a/Plugins/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml b/Plugins/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml
index 7daddb997..471754299 100644
--- a/Plugins/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml
+++ b/Plugins/Nautilus.Game.Arcade/Nautilus.Game.Arcade.iml
@@ -15,6 +15,8 @@
+
+
diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java
index 627744d05..5c05db3c1 100644
--- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java
+++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java
@@ -1,6 +1,7 @@
package nautilus.game.arcade;
import java.io.File;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -997,7 +998,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation
@Override
public void run()
{
- getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
+ try
+ {
+ getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
}
});
}
@@ -1021,7 +1029,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation
@Override
public void run()
{
- getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
+ try
+ {
+ getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
}
});
}
diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeRepository.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeRepository.java
index 940f5b80f..57e158d02 100644
--- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeRepository.java
+++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeRepository.java
@@ -1,12 +1,16 @@
package nautilus.game.arcade;
+import java.sql.Connection;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
+import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.database.Tables;
import mineplex.database.tables.records.GamesRecord;
@@ -18,9 +22,9 @@ public class ArcadeRepository extends RepositoryBase
{
private final String serverName;
- public ArcadeRepository(JavaPlugin plugin)
+ public ArcadeRepository(Plugin plugin)
{
- super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
+ super(plugin, DBPool.ACCOUNT);
serverName = plugin.getConfig().getString("serverstatus.name");
}
@@ -37,71 +41,67 @@ public class ArcadeRepository extends RepositoryBase
}
- public void saveBasicStats(GameType type, boolean tournament, int duration, Map players)
+ public void saveBasicStats(GameType type, boolean tournament, int duration, Map players) throws SQLException
{
- DSLContext context;
-
- synchronized (this)
+ try (Connection connection = getConnection())
{
- context = DSL.using(getConnection());
+ DSLContext context = DSL.using(connection);
+
+ GamesRecord record = context.newRecord(Tables.games);
+ record.setDuration(duration);
+ record.setTournament(tournament);
+ record.setType(type.name());
+ record.setServer(serverName);
+ record.store();
+
+ List queryList = new ArrayList<>(players.size());
+
+ for (Map.Entry entry : players.entrySet())
+ {
+ Query query = context
+ .insertInto(Tables.gamePlayers)
+ .set(Tables.gamePlayers.gameId, record.getId())
+ .set(Tables.gamePlayers.accountId, DSL.select(Tables.accounts.id)
+ .from(Tables.accounts)
+ .where(Tables.accounts.uuid.eq(entry.getKey().toString())))
+ .set(Tables.gamePlayers.winner, entry.getValue());
+
+ queryList.add(query);
+ }
+
+ context.batch(queryList).execute();
}
-
- GamesRecord record = context.newRecord(Tables.games);
- record.setDuration(duration);
- record.setTournament(tournament);
- record.setType(type.name());
- record.setServer(serverName);
- record.store();
-
- List queryList = new ArrayList<>(players.size());
-
- for (Map.Entry entry : players.entrySet())
- {
- Query query = context
- .insertInto(Tables.gamePlayers)
- .set(Tables.gamePlayers.gameId, record.getId())
- .set(Tables.gamePlayers.accountId, DSL.select(Tables.accounts.id)
- .from(Tables.accounts)
- .where(Tables.accounts.uuid.eq(entry.getKey().toString())))
- .set(Tables.gamePlayers.winner, entry.getValue());
-
- queryList.add(query);
- }
-
- context.batch(queryList).execute();
}
- public void saveLeaderboardStats(int tournamentId, int gameId, Map players)
+ public void saveLeaderboardStats(int tournamentId, int gameId, Map players) throws SQLException
{
- DSLContext context;
-
- synchronized (this)
+ try (Connection connection = getConnection())
{
- context = DSL.using(getConnection());
+ DSLContext context = DSL.using(connection);
+
+ List queryList = new ArrayList<>(players.size());
+
+ for (Map.Entry entry : players.entrySet())
+ {
+ int winIncrement = entry.getValue() ? 1 : 0;
+
+ Query query = context
+ .insertInto(Tables.tournamentLeaderboard)
+ .set(Tables.tournamentLeaderboard.tournamentId, tournamentId)
+ .set(Tables.tournamentLeaderboard.gameId, gameId)
+ .set(Tables.tournamentLeaderboard.accountId, DSL.select(Tables.accounts.id)
+ .from(Tables.accounts)
+ .where(Tables.accounts.uuid.eq(entry.getKey().toString())))
+ .set(Tables.tournamentLeaderboard.wins, winIncrement)
+ .set(Tables.tournamentLeaderboard.total, 1)
+ .onDuplicateKeyUpdate()
+ .set(Tables.tournamentLeaderboard.wins, Tables.tournamentLeaderboard.wins.plus(winIncrement))
+ .set(Tables.tournamentLeaderboard.total, Tables.tournamentLeaderboard.total.plus(1));
+
+ queryList.add(query);
+ }
+
+ context.batch(queryList).execute();
}
-
- List queryList = new ArrayList<>(players.size());
-
- for (Map.Entry entry : players.entrySet())
- {
- int winIncrement = entry.getValue() ? 1 : 0;
-
- Query query = context
- .insertInto(Tables.tournamentLeaderboard)
- .set(Tables.tournamentLeaderboard.tournamentId, tournamentId)
- .set(Tables.tournamentLeaderboard.gameId, gameId)
- .set(Tables.tournamentLeaderboard.accountId, DSL.select(Tables.accounts.id)
- .from(Tables.accounts)
- .where(Tables.accounts.uuid.eq(entry.getKey().toString())))
- .set(Tables.tournamentLeaderboard.wins, winIncrement)
- .set(Tables.tournamentLeaderboard.total, 1)
- .onDuplicateKeyUpdate()
- .set(Tables.tournamentLeaderboard.wins, Tables.tournamentLeaderboard.wins.plus(winIncrement))
- .set(Tables.tournamentLeaderboard.total, Tables.tournamentLeaderboard.total.plus(1));
-
- queryList.add(query);
- }
-
- context.batch(queryList).execute();
}
}
diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java
index 3522003f4..deef76245 100644
--- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java
+++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java
@@ -279,6 +279,7 @@ public abstract class Game implements Listener
}
WorldData = new WorldData(this);
+ //Stat Trackers
registerStatTrackers(
new KillsStatTracker(this),
new DeathsStatTracker(this),
@@ -287,10 +288,16 @@ public abstract class Game implements Listener
new LoseStatTracker(this),
new DamageDealtStatTracker(this),
new DamageTakenStatTracker(this),
- new TeamDeathsStatTracker(this),
- new TeamKillsStatTracker(this),
new GamesPlayedStatTracker(this)
);
+
+ if (gameType != GameType.UHC)
+ {
+ registerStatTrackers(
+ new TeamDeathsStatTracker(this),
+ new TeamKillsStatTracker(this)
+ );
+ }
System.out.println("Loading " + GetName() + "...");
}