Merge branch 'feature/database-pool'
This commit is contained in:
commit
f3770933b6
@ -8,6 +8,9 @@
|
|||||||
<fileset dir="../Mineplex.Core.Common/bin">
|
<fileset dir="../Mineplex.Core.Common/bin">
|
||||||
<include name="**/*.class"/>
|
<include name="**/*.class"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
|
<fileset dir="../Mineplex.Database/bin">
|
||||||
|
<include name="**/*.class"/>
|
||||||
|
</fileset>
|
||||||
|
|
||||||
<fileset dir="../Mineplex.EnjinTranslator/bin">
|
<fileset dir="../Mineplex.EnjinTranslator/bin">
|
||||||
<include name="**/*.class"/>
|
<include name="**/*.class"/>
|
||||||
|
@ -5,10 +5,12 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class RankBenefitsGiver9000Repository extends RepositoryBase
|
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 INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
|
||||||
private static String RETRIEVE_BENEFITS = "SELECT benefit FROM rankBenefits WHERE uuid = ?;";
|
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
|
@Override
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.account.repository.token.LoginToken;
|
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.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnBoolean;
|
import mineplex.core.database.column.ColumnBoolean;
|
||||||
@ -32,9 +34,9 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
private String _webAddress;
|
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;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.logger.Logger;
|
import mineplex.core.logger.Logger;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
|
||||||
@ -12,15 +13,8 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class AntiHackRepository
|
public class AntiHackRepository
|
||||||
{
|
{
|
||||||
private static Object _connectionLock = new Object();
|
|
||||||
|
|
||||||
private String _serverName;
|
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 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(), ?, ?, ?, ?, ?, ?, ?);";
|
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;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
if (_connection == null || _connection.isClosed())
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -70,47 +61,40 @@ public class AntiHackRepository
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
synchronized (_connectionLock)
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
try
|
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_OFFENSES);
|
||||||
{
|
|
||||||
if (_connection == null || _connection.isClosed())
|
preparedStatement.setString(1, player.getName());
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
preparedStatement.setString(2, motd);
|
||||||
|
preparedStatement.setString(3, game);
|
||||||
preparedStatement = _connection.prepareStatement(UPDATE_PLAYER_OFFENSES);
|
preparedStatement.setString(4, map);
|
||||||
|
preparedStatement.setString(5, _serverName);
|
||||||
|
preparedStatement.setString(6, report);
|
||||||
preparedStatement.setString(1, player.getName());
|
preparedStatement.setString(7, ((CraftPlayer)player).getHandle().ping + "ms");
|
||||||
preparedStatement.setString(2, motd);
|
|
||||||
preparedStatement.setString(3, game);
|
preparedStatement.execute();
|
||||||
preparedStatement.setString(4, map);
|
}
|
||||||
preparedStatement.setString(5, _serverName);
|
catch (Exception exception)
|
||||||
preparedStatement.setString(6, report);
|
{
|
||||||
preparedStatement.setString(7, ((CraftPlayer)player).getHandle().ping + "ms");
|
exception.printStackTrace();
|
||||||
|
Logger.Instance.log(exception);
|
||||||
preparedStatement.execute();
|
}
|
||||||
}
|
finally
|
||||||
catch (Exception exception)
|
{
|
||||||
{
|
if (preparedStatement != null)
|
||||||
exception.printStackTrace();
|
{
|
||||||
Logger.Instance.log(exception);
|
try
|
||||||
}
|
{
|
||||||
finally
|
preparedStatement.close();
|
||||||
{
|
}
|
||||||
if (preparedStatement != null)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
try
|
e.printStackTrace();
|
||||||
{
|
}
|
||||||
preparedStatement.close();
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -1,51 +1,33 @@
|
|||||||
package mineplex.core.database;
|
package mineplex.core.database;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.apache.commons.dbcp2.BasicDataSource;
|
import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
|
|
||||||
public class DBPool
|
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;
|
return source;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,99 +1,73 @@
|
|||||||
package mineplex.core.database;
|
package mineplex.core.database;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Iterator;
|
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.common.util.NautHashMap;
|
||||||
import mineplex.core.database.column.Column;
|
import mineplex.core.database.column.Column;
|
||||||
import mineplex.core.logger.Logger;
|
import mineplex.core.logger.Logger;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
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
|
public abstract class RepositoryBase implements Listener
|
||||||
{
|
{
|
||||||
protected static Object _connectionLock = new Object();
|
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
|
|
||||||
private static Object _queueLock = new Object();
|
private static Object _queueLock = new Object();
|
||||||
|
|
||||||
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
||||||
|
|
||||||
private String _connectionString;
|
private final Plugin _plugin;
|
||||||
private String _userName;
|
private final DataSource _dataSource;
|
||||||
private String _password;
|
|
||||||
|
public RepositoryBase(Plugin plugin, DataSource dataSource)
|
||||||
protected JavaPlugin Plugin;
|
|
||||||
|
|
||||||
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
_plugin = plugin;
|
||||||
|
_dataSource = dataSource;
|
||||||
_connectionString = connectionString;
|
|
||||||
_userName = username;
|
|
||||||
_password = password;
|
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
initialize();
|
||||||
{
|
update();
|
||||||
initialize();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initialize();
|
protected abstract void initialize();
|
||||||
|
|
||||||
protected abstract void update();
|
protected abstract void update();
|
||||||
|
|
||||||
protected Connection getConnection()
|
protected Connection getConnection() throws SQLException
|
||||||
{
|
{
|
||||||
try
|
return getDataSource().getConnection();
|
||||||
{
|
|
||||||
if (_connection == null || !_connection.isValid(1))
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int executeUpdate(String query, Column<?>...columns)
|
protected int executeUpdate(String query, Column<?>... columns)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try
|
try (Connection connection = getConnection())
|
||||||
{
|
{
|
||||||
if (_connection == null || !_connection.isValid(1))
|
preparedStatement = connection.prepareStatement(query);
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
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();
|
affectedRows = preparedStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -107,30 +81,30 @@ public abstract class RepositoryBase implements Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
preparedStatement.close();
|
preparedStatement.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>... columns)
|
||||||
{
|
{
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
try
|
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();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
callable.processResultSet(resultSet);
|
callable.processResultSet(resultSet);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -138,13 +112,13 @@ public abstract class RepositoryBase implements Listener
|
|||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (resultSet != null)
|
if (resultSet != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
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;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = getConnection())
|
||||||
{
|
{
|
||||||
if (_connection == null || !_connection.isValid(1))
|
preparedStatement = connection.prepareStatement(query);
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(query);
|
|
||||||
|
|
||||||
executeQuery(preparedStatement, callable, columns);
|
executeQuery(preparedStatement, callable, columns);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -177,7 +148,7 @@ public abstract class RepositoryBase implements Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
preparedStatement.close();
|
preparedStatement.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
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;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try
|
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();
|
affectedRows = preparedStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
||||||
{
|
{
|
||||||
Thread asyncThread = new Thread(new Runnable()
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
databaseRunnable.run();
|
databaseRunnable.run();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Logger.Instance.log(errorMessage + exception.getMessage());
|
Logger.Instance.log(errorMessage + exception.getMessage());
|
||||||
|
|
||||||
databaseRunnable.incrementFailCount();
|
databaseRunnable.incrementFailCount();
|
||||||
|
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
{
|
{
|
||||||
_failedQueue.put(databaseRunnable, errorMessage);
|
_failedQueue.put(databaseRunnable, errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncThread.start();
|
asyncThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void processDatabaseQueue(UpdateEvent event)
|
public void processDatabaseQueue(UpdateEvent event)
|
||||||
{
|
{
|
||||||
if (event.getType() != UpdateType.MIN_01)
|
if (event.getType() != UpdateType.MIN_01)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
processFailedQueue();
|
processFailedQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processFailedQueue()
|
private void processFailedQueue()
|
||||||
{
|
{
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
{
|
{
|
||||||
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();)
|
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext(); )
|
||||||
{
|
{
|
||||||
final DatabaseRunnable databaseRunnable = runnablesIterator.next();
|
final DatabaseRunnable databaseRunnable = runnablesIterator.next();
|
||||||
|
|
||||||
Thread asyncThread = new Thread(new Runnable()
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
databaseRunnable.run();
|
databaseRunnable.run();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
|
Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
|
||||||
|
|
||||||
if (databaseRunnable.getFailedCounts() < 4)
|
if (databaseRunnable.getFailedCounts() < 4)
|
||||||
{
|
{
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
{
|
{
|
||||||
_failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
|
_failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
|
Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runnablesIterator.remove();
|
runnablesIterator.remove();
|
||||||
asyncThread.start();
|
asyncThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return _plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataSource getDataSource()
|
||||||
|
{
|
||||||
|
return _dataSource;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<Column<?>> _primaryKeys;
|
|
||||||
private NautHashMap<String, Column<?>> _columns = new NautHashMap<String, Column<?>>();
|
|
||||||
private Column<?> _index;
|
|
||||||
|
|
||||||
public Table(String name, List<Column<?>> primaryKeys, List<Column<?>> 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<String> columnExists = new HashSet<String>();
|
|
||||||
|
|
||||||
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<Column<?>> 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<Column<?>> 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<Column<?>> columns, Column<?> whereColumn)
|
|
||||||
{
|
|
||||||
List<Column<?>> whereColumnList = new ArrayList<Column<?>>();
|
|
||||||
whereColumnList.add(whereColumn);
|
|
||||||
|
|
||||||
return update(columns, whereColumnList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean update(List<Column<?>> columns, List<Column<?>> 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<Row> retrieve(List<Column<?>> columns)
|
|
||||||
{
|
|
||||||
StringBuilder temporaryBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
for (Iterator<Column<?>> 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<Row> rows = new ArrayList<Row>();
|
|
||||||
|
|
||||||
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<Column<?>> columns, List<Column<?>> 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<Column<?>> 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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,10 +2,12 @@ package mineplex.core.donation.repository;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -28,9 +30,9 @@ public class DonationRepository extends RepositoryBase
|
|||||||
|
|
||||||
private String _webAddress;
|
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;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -22,27 +22,11 @@ public class EloManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
super("Elo Rating", plugin);
|
super("Elo Rating", plugin);
|
||||||
|
|
||||||
setupConfigValues(plugin);
|
_repository = new EloRepository();
|
||||||
|
|
||||||
_repository = new EloRepository(plugin.getConfig().getString("elo.connectionurl"));
|
|
||||||
_ratingSystem = new EloRatingSystem(new KFactor(0, 1200, 25), new KFactor(1201, 1600, 20), new KFactor(1601, 2000, 15), new KFactor(2001, 2500, 10));
|
_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<String, NautHashMap<String, Integer>>();
|
_playerElos = new NautHashMap<String, NautHashMap<String, Integer>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
@EventHandler
|
||||||
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
|
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
|
||||||
{
|
{
|
||||||
|
@ -7,24 +7,18 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
|
|
||||||
public class EloRepository
|
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 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 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 static String RETRIEVE_ELO = "SELECT gameType, elo FROM eloRating WHERE uuid = ?;";
|
||||||
|
|
||||||
private Connection _connection = null;
|
public EloRepository()
|
||||||
|
|
||||||
public EloRepository(String connectionUrl)
|
|
||||||
{
|
{
|
||||||
_connectionString = connectionUrl;
|
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,12 +26,10 @@ public class EloRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_ELO_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_ELO_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -66,14 +58,9 @@ public class EloRepository
|
|||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
if (_connection.isClosed())
|
preparedStatement = connection.prepareStatement(INSERT_ELO);
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(INSERT_ELO);
|
|
||||||
|
|
||||||
preparedStatement.setString(1, uuid);
|
preparedStatement.setString(1, uuid);
|
||||||
preparedStatement.setString(2, gameType);
|
preparedStatement.setString(2, gameType);
|
||||||
@ -118,14 +105,9 @@ public class EloRepository
|
|||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
if (_connection.isClosed())
|
preparedStatement = connection.prepareStatement(RETRIEVE_ELO);
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_ELO);
|
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
@ -5,9 +5,11 @@ import java.sql.SQLException;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
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.
|
// Not mutual, need to drop accountFriend to recreate with constraint.
|
||||||
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
|
// 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
|
@Override
|
||||||
|
@ -5,8 +5,10 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
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 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 = ?;";
|
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
|
@Override
|
||||||
|
@ -21,9 +21,7 @@ public class Logger
|
|||||||
|
|
||||||
public Logger(JavaPlugin plugin)
|
public Logger(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
setupConfigValues(plugin);
|
_repository = new LoggerRepository(plugin.getConfig().getString("serverstatus.name"));
|
||||||
|
|
||||||
_repository = new LoggerRepository(plugin.getConfig().getString("log.connectionurl"), plugin.getConfig().getString("serverstatus.name"));
|
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
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)
|
public void log(final String message)
|
||||||
{
|
{
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
|
@ -5,23 +5,17 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
|
|
||||||
public class LoggerRepository
|
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 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 static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());";
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
private String _serverName;
|
private String _serverName;
|
||||||
|
|
||||||
public LoggerRepository(String connectionUrl, String serverName)
|
public LoggerRepository(String serverName)
|
||||||
{
|
{
|
||||||
_connectionString = connectionUrl;
|
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
@ -31,12 +25,10 @@ public class LoggerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_LOG_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_LOG_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -63,26 +55,18 @@ public class LoggerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
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())
|
preparedStatement.setString(1, _serverName);
|
||||||
{
|
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
preparedStatement.addBatch();
|
||||||
}
|
|
||||||
|
|
||||||
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.executeBatch();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -106,21 +106,6 @@ public class NpcManager extends MiniPlugin
|
|||||||
private final Set<UUID> _npcDeletingPlayers = new HashSet<>();
|
private final Set<UUID> _npcDeletingPlayers = new HashSet<>();
|
||||||
private Connection _connection;
|
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)
|
public NpcManager(JavaPlugin plugin, Creature creature)
|
||||||
{
|
{
|
||||||
super("NpcManager", plugin);
|
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
|
public Entity addNpc(Player player, EntityType entityType, double radius, boolean adult, String name, String entityMeta) throws SQLException
|
||||||
{
|
{
|
||||||
Connection connection = getConnection();
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
|
|
||||||
//try (Connection connection = DBPool.getInstance().getConnection())
|
|
||||||
{
|
{
|
||||||
String helmet = itemStackToYaml(player.getInventory().getHelmet());
|
String helmet = itemStackToYaml(player.getInventory().getHelmet());
|
||||||
String chestplate = itemStackToYaml(player.getInventory().getChestplate());
|
String chestplate = itemStackToYaml(player.getInventory().getChestplate());
|
||||||
@ -393,9 +376,7 @@ public class NpcManager extends MiniPlugin
|
|||||||
|
|
||||||
if (npc != null)
|
if (npc != null)
|
||||||
{
|
{
|
||||||
Connection connection = getConnection();
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
|
|
||||||
try// (Connection connection = DBPool.getInstance().getConnection())
|
|
||||||
{
|
{
|
||||||
npc.getDatabaseRecord().attach(DSL.using(connection).configuration());
|
npc.getDatabaseRecord().attach(DSL.using(connection).configuration());
|
||||||
npc.getDatabaseRecord().delete();
|
npc.getDatabaseRecord().delete();
|
||||||
@ -502,9 +483,7 @@ public class NpcManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
String serverType = getServerName();
|
String serverType = getServerName();
|
||||||
|
|
||||||
Connection connection = getConnection();
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
|
|
||||||
//try (Connection connection = DBPool.getInstance().getConnection())
|
|
||||||
{
|
{
|
||||||
Result<NpcsRecord> result = DSL.using(connection)
|
Result<NpcsRecord> result = DSL.using(connection)
|
||||||
.selectFrom(Tables.npcs)
|
.selectFrom(Tables.npcs)
|
||||||
@ -530,9 +509,7 @@ public class NpcManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
String serverType = getServerName();
|
String serverType = getServerName();
|
||||||
|
|
||||||
Connection connection = getConnection();
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
|
|
||||||
//try (Connection connection = DBPool.getInstance().getConnection())
|
|
||||||
{
|
{
|
||||||
DSL.using(connection)
|
DSL.using(connection)
|
||||||
.delete(Tables.npcs)
|
.delete(Tables.npcs)
|
||||||
|
@ -6,14 +6,10 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
|
|
||||||
public class PlayerTrackerRepository
|
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 String _serverName = "";
|
||||||
private boolean _us = true;
|
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 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 static String DELETE_PLAYERMAP = "DELETE FROM playerMap WHERE playerName = ? AND serverName = ? AND us = ?;";
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
|
|
||||||
public void initialize(String serverName, boolean us)
|
public void initialize(String serverName, boolean us)
|
||||||
{
|
{
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
@ -31,14 +25,10 @@ public class PlayerTrackerRepository
|
|||||||
|
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
{
|
{
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -67,25 +57,17 @@ public class PlayerTrackerRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
String server = "N/A";
|
String server = "N/A";
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
||||||
{
|
preparedStatement.setString(1, playerName);
|
||||||
if (_connection.isClosed())
|
preparedStatement.setBoolean(2, _us);
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setBoolean(2, _us);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
server = resultSet.getString(1);
|
server = resultSet.getString(1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -126,22 +108,14 @@ public class PlayerTrackerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(DELETE_PLAYERMAP);
|
||||||
{
|
preparedStatement.setString(1, playerName);
|
||||||
if (_connection.isClosed())
|
preparedStatement.setString(2, _serverName);
|
||||||
{
|
preparedStatement.setBoolean(3, _us);
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(DELETE_PLAYERMAP);
|
preparedStatement.executeUpdate();
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setString(2, _serverName);
|
|
||||||
preparedStatement.setBoolean(3, _us);
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -167,22 +141,14 @@ public class PlayerTrackerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(INSERT_PLAYERMAP);
|
||||||
{
|
preparedStatement.setString(1, playerName);
|
||||||
if (_connection.isClosed())
|
preparedStatement.setString(2, _serverName);
|
||||||
{
|
preparedStatement.setBoolean(3, _us);
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(INSERT_PLAYERMAP);
|
preparedStatement.executeUpdate();
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setString(2, _serverName);
|
|
||||||
preparedStatement.setBoolean(3, _us);
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -36,28 +36,13 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
|
|||||||
{
|
{
|
||||||
super("Preferences", plugin);
|
super("Preferences", plugin);
|
||||||
|
|
||||||
setupConfigValues();
|
_repository = new PreferencesRepository(plugin);
|
||||||
|
|
||||||
_repository = new PreferencesRepository(plugin, plugin.getConfig().getString("preferences.connectionurl"));
|
|
||||||
_shop = new PreferencesShop(this, clientManager, donationManager);
|
_shop = new PreferencesShop(this, clientManager, donationManager);
|
||||||
|
|
||||||
AddCommand(new PreferencesCommand(this));
|
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
|
@Override
|
||||||
protected UserPreferences AddPlayer(String player)
|
protected UserPreferences AddPlayer(String player)
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
package mineplex.core.preferences;
|
package mineplex.core.preferences;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
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 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=?;";
|
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
|
@Override
|
||||||
@ -40,9 +43,9 @@ public class PreferencesRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = getConnection())
|
||||||
{
|
{
|
||||||
preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
||||||
|
|
||||||
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
package mineplex.core.reward;
|
package mineplex.core.reward;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.database.Tables;
|
import mineplex.database.Tables;
|
||||||
import org.jooq.DSLContext;
|
import org.jooq.DSLContext;
|
||||||
@ -13,9 +18,9 @@ import org.jooq.impl.DSL;
|
|||||||
*/
|
*/
|
||||||
public class RewardRepository extends RepositoryBase
|
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
|
@Override
|
||||||
@ -32,21 +37,26 @@ public class RewardRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void logReward(Player player, String type, String rarity, String reward)
|
public void logReward(Player player, String type, String rarity, String reward)
|
||||||
{
|
{
|
||||||
DSLContext context;
|
try
|
||||||
|
|
||||||
synchronized (this)
|
|
||||||
{
|
{
|
||||||
context = DSL.using(getConnection());
|
try (Connection connection = getConnection())
|
||||||
}
|
{
|
||||||
|
DSLContext context = DSL.using(connection);
|
||||||
|
|
||||||
context.insertInto(Tables.rewardLog)
|
context.insertInto(Tables.rewardLog)
|
||||||
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
||||||
.from(Tables.accounts)
|
.from(Tables.accounts)
|
||||||
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
||||||
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
||||||
.set(Tables.rewardLog.type, type)
|
.set(Tables.rewardLog.type, type)
|
||||||
.set(Tables.rewardLog.rarity, rarity)
|
.set(Tables.rewardLog.rarity, rarity)
|
||||||
.set(Tables.rewardLog.reward, reward)
|
.set(Tables.rewardLog.reward, reward)
|
||||||
.execute();
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,35 +6,25 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
|
|
||||||
public class SimpleStatsRepository
|
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 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 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 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 static String RETRIEVE_STAT_RECORD = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats WHERE statName = '?';";
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
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
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_STATS_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_STATS_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -63,23 +53,15 @@ public class SimpleStatsRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||||
|
|
||||||
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())
|
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||||
{
|
|
||||||
_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)
|
catch (Exception exception)
|
||||||
@ -120,21 +102,13 @@ public class SimpleStatsRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(STORE_STATS_RECORD);
|
||||||
{
|
preparedStatement.setString(1, statName);
|
||||||
if (_connection.isClosed())
|
preparedStatement.setString(2, statValue);
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
preparedStatement.executeUpdate();
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(STORE_STATS_RECORD);
|
|
||||||
preparedStatement.setString(1, statName);
|
|
||||||
preparedStatement.setString(2, statValue);
|
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -162,24 +136,16 @@ public class SimpleStatsRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||||
|
|
||||||
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())
|
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||||
{
|
|
||||||
_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)
|
catch (Exception exception)
|
||||||
|
@ -130,7 +130,7 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStats getOfflinePlayerStats(String playerName)
|
public PlayerStats getOfflinePlayerStats(String playerName) throws SQLException
|
||||||
{
|
{
|
||||||
return _repository.loadOfflinePlayerStats(playerName);
|
return _repository.loadOfflinePlayerStats(playerName);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.core.stats;
|
package mineplex.core.stats;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -7,9 +8,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
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 RETRIEVE_STATS = "SELECT id, name FROM stats;";
|
||||||
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
|
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
|
@Override
|
||||||
@ -85,9 +88,9 @@ public class StatsRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
System.out.println("saving stats.");
|
System.out.println("saving stats.");
|
||||||
|
|
||||||
try
|
try (Connection connection = getConnection())
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(getConnection());
|
DSLContext context = DSL.using(connection);
|
||||||
|
|
||||||
List<Update> updates = new ArrayList<>();
|
List<Update> updates = new ArrayList<>();
|
||||||
List<Insert> inserts = new ArrayList<>();
|
List<Insert> 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;
|
try (Connection connection = getConnection())
|
||||||
|
|
||||||
DSLContext context;
|
|
||||||
|
|
||||||
synchronized (this)
|
|
||||||
{
|
{
|
||||||
context = DSL.using(getConnection());
|
PlayerStats playerStats = null;
|
||||||
}
|
|
||||||
|
|
||||||
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
|
DSLContext context = DSL.using(connection);
|
||||||
.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();
|
|
||||||
|
|
||||||
|
Result<Record2<String, Integer>> 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())
|
if (result.isNotEmpty())
|
||||||
{
|
|
||||||
playerStats = new PlayerStats();
|
|
||||||
for (Record2<String, Integer> record : result)
|
|
||||||
{
|
{
|
||||||
playerStats.addStat(record.value1(), record.value2());
|
playerStats = new PlayerStats();
|
||||||
|
for (Record2<String, Integer> record : result)
|
||||||
|
{
|
||||||
|
playerStats.addStat(record.value1(), record.value2());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return playerStats;
|
return playerStats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStats loadClientInformation(String uuid)
|
public PlayerStats loadClientInformation(String uuid)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package mineplex.core.stats.command;
|
package mineplex.core.stats.command;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import mineplex.core.achievement.AchievementManager;
|
import mineplex.core.achievement.AchievementManager;
|
||||||
@ -39,25 +41,31 @@ public class TimeCommand extends CommandBase<StatsManager>
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
final PlayerStats stats = Plugin.getOfflinePlayerStats(args[0]);
|
try
|
||||||
|
|
||||||
Plugin.GetPlugin().getServer().getScheduler().runTask(Plugin.GetPlugin(), new Runnable()
|
|
||||||
{
|
{
|
||||||
@Override
|
final PlayerStats stats = Plugin.getOfflinePlayerStats(args[0]);
|
||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar" sourcepath="/REPO_DIR/GitHubLibraries/CraftBukkit/src"/>
|
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar" sourcepath="/REPO_DIR/GitHubLibraries/CraftBukkit/src"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
|
||||||
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Database"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package mineplex.enjinTranslator;
|
package mineplex.enjinTranslator;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
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);";
|
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)
|
public void addGemBooster(String name, int amount)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
<orderEntry type="module" module-name="Mineplex.Minecraft.Game.Core" />
|
<orderEntry type="module" module-name="Mineplex.Minecraft.Game.Core" />
|
||||||
<orderEntry type="library" name="craftbukkit" level="project" />
|
<orderEntry type="library" name="craftbukkit" level="project" />
|
||||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||||
|
<orderEntry type="library" name="commons-dbcp2" level="project" />
|
||||||
|
<orderEntry type="library" name="commons-pool2" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
@ -11,17 +11,13 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class HubRepository
|
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 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));";
|
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 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 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)
|
public void initialize(boolean us)
|
||||||
{
|
{
|
||||||
_us = us;
|
_us = us;
|
||||||
|
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_NEWS_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_NEWS_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -78,23 +68,15 @@ public class HubRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
HashMap<String, String> newsEntries = new HashMap<String, String>();
|
HashMap<String, String> newsEntries = new HashMap<String, String>();
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(RETRIEVE_NEWS_ENTRIES);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
if (_connection.isClosed())
|
newsEntries.put(resultSet.getString(2), resultSet.getString(1));
|
||||||
{
|
|
||||||
_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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -135,22 +117,14 @@ public class HubRepository
|
|||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(SET_NEWS_ENTRY);
|
||||||
{
|
preparedStatement.setString(1, newsEntry);
|
||||||
if (_connection.isClosed())
|
preparedStatement.setInt(2, newsPosition);
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
result = preparedStatement.executeUpdate();
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(SET_NEWS_ENTRY);
|
|
||||||
preparedStatement.setString(1, newsEntry);
|
|
||||||
preparedStatement.setInt(2, newsPosition);
|
|
||||||
|
|
||||||
result = preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -179,23 +153,15 @@ public class HubRepository
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = 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())
|
result = Integer.parseInt(resultSet.getString(1));
|
||||||
{
|
|
||||||
_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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -225,22 +191,14 @@ public class HubRepository
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int maxPos = retrieveMaxNewsPosition();
|
int maxPos = retrieveMaxNewsPosition();
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
if (_connection.isClosed())
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(ADD_NEWS_ENTRY);
|
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||||
preparedStatement.setString(1, newsEntry);
|
{
|
||||||
preparedStatement.setInt(2, maxPos + 1);
|
preparedStatement = connection.prepareStatement(ADD_NEWS_ENTRY);
|
||||||
|
preparedStatement.setString(1, newsEntry);
|
||||||
result = preparedStatement.executeUpdate();
|
preparedStatement.setInt(2, maxPos + 1);
|
||||||
}
|
|
||||||
|
result = preparedStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -269,30 +227,22 @@ public class HubRepository
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int maxPos = retrieveMaxNewsPosition();
|
int maxPos = retrieveMaxNewsPosition();
|
||||||
PreparedStatement preparedStatement = null;
|
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);
|
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||||
preparedStatement.setInt(1, newsPosition);
|
{
|
||||||
|
//preparedStatement = connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY);
|
||||||
result = preparedStatement.executeUpdate();
|
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)
|
catch (Exception exception)
|
||||||
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -28,7 +29,7 @@ public class PollRepository extends RepositoryBase
|
|||||||
|
|
||||||
public PollRepository(JavaPlugin plugin)
|
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
|
@Override
|
||||||
|
@ -41,16 +41,13 @@ public class QueueManager extends MiniPlugin
|
|||||||
|
|
||||||
_eloManager = eloManager;
|
_eloManager = eloManager;
|
||||||
_partyManager = partyManager;
|
_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()
|
private void setupConfigValues()
|
||||||
{
|
{
|
||||||
try
|
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().addDefault("queue.us", true);
|
||||||
GetPlugin().getConfig().set("queue.us", GetPlugin().getConfig().getBoolean("queue.us"));
|
GetPlugin().getConfig().set("queue.us", GetPlugin().getConfig().getBoolean("queue.us"));
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,11 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
|
|
||||||
public class QueueRepository
|
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 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));";
|
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_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 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(boolean us)
|
||||||
|
|
||||||
public QueueRepository(String connectionUrl, boolean us)
|
|
||||||
{
|
{
|
||||||
_connectionString = connectionUrl;
|
|
||||||
_us = us;
|
_us = us;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
@ -38,12 +32,10 @@ public class QueueRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||||
{
|
{
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = _connection.prepareStatement(CREATE_ELO_QUEUE_TABLE);
|
preparedStatement = connection.prepareStatement(CREATE_ELO_QUEUE_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -70,23 +62,15 @@ public class QueueRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
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())
|
System.out.println("Error deleting queue record.");
|
||||||
{
|
|
||||||
_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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -113,23 +97,15 @@ public class QueueRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
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())
|
System.out.println("Error updating state.");
|
||||||
{
|
|
||||||
_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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -158,29 +134,21 @@ public class QueueRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
PlayerMatchStatus matchStatus = new PlayerMatchStatus();
|
PlayerMatchStatus matchStatus = new PlayerMatchStatus();
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(INSERT_ACCOUNT, Statement.RETURN_GENERATED_KEYS);
|
||||||
{
|
preparedStatement.setString(1, playerList);
|
||||||
if (_connection.isClosed())
|
preparedStatement.setString(2, gameType);
|
||||||
{
|
preparedStatement.setInt(3, elo);
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
//preparedStatement.setBoolean(4, _us);
|
||||||
}
|
preparedStatement.setInt(4, playerCount);
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
preparedStatement.executeUpdate();
|
||||||
{
|
resultSet = preparedStatement.getGeneratedKeys();
|
||||||
matchStatus.Id = resultSet.getInt(1);
|
|
||||||
}
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
matchStatus.Id = resultSet.getInt(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -223,28 +191,20 @@ public class QueueRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
PlayerMatchStatus matchStatus = null;
|
PlayerMatchStatus matchStatus = null;
|
||||||
|
|
||||||
try
|
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||||
{
|
{
|
||||||
synchronized (_connectionLock)
|
preparedStatement = connection.prepareStatement(RETRIEVE_MATCH_STATUS);
|
||||||
{
|
preparedStatement.setInt(1, id);
|
||||||
if (_connection.isClosed())
|
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(RETRIEVE_MATCH_STATUS);
|
|
||||||
preparedStatement.setInt(1, id);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
resultSet = preparedStatement.executeQuery();
|
||||||
{
|
|
||||||
matchStatus = new PlayerMatchStatus();
|
while (resultSet.next())
|
||||||
|
{
|
||||||
matchStatus.Id = id;
|
matchStatus = new PlayerMatchStatus();
|
||||||
matchStatus.State = resultSet.getString(1);
|
|
||||||
matchStatus.AssignedMatch = resultSet.getInt(2);
|
matchStatus.Id = id;
|
||||||
}
|
matchStatus.State = resultSet.getString(1);
|
||||||
|
matchStatus.AssignedMatch = resultSet.getInt(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -286,29 +246,21 @@ public class QueueRepository
|
|||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = 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())
|
int playerCount = resultSet.getInt(2);
|
||||||
{
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
for (int i = 0; i < playerCount; i++)
|
||||||
}
|
matchStatus.OtherStatuses.add(resultSet.getString(1));
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
<orderEntry type="library" name="jooq" level="project" />
|
<orderEntry type="library" name="jooq" level="project" />
|
||||||
<orderEntry type="module" module-name="Mineplex.Database" />
|
<orderEntry type="module" module-name="Mineplex.Database" />
|
||||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||||
|
<orderEntry type="library" name="commons-dbcp2" level="project" />
|
||||||
|
<orderEntry type="library" name="commons-pool2" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package nautilus.game.arcade;
|
package nautilus.game.arcade;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -997,7 +998,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
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
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
try
|
||||||
|
{
|
||||||
|
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package nautilus.game.arcade;
|
package nautilus.game.arcade;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.database.Tables;
|
import mineplex.database.Tables;
|
||||||
import mineplex.database.tables.records.GamesRecord;
|
import mineplex.database.tables.records.GamesRecord;
|
||||||
@ -18,9 +22,9 @@ public class ArcadeRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
private final String serverName;
|
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");
|
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<UUID, Boolean> players)
|
public void saveBasicStats(GameType type, boolean tournament, int duration, Map<UUID, Boolean> players) throws SQLException
|
||||||
{
|
{
|
||||||
DSLContext context;
|
try (Connection connection = getConnection())
|
||||||
|
|
||||||
synchronized (this)
|
|
||||||
{
|
{
|
||||||
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<Query> queryList = new ArrayList<>(players.size());
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, Boolean> 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<Query> queryList = new ArrayList<>(players.size());
|
|
||||||
|
|
||||||
for (Map.Entry<UUID, Boolean> 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<UUID, Boolean> players)
|
public void saveLeaderboardStats(int tournamentId, int gameId, Map<UUID, Boolean> players) throws SQLException
|
||||||
{
|
{
|
||||||
DSLContext context;
|
try (Connection connection = getConnection())
|
||||||
|
|
||||||
synchronized (this)
|
|
||||||
{
|
{
|
||||||
context = DSL.using(getConnection());
|
DSLContext context = DSL.using(connection);
|
||||||
|
|
||||||
|
List<Query> queryList = new ArrayList<>(players.size());
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, Boolean> 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<Query> queryList = new ArrayList<>(players.size());
|
|
||||||
|
|
||||||
for (Map.Entry<UUID, Boolean> 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user