Reverted database connection pooling because it caused severe login delays.
This commit is contained in:
parent
30a1df1473
commit
1a09c14642
@ -0,0 +1,49 @@
|
|||||||
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
|
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class PlayerTracker implements Listener
|
||||||
|
{
|
||||||
|
private Plugin _plugin;
|
||||||
|
private PlayerTrackerRepository _repository = null;
|
||||||
|
|
||||||
|
public PlayerTracker(Plugin plugin)
|
||||||
|
{
|
||||||
|
_plugin = plugin;
|
||||||
|
|
||||||
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
|
|
||||||
|
_repository = new PlayerTrackerRepository();
|
||||||
|
_repository.initialize(!new File("eu.dat").exists());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerConnect(final ServerSwitchEvent event)
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_repository.updatePlayerServer(event.getPlayer().getName(), event.getPlayer().getServer().getInfo().getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerDisconnect(final PlayerDisconnectEvent event)
|
||||||
|
{
|
||||||
|
_plugin.getProxy().getScheduler().runAsync(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
_repository.deleteServerTransfers(event.getPlayer().getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mineplex.core.playerTracker;
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
@ -6,29 +6,37 @@ 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 String _serverName = "";
|
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 boolean _us = true;
|
private boolean _us = true;
|
||||||
|
|
||||||
private static String CREATE_PLAYERMAP_TABLE = "CREATE TABLE IF NOT EXISTS playerMap (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(256), serverName VARCHAR(256), us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX playerIndex (playerName));";
|
private static String CREATE_PLAYERMAP_TABLE = "CREATE TABLE IF NOT EXISTS playerMap (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(256), serverName VARCHAR(256), us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX playerIndex (playerName));";
|
||||||
private static String RETRIEVE_PLAYERMAP = "SELECT playerName, serverName FROM playerMap WHERE playerName = ? AND us = ?;";
|
private static String RETRIEVE_PLAYERMAP = "SELECT playerName, serverName FROM playerMap WHERE playerName = ? AND us = ?;";
|
||||||
private static String INSERT_PLAYERMAP = "INSERT INTO playerMap (playerName, serverName, us) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE serverName = VALUES(serverName), us = VALUES(us);";
|
private static String 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 us = ?;";
|
||||||
|
|
||||||
public void initialize(String serverName, boolean us)
|
private Connection _connection = null;
|
||||||
|
|
||||||
|
public void initialize(boolean us)
|
||||||
{
|
{
|
||||||
_serverName = serverName;
|
|
||||||
_us = us;
|
_us = us;
|
||||||
|
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
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)
|
||||||
@ -57,17 +65,25 @@ public class PlayerTrackerRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
String server = "N/A";
|
String server = "N/A";
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setBoolean(2, _us);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
{
|
||||||
server = resultSet.getString(1);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
||||||
|
preparedStatement.setString(1, playerName);
|
||||||
|
preparedStatement.setBoolean(2, _us);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
server = resultSet.getString(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -108,14 +124,21 @@ public class PlayerTrackerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(DELETE_PLAYERMAP);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, playerName);
|
{
|
||||||
preparedStatement.setString(2, _serverName);
|
if (_connection.isClosed())
|
||||||
preparedStatement.setBoolean(3, _us);
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement = _connection.prepareStatement(DELETE_PLAYERMAP);
|
||||||
|
preparedStatement.setString(1, playerName);
|
||||||
|
preparedStatement.setBoolean(2, _us);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -137,18 +160,26 @@ public class PlayerTrackerRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayerServer(String playerName)
|
public void updatePlayerServer(String playerName, String serverName)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(INSERT_PLAYERMAP);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, playerName);
|
{
|
||||||
preparedStatement.setString(2, _serverName);
|
if (_connection.isClosed())
|
||||||
preparedStatement.setBoolean(3, _us);
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement = _connection.prepareStatement(INSERT_PLAYERMAP);
|
||||||
|
preparedStatement.setString(1, playerName);
|
||||||
|
preparedStatement.setString(2, serverName);
|
||||||
|
preparedStatement.setBoolean(3, _us);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
@ -20,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(Plugin plugin)
|
public RankBenefitsGiver9000Repository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,14 +5,13 @@ 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 mineplex.core.account.repository.token.LoginToken;
|
import mineplex.core.account.repository.token.LoginToken;
|
||||||
import mineplex.core.account.repository.token.RankUpdateToken;
|
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;
|
||||||
@ -33,9 +32,9 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
private String _webAddress;
|
private String _webAddress;
|
||||||
|
|
||||||
public AccountRepository(Plugin plugin, String webAddress)
|
public AccountRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,56 @@
|
|||||||
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 final Plugin _plugin;
|
private String _connectionString;
|
||||||
private final DataSource _dataSource;
|
private String _userName;
|
||||||
|
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()
|
||||||
{
|
{
|
||||||
initialize();
|
synchronized (_connectionLock)
|
||||||
update();
|
{
|
||||||
|
initialize();
|
||||||
|
update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,24 +61,37 @@ public abstract class RepositoryBase implements Listener
|
|||||||
|
|
||||||
protected abstract void update();
|
protected abstract void update();
|
||||||
|
|
||||||
protected Connection getConnection() throws SQLException
|
protected Connection getConnection()
|
||||||
{
|
{
|
||||||
return getDataSource().getConnection();
|
try
|
||||||
|
{
|
||||||
|
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 (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(query);
|
if (_connection == null || !_connection.isValid(1))
|
||||||
|
_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();
|
||||||
@ -92,15 +118,15 @@ public abstract class RepositoryBase implements Listener
|
|||||||
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();
|
||||||
@ -127,13 +153,16 @@ 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 (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(query);
|
if (_connection == null || !_connection.isValid(1))
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(query);
|
||||||
|
|
||||||
executeQuery(preparedStatement, callable, columns);
|
executeQuery(preparedStatement, callable, columns);
|
||||||
}
|
}
|
||||||
@ -157,15 +186,15 @@ 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();
|
||||||
@ -180,27 +209,27 @@ public abstract class RepositoryBase implements Listener
|
|||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
@ -218,50 +247,40 @@ public abstract class RepositoryBase implements Listener
|
|||||||
{
|
{
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,10 @@ 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;
|
||||||
@ -30,9 +28,9 @@ public class DonationRepository extends RepositoryBase
|
|||||||
|
|
||||||
private String _webAddress;
|
private String _webAddress;
|
||||||
|
|
||||||
public DonationRepository(Plugin plugin, String webAddress)
|
public DonationRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,27 @@ public class EloManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
super("Elo Rating", plugin);
|
super("Elo Rating", plugin);
|
||||||
|
|
||||||
_repository = new EloRepository();
|
setupConfigValues(plugin);
|
||||||
|
|
||||||
|
_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,18 +7,24 @@ 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 = ?;";
|
||||||
|
|
||||||
public EloRepository()
|
private Connection _connection = null;
|
||||||
|
|
||||||
|
public EloRepository(String connectionUrl)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionUrl;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,10 +32,12 @@ public class EloRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
_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)
|
||||||
@ -58,9 +66,14 @@ public class EloRepository
|
|||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(INSERT_ELO);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_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);
|
||||||
@ -105,9 +118,14 @@ public class EloRepository
|
|||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_ELO);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_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,11 +5,9 @@ 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;
|
||||||
@ -28,9 +26,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(Plugin plugin)
|
public FriendRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,10 +5,8 @@ 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;
|
||||||
@ -31,9 +29,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(Plugin plugin)
|
public InventoryRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,9 @@ public class Logger
|
|||||||
|
|
||||||
public Logger(JavaPlugin plugin)
|
public Logger(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
_repository = new LoggerRepository(plugin.getConfig().getString("serverstatus.name"));
|
setupConfigValues(plugin);
|
||||||
|
|
||||||
|
_repository = new LoggerRepository(plugin.getConfig().getString("log.connectionurl"), plugin.getConfig().getString("serverstatus.name"));
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
||||||
{
|
{
|
||||||
@ -34,6 +36,20 @@ 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,17 +5,23 @@ 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 serverName)
|
public LoggerRepository(String connectionUrl, String serverName)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionUrl;
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
@ -25,10 +31,12 @@ public class LoggerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
_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)
|
||||||
@ -55,18 +63,26 @@ public class LoggerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(INSERT_LOG);
|
synchronized (_connectionLock)
|
||||||
|
|
||||||
for (String msg : message)
|
|
||||||
{
|
{
|
||||||
preparedStatement.setString(1, _serverName);
|
if (_connection.isClosed())
|
||||||
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
|
{
|
||||||
preparedStatement.addBatch();
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
}
|
}
|
||||||
|
|
||||||
preparedStatement.executeBatch();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package mineplex.core.playerTracker;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import mineplex.core.MiniPlugin;
|
|
||||||
import mineplex.core.account.event.ClientUnloadEvent;
|
|
||||||
|
|
||||||
public class PlayerTracker extends MiniPlugin
|
|
||||||
{
|
|
||||||
private PlayerTrackerRepository _repository = null;
|
|
||||||
|
|
||||||
public PlayerTracker(JavaPlugin plugin, String serverName, boolean us)
|
|
||||||
{
|
|
||||||
super("Player Tracker", plugin);
|
|
||||||
|
|
||||||
_repository = new PlayerTrackerRepository();
|
|
||||||
_repository.initialize(serverName, us);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void trackPlayer(final PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
_repository.updatePlayerServer(event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void untrackPlayer(final ClientUnloadEvent event)
|
|
||||||
{
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
_repository.deleteServerTransfers(event.GetName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -36,13 +36,28 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
|
|||||||
{
|
{
|
||||||
super("Preferences", plugin);
|
super("Preferences", plugin);
|
||||||
|
|
||||||
_repository = new PreferencesRepository(plugin);
|
setupConfigValues();
|
||||||
|
|
||||||
|
_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,17 +1,14 @@
|
|||||||
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;
|
||||||
@ -23,9 +20,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(Plugin plugin)
|
public PreferencesRepository(JavaPlugin plugin, String connectionString)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,9 +40,9 @@ public class PreferencesRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
||||||
|
|
||||||
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
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;
|
||||||
@ -18,9 +13,9 @@ import org.jooq.impl.DSL;
|
|||||||
*/
|
*/
|
||||||
public class RewardRepository extends RepositoryBase
|
public class RewardRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
public RewardRepository(Plugin plugin)
|
public RewardRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,26 +32,21 @@ 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)
|
||||||
{
|
{
|
||||||
try
|
DSLContext context;
|
||||||
{
|
|
||||||
try (Connection connection = getConnection())
|
|
||||||
{
|
|
||||||
DSLContext context = DSL.using(connection);
|
|
||||||
|
|
||||||
context.insertInto(Tables.rewardLog)
|
synchronized (this)
|
||||||
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
|
||||||
.from(Tables.accounts)
|
|
||||||
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
|
||||||
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
|
||||||
.set(Tables.rewardLog.type, type)
|
|
||||||
.set(Tables.rewardLog.rarity, rarity)
|
|
||||||
.set(Tables.rewardLog.reward, reward)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
context = DSL.using(getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.insertInto(Tables.rewardLog)
|
||||||
|
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
||||||
|
.from(Tables.accounts)
|
||||||
|
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
||||||
|
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
||||||
|
.set(Tables.rewardLog.type, type)
|
||||||
|
.set(Tables.rewardLog.rarity, rarity)
|
||||||
|
.set(Tables.rewardLog.reward, reward)
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,25 +6,35 @@ 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 (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
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)
|
||||||
@ -53,15 +63,23 @@ 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 (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_STATS_RECORDS);
|
synchronized (_connectionLock)
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
{
|
||||||
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_STATS_RECORDS);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -102,13 +120,21 @@ public class SimpleStatsRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(STORE_STATS_RECORD);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, statName);
|
{
|
||||||
preparedStatement.setString(2, statValue);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_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)
|
||||||
{
|
{
|
||||||
@ -136,16 +162,24 @@ 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 (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_STAT_RECORD);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, statName);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
{
|
||||||
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_STAT_RECORD);
|
||||||
|
preparedStatement.setString(1, statName);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -8,11 +7,9 @@ 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;
|
||||||
@ -39,9 +36,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(Plugin plugin)
|
public StatsRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,9 +85,9 @@ public class StatsRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
System.out.println("saving stats.");
|
System.out.println("saving stats.");
|
||||||
|
|
||||||
try (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(connection);
|
DSLContext context = DSL.using(getConnection());
|
||||||
|
|
||||||
List<Update> updates = new ArrayList<>();
|
List<Update> updates = new ArrayList<>();
|
||||||
List<Insert> inserts = new ArrayList<>();
|
List<Insert> inserts = new ArrayList<>();
|
||||||
@ -137,33 +134,36 @@ public class StatsRepository extends RepositoryBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStats loadOfflinePlayerStats(String playerName) throws SQLException
|
public PlayerStats loadOfflinePlayerStats(String playerName)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
PlayerStats playerStats = null;
|
||||||
|
|
||||||
|
DSLContext context;
|
||||||
|
|
||||||
|
synchronized (this)
|
||||||
{
|
{
|
||||||
PlayerStats playerStats = null;
|
context = DSL.using(getConnection());
|
||||||
|
|
||||||
DSLContext context = DSL.using(connection);
|
|
||||||
|
|
||||||
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())
|
|
||||||
{
|
|
||||||
playerStats = new PlayerStats();
|
|
||||||
for (Record2<String, Integer> record : result)
|
|
||||||
{
|
|
||||||
playerStats.addStat(record.value1(), record.value2());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return playerStats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
playerStats = new PlayerStats();
|
||||||
|
for (Record2<String, Integer> record : result)
|
||||||
|
{
|
||||||
|
playerStats.addStat(record.value1(), record.value2());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStats loadClientInformation(String uuid)
|
public PlayerStats loadClientInformation(String uuid)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
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;
|
||||||
@ -12,9 +10,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(Plugin plugin)
|
public TempRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGemBooster(String name, int amount)
|
public void addGemBooster(String name, int amount)
|
||||||
|
@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.CustomTagFix;
|
import mineplex.core.CustomTagFix;
|
||||||
import mineplex.core.Replay;
|
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
import mineplex.core.antihack.AntiHack;
|
import mineplex.core.antihack.AntiHack;
|
||||||
import mineplex.core.antistack.AntiStack;
|
import mineplex.core.antistack.AntiStack;
|
||||||
@ -26,12 +25,12 @@ import mineplex.core.movement.Movement;
|
|||||||
import mineplex.core.npc.NpcManager;
|
import mineplex.core.npc.NpcManager;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
import mineplex.core.pet.PetManager;
|
import mineplex.core.pet.PetManager;
|
||||||
import mineplex.core.playerTracker.PlayerTracker;
|
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.projectile.ProjectileManager;
|
import mineplex.core.projectile.ProjectileManager;
|
||||||
import mineplex.core.punish.Punish;
|
import mineplex.core.punish.Punish;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
|
import mineplex.core.serverConfig.ServerConfiguration;
|
||||||
import mineplex.core.spawn.Spawn;
|
import mineplex.core.spawn.Spawn;
|
||||||
import mineplex.core.status.ServerStatusManager;
|
import mineplex.core.status.ServerStatusManager;
|
||||||
import mineplex.core.task.TaskManager;
|
import mineplex.core.task.TaskManager;
|
||||||
@ -81,6 +80,8 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
|
|
||||||
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
||||||
|
|
||||||
|
ServerConfiguration configuration = new ServerConfiguration(this);
|
||||||
|
|
||||||
//Other Modules
|
//Other Modules
|
||||||
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
||||||
preferenceManager.GiveItem = true;
|
preferenceManager.GiveItem = true;
|
||||||
@ -100,7 +101,6 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
PacketHandler packetHandler = new PacketHandler(this);
|
PacketHandler packetHandler = new PacketHandler(this);
|
||||||
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
|
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
|
||||||
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager);
|
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager);
|
||||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
|
||||||
|
|
||||||
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
|
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
new ClassCombatShop(shopManager, clientManager, donationManager, "Knight", classManager.GetClass("Knight"));
|
new ClassCombatShop(shopManager, clientManager, donationManager, "Knight", classManager.GetClass("Knight"));
|
||||||
new ClassCombatShop(shopManager, clientManager, donationManager, "Assassin", classManager.GetClass("Assassin"));
|
new ClassCombatShop(shopManager, clientManager, donationManager, "Assassin", classManager.GetClass("Assassin"));
|
||||||
|
|
||||||
new FriendManager(this, preferenceManager);
|
new FriendManager(this, clientManager, preferenceManager);
|
||||||
|
|
||||||
//Updates
|
//Updates
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||||
|
@ -8,7 +8,6 @@ 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;
|
||||||
@ -29,7 +28,7 @@ public class PollRepository extends RepositoryBase
|
|||||||
|
|
||||||
public PollRepository(JavaPlugin plugin)
|
public PollRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,7 +9,6 @@ import mineplex.core.inventory.InventoryManager;
|
|||||||
import mineplex.core.memory.MemoryFix;
|
import mineplex.core.memory.MemoryFix;
|
||||||
import mineplex.core.monitor.LagMeter;
|
import mineplex.core.monitor.LagMeter;
|
||||||
import mineplex.core.npc.NpcManager;
|
import mineplex.core.npc.NpcManager;
|
||||||
import mineplex.core.playerTracker.PlayerTracker;
|
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
|
@ -37,7 +37,6 @@ import mineplex.core.mount.MountManager;
|
|||||||
import mineplex.core.npc.NpcManager;
|
import mineplex.core.npc.NpcManager;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
import mineplex.core.pet.PetManager;
|
import mineplex.core.pet.PetManager;
|
||||||
import mineplex.core.playerTracker.PlayerTracker;
|
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.projectile.ProjectileManager;
|
import mineplex.core.projectile.ProjectileManager;
|
||||||
@ -122,12 +121,11 @@ public class Arcade extends JavaPlugin
|
|||||||
|
|
||||||
//Arcade Manager
|
//Arcade Manager
|
||||||
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
|
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
|
||||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
|
||||||
|
|
||||||
new MemoryFix(this);
|
new MemoryFix(this);
|
||||||
new CustomTagFix(this, packetHandler);
|
new CustomTagFix(this, packetHandler);
|
||||||
|
|
||||||
new FriendManager(this, preferenceManager);
|
new FriendManager(this, _clientManager, preferenceManager);
|
||||||
|
|
||||||
//Updates
|
//Updates
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||||
|
@ -998,14 +998,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
|
||||||
{
|
|
||||||
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1029,14 +1022,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
||||||
{
|
|
||||||
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
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;
|
||||||
@ -22,9 +18,9 @@ public class ArcadeRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
private final String serverName;
|
private final String serverName;
|
||||||
|
|
||||||
public ArcadeRepository(Plugin plugin)
|
public ArcadeRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
serverName = plugin.getConfig().getString("serverstatus.name");
|
serverName = plugin.getConfig().getString("serverstatus.name");
|
||||||
}
|
}
|
||||||
@ -41,67 +37,71 @@ public class ArcadeRepository extends RepositoryBase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveBasicStats(GameType type, boolean tournament, int duration, Map<UUID, Boolean> players) throws SQLException
|
public void saveBasicStats(GameType type, boolean tournament, int duration, Map<UUID, Boolean> players)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
DSLContext context;
|
||||||
|
|
||||||
|
synchronized (this)
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(connection);
|
context = DSL.using(getConnection());
|
||||||
|
|
||||||
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) throws SQLException
|
public void saveLeaderboardStats(int tournamentId, int gameId, Map<UUID, Boolean> players)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
DSLContext context;
|
||||||
|
|
||||||
|
synchronized (this)
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(connection);
|
context = DSL.using(getConnection());
|
||||||
|
|
||||||
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