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
|
Debug
|
||||||
*.gitignore
|
*.gitignore
|
||||||
/Maps/GRASER UHC
|
/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.motd.MotdManager;
|
||||||
import mineplex.bungee.playerCount.PlayerCount;
|
import mineplex.bungee.playerCount.PlayerCount;
|
||||||
import mineplex.bungee.playerStats.PlayerStats;
|
import mineplex.bungee.playerStats.PlayerStats;
|
||||||
|
import mineplex.bungee.playerTracker.PlayerTracker;
|
||||||
import mineplex.bungee.status.InternetStatus;
|
import mineplex.bungee.status.InternetStatus;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
@ -18,5 +19,6 @@ public class Mineplexer extends Plugin
|
|||||||
new FileUpdater(this);
|
new FileUpdater(this);
|
||||||
new PlayerStats(this);
|
new PlayerStats(this);
|
||||||
new InternetStatus(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();
|
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.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
@ -6,29 +6,37 @@ import java.sql.PreparedStatement;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
|
|
||||||
public class PlayerTrackerRepository
|
public class PlayerTrackerRepository
|
||||||
{
|
{
|
||||||
private String _serverName = "";
|
private static Object _connectionLock = new Object();
|
||||||
|
|
||||||
|
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
private boolean _us = true;
|
private boolean _us = true;
|
||||||
|
|
||||||
private static String CREATE_PLAYERMAP_TABLE = "CREATE TABLE IF NOT EXISTS playerMap (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(256), serverName VARCHAR(256), us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX playerIndex (playerName));";
|
private static String CREATE_PLAYERMAP_TABLE = "CREATE TABLE IF NOT EXISTS playerMap (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(256), serverName VARCHAR(256), us BOOLEAN NOT NULL DEFAULT 1, PRIMARY KEY (id), UNIQUE INDEX playerIndex (playerName));";
|
||||||
private static String RETRIEVE_PLAYERMAP = "SELECT playerName, serverName FROM playerMap WHERE playerName = ? AND us = ?;";
|
private static String RETRIEVE_PLAYERMAP = "SELECT playerName, serverName FROM playerMap WHERE playerName = ? AND us = ?;";
|
||||||
private static String INSERT_PLAYERMAP = "INSERT INTO playerMap (playerName, serverName, us) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE serverName = VALUES(serverName), us = VALUES(us);";
|
private static String INSERT_PLAYERMAP = "INSERT INTO playerMap (playerName, serverName, us) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE serverName = VALUES(serverName), us = VALUES(us);";
|
||||||
private static String DELETE_PLAYERMAP = "DELETE FROM playerMap WHERE playerName = ? AND serverName = ? AND us = ?;";
|
private static String DELETE_PLAYERMAP = "DELETE FROM playerMap WHERE playerName = ? AND us = ?;";
|
||||||
|
|
||||||
public void initialize(String serverName, boolean us)
|
private Connection _connection = null;
|
||||||
|
|
||||||
|
public void initialize(boolean us)
|
||||||
{
|
{
|
||||||
_serverName = serverName;
|
|
||||||
_us = us;
|
_us = us;
|
||||||
|
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
preparedStatement = _connection.prepareStatement(CREATE_PLAYERMAP_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -57,17 +65,25 @@ public class PlayerTrackerRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
String server = "N/A";
|
String server = "N/A";
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, playerName);
|
|
||||||
preparedStatement.setBoolean(2, _us);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
{
|
||||||
server = resultSet.getString(1);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERMAP);
|
||||||
|
preparedStatement.setString(1, playerName);
|
||||||
|
preparedStatement.setBoolean(2, _us);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
server = resultSet.getString(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -108,14 +124,21 @@ public class PlayerTrackerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(DELETE_PLAYERMAP);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, playerName);
|
{
|
||||||
preparedStatement.setString(2, _serverName);
|
if (_connection.isClosed())
|
||||||
preparedStatement.setBoolean(3, _us);
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement = _connection.prepareStatement(DELETE_PLAYERMAP);
|
||||||
|
preparedStatement.setString(1, playerName);
|
||||||
|
preparedStatement.setBoolean(2, _us);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -137,18 +160,26 @@ public class PlayerTrackerRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayerServer(String playerName)
|
public void updatePlayerServer(String playerName, String serverName)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(INSERT_PLAYERMAP);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, playerName);
|
{
|
||||||
preparedStatement.setString(2, _serverName);
|
if (_connection.isClosed())
|
||||||
preparedStatement.setBoolean(3, _us);
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement = _connection.prepareStatement(INSERT_PLAYERMAP);
|
||||||
|
preparedStatement.setString(1, playerName);
|
||||||
|
preparedStatement.setString(2, serverName);
|
||||||
|
preparedStatement.setBoolean(3, _us);
|
||||||
|
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
@ -45,11 +45,17 @@ public class BungeeRotator
|
|||||||
{
|
{
|
||||||
if (usServers.size() < maxRecordCount && server.US)
|
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);
|
System.out.println("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
|
||||||
usServers.add(server.Address);
|
usServers.add(server.Address);
|
||||||
}
|
}
|
||||||
else if (euServers.size() < maxRecordCount && !server.US)
|
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);
|
System.out.println("SELECTED " + server.Address + " " + (server.US ? "us" : "eu") + " " + server.Players + "/" + server.MaxPlayers);
|
||||||
euServers.add(server.Address);
|
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 INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
|
||||||
private static String RETRIEVE_BENEFITS = "SELECT benefit FROM rankBenefits WHERE uuid = ?;";
|
private static String RETRIEVE_BENEFITS = "SELECT benefit FROM rankBenefits WHERE uuid = ?;";
|
||||||
|
|
||||||
public RankBenefitsGiver9000Repository(Plugin plugin)
|
public RankBenefitsGiver9000Repository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,14 +5,13 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.account.repository.token.LoginToken;
|
import mineplex.core.account.repository.token.LoginToken;
|
||||||
import mineplex.core.account.repository.token.RankUpdateToken;
|
import mineplex.core.account.repository.token.RankUpdateToken;
|
||||||
import mineplex.core.common.Rank;
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnBoolean;
|
import mineplex.core.database.column.ColumnBoolean;
|
||||||
@ -33,9 +32,9 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
private String _webAddress;
|
private String _webAddress;
|
||||||
|
|
||||||
public AccountRepository(Plugin plugin, String webAddress)
|
public AccountRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -1,73 +1,99 @@
|
|||||||
package mineplex.core.database;
|
package mineplex.core.database;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.column.Column;
|
import mineplex.core.database.column.Column;
|
||||||
import mineplex.core.logger.Logger;
|
import mineplex.core.logger.Logger;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public abstract class RepositoryBase implements Listener
|
public abstract class RepositoryBase implements Listener
|
||||||
{
|
{
|
||||||
|
protected static Object _connectionLock = new Object();
|
||||||
|
|
||||||
|
private Connection _connection = null;
|
||||||
|
|
||||||
private static Object _queueLock = new Object();
|
private static Object _queueLock = new Object();
|
||||||
|
|
||||||
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
||||||
|
|
||||||
private final Plugin _plugin;
|
private String _connectionString;
|
||||||
private final DataSource _dataSource;
|
private String _userName;
|
||||||
|
private String _password;
|
||||||
public RepositoryBase(Plugin plugin, DataSource dataSource)
|
|
||||||
|
protected JavaPlugin Plugin;
|
||||||
|
|
||||||
|
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
||||||
{
|
{
|
||||||
_plugin = plugin;
|
Plugin = plugin;
|
||||||
_dataSource = dataSource;
|
|
||||||
|
_connectionString = connectionString;
|
||||||
|
_userName = username;
|
||||||
|
_password = password;
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
initialize();
|
synchronized (_connectionLock)
|
||||||
update();
|
{
|
||||||
|
initialize();
|
||||||
|
update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initialize();
|
protected abstract void initialize();
|
||||||
|
|
||||||
protected abstract void update();
|
protected abstract void update();
|
||||||
|
|
||||||
protected Connection getConnection() throws SQLException
|
protected Connection getConnection()
|
||||||
{
|
{
|
||||||
return getDataSource().getConnection();
|
try
|
||||||
|
{
|
||||||
|
if (_connection == null || !_connection.isValid(1))
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int executeUpdate(String query, Column<?>... columns)
|
protected int executeUpdate(String query, Column<?>...columns)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(query);
|
if (_connection == null || !_connection.isValid(1))
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
for (int i = 0; i < columns.length; i++)
|
|
||||||
|
preparedStatement = _connection.prepareStatement(query);
|
||||||
|
|
||||||
|
for (int i=0; i < columns.length; i++)
|
||||||
{
|
{
|
||||||
columns[i].setValue(preparedStatement, i + 1);
|
columns[i].setValue(preparedStatement, i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
affectedRows = preparedStatement.executeUpdate();
|
affectedRows = preparedStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -81,30 +107,30 @@ public abstract class RepositoryBase implements Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
preparedStatement.close();
|
preparedStatement.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>... columns)
|
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i = 0; i < columns.length; i++)
|
for (int i=0; i < columns.length; i++)
|
||||||
{
|
{
|
||||||
columns[i].setValue(statement, i + 1);
|
columns[i].setValue(statement, i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
|
|
||||||
callable.processResultSet(resultSet);
|
callable.processResultSet(resultSet);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -112,13 +138,13 @@ public abstract class RepositoryBase implements Listener
|
|||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (resultSet != null)
|
if (resultSet != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resultSet.close();
|
resultSet.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -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;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(query);
|
if (_connection == null || !_connection.isValid(1))
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(query);
|
||||||
|
|
||||||
executeQuery(preparedStatement, callable, columns);
|
executeQuery(preparedStatement, callable, columns);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -148,7 +177,7 @@ public abstract class RepositoryBase implements Listener
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
preparedStatement.close();
|
preparedStatement.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
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;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i = 0; i < columns.length; i++)
|
for (int i=0; i < columns.length; i++)
|
||||||
{
|
{
|
||||||
columns[i].setValue(preparedStatement, i + 1);
|
columns[i].setValue(preparedStatement, i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
affectedRows = preparedStatement.executeUpdate();
|
affectedRows = preparedStatement.executeUpdate();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
||||||
{
|
{
|
||||||
Thread asyncThread = new Thread(new Runnable()
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
databaseRunnable.run();
|
databaseRunnable.run();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Logger.Instance.log(errorMessage + exception.getMessage());
|
Logger.Instance.log(errorMessage + exception.getMessage());
|
||||||
|
|
||||||
databaseRunnable.incrementFailCount();
|
databaseRunnable.incrementFailCount();
|
||||||
|
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
{
|
{
|
||||||
_failedQueue.put(databaseRunnable, errorMessage);
|
_failedQueue.put(databaseRunnable, errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncThread.start();
|
asyncThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void processDatabaseQueue(UpdateEvent event)
|
public void processDatabaseQueue(UpdateEvent event)
|
||||||
{
|
{
|
||||||
if (event.getType() != UpdateType.MIN_01)
|
if (event.getType() != UpdateType.MIN_01)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
processFailedQueue();
|
processFailedQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processFailedQueue()
|
private void processFailedQueue()
|
||||||
{
|
{
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
{
|
{
|
||||||
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext(); )
|
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();)
|
||||||
{
|
{
|
||||||
final DatabaseRunnable databaseRunnable = runnablesIterator.next();
|
final DatabaseRunnable databaseRunnable = runnablesIterator.next();
|
||||||
|
|
||||||
Thread asyncThread = new Thread(new Runnable()
|
Thread asyncThread = new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
databaseRunnable.run();
|
databaseRunnable.run();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
|
Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage());
|
||||||
|
|
||||||
if (databaseRunnable.getFailedCounts() < 4)
|
if (databaseRunnable.getFailedCounts() < 4)
|
||||||
{
|
{
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
{
|
{
|
||||||
_failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
|
_failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
|
Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
runnablesIterator.remove();
|
runnablesIterator.remove();
|
||||||
asyncThread.start();
|
asyncThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin()
|
|
||||||
{
|
|
||||||
return _plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataSource getDataSource()
|
|
||||||
{
|
|
||||||
return _dataSource;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ public class DonationManager extends MiniPlugin
|
|||||||
private Object _donorLock = new Object();
|
private Object _donorLock = new Object();
|
||||||
|
|
||||||
private NautHashMap<Player, NautHashMap<String, Integer>> _gemQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
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)
|
public DonationManager(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
@ -247,4 +248,56 @@ public class DonationManager extends MiniPlugin
|
|||||||
}
|
}
|
||||||
}, caller, name, uuid.toString(), amount);
|
}, 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 java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -30,9 +28,9 @@ public class DonationRepository extends RepositoryBase
|
|||||||
|
|
||||||
private String _webAddress;
|
private String _webAddress;
|
||||||
|
|
||||||
public DonationRepository(Plugin plugin, String webAddress)
|
public DonationRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,27 @@ public class EloManager extends MiniPlugin
|
|||||||
{
|
{
|
||||||
super("Elo Rating", plugin);
|
super("Elo Rating", plugin);
|
||||||
|
|
||||||
_repository = new EloRepository();
|
setupConfigValues(plugin);
|
||||||
|
|
||||||
|
_repository = new EloRepository(plugin.getConfig().getString("elo.connectionurl"));
|
||||||
_ratingSystem = new EloRatingSystem(new KFactor(0, 1200, 25), new KFactor(1201, 1600, 20), new KFactor(1601, 2000, 15), new KFactor(2001, 2500, 10));
|
_ratingSystem = new EloRatingSystem(new KFactor(0, 1200, 25), new KFactor(1201, 1600, 20), new KFactor(1601, 2000, 15), new KFactor(2001, 2500, 10));
|
||||||
_playerElos = new NautHashMap<String, NautHashMap<String, Integer>>();
|
_playerElos = new NautHashMap<String, NautHashMap<String, Integer>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupConfigValues(JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
plugin.getConfig().addDefault("elo.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
|
||||||
|
plugin.getConfig().set("elo.connectionurl", plugin.getConfig().getString("elo.connectionurl"));
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
|
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
|
||||||
{
|
{
|
||||||
|
@ -7,18 +7,24 @@ import java.sql.ResultSet;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
|
|
||||||
public class EloRepository
|
public class EloRepository
|
||||||
{
|
{
|
||||||
|
private String _connectionString;
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), gameType VARCHAR(256), elo INT, PRIMARY KEY (id), UNIQUE INDEX uuid_gameType_index (uuid, gameType));";
|
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), gameType VARCHAR(256), elo INT, PRIMARY KEY (id), UNIQUE INDEX uuid_gameType_index (uuid, gameType));";
|
||||||
private static String INSERT_ELO = "INSERT INTO eloRating (uuid, gameType, elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE elo=VALUES(elo);";
|
private static String INSERT_ELO = "INSERT INTO eloRating (uuid, gameType, elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE elo=VALUES(elo);";
|
||||||
private static String RETRIEVE_ELO = "SELECT gameType, elo FROM eloRating WHERE uuid = ?;";
|
private static String RETRIEVE_ELO = "SELECT gameType, elo FROM eloRating WHERE uuid = ?;";
|
||||||
|
|
||||||
public EloRepository()
|
private Connection _connection = null;
|
||||||
|
|
||||||
|
public EloRepository(String connectionUrl)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionUrl;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,10 +32,12 @@ public class EloRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = connection.prepareStatement(CREATE_ELO_TABLE);
|
preparedStatement = _connection.prepareStatement(CREATE_ELO_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -58,9 +66,14 @@ public class EloRepository
|
|||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(INSERT_ELO);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(INSERT_ELO);
|
||||||
|
|
||||||
preparedStatement.setString(1, uuid);
|
preparedStatement.setString(1, uuid);
|
||||||
preparedStatement.setString(2, gameType);
|
preparedStatement.setString(2, gameType);
|
||||||
@ -105,9 +118,14 @@ public class EloRepository
|
|||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_ELO);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_ELO);
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
@ -12,7 +12,9 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.MiniClientPlugin;
|
import mineplex.core.MiniClientPlugin;
|
||||||
|
import mineplex.core.account.CoreClientManager;
|
||||||
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
import mineplex.core.account.event.RetrieveClientInformationEvent;
|
||||||
|
import mineplex.core.common.Rank;
|
||||||
import mineplex.core.common.jsonchat.ChildJsonMessage;
|
import mineplex.core.common.jsonchat.ChildJsonMessage;
|
||||||
import mineplex.core.common.jsonchat.JsonMessage;
|
import mineplex.core.common.jsonchat.JsonMessage;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
@ -33,13 +35,15 @@ public class FriendManager extends MiniClientPlugin<FriendData>
|
|||||||
{
|
{
|
||||||
private static FriendSorter _friendSorter = new FriendSorter();
|
private static FriendSorter _friendSorter = new FriendSorter();
|
||||||
|
|
||||||
|
private CoreClientManager _clientManager;
|
||||||
private PreferencesManager _preferenceManager;
|
private PreferencesManager _preferenceManager;
|
||||||
private FriendRepository _repository;
|
private FriendRepository _repository;
|
||||||
|
|
||||||
public FriendManager(JavaPlugin plugin, PreferencesManager preferences)
|
public FriendManager(JavaPlugin plugin, CoreClientManager clientManager, PreferencesManager preferences)
|
||||||
{
|
{
|
||||||
super("Friends", plugin);
|
super("Friends", plugin);
|
||||||
|
|
||||||
|
_clientManager = clientManager;
|
||||||
_preferenceManager = preferences;
|
_preferenceManager = preferences;
|
||||||
_repository = new FriendRepository(plugin);
|
_repository = new FriendRepository(plugin);
|
||||||
}
|
}
|
||||||
@ -258,6 +262,7 @@ public class FriendManager extends MiniClientPlugin<FriendData>
|
|||||||
|
|
||||||
public void showFriends(Player caller)
|
public void showFriends(Player caller)
|
||||||
{
|
{
|
||||||
|
boolean isStaff = _clientManager.Get(caller).GetRank().Has(Rank.HELPER);
|
||||||
boolean gotAFriend = false;
|
boolean gotAFriend = false;
|
||||||
List<FriendStatus> friendStatuses = Get(caller).Friends;
|
List<FriendStatus> friendStatuses = Get(caller).Friends;
|
||||||
Collections.sort(friendStatuses, _friendSorter);
|
Collections.sort(friendStatuses, _friendSorter);
|
||||||
@ -286,13 +291,31 @@ public class FriendManager extends MiniClientPlugin<FriendData>
|
|||||||
//Online Friend
|
//Online Friend
|
||||||
if (friend.Online)
|
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(" - ").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("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(" - ").color("white");
|
||||||
message.add(friend.Name).color(friend.Online ? "green" : "gray");
|
message.add(friend.Name).color(friend.Online ? "green" : "gray");
|
||||||
message.add(" - ").color("white");
|
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);
|
onlineLines.add(message);
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,9 @@ import java.sql.SQLException;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -28,9 +26,9 @@ public class FriendRepository extends RepositoryBase
|
|||||||
// Not mutual, need to drop accountFriend to recreate with constraint.
|
// Not mutual, need to drop accountFriend to recreate with constraint.
|
||||||
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
|
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
|
||||||
|
|
||||||
public FriendRepository(Plugin plugin)
|
public FriendRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -110,7 +110,7 @@ public class ItemCoinBomb extends ItemGadget
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
event.getItem().remove();
|
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);
|
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.setCancelled(true);
|
||||||
event.getItem().remove();
|
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);
|
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.setCancelled(true);
|
||||||
event.getItem().remove();
|
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);
|
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.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -100,14 +101,13 @@ public class ParticleFoot extends ParticleGadget
|
|||||||
if (_steps.isEmpty())
|
if (_steps.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Iterator<Location> stepIterator = _steps.keySet().iterator();
|
Iterator<Entry<Location, Long>> stepIterator = _steps.entrySet().iterator();
|
||||||
|
|
||||||
while (stepIterator.hasNext())
|
while (stepIterator.hasNext())
|
||||||
{
|
{
|
||||||
Location step = stepIterator.next();
|
Entry<Location, Long> entry = stepIterator.next();
|
||||||
long time = _steps.get(step);
|
|
||||||
|
if (UtilTime.elapsed(entry.getValue(), 10000))
|
||||||
if (UtilTime.elapsed(time, 10000))
|
|
||||||
stepIterator.remove();
|
stepIterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -31,9 +29,9 @@ public class InventoryRepository extends RepositoryBase
|
|||||||
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
|
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
|
||||||
private static String RETRIEVE_CLIENT_INVENTORY = "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = ?;";
|
private static String RETRIEVE_CLIENT_INVENTORY = "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = ?;";
|
||||||
|
|
||||||
public InventoryRepository(Plugin plugin)
|
public InventoryRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +21,9 @@ public class Logger
|
|||||||
|
|
||||||
public Logger(JavaPlugin plugin)
|
public Logger(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
_repository = new LoggerRepository(plugin.getConfig().getString("serverstatus.name"));
|
setupConfigValues(plugin);
|
||||||
|
|
||||||
|
_repository = new LoggerRepository(plugin.getConfig().getString("log.connectionurl"), plugin.getConfig().getString("serverstatus.name"));
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler()
|
||||||
{
|
{
|
||||||
@ -34,6 +36,20 @@ public class Logger
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupConfigValues(JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
plugin.getConfig().addDefault("log.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
|
||||||
|
plugin.getConfig().set("log.connectionurl", plugin.getConfig().getString("log.connectionurl"));
|
||||||
|
plugin.saveConfig();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void log(final String message)
|
public void log(final String message)
|
||||||
{
|
{
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
|
@ -5,17 +5,23 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
|
|
||||||
public class LoggerRepository
|
public class LoggerRepository
|
||||||
{
|
{
|
||||||
|
private static Object _connectionLock = new Object();
|
||||||
|
|
||||||
|
private String _connectionString;
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh";
|
||||||
|
|
||||||
private static String CREATE_LOG_TABLE = "CREATE TABLE IF NOT EXISTS errorLog (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(256), message VARCHAR(256), date LONG, PRIMARY KEY (id));";
|
private static String CREATE_LOG_TABLE = "CREATE TABLE IF NOT EXISTS errorLog (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(256), message VARCHAR(256), date LONG, PRIMARY KEY (id));";
|
||||||
private static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());";
|
private static String INSERT_LOG = "INSERT INTO errorLog (server, message, date) VALUES (?, ?, now());";
|
||||||
|
|
||||||
|
private Connection _connection = null;
|
||||||
private String _serverName;
|
private String _serverName;
|
||||||
|
|
||||||
public LoggerRepository(String serverName)
|
public LoggerRepository(String connectionUrl, String serverName)
|
||||||
{
|
{
|
||||||
|
_connectionString = connectionUrl;
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
@ -25,10 +31,12 @@ public class LoggerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = connection.prepareStatement(CREATE_LOG_TABLE);
|
preparedStatement = _connection.prepareStatement(CREATE_LOG_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -55,18 +63,26 @@ public class LoggerRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(INSERT_LOG);
|
synchronized (_connectionLock)
|
||||||
|
|
||||||
for (String msg : message)
|
|
||||||
{
|
{
|
||||||
preparedStatement.setString(1, _serverName);
|
if (_connection.isClosed())
|
||||||
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
|
{
|
||||||
preparedStatement.addBatch();
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(INSERT_LOG);
|
||||||
|
|
||||||
|
for (String msg : message)
|
||||||
|
{
|
||||||
|
preparedStatement.setString(1, _serverName);
|
||||||
|
preparedStatement.setString(2, msg.substring(0, Math.min(257, msg.length())));
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement.executeBatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
preparedStatement.executeBatch();
|
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package mineplex.core.playerTracker;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import mineplex.core.MiniPlugin;
|
|
||||||
import mineplex.core.account.event.ClientUnloadEvent;
|
|
||||||
|
|
||||||
public class PlayerTracker extends MiniPlugin
|
|
||||||
{
|
|
||||||
private PlayerTrackerRepository _repository = null;
|
|
||||||
|
|
||||||
public PlayerTracker(JavaPlugin plugin, String serverName, boolean us)
|
|
||||||
{
|
|
||||||
super("Player Tracker", plugin);
|
|
||||||
|
|
||||||
_repository = new PlayerTrackerRepository();
|
|
||||||
_repository.initialize(serverName, us);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void trackPlayer(final PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
_repository.updatePlayerServer(event.getPlayer().getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void untrackPlayer(final ClientUnloadEvent event)
|
|
||||||
{
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
_repository.deleteServerTransfers(event.GetName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -36,13 +36,28 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
|
|||||||
{
|
{
|
||||||
super("Preferences", plugin);
|
super("Preferences", plugin);
|
||||||
|
|
||||||
_repository = new PreferencesRepository(plugin);
|
setupConfigValues();
|
||||||
|
|
||||||
|
_repository = new PreferencesRepository(plugin, plugin.getConfig().getString("preferences.connectionurl"));
|
||||||
_shop = new PreferencesShop(this, clientManager, donationManager);
|
_shop = new PreferencesShop(this, clientManager, donationManager);
|
||||||
|
|
||||||
AddCommand(new PreferencesCommand(this));
|
AddCommand(new PreferencesCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupConfigValues()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
GetPlugin().getConfig().addDefault("preferences.connectionurl", "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
|
||||||
|
GetPlugin().getConfig().set("preferences.connectionurl", GetPlugin().getConfig().getString("preferences.connectionurl"));
|
||||||
|
GetPlugin().saveConfig();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected UserPreferences AddPlayer(String player)
|
protected UserPreferences AddPlayer(String player)
|
||||||
{
|
{
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
package mineplex.core.preferences;
|
package mineplex.core.preferences;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -23,9 +20,9 @@ public class PreferencesRepository extends RepositoryBase
|
|||||||
private static String RETRIEVE_ACCOUNT_PREFERENCES = "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE uuid = ?;";
|
private static String RETRIEVE_ACCOUNT_PREFERENCES = "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE uuid = ?;";
|
||||||
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;";
|
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;";
|
||||||
|
|
||||||
public PreferencesRepository(Plugin plugin)
|
public PreferencesRepository(JavaPlugin plugin, String connectionString)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,9 +40,9 @@ public class PreferencesRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
||||||
|
|
||||||
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package mineplex.core.reward;
|
package mineplex.core.reward;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.database.Tables;
|
import mineplex.database.Tables;
|
||||||
import org.jooq.DSLContext;
|
import org.jooq.DSLContext;
|
||||||
@ -18,9 +13,9 @@ import org.jooq.impl.DSL;
|
|||||||
*/
|
*/
|
||||||
public class RewardRepository extends RepositoryBase
|
public class RewardRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
public RewardRepository(Plugin plugin)
|
public RewardRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -37,26 +32,21 @@ public class RewardRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void logReward(Player player, String type, String rarity, String reward)
|
public void logReward(Player player, String type, String rarity, String reward)
|
||||||
{
|
{
|
||||||
try
|
DSLContext context;
|
||||||
{
|
|
||||||
try (Connection connection = getConnection())
|
|
||||||
{
|
|
||||||
DSLContext context = DSL.using(connection);
|
|
||||||
|
|
||||||
context.insertInto(Tables.rewardLog)
|
synchronized (this)
|
||||||
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
|
||||||
.from(Tables.accounts)
|
|
||||||
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
|
||||||
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
|
||||||
.set(Tables.rewardLog.type, type)
|
|
||||||
.set(Tables.rewardLog.rarity, rarity)
|
|
||||||
.set(Tables.rewardLog.reward, reward)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
context = DSL.using(getConnection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.insertInto(Tables.rewardLog)
|
||||||
|
.set(Tables.rewardLog.accountId, DSL.select(Tables.accounts.id)
|
||||||
|
.from(Tables.accounts)
|
||||||
|
.where(Tables.accounts.uuid.eq(player.getUniqueId().toString())))
|
||||||
|
.set(Tables.rewardLog.date, DSL.currentTimestamp())
|
||||||
|
.set(Tables.rewardLog.type, type)
|
||||||
|
.set(Tables.rewardLog.rarity, rarity)
|
||||||
|
.set(Tables.rewardLog.reward, reward)
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
|
|
||||||
public class SimpleStatsRepository
|
public class SimpleStatsRepository
|
||||||
{
|
{
|
||||||
|
private static Object _connectionLock = new Object();
|
||||||
|
|
||||||
|
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
||||||
|
private String _userName = "root";
|
||||||
|
private String _password = "tAbechAk3wR7tuTh"; //try to obfuscate this in the future!
|
||||||
|
|
||||||
private static String CREATE_STATS_TABLE = "CREATE TABLE IF NOT EXISTS simpleStats (id INT NOT NULL AUTO_INCREMENT, statName VARCHAR(64), statValue VARCHAR(64), PRIMARY KEY (id));";
|
private static String CREATE_STATS_TABLE = "CREATE TABLE IF NOT EXISTS simpleStats (id INT NOT NULL AUTO_INCREMENT, statName VARCHAR(64), statValue VARCHAR(64), PRIMARY KEY (id));";
|
||||||
private static String RETRIEVE_STATS_RECORDS = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats;";
|
private static String RETRIEVE_STATS_RECORDS = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats;";
|
||||||
private static String STORE_STATS_RECORD = "INSERT INTO simpleStats (statName,statValue) VALUES(?,?);";
|
private static String STORE_STATS_RECORD = "INSERT INTO simpleStats (statName,statValue) VALUES(?,?);";
|
||||||
private static String RETRIEVE_STAT_RECORD = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats WHERE statName = '?';";
|
private static String RETRIEVE_STAT_RECORD = "SELECT simpleStats.statName, simpleStats.statValue FROM simpleStats WHERE statName = '?';";
|
||||||
|
|
||||||
|
private Connection _connection = null;
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
// Create table
|
// Create table
|
||||||
preparedStatement = connection.prepareStatement(CREATE_STATS_TABLE);
|
preparedStatement = _connection.prepareStatement(CREATE_STATS_TABLE);
|
||||||
preparedStatement.execute();
|
preparedStatement.execute();
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -53,15 +63,23 @@ public class SimpleStatsRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_STATS_RECORDS);
|
synchronized (_connectionLock)
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
{
|
||||||
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_STATS_RECORDS);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
@ -102,13 +120,21 @@ public class SimpleStatsRepository
|
|||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(STORE_STATS_RECORD);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, statName);
|
{
|
||||||
preparedStatement.setString(2, statValue);
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
preparedStatement.executeUpdate();
|
_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)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@ -136,16 +162,24 @@ public class SimpleStatsRepository
|
|||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
NautHashMap<String, String> statRecords = new NautHashMap<String, String>();
|
||||||
|
|
||||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
try
|
||||||
{
|
{
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_STAT_RECORD);
|
synchronized (_connectionLock)
|
||||||
preparedStatement.setString(1, statName);
|
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (resultSet.next())
|
|
||||||
{
|
{
|
||||||
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
if (_connection.isClosed())
|
||||||
|
{
|
||||||
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
}
|
||||||
|
|
||||||
|
preparedStatement = _connection.prepareStatement(RETRIEVE_STAT_RECORD);
|
||||||
|
preparedStatement.setString(1, statName);
|
||||||
|
|
||||||
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
|
while (resultSet.next())
|
||||||
|
{
|
||||||
|
statRecords.put(resultSet.getString(1), resultSet.getString(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package mineplex.core.stats;
|
package mineplex.core.stats;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -8,11 +7,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -39,9 +36,9 @@ public class StatsRepository extends RepositoryBase
|
|||||||
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
|
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
|
||||||
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
|
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
|
||||||
|
|
||||||
public StatsRepository(Plugin plugin)
|
public StatsRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,9 +85,9 @@ public class StatsRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
System.out.println("saving stats.");
|
System.out.println("saving stats.");
|
||||||
|
|
||||||
try (Connection connection = getConnection())
|
try
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(connection);
|
DSLContext context = DSL.using(getConnection());
|
||||||
|
|
||||||
List<Update> updates = new ArrayList<>();
|
List<Update> updates = new ArrayList<>();
|
||||||
List<Insert> inserts = new ArrayList<>();
|
List<Insert> inserts = new ArrayList<>();
|
||||||
@ -137,33 +134,36 @@ public class StatsRepository extends RepositoryBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStats loadOfflinePlayerStats(String playerName) throws SQLException
|
public PlayerStats loadOfflinePlayerStats(String playerName)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
PlayerStats playerStats = null;
|
||||||
|
|
||||||
|
DSLContext context;
|
||||||
|
|
||||||
|
synchronized (this)
|
||||||
{
|
{
|
||||||
PlayerStats playerStats = null;
|
context = DSL.using(getConnection());
|
||||||
|
|
||||||
DSLContext context = DSL.using(connection);
|
|
||||||
|
|
||||||
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
|
|
||||||
.join(Tables.stats)
|
|
||||||
.on(Tables.stats.id.eq(Tables.accountStats.statId))
|
|
||||||
.where(Tables.accountStats.accountId.eq(DSL.select(Tables.accounts.id)
|
|
||||||
.from(Tables.accounts)
|
|
||||||
.where(Tables.accounts.name.eq(playerName)))
|
|
||||||
).fetch();
|
|
||||||
|
|
||||||
if (result.isNotEmpty())
|
|
||||||
{
|
|
||||||
playerStats = new PlayerStats();
|
|
||||||
for (Record2<String, Integer> record : result)
|
|
||||||
{
|
|
||||||
playerStats.addStat(record.value1(), record.value2());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return playerStats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
|
||||||
|
.join(Tables.stats)
|
||||||
|
.on(Tables.stats.id.eq(Tables.accountStats.statId))
|
||||||
|
.where(Tables.accountStats.accountId.eq(DSL.select(Tables.accounts.id)
|
||||||
|
.from(Tables.accounts)
|
||||||
|
.where(Tables.accounts.name.eq(playerName)))
|
||||||
|
).fetch();
|
||||||
|
|
||||||
|
|
||||||
|
if (result.isNotEmpty())
|
||||||
|
{
|
||||||
|
playerStats = new PlayerStats();
|
||||||
|
for (Record2<String, Integer> record : result)
|
||||||
|
{
|
||||||
|
playerStats.addStat(record.value1(), record.value2());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerStats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerStats loadClientInformation(String uuid)
|
public PlayerStats loadClientInformation(String uuid)
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package mineplex.enjinTranslator;
|
package mineplex.enjinTranslator;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -12,9 +10,9 @@ public class TempRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, 5, ? FROM accounts WHERE accounts.name = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
|
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, 5, ? FROM accounts WHERE accounts.name = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
|
||||||
|
|
||||||
public TempRepository(Plugin plugin)
|
public TempRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGemBooster(String name, int amount)
|
public void addGemBooster(String name, int amount)
|
||||||
|
@ -4,7 +4,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.CustomTagFix;
|
import mineplex.core.CustomTagFix;
|
||||||
import mineplex.core.Replay;
|
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
import mineplex.core.antihack.AntiHack;
|
import mineplex.core.antihack.AntiHack;
|
||||||
import mineplex.core.antistack.AntiStack;
|
import mineplex.core.antistack.AntiStack;
|
||||||
@ -26,12 +25,12 @@ import mineplex.core.movement.Movement;
|
|||||||
import mineplex.core.npc.NpcManager;
|
import mineplex.core.npc.NpcManager;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
import mineplex.core.pet.PetManager;
|
import mineplex.core.pet.PetManager;
|
||||||
import mineplex.core.playerTracker.PlayerTracker;
|
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.projectile.ProjectileManager;
|
import mineplex.core.projectile.ProjectileManager;
|
||||||
import mineplex.core.punish.Punish;
|
import mineplex.core.punish.Punish;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
|
import mineplex.core.serverConfig.ServerConfiguration;
|
||||||
import mineplex.core.spawn.Spawn;
|
import mineplex.core.spawn.Spawn;
|
||||||
import mineplex.core.status.ServerStatusManager;
|
import mineplex.core.status.ServerStatusManager;
|
||||||
import mineplex.core.task.TaskManager;
|
import mineplex.core.task.TaskManager;
|
||||||
@ -61,7 +60,7 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
|
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
|
||||||
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
|
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
|
||||||
saveConfig();
|
saveConfig();
|
||||||
@ -80,6 +79,8 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
Punish punish = new Punish(this, webServerAddress, clientManager);
|
Punish punish = new Punish(this, webServerAddress, clientManager);
|
||||||
|
|
||||||
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
DonationManager donationManager = new DonationManager(this, webServerAddress);
|
||||||
|
|
||||||
|
new ServerConfiguration(this);
|
||||||
|
|
||||||
//Other Modules
|
//Other Modules
|
||||||
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
||||||
@ -100,7 +101,6 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
PacketHandler packetHandler = new PacketHandler(this);
|
PacketHandler packetHandler = new PacketHandler(this);
|
||||||
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
|
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
|
||||||
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager);
|
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager);
|
||||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
|
||||||
|
|
||||||
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
|
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ public class Hub extends JavaPlugin implements IRelation
|
|||||||
new ClassCombatShop(shopManager, clientManager, donationManager, "Knight", classManager.GetClass("Knight"));
|
new ClassCombatShop(shopManager, clientManager, donationManager, "Knight", classManager.GetClass("Knight"));
|
||||||
new ClassCombatShop(shopManager, clientManager, donationManager, "Assassin", classManager.GetClass("Assassin"));
|
new ClassCombatShop(shopManager, clientManager, donationManager, "Assassin", classManager.GetClass("Assassin"));
|
||||||
|
|
||||||
new FriendManager(this, preferenceManager);
|
new FriendManager(this, clientManager, preferenceManager);
|
||||||
|
|
||||||
//Updates
|
//Updates
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||||
|
@ -8,7 +8,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -29,7 +28,7 @@ public class PollRepository extends RepositoryBase
|
|||||||
|
|
||||||
public PollRepository(JavaPlugin plugin)
|
public PollRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,6 +68,9 @@ public class ServerGroup
|
|||||||
private boolean _tournament;
|
private boolean _tournament;
|
||||||
public boolean getTournament() { return _tournament; }
|
public boolean getTournament() { return _tournament; }
|
||||||
|
|
||||||
|
private boolean _tournamentPoints;
|
||||||
|
public boolean getTournamentPoints() { return _tournamentPoints; }
|
||||||
|
|
||||||
private boolean _teamRejoin;
|
private boolean _teamRejoin;
|
||||||
public boolean getTeamRejoin() { return _teamRejoin; }
|
public boolean getTeamRejoin() { return _teamRejoin; }
|
||||||
|
|
||||||
@ -116,6 +119,14 @@ public class ServerGroup
|
|||||||
private boolean _addNoCheat;
|
private boolean _addNoCheat;
|
||||||
public boolean getAddNoCheat() { return _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
|
// The set of active MinecraftServers that belong to this server group
|
||||||
private Set<MinecraftServer> _servers;
|
private Set<MinecraftServer> _servers;
|
||||||
public Set<MinecraftServer> getServers() { return _servers; }
|
public Set<MinecraftServer> getServers() { return _servers; }
|
||||||
@ -144,6 +155,7 @@ public class ServerGroup
|
|||||||
_maxPlayers = Integer.valueOf(data.get("maxPlayers"));
|
_maxPlayers = Integer.valueOf(data.get("maxPlayers"));
|
||||||
_pvp = Boolean.valueOf(data.get("pvp"));
|
_pvp = Boolean.valueOf(data.get("pvp"));
|
||||||
_tournament = Boolean.valueOf(data.get("tournament"));
|
_tournament = Boolean.valueOf(data.get("tournament"));
|
||||||
|
_tournamentPoints = Boolean.valueOf(data.get("tournamentPoints"));
|
||||||
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
|
_generateFreeVersions = Boolean.valueOf(data.get("generateFreeVersions"));
|
||||||
_games = data.get("games");
|
_games = data.get("games");
|
||||||
_serverType = data.get("serverType");
|
_serverType = data.get("serverType");
|
||||||
@ -160,6 +172,9 @@ public class ServerGroup
|
|||||||
_hotbarInventory = Boolean.valueOf(data.get("hotbarInventory"));
|
_hotbarInventory = Boolean.valueOf(data.get("hotbarInventory"));
|
||||||
_hotbarHubClock = Boolean.valueOf(data.get("hotbarHubClock"));
|
_hotbarHubClock = Boolean.valueOf(data.get("hotbarHubClock"));
|
||||||
_playerKickIdle = Boolean.valueOf(data.get("playerKickIdle"));
|
_playerKickIdle = Boolean.valueOf(data.get("playerKickIdle"));
|
||||||
|
_staffOnly = Boolean.valueOf(data.get("staffOnly"));
|
||||||
|
_whitelist = Boolean.valueOf(data.get("whitelist"));
|
||||||
|
_resourcePack = data.get("resourcePack");
|
||||||
|
|
||||||
fetchServers(region);
|
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)
|
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 groupPrefix = serverGroup.getPrefix();
|
||||||
final String serverName = serverSpace.getName();
|
final String serverName = serverSpace.getName();
|
||||||
final String serverAddress = serverSpace.getPublicAddress();
|
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>()
|
pr.start(new GenericRunnable<Boolean>()
|
||||||
{
|
{
|
||||||
public void run(Boolean error)
|
public void run(Boolean error)
|
||||||
|
@ -9,7 +9,6 @@ import mineplex.core.inventory.InventoryManager;
|
|||||||
import mineplex.core.memory.MemoryFix;
|
import mineplex.core.memory.MemoryFix;
|
||||||
import mineplex.core.monitor.LagMeter;
|
import mineplex.core.monitor.LagMeter;
|
||||||
import mineplex.core.npc.NpcManager;
|
import mineplex.core.npc.NpcManager;
|
||||||
import mineplex.core.playerTracker.PlayerTracker;
|
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
package nautilus.game.arcade;
|
package nautilus.game.arcade;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -37,12 +31,12 @@ import mineplex.core.mount.MountManager;
|
|||||||
import mineplex.core.npc.NpcManager;
|
import mineplex.core.npc.NpcManager;
|
||||||
import mineplex.core.packethandler.PacketHandler;
|
import mineplex.core.packethandler.PacketHandler;
|
||||||
import mineplex.core.pet.PetManager;
|
import mineplex.core.pet.PetManager;
|
||||||
import mineplex.core.playerTracker.PlayerTracker;
|
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.preferences.PreferencesManager;
|
import mineplex.core.preferences.PreferencesManager;
|
||||||
import mineplex.core.projectile.ProjectileManager;
|
import mineplex.core.projectile.ProjectileManager;
|
||||||
import mineplex.core.punish.Punish;
|
import mineplex.core.punish.Punish;
|
||||||
import mineplex.core.recharge.Recharge;
|
import mineplex.core.recharge.Recharge;
|
||||||
|
import mineplex.core.serverConfig.ServerConfiguration;
|
||||||
import mineplex.core.spawn.Spawn;
|
import mineplex.core.spawn.Spawn;
|
||||||
import mineplex.core.status.ServerStatusManager;
|
import mineplex.core.status.ServerStatusManager;
|
||||||
import mineplex.core.teleport.Teleport;
|
import mineplex.core.teleport.Teleport;
|
||||||
@ -62,6 +56,8 @@ public class Arcade extends JavaPlugin
|
|||||||
private DamageManager _damageManager;
|
private DamageManager _damageManager;
|
||||||
|
|
||||||
private ArcadeManager _gameManager;
|
private ArcadeManager _gameManager;
|
||||||
|
|
||||||
|
private ServerConfiguration _serverConfiguration;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
@ -88,6 +84,8 @@ public class Arcade extends JavaPlugin
|
|||||||
|
|
||||||
_donationManager = new DonationManager(this, webServerAddress);
|
_donationManager = new DonationManager(this, webServerAddress);
|
||||||
|
|
||||||
|
_serverConfiguration = new ServerConfiguration(this);
|
||||||
|
|
||||||
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
|
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
|
||||||
new MessageManager(this, _clientManager, preferenceManager);
|
new MessageManager(this, _clientManager, preferenceManager);
|
||||||
|
|
||||||
@ -122,12 +120,11 @@ public class Arcade extends JavaPlugin
|
|||||||
|
|
||||||
//Arcade Manager
|
//Arcade Manager
|
||||||
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
|
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
|
||||||
new PlayerTracker(this, serverStatusManager.getCurrentServerName(), serverStatusManager.getUs());
|
|
||||||
|
|
||||||
new MemoryFix(this);
|
new MemoryFix(this);
|
||||||
new CustomTagFix(this, packetHandler);
|
new CustomTagFix(this, packetHandler);
|
||||||
|
|
||||||
new FriendManager(this, preferenceManager);
|
new FriendManager(this, _clientManager, preferenceManager);
|
||||||
|
|
||||||
//Updates
|
//Updates
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);
|
||||||
@ -135,7 +132,6 @@ public class Arcade extends JavaPlugin
|
|||||||
MinecraftServer.getServer().getPropertyManager().setProperty("debug", true);
|
MinecraftServer.getServer().getPropertyManager().setProperty("debug", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
@ -151,128 +147,40 @@ public class Arcade extends JavaPlugin
|
|||||||
{
|
{
|
||||||
GameServerConfig config = new GameServerConfig();
|
GameServerConfig config = new GameServerConfig();
|
||||||
|
|
||||||
//Load Track Data
|
config.ServerType = _serverConfiguration.getServerGroup().getServerType();
|
||||||
String line = null;
|
config.MinPlayers = _serverConfiguration.getServerGroup().getMinPlayers();
|
||||||
|
config.MaxPlayers = _serverConfiguration.getServerGroup().getMaxPlayers();
|
||||||
try
|
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");
|
try
|
||||||
if (!file.exists())
|
{
|
||||||
WriteServerConfig(GetDefaultConfig());
|
GameType type = GameType.valueOf(gameName);
|
||||||
|
config.GameList.add(type);
|
||||||
FileInputStream fstream = new FileInputStream("ArcadeSettings.config");
|
}
|
||||||
DataInputStream in = new DataInputStream(fstream);
|
catch (Exception e)
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
||||||
|
|
||||||
while ((line = br.readLine()) != null)
|
|
||||||
{
|
{
|
||||||
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())
|
if (!config.IsValid())
|
||||||
config = GetDefaultConfig();
|
config = GetDefaultConfig();
|
||||||
|
|
||||||
WriteServerConfig(config);
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,57 +196,6 @@ public class Arcade extends JavaPlugin
|
|||||||
return config;
|
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()
|
private void DeleteFolders()
|
||||||
{
|
{
|
||||||
File curDir = new File(".");
|
File curDir = new File(".");
|
||||||
|
@ -1013,14 +1013,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
|
||||||
{
|
|
||||||
getArcadeRepository().saveBasicStats(game.GetType(), IsTournamentServer(), (int) (System.currentTimeMillis() - game.getGameLiveTime()), data);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1044,14 +1037,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
||||||
{
|
|
||||||
getArcadeRepository().saveLeaderboardStats(0, type.ordinal(), data);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
package nautilus.game.arcade;
|
package nautilus.game.arcade;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.database.DBPool;
|
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.database.Tables;
|
import mineplex.database.Tables;
|
||||||
import mineplex.database.tables.records.GamesRecord;
|
import mineplex.database.tables.records.GamesRecord;
|
||||||
@ -22,9 +18,9 @@ public class ArcadeRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
private final String serverName;
|
private final String serverName;
|
||||||
|
|
||||||
public ArcadeRepository(Plugin plugin)
|
public ArcadeRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, DBPool.ACCOUNT);
|
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||||
|
|
||||||
serverName = plugin.getConfig().getString("serverstatus.name");
|
serverName = plugin.getConfig().getString("serverstatus.name");
|
||||||
}
|
}
|
||||||
@ -41,67 +37,71 @@ public class ArcadeRepository extends RepositoryBase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveBasicStats(GameType type, boolean tournament, int duration, Map<UUID, Boolean> players) throws SQLException
|
public void saveBasicStats(GameType type, boolean tournament, int duration, Map<UUID, Boolean> players)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
DSLContext context;
|
||||||
|
|
||||||
|
synchronized (this)
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(connection);
|
context = DSL.using(getConnection());
|
||||||
|
|
||||||
GamesRecord record = context.newRecord(Tables.games);
|
|
||||||
record.setDuration(duration);
|
|
||||||
record.setTournament(tournament);
|
|
||||||
record.setType(type.name());
|
|
||||||
record.setServer(serverName);
|
|
||||||
record.store();
|
|
||||||
|
|
||||||
List<Query> queryList = new ArrayList<>(players.size());
|
|
||||||
|
|
||||||
for (Map.Entry<UUID, Boolean> entry : players.entrySet())
|
|
||||||
{
|
|
||||||
Query query = context
|
|
||||||
.insertInto(Tables.gamePlayers)
|
|
||||||
.set(Tables.gamePlayers.gameId, record.getId())
|
|
||||||
.set(Tables.gamePlayers.accountId, DSL.select(Tables.accounts.id)
|
|
||||||
.from(Tables.accounts)
|
|
||||||
.where(Tables.accounts.uuid.eq(entry.getKey().toString())))
|
|
||||||
.set(Tables.gamePlayers.winner, entry.getValue());
|
|
||||||
|
|
||||||
queryList.add(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.batch(queryList).execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GamesRecord record = context.newRecord(Tables.games);
|
||||||
|
record.setDuration(duration);
|
||||||
|
record.setTournament(tournament);
|
||||||
|
record.setType(type.name());
|
||||||
|
record.setServer(serverName);
|
||||||
|
record.store();
|
||||||
|
|
||||||
|
List<Query> queryList = new ArrayList<>(players.size());
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, Boolean> entry : players.entrySet())
|
||||||
|
{
|
||||||
|
Query query = context
|
||||||
|
.insertInto(Tables.gamePlayers)
|
||||||
|
.set(Tables.gamePlayers.gameId, record.getId())
|
||||||
|
.set(Tables.gamePlayers.accountId, DSL.select(Tables.accounts.id)
|
||||||
|
.from(Tables.accounts)
|
||||||
|
.where(Tables.accounts.uuid.eq(entry.getKey().toString())))
|
||||||
|
.set(Tables.gamePlayers.winner, entry.getValue());
|
||||||
|
|
||||||
|
queryList.add(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.batch(queryList).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveLeaderboardStats(int tournamentId, int gameId, Map<UUID, Boolean> players) throws SQLException
|
public void saveLeaderboardStats(int tournamentId, int gameId, Map<UUID, Boolean> players)
|
||||||
{
|
{
|
||||||
try (Connection connection = getConnection())
|
DSLContext context;
|
||||||
|
|
||||||
|
synchronized (this)
|
||||||
{
|
{
|
||||||
DSLContext context = DSL.using(connection);
|
context = DSL.using(getConnection());
|
||||||
|
|
||||||
List<Query> queryList = new ArrayList<>(players.size());
|
|
||||||
|
|
||||||
for (Map.Entry<UUID, Boolean> entry : players.entrySet())
|
|
||||||
{
|
|
||||||
int winIncrement = entry.getValue() ? 1 : 0;
|
|
||||||
|
|
||||||
Query query = context
|
|
||||||
.insertInto(Tables.tournamentLeaderboard)
|
|
||||||
.set(Tables.tournamentLeaderboard.tournamentId, tournamentId)
|
|
||||||
.set(Tables.tournamentLeaderboard.gameId, gameId)
|
|
||||||
.set(Tables.tournamentLeaderboard.accountId, DSL.select(Tables.accounts.id)
|
|
||||||
.from(Tables.accounts)
|
|
||||||
.where(Tables.accounts.uuid.eq(entry.getKey().toString())))
|
|
||||||
.set(Tables.tournamentLeaderboard.wins, winIncrement)
|
|
||||||
.set(Tables.tournamentLeaderboard.total, 1)
|
|
||||||
.onDuplicateKeyUpdate()
|
|
||||||
.set(Tables.tournamentLeaderboard.wins, Tables.tournamentLeaderboard.wins.plus(winIncrement))
|
|
||||||
.set(Tables.tournamentLeaderboard.total, Tables.tournamentLeaderboard.total.plus(1));
|
|
||||||
|
|
||||||
queryList.add(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
context.batch(queryList).execute();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Query> queryList = new ArrayList<>(players.size());
|
||||||
|
|
||||||
|
for (Map.Entry<UUID, Boolean> entry : players.entrySet())
|
||||||
|
{
|
||||||
|
int winIncrement = entry.getValue() ? 1 : 0;
|
||||||
|
|
||||||
|
Query query = context
|
||||||
|
.insertInto(Tables.tournamentLeaderboard)
|
||||||
|
.set(Tables.tournamentLeaderboard.tournamentId, tournamentId)
|
||||||
|
.set(Tables.tournamentLeaderboard.gameId, gameId)
|
||||||
|
.set(Tables.tournamentLeaderboard.accountId, DSL.select(Tables.accounts.id)
|
||||||
|
.from(Tables.accounts)
|
||||||
|
.where(Tables.accounts.uuid.eq(entry.getKey().toString())))
|
||||||
|
.set(Tables.tournamentLeaderboard.wins, winIncrement)
|
||||||
|
.set(Tables.tournamentLeaderboard.total, 1)
|
||||||
|
.onDuplicateKeyUpdate()
|
||||||
|
.set(Tables.tournamentLeaderboard.wins, Tables.tournamentLeaderboard.wins.plus(winIncrement))
|
||||||
|
.set(Tables.tournamentLeaderboard.total, Tables.tournamentLeaderboard.total.plus(1));
|
||||||
|
|
||||||
|
queryList.add(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.batch(queryList).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,14 @@
|
|||||||
{
|
{
|
||||||
public class GemRewardToken
|
public class GemRewardToken
|
||||||
{
|
{
|
||||||
|
public int OriginalBalance;
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string Source { get; set; }
|
public string Source { get; set; }
|
||||||
|
|
||||||
public int Amount { get; set; }
|
public int Amount { get; set; }
|
||||||
|
|
||||||
|
public int Retries { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,5 +7,7 @@
|
|||||||
public string Rank { get; set; }
|
public string Rank { get; set; }
|
||||||
|
|
||||||
public bool Perm { get; set; }
|
public bool Perm { get; set; }
|
||||||
|
|
||||||
|
public int Retries { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
using LOC.Website.Common.Contexts;
|
using LOC.Website.Common.Contexts;
|
||||||
using System.Data.Entity.Infrastructure;
|
using System.Data.Entity.Infrastructure;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
public class AccountAdministrator : IAccountAdministrator
|
public class AccountAdministrator : IAccountAdministrator
|
||||||
{
|
{
|
||||||
@ -23,7 +24,7 @@
|
|||||||
private readonly IGameServerMonitor _gameServerMonitor;
|
private readonly IGameServerMonitor _gameServerMonitor;
|
||||||
private readonly ILogger _logger;
|
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)
|
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)
|
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);
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
account.LoadNavigationProperties(repository.Context);
|
|
||||||
account.LastLogin = DateTime.Now.Ticks;
|
|
||||||
|
|
||||||
// Expire punishments
|
|
||||||
if (account.Punishments != null)
|
|
||||||
{
|
{
|
||||||
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)
|
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();
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
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"))
|
|
||||||
{
|
{
|
||||||
var gemTransaction = new GemTransaction
|
var account = repository.Where<Account>(x => x.Name == token.Name).FirstOrDefault();
|
||||||
{
|
|
||||||
Source = token.Source,
|
|
||||||
Account = account,
|
|
||||||
Amount = token.Amount,
|
|
||||||
Date = (long)TimeUtil.GetCurrentMilliseconds()
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
return true;
|
||||||
@ -226,31 +248,35 @@
|
|||||||
|
|
||||||
public bool CoinReward(GemRewardToken token)
|
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();
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
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"))
|
|
||||||
{
|
{
|
||||||
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,
|
var coinTransaction = new CoinTransaction
|
||||||
Account = account,
|
{
|
||||||
Amount = token.Amount,
|
Source = token.Source,
|
||||||
Date = (long)TimeUtil.GetCurrentMilliseconds()
|
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;
|
return true;
|
||||||
@ -358,9 +384,9 @@
|
|||||||
|
|
||||||
public string PurchaseGameSalesPackage(PurchaseToken token)
|
public string PurchaseGameSalesPackage(PurchaseToken token)
|
||||||
{
|
{
|
||||||
lock (_transactionLock)
|
try
|
||||||
{
|
{
|
||||||
try
|
lock (getAccountLock(token.AccountName))
|
||||||
{
|
{
|
||||||
using (var repository = _repositoryFactory.CreateRepository())
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
{
|
{
|
||||||
@ -390,7 +416,7 @@
|
|||||||
repository.Edit(account);
|
repository.Edit(account);
|
||||||
|
|
||||||
if (account.PvpTransactions == null)
|
if (account.PvpTransactions == null)
|
||||||
account.PvpTransactions = new List<GameTransaction> {accountTransaction};
|
account.PvpTransactions = new List<GameTransaction> { accountTransaction };
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
account.PvpTransactions.Add(accountTransaction);
|
account.PvpTransactions.Add(accountTransaction);
|
||||||
@ -403,10 +429,10 @@
|
|||||||
return TransactionResponse.Success.ToString();
|
return TransactionResponse.Success.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
}
|
||||||
{
|
catch (Exception exception)
|
||||||
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
{
|
||||||
}
|
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,43 +446,46 @@
|
|||||||
|
|
||||||
public void SaveCustomBuild(CustomBuildToken token)
|
public void SaveCustomBuild(CustomBuildToken token)
|
||||||
{
|
{
|
||||||
using (var repository = _repositoryFactory.CreateRepository())
|
lock (getAccountLock(token.PlayerName))
|
||||||
{
|
{
|
||||||
var account =
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
customBuild = repository.Add(token.GetCustomBuild());
|
var account =
|
||||||
account.CustomBuilds.Add(customBuild);
|
repository.Where<Account>(x => x.Name == token.PlayerName).Include(x => x.CustomBuilds).First();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
token.UpdateCustomBuild(customBuild);
|
|
||||||
repository.Edit(customBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (customBuild.Active)
|
var customBuild =
|
||||||
{
|
account.CustomBuilds.FirstOrDefault(
|
||||||
foreach (
|
x => String.Equals(x.PvpClass, token.PvpClass) && x.CustomBuildNumber == token.CustomBuildNumber);
|
||||||
var otherClassBuild in
|
|
||||||
account.CustomBuilds.Where(
|
if (customBuild == null)
|
||||||
x =>
|
|
||||||
String.Equals(x.PvpClass, token.PvpClass) && x.CustomBuildNumber != customBuild.CustomBuildNumber)
|
|
||||||
.ToList())
|
|
||||||
{
|
{
|
||||||
otherClassBuild.Active = false;
|
customBuild = repository.Add(token.GetCustomBuild());
|
||||||
repository.Edit(otherClassBuild);
|
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)
|
public string PurchaseUnknownSalesPackage(UnknownPurchaseToken token)
|
||||||
{
|
{
|
||||||
lock (_transactionLock)
|
try
|
||||||
{
|
{
|
||||||
try
|
lock (getAccountLock(token.AccountName))
|
||||||
{
|
{
|
||||||
using (var repository = _repositoryFactory.CreateRepository())
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
{
|
{
|
||||||
@ -532,16 +561,17 @@
|
|||||||
return TransactionResponse.Success.ToString();
|
return TransactionResponse.Success.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
}
|
||||||
{
|
catch (Exception exception)
|
||||||
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
{
|
||||||
}
|
return TransactionResponse.Failed.ToString() + ":" + exception.Message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string UpdateRank(RankUpdateToken token)
|
public string UpdateRank(RankUpdateToken token)
|
||||||
{
|
{
|
||||||
Rank rank = null;
|
Rank rank = null;
|
||||||
|
var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -559,8 +589,6 @@
|
|||||||
if (rank == null)
|
if (rank == null)
|
||||||
return account.Rank.ToString();
|
return account.Rank.ToString();
|
||||||
|
|
||||||
var expire = DateTime.Now.AddMonths(1).AddMilliseconds(-DateTime.Now.Millisecond);
|
|
||||||
|
|
||||||
account.Rank = rank;
|
account.Rank = rank;
|
||||||
account.RankExpire = expire;
|
account.RankExpire = expire;
|
||||||
account.RankPerm = token.Perm;
|
account.RankPerm = token.Perm;
|
||||||
@ -574,7 +602,14 @@
|
|||||||
using (var repository = _repositoryFactory.CreateRepository())
|
using (var repository = _repositoryFactory.CreateRepository())
|
||||||
{
|
{
|
||||||
var account = repository.Where<Account>(x => String.Equals(x.Name, token.Name)).Include(x => x.Rank).FirstOrDefault();
|
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)
|
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