Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
Cheese 2015-03-13 15:40:41 +11:00
commit 98960b6ce7
37 changed files with 789 additions and 1673 deletions

Binary file not shown.

View File

@ -37,7 +37,7 @@ public class LobbyBalancer implements Listener, Runnable
loadLobbyServers();
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
_plugin.getProxy().getScheduler().schedule(_plugin, this, 150L, 150L, TimeUnit.MILLISECONDS);
_plugin.getProxy().getScheduler().schedule(_plugin, this, 250L, 250L, TimeUnit.MILLISECONDS);
}
@EventHandler

View File

@ -28,6 +28,8 @@ public class PlayerStats implements Listener
public void run()
{
_repository.addPlayer(event.getPlayer().getName());
_repository.addPlayerVersion(event.getPlayer().getName(), event.getPlayer().getPendingConnection().getVersion());
_repository.addPlayerIP(event.getPlayer().getName(), event.getPlayer().getPendingConnection().getAddress().getAddress().getHostAddress());
}
});
}

View File

@ -1,5 +1,6 @@
package mineplex.bungee.playerStats;
import java.net.InetAddress;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@ -16,8 +17,12 @@ public class PlayerStatsRepository
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS DailyUnique (id INT NOT NULL AUTO_INCREMENT, day VARCHAR(100), playerName VARCHAR(20), PRIMARY KEY (id), UNIQUE KEY unique_player_per_day (day, playerName));";
private static String INSERT_PLAYER = "INSERT INTO DailyUnique (day, playerName) values(curdate(), ?) ON DUPLICATE KEY UPDATE playerName=playerName;";
private static String CREATE_VER_TABLE = "CREATE TABLE IF NOT EXISTS PlayerVersion (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), version VARCHAR(40), PRIMARY KEY (id), UNIQUE KEY unique_player (playerName));";
private static String INSERT_VER_PLAYER = "INSERT INTO PlayerVersion (playerName, version) values(?, ?) ON DUPLICATE KEY UPDATE version=version;";
private static String CREATE_VER_TABLE = "CREATE TABLE IF NOT EXISTS PlayerVersion (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), version INT, PRIMARY KEY (id), UNIQUE KEY unique_player (playerName));";
private static String INSERT_VER_PLAYER = "INSERT INTO PlayerVersion (playerName, version) values(?, ?);";
private static String UPDATE_VER_PLAYER = "UPDATE PlayerVersion SET version = ? WHERE playerName = ?;";
private static String CREATE_IP_TABLE = "CREATE TABLE IF NOT EXISTS PlayerIP (id INT NOT NULL AUTO_INCREMENT, playerName VARCHAR(20), ip VARCHAR(20), PRIMARY KEY (id), UNIQUE INDEX unique_player_ip (playerName, ip));";
private static String INSERT_IP_PLAYER = "INSERT IGNORE INTO PlayerIP (playerName, ip) values(?, ?);";
public void initialize()
{
@ -36,6 +41,11 @@ public class PlayerStatsRepository
preparedStatement = _connection.prepareStatement(CREATE_VER_TABLE);
preparedStatement.execute();
preparedStatement.close();
preparedStatement = _connection.prepareStatement(CREATE_IP_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
@ -103,7 +113,7 @@ public class PlayerStatsRepository
}
}
public boolean addPlayerVersion(String playerName, String version)
public void addPlayerVersion(String playerName, int version)
{
PreparedStatement preparedStatement = null;
@ -112,34 +122,63 @@ public class PlayerStatsRepository
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_VER_PLAYER, Statement.RETURN_GENERATED_KEYS);
preparedStatement = _connection.prepareStatement(UPDATE_VER_PLAYER);
preparedStatement.setString(1, playerName);
preparedStatement.setString(2, version);
preparedStatement.setInt(1, version);
preparedStatement.setString(2, playerName);
int affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Adding player version record failed, no rows affected.");
}
preparedStatement.close();
preparedStatement = _connection.prepareStatement(INSERT_VER_PLAYER, Statement.RETURN_GENERATED_KEYS);
return true;
preparedStatement.setString(1, playerName);
preparedStatement.setInt(2, version);
preparedStatement.executeUpdate();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
Thread.sleep(10);
preparedStatement.close();
}
catch (InterruptedException e)
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
return addPlayer(playerName);
public void addPlayerIP(String playerName, String address)
{
PreparedStatement preparedStatement = null;
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_IP_PLAYER, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, playerName);
preparedStatement.setString(2, address);
preparedStatement.executeUpdate();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{

View File

@ -119,13 +119,7 @@ public class BungeeRotator
for (String address : usServers)
{
recordsToAdd.add(new ARecord("us", address, 300));
log("Addding server address in DNS : " + "us " + address);
}
for (String address : euServers)
{
recordsToAdd.add(new ARecord("eu", address, 300));
log("Addding server address in DNS : " + "eu " + address);
log("Adding server address in DNS : " + "us " + address);
}
if (recordsToAdd.size() > 0)
@ -134,6 +128,22 @@ public class BungeeRotator
log("Created " + recordsToAdd.size() + " records.");
}
recordsToAdd.clear();
for (String address : euServers)
{
recordsToAdd.add(new ARecord("eu", address, 300));
log("Adding server address in DNS : " + "eu " + address);
}
if (recordsToAdd.size() > 0)
{
new ApiPostCall("https://api.dnsmadeeasy.com/V2.0/dns/managed/", 962728, "/records/", "createMulti").Execute(recordsToAdd);
log("Created " + recordsToAdd.size() + " records.");
}
recordsToAdd.clear();
if (recordsToDelete.size() > 0)
{
StringBuilder idBuilder = new StringBuilder();

View File

@ -51,13 +51,13 @@ public abstract class DnsMadeEasyApiCallBase
try
{
String timeStamp = getServerTime();
SecretKeySpec keySpec = new SecretKeySpec("8c9af8cc-d306-4df3-8de8-944deafa8239".getBytes(), "HmacSHA1");
SecretKeySpec keySpec = new SecretKeySpec("35bb3b97-3815-4b63-b60b-eb1882c07b40".getBytes(), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(keySpec);
byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes());
Hex.encodeHexString(hashBytes);
request.addHeader("x-dnsme-apiKey", "610e21ee-4250-4b55-b637-a1fcc3847850");
request.addHeader("x-dnsme-apiKey", "a9750980-b7df-4a7e-a047-2ade43628f0d");
request.addHeader("x-dnsme-requestDate", timeStamp + "");
request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes));
request.addHeader("Content-Type", "application/json");

