Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex
Conflicts: Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java
This commit is contained in:
commit
4c675cca9c
3
.gitignore
vendored
3
.gitignore
vendored
@ -26,3 +26,6 @@ Servers
|
||||
Debug
|
||||
*.gitignore
|
||||
/Maps/GRASER UHC
|
||||
/MutualNDA (1)-signed.pdf
|
||||
/MutualNDA - signed-signed.pdf
|
||||
/MutualNDA - signed.pdf
|
||||
|
@ -4,6 +4,7 @@ import mineplex.bungee.lobbyBalancer.LobbyBalancer;
|
||||
import mineplex.bungee.motd.MotdManager;
|
||||
import mineplex.bungee.playerCount.PlayerCount;
|
||||
import mineplex.bungee.playerStats.PlayerStats;
|
||||
import mineplex.bungee.playerTracker.PlayerTracker;
|
||||
import mineplex.bungee.status.InternetStatus;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
@ -18,5 +19,6 @@ public class Mineplexer extends Plugin
|
||||
new FileUpdater(this);
|
||||
new PlayerStats(this);
|
||||
new InternetStatus(this);
|
||||
new PlayerTracker(this);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,6 @@ public class PlayerCount implements Listener, Runnable
|
||||
{
|
||||
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
|
||||
|
||||
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), new Players(_totalMaxPlayers, _totalPlayers, null), serverPing.getDescription(), serverPing.getFaviconObject()));
|
||||
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), new Players(_totalPlayers + 1, _totalPlayers, null), serverPing.getDescription(), serverPing.getFaviconObject()));
|
||||
}
|
||||
}
|
||||
|
@ -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.DriverManager;
|
||||
@ -6,29 +6,37 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
|
||||
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 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 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;
|
||||
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
||||
preparedStatement = _connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -57,17 +65,25 @@ public class PlayerTrackerRepository
|
||||
PreparedStatement preparedStatement = null;
|
||||
String server = "N/A";
|
||||
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
||||
preparedStatement.setString(1, playerName);
|
||||
preparedStatement.setBoolean(2, _us);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next())
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
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)
|
||||
@ -108,14 +124,21 @@ public class PlayerTrackerRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(DELETE_PLAYERMAP);
|
||||
preparedStatement.setString(1, playerName);
|
||||
preparedStatement.setString(2, _serverName);
|
||||
preparedStatement.setBoolean(3, _us);
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
if (_connection.isClosed())
|
||||
{
|
||||
_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)
|
||||
{
|
||||
@ -137,18 +160,26 @@ public class PlayerTrackerRepository
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerServer(String playerName)
|
||||
public void updatePlayerServer(String playerName, String serverName)
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(INSERT_PLAYERMAP);
|
||||
preparedStatement.setString(1, playerName);
|
||||
preparedStatement.setString(2, _serverName);
|
||||
preparedStatement.setBoolean(3, _us);
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
if (_connection.isClosed())
|
||||
{
|
||||
_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)
|
||||
{
|
@ -45,11 +45,17 @@ public class BungeeRotator
|
||||
{
|
||||
if (usServers.size() < maxRecordCount && server.US)
|
||||
{
|
||||
if (usServers.size() >= 2 && server.Players > 900)
|
||||
continue;
|
||||
|
||||
System.out.println("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
|
||||
usServers.add(server.Address);
|
||||
}
|
||||
else if (euServers.size() < maxRecordCount && !server.US)
|
||||
{
|
||||
if (euServers.size() >= 2 && server.Players > 900)
|
||||
continue;
|
||||
|
||||
System.out.println("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
|
||||
euServers.add(server.Address);
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ public class RankBenefitsGiver9000Repository extends RepositoryBase
|
||||
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
|
||||
private static String RETRIEVE_BENEFITS = "SELECT benefit FROM rankBenefits WHERE uuid = ?;";
|
||||
|
||||
public RankBenefitsGiver9000Repository(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
|
||||
|
@ -5,14 +5,13 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.account.repository.token.LoginToken;
|
||||
import mineplex.core.account.repository.token.RankUpdateToken;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.UUIDFetcher;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.DatabaseRunnable;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.column.ColumnBoolean;
|
||||
@ -33,9 +32,9 @@ public class AccountRepository extends RepositoryBase
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,73 +1,99 @@
|
||||
package mineplex.core.database;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.column.Column;
|
||||
import mineplex.core.logger.Logger;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public abstract class RepositoryBase implements Listener
|
||||
{
|
||||
protected static Object _connectionLock = new Object();
|
||||
|
||||
private Connection _connection = null;
|
||||
|
||||
private static Object _queueLock = new Object();
|
||||
|
||||
|
||||
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
||||
|
||||
private final Plugin _plugin;
|
||||
private final DataSource _dataSource;
|
||||
|
||||
public RepositoryBase(Plugin plugin, DataSource dataSource)
|
||||
|
||||
private String _connectionString;
|
||||
private String _userName;
|
||||
private String _password;
|
||||
|
||||
protected JavaPlugin Plugin;
|
||||
|
||||
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_dataSource = dataSource;
|
||||
|
||||
Plugin = plugin;
|
||||
|
||||
_connectionString = connectionString;
|
||||
_userName = username;
|
||||
_password = password;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
initialize();
|
||||
update();
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
initialize();
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
|
||||
protected abstract void initialize();
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
int affectedRows = 0;
|
||||
|
||||
try (Connection connection = getConnection())
|
||||
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(query);
|
||||
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
if (_connection == null || !_connection.isValid(1))
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(query);
|
||||
|
||||
for (int i=0; i < columns.length; i++)
|
||||
{
|
||||
columns[i].setValue(preparedStatement, i + 1);
|
||||
columns[i].setValue(preparedStatement, i+1);
|
||||
}
|
||||
|
||||
|
||||
affectedRows = preparedStatement.executeUpdate();
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -81,30 +107,30 @@ public abstract class RepositoryBase implements Listener
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return affectedRows;
|
||||
}
|
||||
|
||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>... columns)
|
||||
|
||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
||||
{
|
||||
ResultSet resultSet = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
for (int i=0; i < columns.length; i++)
|
||||
{
|
||||
columns[i].setValue(statement, i + 1);
|
||||
columns[i].setValue(statement, i+1);
|
||||
}
|
||||
|
||||
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
|
||||
callable.processResultSet(resultSet);
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -112,13 +138,13 @@ public abstract class RepositoryBase implements Listener
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
{
|
||||
if (resultSet != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
resultSet.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
@ -126,15 +152,18 @@ public abstract class RepositoryBase implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeQuery(String query, ResultSetCallable callable, Column<?>... columns)
|
||||
|
||||
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (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);
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -148,7 +177,7 @@ public abstract class RepositoryBase implements Listener
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
@ -156,112 +185,102 @@ public abstract class RepositoryBase implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>... columns)
|
||||
|
||||
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>...columns)
|
||||
{
|
||||
int affectedRows = 0;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < columns.length; i++)
|
||||
for (int i=0; i < columns.length; i++)
|
||||
{
|
||||
columns[i].setValue(preparedStatement, i + 1);
|
||||
columns[i].setValue(preparedStatement, i+1);
|
||||
}
|
||||
|
||||
|
||||
affectedRows = preparedStatement.executeUpdate();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return affectedRows;
|
||||
}
|
||||
|
||||
|
||||
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
||||
{
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
databaseRunnable.run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Instance.log(errorMessage + exception.getMessage());
|
||||
|
||||
databaseRunnable.incrementFailCount();
|
||||
|
||||
synchronized (_queueLock)
|
||||
{
|
||||
_failedQueue.put(databaseRunnable, errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
databaseRunnable.run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Instance.log(errorMessage + exception.getMessage());
|
||||
|
||||
databaseRunnable.incrementFailCount();
|
||||
|
||||
synchronized (_queueLock)
|
||||
{
|
||||
_failedQueue.put(databaseRunnable, errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
asyncThread.start();
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void processDatabaseQueue(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.MIN_01)
|
||||
return;
|
||||
|
||||
|
||||
processFailedQueue();
|
||||
}
|
||||
|
||||
|
||||
private void processFailedQueue()
|
||||
{
|
||||
synchronized (_queueLock)
|
||||
{
|
||||
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext(); )
|
||||
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();)
|
||||
{
|
||||
final DatabaseRunnable databaseRunnable = runnablesIterator.next();
|
||||
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
databaseRunnable.run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
|
||||
|
||||
if (databaseRunnable.getFailedCounts() < 4)
|
||||
{
|
||||
synchronized (_queueLock)
|
||||
{
|
||||
_failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
runnablesIterator.remove();
|
||||
|
||||
Thread asyncThread = new Thread(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
databaseRunnable.run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
|
||||
|
||||
if (databaseRunnable.getFailedCounts() < 4)
|
||||
{
|
||||
synchronized (_queueLock)
|
||||
{
|
||||
_failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
runnablesIterator.remove();
|
||||
asyncThread.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Plugin getPlugin()
|
||||
{
|
||||
return _plugin;
|
||||
}
|
||||
|
||||
public DataSource getDataSource()
|
||||
{
|
||||
return _dataSource;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public class DonationManager extends MiniPlugin
|
||||
private Object _donorLock = new Object();
|
||||
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _gemQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _coinQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
|
||||
public DonationManager(JavaPlugin plugin, String webAddress)
|
||||
{
|
||||
@ -247,4 +248,56 @@ public class DonationManager extends MiniPlugin
|
||||
}
|
||||
}, caller, name, uuid.toString(), amount);
|
||||
}
|
||||
|
||||
public void RewardCoinsLater(final String caller, final Player player, final int amount)
|
||||
{
|
||||
if (!_coinQueue.containsKey(player))
|
||||
_coinQueue.put(player, new NautHashMap<String, Integer>());
|
||||
|
||||
int totalAmount = amount;
|
||||
|
||||
if (_coinQueue.get(player).containsKey(caller))
|
||||
totalAmount += _coinQueue.get(player).get(caller);
|
||||
|
||||
_coinQueue.get(player).put(caller, totalAmount);
|
||||
|
||||
//Do Temp Change
|
||||
Donor donor = Get(player.getName());
|
||||
|
||||
if (donor != null)
|
||||
donor.addCoins(amount);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void UpdateCoinQueue(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.SLOWER)
|
||||
return;
|
||||
|
||||
for (Player player : _coinQueue.keySet())
|
||||
{
|
||||
String caller = null;
|
||||
int total = 0;
|
||||
|
||||
for (String curCaller : _coinQueue.get(player).keySet())
|
||||
{
|
||||
caller = curCaller;
|
||||
total += _coinQueue.get(player).get(curCaller);
|
||||
}
|
||||
|
||||
if (caller == null)
|
||||
continue;
|
||||
|
||||
//Actually Add Gems
|
||||
RewardCoins(null, caller, player.getName(), player.getUniqueId(), total, false);
|
||||
|
||||
System.out.println("Queue Added [" + player + "] with Coins [" + total + "] for [" + caller + "]");
|
||||
|
||||
//Clean
|
||||
_coinQueue.get(player).clear();
|
||||
}
|
||||
|
||||
//Clean
|
||||
_coinQueue.clear();
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,10 @@ package mineplex.core.donation.repository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.UUIDFetcher;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.DatabaseRunnable;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
@ -30,9 +28,9 @@ public class DonationRepository extends RepositoryBase
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -22,11 +22,27 @@ public class EloManager extends MiniPlugin
|
||||
{
|
||||
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));
|
||||
_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
|
||||
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
|
||||
{
|
||||
|
@ -7,18 +7,24 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.DBPool;
|
||||
|
||||
public class EloRepository
|
||||
{
|
||||
private String _connectionString;
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh";
|
||||
|
||||
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), gameType VARCHAR(256), elo INT, PRIMARY KEY (id), UNIQUE INDEX uuid_gameType_index (uuid, gameType));";
|
||||
private static String INSERT_ELO = "INSERT INTO eloRating (uuid, gameType, elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE elo=VALUES(elo);";
|
||||
private static String RETRIEVE_ELO = "SELECT gameType, elo FROM eloRating WHERE uuid = ?;";
|
||||
|
||||
public EloRepository()
|
||||
private Connection _connection = null;
|
||||
|
||||
public EloRepository(String connectionUrl)
|
||||
{
|
||||
_connectionString = connectionUrl;
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
@ -26,10 +32,12 @@ public class EloRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = connection.prepareStatement(CREATE_ELO_TABLE);
|
||||
preparedStatement = _connection.prepareStatement(CREATE_ELO_TABLE);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -58,9 +66,14 @@ public class EloRepository
|
||||
|
||||
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(2, gameType);
|
||||
@ -105,9 +118,14 @@ public class EloRepository
|
||||
ResultSet resultSet = 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());
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
@ -12,7 +12,9 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.jsonchat.ChildJsonMessage;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
@ -33,13 +35,15 @@ public class FriendManager extends MiniClientPlugin<FriendData>
|
||||
{
|
||||
private static FriendSorter _friendSorter = new FriendSorter();
|
||||
|
||||
private CoreClientManager _clientManager;
|
||||
private PreferencesManager _preferenceManager;
|
||||
private FriendRepository _repository;
|
||||
|
||||
public FriendManager(JavaPlugin plugin, PreferencesManager preferences)
|
||||
public FriendManager(JavaPlugin plugin, CoreClientManager clientManager, PreferencesManager preferences)
|
||||
{
|
||||
super("Friends", plugin);
|
||||
|
||||
_clientManager = clientManager;
|
||||
_preferenceManager = preferences;
|
||||
_repository = new FriendRepository(plugin);
|
||||
}
|
||||
@ -258,6 +262,7 @@ public class FriendManager extends MiniClientPlugin<FriendData>
|
||||
|
||||
public void showFriends(Player caller)
|
||||
{
|
||||
boolean isStaff = _clientManager.Get(caller).GetRank().Has(Rank.HELPER);
|
||||
boolean gotAFriend = false;
|
||||
List<FriendStatus> friendStatuses = Get(caller).Friends;
|
||||
Collections.sort(friendStatuses, _friendSorter);
|
||||
@ -286,13 +291,31 @@ public class FriendManager extends MiniClientPlugin<FriendData>
|
||||
//Online Friend
|
||||
if (friend.Online)
|
||||
{
|
||||
message.add("Teleport").color("green").bold().click("run_command", "/server " + friend.ServerName).hover("show_text", "Teleport to " + friend.Name + "'s server.");
|
||||
if (friend.ServerName.contains("STAFF") || friend.ServerName.contains("CUST"))
|
||||
{
|
||||
if (isStaff && friend.ServerName.contains("STAFF"))
|
||||
message.add("Teleport").color("green").bold().click("run_command", "/server " + friend.ServerName).hover("show_text", "Teleport to " + friend.Name + "'s server.");
|
||||
else
|
||||
message.add("No Teleport").color("yellow").bold();
|
||||
}
|
||||
else
|
||||
message.add("Teleport").color("green").bold().click("run_command", "/server " + friend.ServerName).hover("show_text", "Teleport to " + friend.Name + "'s server.");
|
||||
|
||||
message.add(" - ").color("white");
|
||||
message.add("Delete").color("red").bold().click("run_command", "/unfriend " + friend.Name).hover("show_text", "Remove " + friend.Name + " from your friends list.");
|
||||
message.add(" - ").color("white");
|
||||
message.add(friend.Name).color(friend.Online ? "green" : "gray");
|
||||
message.add(" - ").color("white");
|
||||
message.add(friend.ServerName).color("dark_green");
|
||||
|
||||
if (friend.ServerName.contains("STAFF") || friend.ServerName.contains("CUST"))
|
||||
{
|
||||
if (isStaff && friend.ServerName.contains("STAFF"))
|
||||
message.add(friend.ServerName).color("dark_green");
|
||||
else
|
||||
message.add("Private Staff Server").color("dark_green");
|
||||
}
|
||||
else
|
||||
message.add(friend.ServerName).color("dark_green");
|
||||
|
||||
onlineLines.add(message);
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
@ -28,9 +26,9 @@ public class FriendRepository extends RepositoryBase
|
||||
// Not mutual, need to drop accountFriend to recreate with constraint.
|
||||
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
|
||||
|
||||
public FriendRepository(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
|
||||
|
@ -110,7 +110,7 @@ public class ItemCoinBomb extends ItemGadget
|
||||
event.setCancelled(true);
|
||||
event.getItem().remove();
|
||||
|
||||
Manager.getDonationManager().RewardCoins(null, this.GetName() + " Pickup", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 4);
|
||||
Manager.getDonationManager().RewardCoinsLater(GetName() + " Pickup", event.getPlayer(), 4);
|
||||
|
||||
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f);
|
||||
|
||||
|
@ -189,7 +189,7 @@ public class ItemGemBomb extends ItemGadget
|
||||
event.setCancelled(true);
|
||||
event.getItem().remove();
|
||||
|
||||
Manager.getDonationManager().RewardGems(null, this.GetName() + " Pickup", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 4);
|
||||
Manager.getDonationManager().RewardGemsLater(GetName() + " Pickup", event.getPlayer(), 4);
|
||||
|
||||
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f);
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ public class MorphVillager extends MorphGadget implements IThrown
|
||||
event.setCancelled(true);
|
||||
event.getItem().remove();
|
||||
|
||||
Manager.getDonationManager().RewardGems(null, this.GetName() + " Pickup", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 16);
|
||||
Manager.getDonationManager().RewardGemsLater(GetName() + " Pickup", event.getPlayer(), 16);
|
||||
|
||||
event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package mineplex.core.gadget.gadgets;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -100,14 +101,13 @@ public class ParticleFoot extends ParticleGadget
|
||||
if (_steps.isEmpty())
|
||||
return;
|
||||
|
||||
Iterator<Location> stepIterator = _steps.keySet().iterator();
|
||||
Iterator<Entry<Location, Long>> stepIterator = _steps.entrySet().iterator();
|
||||
|
||||
while (stepIterator.hasNext())
|
||||
{
|
||||
Location step = stepIterator.next();
|
||||
long time = _steps.get(step);
|
||||
|
||||
if (UtilTime.elapsed(time, 10000))
|
||||
Entry<Location, Long> entry = stepIterator.next();
|
||||
|
||||
if (UtilTime.elapsed(entry.getValue(), 10000))
|
||||
stepIterator.remove();
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,8 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
@ -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 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
|
||||
|
@ -21,7 +21,9 @@ public class Logger
|
||||
|
||||
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()
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
System.out.println(message);
|
||||
|
@ -5,17 +5,23 @@ import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
|
||||
public class LoggerRepository
|
||||
{
|
||||
private static Object _connectionLock = new Object();
|
||||
|
||||
private String _connectionString;
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh";
|
||||
|
||||
private static String CREATE_LOG_TABLE = "CREATE TABLE IF NOT EXISTS errorLog (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(256), message VARCHAR(256), date LONG, PRIMARY KEY (id));";
|
||||
private static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());";
|
||||
|
||||
|
||||
private Connection _connection = null;
|
||||
private String _serverName;
|
||||
|
||||
public LoggerRepository(String serverName)
|
||||
public LoggerRepository(String connectionUrl, String serverName)
|
||||
{
|
||||
_connectionString = connectionUrl;
|
||||
_serverName = serverName;
|
||||
|
||||
initialize();
|
||||
@ -25,10 +31,12 @@ public class LoggerRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = connection.prepareStatement(CREATE_LOG_TABLE);
|
||||
preparedStatement = _connection.prepareStatement(CREATE_LOG_TABLE);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -55,18 +63,26 @@ public class LoggerRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(INSERT_LOG);
|
||||
|
||||
for (String msg : message)
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
preparedStatement.setString(1, _serverName);
|
||||
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
|
||||
preparedStatement.addBatch();
|
||||
if (_connection.isClosed())
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
|
||||
preparedStatement = _connection.prepareStatement(INSERT_LOG);
|
||||
|
||||
for (String msg : message)
|
||||
{
|
||||
preparedStatement.setString(1, _serverName);
|
||||
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
|
||||
preparedStatement.addBatch();
|
||||
}
|
||||
|
||||
preparedStatement.executeBatch();
|
||||
}
|
||||
|
||||
preparedStatement.executeBatch();
|
||||
}
|
||||
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);
|
||||
|
||||
_repository = new PreferencesRepository(plugin);
|
||||
|
||||
setupConfigValues();
|
||||
|
||||
_repository = new PreferencesRepository(plugin, plugin.getConfig().getString("preferences.connectionurl"));
|
||||
_shop = new PreferencesShop(this, clientManager, donationManager);
|
||||
|
||||
AddCommand(new PreferencesCommand(this));
|
||||
}
|
||||
|
||||
private void setupConfigValues()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetPlugin().getConfig().addDefault("preferences.connectionurl", "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
|
||||
GetPlugin().getConfig().set("preferences.connectionurl", GetPlugin().getConfig().getString("preferences.connectionurl"));
|
||||
GetPlugin().saveConfig();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UserPreferences AddPlayer(String player)
|
||||
{
|
||||
|
@ -1,17 +1,14 @@
|
||||
package mineplex.core.preferences;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
@ -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 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
|
||||
@ -43,9 +40,9 @@ public class PreferencesRepository extends RepositoryBase
|
||||
{
|
||||
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())
|
||||
{
|
||||
|
@ -1,13 +1,8 @@
|
||||
package mineplex.core.reward;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.database.Tables;
|
||||
import org.jooq.DSLContext;
|
||||
@ -18,9 +13,9 @@ import org.jooq.impl.DSL;
|
||||
*/
|
||||
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
|
||||
@ -37,26 +32,21 @@ public class RewardRepository extends RepositoryBase
|
||||
|
||||
public void logReward(Player player, String type, String rarity, String reward)
|
||||
{
|
||||
try
|
||||
{
|
||||
try (Connection connection = getConnection())
|
||||
{
|
||||
DSLContext context = DSL.using(connection);
|
||||
DSLContext context;
|
||||
|
||||
context.insertInto(Tables.rewardLog)
|
||||
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
||||
.from(Tables.accounts)
|
||||
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
||||
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
||||
.set(Tables.rewardLog.type, type)
|
||||
.set(Tables.rewardLog.rarity, rarity)
|
||||
.set(Tables.rewardLog.reward, reward)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
synchronized (this)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package mineplex.core.serverConfig;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import net.minecraft.server.v1_7_R4.PlayerList;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R4.CraftServer;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.ServerGroup;
|
||||
import mineplex.serverdata.ServerManager;
|
||||
|
||||
public class ServerConfiguration extends MiniPlugin
|
||||
{
|
||||
private Field _playerListMaxPlayers;
|
||||
private ServerGroup _serverGroup;
|
||||
|
||||
public ServerConfiguration(JavaPlugin plugin)
|
||||
{
|
||||
super("Server Configuration", plugin);
|
||||
|
||||
Region region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
|
||||
|
||||
for (ServerGroup serverGroup : ServerManager.getServerRepository(region).getServerGroups())
|
||||
{
|
||||
if (serverGroup.getName().equalsIgnoreCase(plugin.getConfig().getString("serverstatus.group")))
|
||||
{
|
||||
_serverGroup = serverGroup;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_serverGroup == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
_playerListMaxPlayers = PlayerList.class.getDeclaredField("maxPlayers");
|
||||
_playerListMaxPlayers.setAccessible(true);
|
||||
_playerListMaxPlayers.setInt(((CraftServer)_plugin.getServer()).getHandle(), _serverGroup.getMaxPlayers());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
_plugin.getServer().setWhitelist(_serverGroup.getWhitelist());
|
||||
((CraftServer)_plugin.getServer()).getServer().setPvP(_serverGroup.getPvp());
|
||||
((CraftServer)_plugin.getServer()).getServer().setTexturePack(_serverGroup.getResourcePack());
|
||||
}
|
||||
|
||||
public ServerGroup getServerGroup()
|
||||
{
|
||||
return _serverGroup;
|
||||
}
|
||||
}
|
@ -6,25 +6,35 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.DBPool;
|
||||
|
||||
public class SimpleStatsRepository
|
||||
{
|
||||
private static Object _connectionLock = new Object();
|
||||
|
||||
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh"; //try to obfuscate this in the future!
|
||||
|
||||
private static String CREATE_STATS_TABLE = "CREATE TABLE IF NOT EXISTS simpleStats (id INT NOT NULL AUTO_INCREMENT, statName VARCHAR(64), statValue VARCHAR(64), PRIMARY KEY (id));";
|
||||
private static String RETRIEVE_STATS_RECORDS = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats;";
|
||||
private static String STORE_STATS_RECORD = "INSERT INTO simpleStats (statName,statValue) VALUES(?,?);";
|
||||
private static String RETRIEVE_STAT_RECORD = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats WHERE statName = '?';";
|
||||
|
||||
|
||||
private Connection _connection = null;
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = connection.prepareStatement(CREATE_STATS_TABLE);
|
||||
preparedStatement = _connection.prepareStatement(CREATE_STATS_TABLE);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -53,15 +63,23 @@ public class SimpleStatsRepository
|
||||
PreparedStatement preparedStatement = null;
|
||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_STATS_RECORDS);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next())
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
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)
|
||||
@ -102,13 +120,21 @@ public class SimpleStatsRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(STORE_STATS_RECORD);
|
||||
preparedStatement.setString(1, statName);
|
||||
preparedStatement.setString(2, statValue);
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
if (_connection.isClosed())
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
|
||||
preparedStatement = _connection.prepareStatement(STORE_STATS_RECORD);
|
||||
preparedStatement.setString(1, statName);
|
||||
preparedStatement.setString(2, statValue);
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@ -136,16 +162,24 @@ public class SimpleStatsRepository
|
||||
PreparedStatement preparedStatement = null;
|
||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_STAT_RECORD);
|
||||
preparedStatement.setString(1, statName);
|
||||
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next())
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
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)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package mineplex.core.stats;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -8,11 +7,9 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
@ -39,9 +36,9 @@ public class StatsRepository extends RepositoryBase
|
||||
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
|
||||
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
|
||||
|
||||
public StatsRepository(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
|
||||
@ -88,9 +85,9 @@ public class StatsRepository extends RepositoryBase
|
||||
{
|
||||
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<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;
|
||||
|
||||
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;
|
||||
context = DSL.using(getConnection());
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -1,9 +1,7 @@
|
||||
package mineplex.enjinTranslator;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
@ -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);";
|
||||
|
||||
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)
|
||||
|
@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.CustomTagFix;
|
||||
import mineplex.core.Replay;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.antihack.AntiHack;
|
||||
import mineplex.core.antistack.AntiStack;
|
||||
@ -26,12 +25,12 @@ import mineplex.core.movement.Movement;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.pet.PetManager;
|
||||
import mineplex.core.playerTracker.PlayerTracker;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.projectile.ProjectileManager;
|
||||
import mineplex.core.punish.Punish;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.serverConfig.ServerConfiguration;
|
||||
import mineplex.core.spawn.Spawn;
|
||||
import mineplex.core.status.ServerStatusManager;
|
||||
import mineplex.core.task.TaskManager;
|
||||
@ -61,7 +60,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
{
|
||||
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
|
||||
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
|
||||
saveConfig();
|
||||
@ -80,6 +79,8 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||
|
||||
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
||||
|
||||
new ServerConfiguration(this);
|
||||
|
||||
//Other Modules
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
||||
@ -100,7 +101,6 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
PacketHandler packetHandler = new PacketHandler(this);
|
||||
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);
|
||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
||||
|
||||
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, "Assassin", classManager.GetClass("Assassin"));
|
||||
|
||||
new FriendManager(this, preferenceManager);
|
||||
new FriendManager(this, clientManager, preferenceManager);
|
||||
|
||||
//Updates
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||
|
@ -8,7 +8,6 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
@ -29,7 +28,7 @@ public class PollRepository extends RepositoryBase
|
||||
|
||||
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
|
||||
|
@ -68,6 +68,9 @@ public class ServerGroup
|
||||
private boolean _tournament;
|
||||
public boolean getTournament() { return _tournament; }
|
||||
|
||||
private boolean _tournamentPoints;
|
||||
public boolean getTournamentPoints() { return _tournamentPoints; }
|
||||
|
||||
private boolean _teamRejoin;
|
||||
public boolean getTeamRejoin() { return _teamRejoin; }
|
||||
|
||||
@ -116,6 +119,14 @@ public class ServerGroup
|
||||
private boolean _addNoCheat;
|
||||
public boolean getAddNoCheat() { return _addNoCheat; }
|
||||
|
||||
private boolean _whitelist;
|
||||
public boolean getWhitelist() { return _whitelist; }
|
||||
|
||||
private boolean _staffOnly;
|
||||
public boolean getStaffOnly() { return _staffOnly; }
|
||||
|
||||
private String _resourcePack;
|
||||
public String getResourcePack() { return _resourcePack; }
|
||||
// The set of active MinecraftServers that belong to this server group
|
||||
private Set<MinecraftServer> _servers;
|
||||
public Set<MinecraftServer> getServers() { return _servers; }
|
||||
@ -144,6 +155,7 @@ public class ServerGroup
|
||||
_maxPlayers = Integer.valueOf(data.get("maxPlayers"));
|
||||
_pvp = Boolean.valueOf(data.get("pvp"));
|
||||
_tournament = Boolean.valueOf(data.get("tournament"));
|
||||
_tournamentPoints = Boolean.valueOf(data.get("tournamentPoints"));
|
||||
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
|
||||
_games = data.get("games");
|
||||
_serverType = data.get("serverType");
|
||||
@ -160,6 +172,9 @@ public class ServerGroup
|
||||
_hotbarInventory = Boolean.valueOf(data.get("hotbarInventory"));
|
||||
_hotbarHubClock = Boolean.valueOf(data.get("hotbarHubClock"));
|
||||
_playerKickIdle = Boolean.valueOf(data.get("playerKickIdle"));
|
||||
_staffOnly = Boolean.valueOf(data.get("staffOnly"));
|
||||
_whitelist = Boolean.valueOf(data.get("whitelist"));
|
||||
_resourcePack = data.get("resourcePack");
|
||||
|
||||
fetchServers(region);
|
||||
}
|
||||
|
@ -416,12 +416,12 @@ public class ServerMonitor
|
||||
|
||||
private static void startServer(final DedicatedServer serverSpace, final ServerGroup serverGroup, final int serverNum, final boolean free)
|
||||
{
|
||||
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
|
||||
String cmd = "/home/mineplex/easyRemoteStartServerCustom.sh";
|
||||
final String groupPrefix = serverGroup.getPrefix();
|
||||
final String serverName = serverSpace.getName();
|
||||
final String serverAddress = serverSpace.getPublicAddress();
|
||||
|
||||
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverSpace.getPrivateAddress(), (serverGroup.getPortSection() + serverNum) + "", serverGroup.getRequiredRam() + "", serverGroup.getWorldZip(), serverGroup.getPlugin(), serverGroup.getConfigPath(), serverGroup.getName(), serverGroup.getPrefix() + "-" + serverNum, serverGroup.getMinPlayers() + "", serverGroup.getMaxPlayers() + "", serverGroup.getPvp() + "", serverGroup.getTournament() + "", free + "", serverSpace.isUsRegion() ? "true" : "false", serverGroup.getArcadeGroup() + "", serverGroup.getGames(), serverGroup.getServerType(), serverGroup.getAddNoCheat() + "", serverGroup.getTeamAutoJoin() + "", serverGroup.getTeamForceBalance() + "", serverGroup.getTeamRejoin() + "", serverGroup.getGameAutoStart() + "", serverGroup.getGameTimeout() + "", serverGroup.getHotbarHubClock() + "", serverGroup.getHotbarInventory() + "", serverGroup.getPlayerKickIdle() + "", serverGroup.getRewardGems() + "", serverGroup.getRewardItems() + "", serverGroup.getRewardAchievements() + "", serverGroup.getRewardStats() + ""});
|
||||
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverAddress, serverSpace.getPrivateAddress(), (serverGroup.getPortSection() + serverNum) + "", serverGroup.getRequiredRam() + "", serverGroup.getWorldZip(), serverGroup.getPlugin(), serverGroup.getConfigPath(), serverGroup.getName(), serverGroup.getPrefix() + "-" + serverNum, serverSpace.isUsRegion() ? "true" : "false", serverGroup.getAddNoCheat() + "" });
|
||||
pr.start(new GenericRunnable<Boolean>()
|
||||
{
|
||||
public void run(Boolean error)
|
||||
|
@ -9,7 +9,6 @@ import mineplex.core.inventory.InventoryManager;
|
||||
import mineplex.core.memory.MemoryFix;
|
||||
import mineplex.core.monitor.LagMeter;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.playerTracker.PlayerTracker;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
|
@ -1,12 +1,6 @@
|
||||
package nautilus.game.arcade;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -37,12 +31,12 @@ import mineplex.core.mount.MountManager;
|
||||
import mineplex.core.npc.NpcManager;
|
||||
import mineplex.core.packethandler.PacketHandler;
|
||||
import mineplex.core.pet.PetManager;
|
||||
import mineplex.core.playerTracker.PlayerTracker;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.projectile.ProjectileManager;
|
||||
import mineplex.core.punish.Punish;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.serverConfig.ServerConfiguration;
|
||||
import mineplex.core.spawn.Spawn;
|
||||
import mineplex.core.status.ServerStatusManager;
|
||||
import mineplex.core.teleport.Teleport;
|
||||
@ -62,6 +56,8 @@ public class Arcade extends JavaPlugin
|
||||
private DamageManager _damageManager;
|
||||
|
||||
private ArcadeManager _gameManager;
|
||||
|
||||
private ServerConfiguration _serverConfiguration;
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
@ -88,6 +84,8 @@ public class Arcade extends JavaPlugin
|
||||
|
||||
_donationManager = new DonationManager(this, webServerAddress);
|
||||
|
||||
_serverConfiguration = new ServerConfiguration(this);
|
||||
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
|
||||
new MessageManager(this, _clientManager, preferenceManager);
|
||||
|
||||
@ -122,12 +120,11 @@ public class Arcade extends JavaPlugin
|
||||
|
||||
//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);
|
||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
||||
|
||||
new MemoryFix(this);
|
||||
new CustomTagFix(this, packetHandler);
|
||||
|
||||
new FriendManager(this, preferenceManager);
|
||||
new FriendManager(this, _clientManager, preferenceManager);
|
||||
|
||||
//Updates
|
||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||
@ -135,7 +132,6 @@ public class Arcade extends JavaPlugin
|
||||
MinecraftServer.getServer().getPropertyManager().setProperty("debug", true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
@ -151,128 +147,40 @@ public class Arcade extends JavaPlugin
|
||||
{
|
||||
GameServerConfig config = new GameServerConfig();
|
||||
|
||||
//Load Track Data
|
||||
String line = null;
|
||||
|
||||
try
|
||||
config.ServerType = _serverConfiguration.getServerGroup().getServerType();
|
||||
config.MinPlayers = _serverConfiguration.getServerGroup().getMinPlayers();
|
||||
config.MaxPlayers = _serverConfiguration.getServerGroup().getMaxPlayers();
|
||||
config.Tournament = _serverConfiguration.getServerGroup().getTournament();
|
||||
config.TournamentPoints = _serverConfiguration.getServerGroup().getTournamentPoints();
|
||||
config.TeamRejoin = _serverConfiguration.getServerGroup().getTeamRejoin();
|
||||
config.TeamAutoJoin = _serverConfiguration.getServerGroup().getTeamAutoJoin();
|
||||
config.TeamForceBalance = _serverConfiguration.getServerGroup().getTeamForceBalance();
|
||||
config.GameAutoStart = _serverConfiguration.getServerGroup().getGameAutoStart();
|
||||
config.GameTimeout = _serverConfiguration.getServerGroup().getGameTimeout();
|
||||
config.RewardGems = _serverConfiguration.getServerGroup().getRewardGems();
|
||||
config.RewardItems = _serverConfiguration.getServerGroup().getRewardItems();
|
||||
config.RewardStats = _serverConfiguration.getServerGroup().getRewardStats();
|
||||
config.RewardAchievements = _serverConfiguration.getServerGroup().getRewardAchievements();
|
||||
config.HotbarInventory = _serverConfiguration.getServerGroup().getHotbarInventory();
|
||||
config.HotbarHubClock = _serverConfiguration.getServerGroup().getHotbarHubClock();
|
||||
config.PlayerKickIdle = _serverConfiguration.getServerGroup().getPlayerKickIdle();
|
||||
|
||||
for (String gameName : _serverConfiguration.getServerGroup().getGames().split(","))
|
||||
{
|
||||
File file = new File("ArcadeSettings.config");
|
||||
if (!file.exists())
|
||||
WriteServerConfig(GetDefaultConfig());
|
||||
|
||||
FileInputStream fstream = new FileInputStream("ArcadeSettings.config");
|
||||
DataInputStream in = new DataInputStream(fstream);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
while ((line = br.readLine()) != null)
|
||||
try
|
||||
{
|
||||
GameType type = GameType.valueOf(gameName);
|
||||
config.GameList.add(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
String[] tokens = line.split("=");
|
||||
|
||||
if (tokens.length < 2)
|
||||
continue;
|
||||
|
||||
if (tokens[0].equals("PLAYER_HOST"))
|
||||
{
|
||||
config.HostName = tokens[1];
|
||||
}
|
||||
else if (tokens[0].equals("SERVER_TYPE"))
|
||||
{
|
||||
config.ServerType = tokens[1];
|
||||
}
|
||||
else if (tokens[0].equals("PLAYERS_MIN"))
|
||||
{
|
||||
config.MinPlayers = Integer.parseInt(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("PLAYERS_MAX"))
|
||||
{
|
||||
config.MaxPlayers = Integer.parseInt(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("TOURNAMENT"))
|
||||
{
|
||||
config.Tournament = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("TOURNAMENT_POINTS"))
|
||||
{
|
||||
config.TournamentPoints = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("TEAM_REJOIN"))
|
||||
{
|
||||
config.TeamRejoin = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("TEAM_AUTO_JOIN"))
|
||||
{
|
||||
config.TeamAutoJoin = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("TEAM_FORCE_BALANCE"))
|
||||
{
|
||||
config.TeamForceBalance = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("GAME_AUTO_START"))
|
||||
{
|
||||
config.GameAutoStart = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("GAME_TIMEOUT"))
|
||||
{
|
||||
config.GameTimeout = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("REWARD_GEMS"))
|
||||
{
|
||||
config.RewardGems = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("REWARD_ITEMS"))
|
||||
{
|
||||
config.RewardItems = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("REWARD_STATS"))
|
||||
{
|
||||
config.RewardStats = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("REWARD_ACHIEVEMENTS"))
|
||||
{
|
||||
config.RewardAchievements = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("HOTBAR_INVENTORY"))
|
||||
{
|
||||
config.HotbarInventory = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("HOTBAR_HUB_CLOCK"))
|
||||
{
|
||||
config.HotbarHubClock = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
else if (tokens[0].equals("PLAYER_KICK_IDLE"))
|
||||
{
|
||||
config.PlayerKickIdle = Boolean.parseBoolean(tokens[1]);
|
||||
}
|
||||
//Games
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
GameType type = GameType.valueOf(tokens[0]);
|
||||
boolean enabled = Boolean.valueOf(tokens[1]);
|
||||
|
||||
if (enabled)
|
||||
config.GameList.add(type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (!config.IsValid())
|
||||
config = GetDefaultConfig();
|
||||
|
||||
WriteServerConfig(config);
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -288,57 +196,6 @@ public class Arcade extends JavaPlugin
|
||||
return config;
|
||||
}
|
||||
|
||||
public void WriteServerConfig(GameServerConfig config)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter fstream = new FileWriter("ArcadeSettings.config");
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
|
||||
|
||||
|
||||
out.write("SERVER_TYPE=" + config.ServerType + "\n");
|
||||
out.write("PLAYERS_MIN=" + config.MinPlayers + "\n");
|
||||
out.write("PLAYERS_MAX=" + config.MaxPlayers + "\n");
|
||||
|
||||
out.write("\nPLAYER_HOST=" + config.HostName + "\n");
|
||||
|
||||
out.write("\nTOURNAMENT=" + config.Tournament + "\n");
|
||||
|
||||
out.write("\nTOURNAMENT_POINTS=" + config.TournamentPoints + "\n");
|
||||
|
||||
out.write("\nTEAM_REJOIN=" + config.TeamRejoin + "\n");
|
||||
out.write("TEAM_AUTO_JOIN=" + config.TeamAutoJoin + "\n");
|
||||
out.write("TEAM_FORCE_BALANCE=" + config.TeamForceBalance + "\n");
|
||||
|
||||
out.write("\nGAME_AUTO_START=" + config.GameAutoStart + "\n");
|
||||
out.write("GAME_TIMEOUT=" + config.GameTimeout + "\n");
|
||||
|
||||
out.write("\nREWARD_GEMS=" + config.RewardGems + "\n");
|
||||
out.write("REWARD_ITEMS=" + config.RewardItems + "\n");
|
||||
out.write("REWARD_STATS=" + config.RewardStats + "\n");
|
||||
out.write("REWARD_ACHIEVEMENTS=" + config.RewardAchievements + "\n");
|
||||
|
||||
out.write("\nHOTBAR_INVENTORY=" + config.HotbarInventory + "\n");
|
||||
out.write("HOTBAR_HUB_CLOCK=" + config.HotbarHubClock + "\n");
|
||||
|
||||
out.write("\nPLAYER_KICK_IDLE=" + config.PlayerKickIdle + "\n");
|
||||
|
||||
out.write("\n\nGames List;\n");
|
||||
|
||||
for (GameType type : GameType.values())
|
||||
{
|
||||
out.write(type.toString() + "=" + config.GameList.contains(type) + "\n");
|
||||
}
|
||||
|
||||
out.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteFolders()
|
||||
{
|
||||
File curDir = new File(".");
|
||||
|
@ -1013,14 +1013,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1044,14 +1037,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
package nautilus.game.arcade;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.database.Tables;
|
||||
import mineplex.database.tables.records.GamesRecord;
|
||||
@ -22,9 +18,9 @@ public class ArcadeRepository extends RepositoryBase
|
||||
{
|
||||
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");
|
||||
}
|
||||
@ -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);
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@
|
||||
{
|
||||
public class GemRewardToken
|
||||
{
|
||||
public int OriginalBalance;
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Source { get; set; }
|
||||
|
||||
public int Amount { get; set; }
|
||||
|
||||
public int Retries { get; set; }
|
||||
}
|
||||
}
|
@ -7,5 +7,7 @@
|
||||
public string Rank { get; set; }
|
||||
|
||||
public bool Perm { get; set; }
|
||||
|
||||
public int Retries { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
using LOC.Website.Common.Contexts;
|
||||
using System.Data.Entity.Infrastructure;
|
||||
using System.Transactions;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public class AccountAdministrator : IAccountAdministrator
|
||||
{
|
||||
@ -23,7 +24,7 @@
|
||||
private readonly IGameServerMonitor _gameServerMonitor;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly object _transactionLock = new object();
|
||||
private static ConditionalWeakTable<string, object> _accountLocks = new ConditionalWeakTable<string, object>();
|
||||
|
||||
public AccountAdministrator(INautilusRepositoryFactory nautilusRepositoryFactory, ILogger logger)
|
||||
{
|
||||
@ -64,47 +65,66 @@
|
||||
}
|
||||
}
|
||||
|
||||
private object getAccountLock(string name)
|
||||
{
|
||||
object lockObject = null;
|
||||
|
||||
if (!_accountLocks.TryGetValue(name, out lockObject))
|
||||
{
|
||||
lockObject = new object();
|
||||
_accountLocks.Add(name, lockObject);
|
||||
}
|
||||
|
||||
return lockObject;
|
||||
}
|
||||
|
||||
public Account Login(LoginRequestToken loginToken)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
lock (getAccountLock(loginToken.Name))
|
||||
{
|
||||
var account = repository.Where<Account>(x => x.Uuid == loginToken.Uuid).FirstOrDefault() ?? CreateAccount(loginToken, repository);
|
||||
account.LoadNavigationProperties(repository.Context);
|
||||
account.LastLogin = DateTime.Now.Ticks;
|
||||
|
||||
// Expire punishments
|
||||
if (account.Punishments != null)
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
foreach (var expiredPunishment in account.Punishments.Where(x => x.Active && (x.Duration - 0d) > 0 && TimeUtil.GetCurrentMilliseconds() > (x.Time + (x.Duration * 3600000))))
|
||||
var account = repository.Where<Account>(x => x.Uuid == loginToken.Uuid).FirstOrDefault() ?? (repository.Where<Account>(x => x.Name == loginToken.Name).FirstOrDefault() ?? CreateAccount(loginToken, repository));
|
||||
account.LoadNavigationProperties(repository.Context);
|
||||
account.LastLogin = DateTime.Now.Ticks;
|
||||
|
||||
if (String.IsNullOrEmpty(account.Uuid))
|
||||
account.Uuid = loginToken.Uuid;
|
||||
|
||||
// Expire punishments
|
||||
if (account.Punishments != null)
|
||||
{
|
||||
expiredPunishment.Active = false;
|
||||
foreach (var expiredPunishment in account.Punishments.Where(x => x.Active && (x.Duration - 0d) > 0 && TimeUtil.GetCurrentMilliseconds() > (x.Time + (x.Duration * 3600000))))
|
||||
{
|
||||
expiredPunishment.Active = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Insert UUID if not there
|
||||
if (String.IsNullOrEmpty(account.Uuid) && !String.IsNullOrEmpty(loginToken.Uuid))
|
||||
{
|
||||
account.Uuid = loginToken.Uuid;
|
||||
}
|
||||
|
||||
// Update account name if changed
|
||||
if (!String.Equals(account.Name, loginToken.Name))
|
||||
{
|
||||
account.Name = loginToken.Name;
|
||||
}
|
||||
|
||||
/*
|
||||
// Expire ranks
|
||||
if ((account.Rank.Name == "ULTRA" || account.Rank.Name == "HERO") && !account.RankPerm && DateTime.Now.CompareTo(account.RankExpire) >= 0)
|
||||
{
|
||||
account.Rank = repository.Where<Rank>(x => x.Name == "ALL").First();
|
||||
repository.Attach(account.Rank);
|
||||
}
|
||||
* */
|
||||
|
||||
repository.CommitChanges();
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
// Insert UUID if not there
|
||||
if (String.IsNullOrEmpty(account.Uuid) && !String.IsNullOrEmpty(loginToken.Uuid))
|
||||
{
|
||||
account.Uuid = loginToken.Uuid;
|
||||
}
|
||||
|
||||
// Update account name if changed
|
||||
if (!String.Equals(account.Name, loginToken.Name))
|
||||
{
|
||||
account.Name = loginToken.Name;
|
||||
}
|
||||
|
||||
/*
|
||||
// Expire ranks
|
||||
if ((account.Rank.Name == "ULTRA" || account.Rank.Name == "HERO") && !account.RankPerm && DateTime.Now.CompareTo(account.RankExpire) >= 0)
|
||||
{
|
||||
account.Rank = repository.Where<Rank>(x => x.Name == "ALL").First();
|
||||
repository.Attach(account.Rank);
|
||||
}
|
||||
* */
|
||||
|
||||
repository.CommitChanges();
|
||||
|
||||
return account;
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,31 +214,33 @@
|
||||
|
||||
public bool GemReward(GemRewardToken token)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
lock (getAccountLock(token.Name))
|
||||
{
|
||||
var account = repository.Where<Account>(x => x.Name == token.Name).FirstOrDefault();
|
||||
account.LoadNavigationProperties(repository.Context);
|
||||
|
||||
if (account == null)
|
||||
return false;
|
||||
|
||||
account.Gems += token.Amount;
|
||||
|
||||
if (!token.Source.Contains("Earned") && !token.Source.Contains("Tutorial") && !token.Source.Contains("Parkour"))
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
var gemTransaction = new GemTransaction
|
||||
{
|
||||
Source = token.Source,
|
||||
Account = account,
|
||||
Amount = token.Amount,
|
||||
Date = (long)TimeUtil.GetCurrentMilliseconds()
|
||||
};
|
||||
var account = repository.Where<Account>(x => x.Name == token.Name).FirstOrDefault();
|
||||
|
||||
repository.Add<GemTransaction>(gemTransaction);
|
||||
if (account == null)
|
||||
return false;
|
||||
|
||||
account.Gems += token.Amount;
|
||||
|
||||
if (!token.Source.Contains("Earned") && !token.Source.Contains("Tutorial") && !token.Source.Contains("Parkour"))
|
||||
{
|
||||
var gemTransaction = new GemTransaction
|
||||
{
|
||||
Source = token.Source,
|
||||
Account = account,
|
||||
Amount = token.Amount,
|
||||
Date = (long)TimeUtil.GetCurrentMilliseconds()
|
||||
};
|
||||
|
||||
repository.Add<GemTransaction>(gemTransaction);
|
||||
}
|
||||
|
||||
repository.Edit(account);
|
||||
repository.CommitChanges();
|
||||
}
|
||||
|
||||
repository.Edit(account);
|
||||
repository.CommitChanges();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -226,31 +248,35 @@
|
||||
|
||||
public bool CoinReward(GemRewardToken token)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
lock (getAccountLock(token.Name))
|
||||
{
|
||||
var account = repository.Where<Account>(x => x.Name == token.Name).FirstOrDefault();
|
||||
account.LoadNavigationProperties(repository.Context);
|
||||
|
||||
if (account == null)
|
||||
return false;
|
||||
|
||||
account.Coins += token.Amount;
|
||||
|
||||
if (!token.Source.Contains("Earned") && !token.Source.Contains("Tutorial") && !token.Source.Contains("Parkour"))
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
var coinTransaction = new CoinTransaction
|
||||
var account = repository.Where<Account>(x => x.Name == token.Name).FirstOrDefault();
|
||||
|
||||
if (account == null)
|
||||
return false;
|
||||
|
||||
token.OriginalBalance = account.Coins;
|
||||
account.Coins += token.Amount;
|
||||
|
||||
if (!token.Source.Contains("Earned") && !token.Source.Contains("Tutorial") && !token.Source.Contains("Parkour"))
|
||||
{
|
||||
Source = token.Source,
|
||||
Account = account,
|
||||
Amount = token.Amount,
|
||||
Date = (long)TimeUtil.GetCurrentMilliseconds()
|
||||
};
|
||||
var coinTransaction = new CoinTransaction
|
||||
{
|
||||
Source = token.Source,
|
||||
Account = account,
|
||||
Amount = token.Amount,
|
||||
Date = (long)TimeUtil.GetCurrentMilliseconds()
|
||||
};
|
||||
|
||||
repository.Add<CoinTransaction>(coinTransaction);
|
||||
}
|
||||
|
||||
repository.Edit(account);
|
||||
repository.CommitChanges();
|
||||
|
||||
repository.Add<CoinTransaction>(coinTransaction);
|
||||
}
|
||||
|
||||
repository.Edit(account);
|
||||
repository.CommitChanges();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -358,9 +384,9 @@
|
||||
|
||||
public string PurchaseGameSalesPackage(PurchaseToken token)
|
||||
{
|
||||
lock (_transactionLock)
|
||||
try
|
||||
{
|
||||
try
|
||||
lock (getAccountLock(token.AccountName))
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
@ -390,7 +416,7 @@
|
||||
repository.Edit(account);
|
||||
|
||||
if (account.PvpTransactions == null)
|
||||
account.PvpTransactions = new List<GameTransaction> {accountTransaction};
|
||||
account.PvpTransactions = new List<GameTransaction> { accountTransaction };
|
||||
else
|
||||
{
|
||||
account.PvpTransactions.Add(accountTransaction);
|
||||
@ -403,10 +429,10 @@
|
||||
return TransactionResponse.Success.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,43 +446,46 @@
|
||||
|
||||
public void SaveCustomBuild(CustomBuildToken token)
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
lock (getAccountLock(token.PlayerName))
|
||||
{
|
||||
var account =
|
||||
repository.Where<Account>(x => x.Name == token.PlayerName).Include(x => x.CustomBuilds).First();
|
||||
|
||||
var customBuild =
|
||||
account.CustomBuilds.FirstOrDefault(
|
||||
x => String.Equals(x.PvpClass, token.PvpClass) && x.CustomBuildNumber == token.CustomBuildNumber);
|
||||
|
||||
if (customBuild == null)
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
customBuild = repository.Add(token.GetCustomBuild());
|
||||
account.CustomBuilds.Add(customBuild);
|
||||
}
|
||||
else
|
||||
{
|
||||
token.UpdateCustomBuild(customBuild);
|
||||
repository.Edit(customBuild);
|
||||
}
|
||||
var account =
|
||||
repository.Where<Account>(x => x.Name == token.PlayerName).Include(x => x.CustomBuilds).First();
|
||||
|
||||
if (customBuild.Active)
|
||||
{
|
||||
foreach (
|
||||
var otherClassBuild in
|
||||
account.CustomBuilds.Where(
|
||||
x =>
|
||||
String.Equals(x.PvpClass, token.PvpClass) && x.CustomBuildNumber != customBuild.CustomBuildNumber)
|
||||
.ToList())
|
||||
var customBuild =
|
||||
account.CustomBuilds.FirstOrDefault(
|
||||
x => String.Equals(x.PvpClass, token.PvpClass) && x.CustomBuildNumber == token.CustomBuildNumber);
|
||||
|
||||
if (customBuild == null)
|
||||
{
|
||||
otherClassBuild.Active = false;
|
||||
repository.Edit(otherClassBuild);
|
||||
customBuild = repository.Add(token.GetCustomBuild());
|
||||
account.CustomBuilds.Add(customBuild);
|
||||
}
|
||||
else
|
||||
{
|
||||
token.UpdateCustomBuild(customBuild);
|
||||
repository.Edit(customBuild);
|
||||
}
|
||||
}
|
||||
|
||||
repository.Edit(account);
|
||||
|
||||
repository.CommitChanges();
|
||||
if (customBuild.Active)
|
||||
{
|
||||
foreach (
|
||||
var otherClassBuild in
|
||||
account.CustomBuilds.Where(
|
||||
x =>
|
||||
String.Equals(x.PvpClass, token.PvpClass) && x.CustomBuildNumber != customBuild.CustomBuildNumber)
|
||||
.ToList())
|
||||
{
|
||||
otherClassBuild.Active = false;
|
||||
repository.Edit(otherClassBuild);
|
||||
}
|
||||
}
|
||||
|
||||
repository.Edit(account);
|
||||
|
||||
repository.CommitChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -486,9 +515,9 @@
|
||||
|
||||
public string PurchaseUnknownSalesPackage(UnknownPurchaseToken token)
|
||||
{
|
||||
lock (_transactionLock)
|
||||
try
|
||||
{
|
||||
try
|
||||
lock (getAccountLock(token.AccountName))
|
||||
{
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
@ -532,16 +561,17 @@
|
||||
return TransactionResponse.Success.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public string UpdateRank(RankUpdateToken token)
|
||||
{
|
||||
Rank rank = null;
|
||||
var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond);
|
||||
|
||||
try
|
||||
{
|
||||
@ -559,8 +589,6 @@
|
||||
if (rank == null)
|
||||
return account.Rank.ToString();
|
||||
|
||||
var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond);
|
||||
|
||||
account.Rank = rank;
|
||||
account.RankExpire = expire;
|
||||
account.RankPerm = token.Perm;
|
||||
@ -574,7 +602,14 @@
|
||||
using (var repository = _repositoryFactory.CreateRepository())
|
||||
{
|
||||
var account = repository.Where<Account>(x => String.Equals(x.Name, token.Name)).Include(x => x.Rank).FirstOrDefault();
|
||||
_logger.Log("INFO", "ACCOUNT " + account.Name + "'s rank is " + account.Rank.Name + " " + (account.RankPerm ? "Permanently" : "Monthly") + "." + " Rank expire : " + account.RankExpire.ToString());
|
||||
|
||||
if (token.Retries >= 3)
|
||||
_logger.Log("ERROR", "Applying UpdateRank, retried 3 times and something didn't stick.");
|
||||
else if (!account.Rank.Name.Equals(token.Rank) || account.RankPerm != token.Perm || account.RankExpire != expire)
|
||||
{
|
||||
token.Retries++;
|
||||
UpdateRank(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue
Block a user