View File

@ -6,6 +6,6 @@ public class DnsRecord
public String name;
public String type;
public String value;
public String gtdLocation;
public String gtdLocation = "DEFAULT";
public int ttl;
}

View File

@ -1,5 +1,6 @@
package mineplex.core.account.repository;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@ -19,6 +20,7 @@ import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
@ -43,34 +45,9 @@ public class AccountRepository extends RepositoryBase
public AccountRepository(JavaPlugin plugin, String webAddress)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
_webAddress = webAddress;
Statement statement = null;
try
{
statement = getConnection().createStatement();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (statement != null)
{
try
{
statement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
@Override
@ -81,13 +58,11 @@ public class AccountRepository extends RepositoryBase
public void login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
{
Statement statement = null;
ResultSet resultSet = null;
try
try (
Connection connection = getConnection();
Statement statement = connection.createStatement()
)
{
statement = getConnection().createStatement();
/*
boolean statementStatus = statement.execute(
"UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';"
@ -152,32 +127,6 @@ public class AccountRepository extends RepositoryBase
{
exception.printStackTrace();
}
finally
{
if (statement != null)
{
try
{
statement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public String GetClient(String name, UUID uuid, String ipAddress)

View File

@ -3,6 +3,7 @@ package mineplex.core.benefit;
import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnVarChar;
@ -16,7 +17,7 @@ public class BenefitManagerRepository extends RepositoryBase
public BenefitManagerRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override

View File

@ -16,6 +16,7 @@ public final class DBPool
{
BasicDataSource source = new BasicDataSource();
source.addConnectionProperty("autoReconnect", "true");
source.addConnectionProperty("allowMultiQueries", "true");
source.setDefaultAutoCommit(true);
source.setEnableAutoCommitOnReturn(true);
source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
@ -23,8 +24,8 @@ public final class DBPool
source.setUrl(url);
source.setUsername(username);
source.setPassword(password);
source.setMaxTotal(2);
source.setMaxIdle(2);
source.setMaxTotal(3);
source.setMaxIdle(3);
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);

View File

@ -1,7 +1,6 @@
package mineplex.core.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -22,59 +21,30 @@ import org.bukkit.plugin.java.JavaPlugin;
public abstract class RepositoryBase implements Listener
{
protected static Object _connectionLock = new Object();
private Connection _connection = null;
// Queue for failed processes
private static Object _queueLock = new Object();
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
private String _connectionString;
private String _userName;
private String _password;
protected JavaPlugin Plugin;
protected DataSource DataSource;
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
{
Plugin = plugin;
_connectionString = connectionString;
_userName = username;
_password = password;
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
public void run()
{
synchronized (_connectionLock)
{
initialize();
update();
}
}
});
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
private DataSource _dataSource; // Connection pool
protected JavaPlugin Plugin; // Plugin responsible for this repository
/**
* Constructor
* @param plugin - the {@link JavaPlugin} module responsible for this repository.
* @param dataSource - the {@link DataSource} responsible for providing the connection pool to this repository.
*/
public RepositoryBase(JavaPlugin plugin, DataSource dataSource)
{
Plugin = plugin;
DataSource = dataSource;
_dataSource = dataSource;
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
public void run()
{
synchronized (_connectionLock)
{
initialize();
update();
}
}
});
plugin.getServer().getPluginManager().registerEvents(this, plugin);
@ -84,34 +54,39 @@ public abstract class RepositoryBase implements Listener
protected abstract void update();
protected Connection getConnection()
/**
* @return the {@link DataSource} used by the repository for connection pooling.
*/
protected DataSource getConnectionPool()
{
return getConnection(false);
return _dataSource;
}
protected Connection getConnection(boolean validate)
{
synchronized (_connectionLock)
/**
* Requirements: {@link Connection}s must be closed after usage so they may be returned to the pool!
* @see Connection#close()
* @return a newly fetched {@link Connection} from the connection pool, if a connection can be made, null otherwise.
*/
protected Connection getConnection()
{
try
{
if (_connection == null || (validate && !_connection.isValid(2)))
{
if (DataSource != null)
_connection = DataSource.getConnection();
else
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
return _dataSource.getConnection();
}
catch (SQLException e)
{
e.printStackTrace();
// TODO: Log connection failures?
return null;
}
}
return _connection;
}
/**
* Execute a query against the repository.
* @param query - the concatenated query to execute in string form.
* @param columns - the column data values used for insertion into the query.
* @return the number of rows affected by this query in the repository.
*/
protected int executeUpdate(String query, Column<?>...columns)
{
return executeInsert(query, null, columns);
@ -119,16 +94,14 @@ public abstract class RepositoryBase implements Listener
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
{
PreparedStatement preparedStatement = null;
int affectedRows = 0;
try
// Automatic resource management for handling/closing objects.
try (
Connection connection = getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)
)
{
getConnection(false);
preparedStatement = _connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
for (int i=0; i < columns.length; i++)
{
columns[i].setValue(preparedStatement, i+1);
@ -137,49 +110,24 @@ public abstract class RepositoryBase implements Listener
affectedRows = preparedStatement.executeUpdate();
if (callable != null)
{
callable.processResultSet(preparedStatement.getGeneratedKeys());
}
}
catch (SQLException exception)
{
getConnection(true);
executeInsert(query, callable, columns);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
try
{
if (DataSource != null)
_connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
return affectedRows;
}
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
{
ResultSet resultSet = null;
try
{
for (int i=0; i < columns.length; i++)
@ -187,116 +135,39 @@ public abstract class RepositoryBase implements Listener
columns[i].setValue(statement, i+1);
}
resultSet = statement.executeQuery();
try (ResultSet resultSet = statement.executeQuery())
{
callable.processResultSet(resultSet);
}
}
catch (SQLException exception)
{
getConnection(true);
executeQuery(statement, callable, columns);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
try
{
if (DataSource != null)
_connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
{
PreparedStatement preparedStatement = null;
try
// Automatic resource management for handling/closing objects.
try (
Connection connection = getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(query)
)
{
getConnection(false);
preparedStatement = _connection.prepareStatement(query);
executeQuery(preparedStatement, callable, columns);
}
catch (SQLException exception)
{
getConnection(true);
executeQuery(query, callable, columns);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
try
{
if (DataSource != null)
_connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>...columns)
{
int affectedRows = 0;
try
{
for (int i=0; i < columns.length; i++)
{
columns[i].setValue(preparedStatement, i+1);
}
affectedRows = preparedStatement.executeUpdate();
}
catch (SQLException exception)
{
getConnection(true);
executeUpdate(preparedStatement, columns);
}
catch (Exception exception)
{
exception.printStackTrace();
}
return affectedRows;
}
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
@ -341,24 +212,6 @@ public abstract class RepositoryBase implements Listener
processFailedQueue();
}
@EventHandler
public void validateConnection(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_02 || DataSource != null)
return;
Bukkit.getScheduler().runTaskAsynchronously(Plugin, new Runnable()
{
public void run()
{
synchronized (_connectionLock)
{
getConnection(true);
}
}
});
}
private void processFailedQueue()
{
synchronized (_queueLock)

View File

@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
@ -33,7 +34,7 @@ public class DonationRepository extends RepositoryBase
public DonationRepository(JavaPlugin plugin, String webAddress)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
_webAddress = webAddress;
}

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
@ -31,7 +32,7 @@ public class InventoryRepository extends RepositoryBase
public InventoryRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override

View File

@ -5,6 +5,7 @@ import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.spawn.command.SpawnCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -58,9 +59,17 @@ public class LeaderboardManager extends MiniPlugin
* @param value - the counter value used to increment the statistic
* @return true, if the stat event was successfully triggered and logged, false otherwise.
*/
public boolean onStatEvent(Player player, StatType type, int gamemode, int value)
public boolean onStatEvent(final Player player, final StatType type, final int gamemode, final int value)
{
// Asynchronously make DB call to insert stat event.
Bukkit.getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
_statEvents.insertStatEvent(player.getName(), gamemode, _serverGroup, type.getTypeId(), value);
}
});
return true;
}

View File

@ -1,5 +1,6 @@
package mineplex.core.leaderboard;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
@ -35,7 +36,7 @@ public class StatEventsRepository extends RepositoryBase
*/
public StatEventsRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override

View File

@ -66,9 +66,9 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
ServerCommandManager.getInstance().registerCommandType("AnnouncementCommand", AnnouncementCommand.class,
new AnnouncementHandler());
//ServerCommandManager.getInstance().registerCommandType("RedisMessage", RedisMessage.class, messageHandler);
//ServerCommandManager.getInstance()
// .registerCommandType("RedisMessageCallback", RedisMessageCallback.class, messageHandler);
ServerCommandManager.getInstance().registerCommandType("RedisMessage", RedisMessage.class, messageHandler);
ServerCommandManager.getInstance()
.registerCommandType("RedisMessageCallback", RedisMessageCallback.class, messageHandler);
}
public void addCommands()
@ -113,7 +113,6 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
public String canReceiverMessageThem(String sender, Player target)
{
// If the receiver has turned off private messaging and the sender isn't a mod
if (!_preferences.Get(target).PrivateMessaging)
{
@ -311,7 +310,6 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
public void receiveMessage(Player to, RedisMessage globalMessage)
{
if (globalMessage.isStaffMessage())
{
// Message the receiver

View File

@ -40,8 +40,8 @@ public class PartyManager extends MiniPlugin
_preferenceManager = preferenceManager;
_serverName = getPlugin().getConfig().getString("serverstatus.name");
//ServerCommandManager.getInstance().registerCommandType("RedisPartyData", RedisPartyData.class,
// new RedisPartyHandler(this));
ServerCommandManager.getInstance().registerCommandType("RedisPartyData", RedisPartyData.class,
new RedisPartyHandler(this));
}
@Override

View File

@ -17,9 +17,14 @@ public class RedisPartyHandler implements CommandCallback
@Override
public void run(ServerCommand command)
{
RedisPartyData data = (RedisPartyData) command;
final RedisPartyData data = (RedisPartyData) command;
_partyManager.getPlugin().getServer().getScheduler().runTask(_partyManager.getPlugin(), new Runnable()
{
public void run()
{
_partyManager.addParty(new Party(_partyManager, data));
}
});
}
}

View File

@ -42,49 +42,11 @@ public class PetFactory
_pets.put(EntityType.OCELOT, new Pet("Cat", EntityType.OCELOT, 6000));
_pets.put(EntityType.MUSHROOM_COW, new Pet("Mooshroom", EntityType.MUSHROOM_COW, 5000));
_pets.put(EntityType.WITHER, new Pet("Widder", EntityType.WITHER, -1));
List<PetSalesToken> petTokens = new ArrayList<PetSalesToken>();
for (Pet pet : _pets.values())
{
PetSalesToken petToken = new PetSalesToken();
petToken.Name = pet.GetPetName();
petToken.PetType = pet.GetPetType().toString();
petTokens.add(petToken);
}
for (PetSalesToken petToken : _repository.GetPets(petTokens))
{
if (_pets.containsKey(EntityType.valueOf(petToken.PetType)))
{
_pets.get(EntityType.valueOf(petToken.PetType)).Update(petToken);
}
}
}
private void CreatePetExtras()
{
_petExtras.put(Material.SIGN, new PetExtra("Name Tag", Material.NAME_TAG, 100));
List<PetExtraToken> petExtraTokens = new ArrayList<PetExtraToken>();
for (PetExtra petExtra : _petExtras.values())
{
PetExtraToken petToken = new PetExtraToken();
petToken.Name = petExtra.GetName();
petToken.Material = petExtra.GetMaterial().toString();
petExtraTokens.add(petToken);
}
for (PetExtraToken token : _repository.GetPetExtras(petExtraTokens))
{
if (_petExtras.containsKey(Material.valueOf(token.Material)))
{
_petExtras.get(Material.valueOf(token.Material)).Update(token);
}
}
}
public Collection<Pet> GetPets()

View File

@ -1,5 +1,6 @@
package mineplex.core.preferences;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -14,7 +15,7 @@ import mineplex.core.database.column.ColumnVarChar;
public class PreferencesRepository extends RepositoryBase
{
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));";
//private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));";
private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ? WHERE uuid=?;";
@ -36,12 +37,12 @@ public class PreferencesRepository extends RepositoryBase
public void saveUserPreferences(NautHashMap<String, UserPreferences> preferences)
{
PreparedStatement preparedStatement = null;
try
(
Connection connection = getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
)
{
preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
for (Entry<String, UserPreferences> entry : preferences.entrySet())
{
preparedStatement.setBoolean(1, entry.getValue().HubGames);
@ -93,20 +94,6 @@ public class PreferencesRepository extends RepositoryBase
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException

View File

@ -7,6 +7,7 @@ import java.util.UUID;
import java.util.Map.Entry;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
@ -40,7 +41,7 @@ This will be used to determine if staff are handling
public ReportRepository(JavaPlugin plugin, String connectionString)
{
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh"); // TODO: Config file for host/pass?
super(plugin, DBPool.ACCOUNT);
}
@Override

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
@ -22,8 +23,7 @@ public class SpawnRepository extends RepositoryBase
public SpawnRepository(JavaPlugin plugin, String serverName)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
_serverName = serverName;
}

View File

@ -9,6 +9,7 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
@ -18,6 +19,7 @@ import org.jooq.DSLContext;
import org.jooq.Insert;
import org.jooq.Record2;
import org.jooq.Result;
import org.jooq.SQLDialect;
import org.jooq.Update;
import org.jooq.impl.DSL;
@ -31,7 +33,7 @@ public class StatsRepository extends RepositoryBase
public StatsRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override
@ -79,8 +81,7 @@ public class StatsRepository extends RepositoryBase
{
try
{
DSLContext context = DSL.using(getConnection(true));
DSLContext context = DSL.using(getConnectionPool(), SQLDialect.MYSQL);
List<Update> updates = new ArrayList<>();
List<Insert> inserts = new ArrayList<>();
@ -133,7 +134,7 @@ public class StatsRepository extends RepositoryBase
synchronized (this)
{
context = DSL.using(getConnection());
context = DSL.using(getConnectionPool(), SQLDialect.MYSQL);
}
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)

View File

@ -26,7 +26,7 @@ import mineplex.serverdata.transfers.SuicideCommand;
public class ServerStatusManager extends MiniPlugin
{
// The default timeout (in seconds) before the ServerStatus expires.
public final int DEFAULT_SERVER_TIMEOUT = 15;
public final int DEFAULT_SERVER_TIMEOUT = 30;
private ServerRepository _repository;
private CoreClientManager _clientManager;

View File

@ -2,6 +2,7 @@ package mineplex.enjinTranslator;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
@ -12,7 +13,7 @@ public class TempRepository extends RepositoryBase
public TempRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
public void addGemBooster(String name, int amount)

View File

@ -9,6 +9,7 @@ import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnBoolean;
@ -59,7 +60,7 @@ public class ClanRepository extends RepositoryBase
public ClanRepository(JavaPlugin plugin, String serverName)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
_serverName = serverName;
}

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnByte;
@ -31,7 +32,7 @@ public class FieldRepository extends RepositoryBase
public FieldRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
public List<FieldBlockToken> getFieldBlocks(String server)

View File

@ -6,9 +6,11 @@ import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.database.Tables;
import mineplex.database.tables.records.MailRecord;
import org.jooq.DSLContext;
import org.jooq.Result;
import org.jooq.impl.DSL;
@ -19,7 +21,7 @@ public class MailRepository extends RepositoryBase
public MailRepository(JavaPlugin plugin, MailManager manager)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
_manager = manager;
}

View File

@ -57,7 +57,7 @@ public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop> implements
slot = Integer.parseInt(serverInfo.Name.split("-")[1]) - 1;
if (slot >= 54)
break;
continue;
if (serverInfo.Name.equalsIgnoreCase(getPlugin().getStatusManager().getCurrentServerName()))
status = Material.EMERALD_BLOCK;
@ -81,6 +81,12 @@ public class LobbyMenu extends ShopPageBase<ServerManager, LobbyShop> implements
else
addItem(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Integer.parseInt(serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1)), false));
}
while (slot < 54)
{
clear(slot);
slot++;
}
}
public void Update()

View File

@ -51,6 +51,12 @@ public class RedisServerRepository implements ServerRepository
@Override
public Collection<MinecraftServer> getServerStatuses()
{
return getServerStatusesByPrefix("");
}
@Override
public Collection<MinecraftServer> getServerStatusesByPrefix(String prefix)
{
Collection<MinecraftServer> servers = new HashSet<MinecraftServer>();
Jedis jedis = _readPool.getResource();
@ -62,10 +68,13 @@ public class RedisServerRepository implements ServerRepository
List<Response<String>> responses = new ArrayList<Response<String>>();
for (String serverName : getActiveNames(setKey))
{
if (prefix.isEmpty() || serverName.startsWith(prefix))
{
String dataKey = concatenate(setKey, serverName);
responses.add(pipeline.get(dataKey));
}
}
pipeline.sync();

View File

@ -28,8 +28,9 @@ public class ServerCommandManager
*/
private ServerCommandManager()
{
_writePool = Utility.generatePool(ServerManager.getPubSubConnection()); // Hardcoded connection to standalone redis instance
_readPool = _writePool;
_writePool = Utility.generatePool(ServerManager.getMasterConnection()); // Publish to master instance
_readPool = Utility.generatePool(ServerManager.getSlaveConnection()); // Read from slave instance
_commandTypes = new HashMap<String, CommandType>();
initialize();

View File

@ -11,8 +11,12 @@ import java.util.Random;
*/
public class ServerManager
{
// Connection host to server database
private static final String DATABASE_HOST = "10.33.53.16";
// Ports associated with slave redis instances
private static final int[] SLAVE_PORTS = {6378, 6380, 6381};
private static final int[] SLAVE_PORTS = {6377, 6378, 6380, 6381, 6382};
private static Random random = new Random();
// The cached repository instances
@ -49,7 +53,7 @@ public class ServerManager
*/
public static ConnectionData getMasterConnection()
{
return new ConnectionData("10.33.53.16", 6379);
return new ConnectionData(DATABASE_HOST, 6379);
}
/**
@ -59,14 +63,6 @@ public class ServerManager
public static ConnectionData getSlaveConnection()
{
int port = SLAVE_PORTS[random.nextInt(SLAVE_PORTS.length)];
return new ConnectionData("10.33.53.16", port);
}
/**
* @return the {@link ConnectionData} associated with the dedicated PubSub instance.
*/
public static ConnectionData getPubSubConnection()
{
return new ConnectionData("10.33.53.16", 6377);
return new ConnectionData(DATABASE_HOST, port);
}
}

View File

@ -18,6 +18,8 @@ public interface ServerRepository
*/
public Collection<MinecraftServer> getServerStatuses();
public Collection<MinecraftServer> getServerStatusesByPrefix(String prefix);
public Collection<MinecraftServer> getServersByGroup(String serverGroup);
/**

View File

@ -1,5 +1,7 @@
package mineplex.staffServer;
import java.util.UUID;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.chat.Chat;
@ -75,52 +77,10 @@ public class StaffServer extends JavaPlugin
((CraftServer)getServer()).setWhitelist(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
((CraftServer)getServer()).getHandle().addWhitelist(new ProfileLoader(UUIDFetcher.getUUIDOf("NDrew").toString(), "NDrew").loadProfile());
}
}, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
((CraftServer)getServer()).getHandle().addWhitelist(new ProfileLoader(UUIDFetcher.getUUIDOf("Morena").toString(), "Morena").loadProfile());
}
}, 40L);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
((CraftServer)getServer()).getHandle().addWhitelist(new ProfileLoader(UUIDFetcher.getUUIDOf("Revolark").toString(), "Revolark").loadProfile());
}
}, 60L);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
((CraftServer)getServer()).getHandle().addWhitelist(new ProfileLoader(UUIDFetcher.getUUIDOf("EvilEsther").toString(), "EvilEsther").loadProfile());
}
}, 80L);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
((CraftServer)getServer()).getHandle().addWhitelist(new ProfileLoader(UUIDFetcher.getUUIDOf("Timmy48081_").toString(), "Timmy48081_").loadProfile());
}
}, 100L);
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
((CraftServer)getServer()).getHandle().addWhitelist(new ProfileLoader(UUIDFetcher.getUUIDOf("issh").toString(), "issh").loadProfile());
}
}, 120L);
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("377bdea3-badc-448d-81c1-65db43b17ea4"), "Strutt20"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("cf1b629c-cc55-4eb4-be9e-3ca86dfc7b9d"), "mannalou"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("04a484d0-93e0-4777-a70c-808046917e3a"), "EvilEsther"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("adaa7613-6683-400f-baf8-7272c04b2cb4"), "Timmy48081_"));
((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("2d5fd31b-0aa5-41db-a62d-a4611a24349a"), "ishh"));
}
}

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
@ -23,8 +24,7 @@ public class PasswordRepository extends RepositoryBase
public PasswordRepository(JavaPlugin plugin, String serverName)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
_serverName = serverName;
}