diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java index 5227ab818..f46641165 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerStats/PlayerStatsRepository.java @@ -10,14 +10,13 @@ import java.util.UUID; import mineplex.bungee.playerStats.data.IpInfo; import mineplex.cache.player.PlayerInfo; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; -public class PlayerStatsRepository +import javax.sql.DataSource; + +public class PlayerStatsRepository extends RepositoryBase { - private Connection _connection = null; - private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true"; - private String _userName = "root"; - private String _password = "tAbechAk3wR7tuTh"; - private static String INSERT_PLAYERINFO = "INSERT INTO playerInfo (uuid, name, version) VALUES (?, ?, ?);"; private static String SELECT_PLAYERINFO = "SELECT id, name, version FROM playerInfo WHERE uuid = ?;"; private static String UPDATE_PLAYERINFO = "UPDATE playerInfo SET name = ?, version = ? WHERE id = ?;"; @@ -30,34 +29,33 @@ public class PlayerStatsRepository + "INSERT IGNORE INTO playerLoginSessions (playerInfoId, loginTime) values(?, now());"; private static String UPDATE_LOGINSESSION = "UPDATE playerLoginSessions SET timeInGame = TIME_TO_SEC(TIMEDIFF(now(), loginTime)) / 60 WHERE id = ?;"; - + + public PlayerStatsRepository() + { + super(DBPool.getStats()); + } + + @Override public void initialize() { - try - { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - - System.out.println("Initialized PlayerStats."); + } - + + @Override + protected void update() + { + + } + public PlayerInfo getPlayer(UUID uuid, String name, int version) { PlayerInfo playerInfo = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(SELECT_PLAYERINFO); + preparedStatement = connection.prepareStatement(SELECT_PLAYERINFO); preparedStatement.setString(1, uuid.toString()); @@ -73,7 +71,7 @@ public class PlayerStatsRepository if (playerInfo == null) { - preparedStatement = _connection.prepareStatement(INSERT_PLAYERINFO, Statement.RETURN_GENERATED_KEYS); + preparedStatement = connection.prepareStatement(INSERT_PLAYERINFO, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, uuid.toString()); preparedStatement.setString(2, name); preparedStatement.setInt(3, version); @@ -96,7 +94,7 @@ public class PlayerStatsRepository } else if (!playerInfo.getName().equalsIgnoreCase(name) || playerInfo.getVersion() != version) { - preparedStatement = _connection.prepareStatement(UPDATE_PLAYERINFO); + preparedStatement = connection.prepareStatement(UPDATE_PLAYERINFO); preparedStatement.setString(1, name); preparedStatement.setInt(2, version); preparedStatement.setInt(3, playerInfo.getId()); @@ -145,12 +143,9 @@ public class PlayerStatsRepository PreparedStatement preparedStatement = null; ResultSet resultSet = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(SELECT_IPINFO); + preparedStatement = connection.prepareStatement(SELECT_IPINFO); preparedStatement.setString(1, ipAddress); resultSet = preparedStatement.executeQuery(); @@ -167,7 +162,7 @@ public class PlayerStatsRepository if (ipInfo == null) { - preparedStatement = _connection.prepareStatement(INSERT_IPINFO, Statement.RETURN_GENERATED_KEYS); + preparedStatement = connection.prepareStatement(INSERT_IPINFO, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, ipAddress); preparedStatement.executeUpdate(); @@ -228,12 +223,9 @@ public class PlayerStatsRepository Statement statement = null; ResultSet resultSet= null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - statement = _connection.createStatement(); + statement = connection.createStatement(); String queryString = UPDATE_PLAYERSTATS; queryString = queryString.replaceFirst("\\?", playerId + ""); @@ -286,12 +278,9 @@ public class PlayerStatsRepository { PreparedStatement preparedStatement = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(UPDATE_LOGINSESSION); + preparedStatement = connection.prepareStatement(UPDATE_LOGINSESSION); preparedStatement.setInt(1, loginSessionId); preparedStatement.executeUpdate(); diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java index f5b298ae9..c664fedb7 100644 --- a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/PlayerStatsRepository.java @@ -1,50 +1,43 @@ package mineplex.bungee; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; + +import java.sql.*; import java.util.ArrayList; import java.util.List; -public class PlayerStatsRepository +public class PlayerStatsRepository extends RepositoryBase { - private Connection _connection = null; - private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true"; - private String _userName = "root"; - private String _password = "tAbechAk3wR7tuTh"; - private static String SELECT_IPINFO = "SELECT id, ipAddress FROM ipInfo WHERE regionName IS NULL LIMIT 1000;"; private static String UPDATE_IPINFO = "UPDATE ipInfo SET countryCode = ?, countryName = ?, regionCode = ?, regionName = ?, city = ?, zipCode = ?, timeZone = ?, latitude = ?, longitude = ?, metroCode = ? WHERE id = ?;"; - - public void initialize() + + public PlayerStatsRepository() { - try - { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - catch (Exception exception) - { - exception.printStackTrace(); - } - - System.out.println("Initialized PlayerStats."); + super(DBPool.getStats()); } - + + @Override + protected void initialize() + { + + } + + @Override + protected void update() + { + + } + public List getIpAddresses() { List ipinfos = new ArrayList(1000); PreparedStatement preparedStatement = null; ResultSet resultSet = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(SELECT_IPINFO); + preparedStatement = connection.prepareStatement(SELECT_IPINFO); resultSet = preparedStatement.executeQuery(); @@ -98,12 +91,9 @@ public class PlayerStatsRepository { PreparedStatement preparedStatement = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(UPDATE_IPINFO); + preparedStatement = connection.prepareStatement(UPDATE_IPINFO); for (IpInfo ipInfo : ips) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 658c984ed..746b3cf6b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -10,6 +10,7 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; +import mineplex.core.database.MinecraftRepository; import org.bukkit.Bukkit; import com.google.gson.reflect.TypeToken; import org.bukkit.plugin.java.JavaPlugin; @@ -21,16 +22,16 @@ import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; import mineplex.core.common.util.NautHashMap; -import mineplex.core.database.DBPool; -import mineplex.core.database.DatabaseRunnable; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.ResultSetCallable; -import mineplex.core.database.column.ColumnBoolean; -import mineplex.core.database.column.ColumnTimestamp; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.DatabaseRunnable; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnBoolean; +import mineplex.serverdata.database.column.ColumnTimestamp; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.core.server.remotecall.JsonWebCall; -public class AccountRepository extends RepositoryBase +public class AccountRepository extends MinecraftRepository { private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));"; private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now());"; @@ -234,7 +235,7 @@ public class AccountRepository extends RepositoryBase executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString())); } - Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() { @Override public void run() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java index 23a0694b0..d80308172 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/AntiHackRepository.java @@ -4,7 +4,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -import mineplex.core.database.DBPool; +import mineplex.serverdata.database.DBPool; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java index eb5628130..60af1605a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManagerRepository.java @@ -3,14 +3,15 @@ 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.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.plugin.java.JavaPlugin; -public class BenefitManagerRepository extends RepositoryBase +public class BenefitManagerRepository extends MinecraftRepository { private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, accountId INT, benefit VARCHAR(100), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index d2ec49e6e..1dd545c93 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -27,7 +27,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; -import mineplex.core.database.DBPool; +import mineplex.serverdata.database.DBPool; import mineplex.core.donation.DonationManager; import mineplex.core.donation.GiveDonorData; import mineplex.core.facebook.FacebookManager; @@ -67,7 +67,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java index 2ce772e8c..a00e6373e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java @@ -10,9 +10,10 @@ import java.sql.Types; import mineplex.core.common.Pair; import mineplex.core.common.util.Callback; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; import mineplex.core.donation.DonationManager; import mineplex.core.recharge.Recharge; import mineplex.database.Tables; @@ -28,7 +29,7 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -public class BonusRepository extends RepositoryBase +public class BonusRepository extends MinecraftRepository { private static String CREATE_BONUS_TABLE = "CREATE TABLE IF NOT EXISTS bonus (accountId INT NOT NULL AUTO_INCREMENT, dailytime TIMESTAMP NULL DEFAULT NULL, ranktime DATE NULL DEFAULT NULL, PRIMARY KEY (accountId), FOREIGN KEY (accountId) REFERENCES accounts(id));"; private BonusManager _manager; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/botspam/repository/BotSpamRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/botspam/repository/BotSpamRepository.java index 3af3d0d4f..30d8f0c62 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/botspam/repository/BotSpamRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/botspam/repository/BotSpamRepository.java @@ -4,16 +4,17 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; import mineplex.core.botspam.SpamText; -import mineplex.core.database.ResultSetCallable; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; -public class BotSpamRepository extends RepositoryBase +public class BotSpamRepository extends MinecraftRepository { private static final String GET_SPAM_TEXT = "SELECT * FROM botSpam"; private static final String ADD_SPAM_TEXT = "INSERT INTO botSpam (text, createdBy, enabledBy) VALUES (?, ?, ?)"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java index c896f2a03..14600c963 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/repository/CustomDataRepository.java @@ -5,24 +5,24 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Map; -import org.bukkit.entity.Player; +import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.customdata.CustomData; import mineplex.core.customdata.CustomDataManager; import mineplex.core.customdata.PlayerCustomData; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.ResultSetCallable; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; /** * Created by William (WilliamTiger). * 16/12/15 */ -public class CustomDataRepository extends RepositoryBase +public class CustomDataRepository extends MinecraftRepository { private static final String SELECT_KEYS = "SELECT id, name FROM customData;"; private static final String INSERT_KEY = "INSERT INTO customData (name) VALUES (?);"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/MinecraftRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/database/MinecraftRepository.java new file mode 100644 index 000000000..690fc9cc6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/MinecraftRepository.java @@ -0,0 +1,112 @@ +package mineplex.core.database; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Iterator; + +import javax.sql.DataSource; + +import mineplex.core.common.util.NautHashMap; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.DatabaseRunnable; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.Column; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import org.jooq.DSLContext; +import org.jooq.SQLDialect; +import org.jooq.impl.DSL; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +public abstract class MinecraftRepository extends RepositoryBase implements Listener +{ + // Queue for failed processes + private static Object _queueLock = new Object(); + private NautHashMap _failedQueue = new NautHashMap(); + + 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 MinecraftRepository(JavaPlugin plugin, DataSource dataSource) + { + super(dataSource); + + _plugin = plugin; + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + protected DSLContext jooq() + { + return DSL.using(DBPool.getAccount(), SQLDialect.MYSQL); + } + + protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage) + { + Thread asyncThread = new Thread(new Runnable() + { + public void run() + { + try + { + databaseRunnable.run(); + } + catch (Exception exception) + { + processFailedDatabaseCall(databaseRunnable, exception.getMessage(), errorMessage); + } + } + }); + + asyncThread.start(); + } + + protected void processFailedDatabaseCall(DatabaseRunnable databaseRunnable, String errorPreMessage, String runnableMessage) + { + if (databaseRunnable.getFailedCounts() < 4) + { + databaseRunnable.incrementFailCount(); + + synchronized (_queueLock) + { + _failedQueue.put(databaseRunnable, runnableMessage); + } + } + } + + @EventHandler + public void processDatabaseQueue(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_01) + return; + + processFailedQueue(); + } + + private void processFailedQueue() + { + synchronized (_queueLock) + { + for (Iterator runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();) + { + DatabaseRunnable databaseRunnable = runnablesIterator.next(); + handleDatabaseCall(databaseRunnable, _failedQueue.get(databaseRunnable)); + } + } + } + + public JavaPlugin getPlugin() + { + return _plugin; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/Row.java b/Plugins/Mineplex.Core/src/mineplex/core/database/Row.java deleted file mode 100644 index 208666a37..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/Row.java +++ /dev/null @@ -1,9 +0,0 @@ -package mineplex.core.database; - -import mineplex.core.common.util.NautHashMap; -import mineplex.core.database.column.Column; - -public class Row -{ - public NautHashMap> Columns = new NautHashMap>(); -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java index b30b30b92..5e696359e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -1,21 +1,18 @@ package mineplex.core.donation.repository; -import java.sql.CallableStatement; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Types; +import mineplex.core.database.MinecraftRepository; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.CurrencyType; 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; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.DatabaseRunnable; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; import mineplex.core.donation.Donor; import mineplex.core.donation.repository.token.GemRewardToken; import mineplex.core.donation.repository.token.PurchaseToken; @@ -24,7 +21,7 @@ import mineplex.core.server.remotecall.AsyncJsonWebCall; import mineplex.core.server.remotecall.JsonWebCall; import mineplex.core.server.util.TransactionResponse; -public class DonationRepository extends RepositoryBase +public class DonationRepository extends MinecraftRepository { private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));"; private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));"; @@ -54,7 +51,7 @@ public class DonationRepository extends RepositoryBase { public void run(final TransactionResponse response) { - Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() { @Override public void run() @@ -100,7 +97,7 @@ public class DonationRepository extends RepositoryBase } } - Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() { @Override public void run() @@ -131,7 +128,7 @@ public class DonationRepository extends RepositoryBase { public void run(final Boolean response) { - Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() { @Override public void run() @@ -168,7 +165,7 @@ public class DonationRepository extends RepositoryBase //executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins)); } - Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable() + Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable() { @Override public void run() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java index 2304a75c0..8c0874208 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloRepository.java @@ -3,14 +3,15 @@ package mineplex.core.elo; import java.sql.ResultSet; import java.sql.SQLException; +import mineplex.core.database.MinecraftRepository; 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; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; -public class EloRepository extends RepositoryBase +public class EloRepository extends MinecraftRepository { 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);"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java index 08b6edf93..b9f19f1d9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java @@ -3,16 +3,17 @@ package mineplex.core.facebook; import java.sql.ResultSet; import java.sql.SQLException; +import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.util.Callback; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.ResultSetCallable; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; -public class FacebookRepository extends RepositoryBase +public class FacebookRepository extends MinecraftRepository { private static final String GET_CODE = "SELECT code, activated FROM facebook WHERE code = ?"; private static final String ACTIVATE_CODE = "UPDATE facebook SET activated = 1, accountId = ?, activationTime = NOW() WHERE code = ?"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java index c09fe1703..e26721864 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/data/FriendRepository.java @@ -5,18 +5,18 @@ import java.sql.SQLException; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; +import mineplex.core.database.MinecraftRepository; import org.bukkit.entity.Player; 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; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.core.friend.FriendStatusType; import mineplex.serverdata.Region; import mineplex.serverdata.data.DataRepository; @@ -24,7 +24,7 @@ import mineplex.serverdata.data.PlayerStatus; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ServerManager; -public class FriendRepository extends RepositoryBase +public class FriendRepository extends MinecraftRepository { private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));"; private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget WHERE uuidSource IN "; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java index 46844bd07..52c0cc50f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java @@ -8,17 +8,17 @@ import java.sql.Types; import java.util.HashMap; import java.util.UUID; -import org.bukkit.Bukkit; +import mineplex.core.database.MinecraftRepository; 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; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.serverdata.Region; -public class GiveawayRepository extends RepositoryBase +public class GiveawayRepository extends MinecraftRepository { private static final String INSERT_GIVEAWAY = "INSERT INTO Account.accountGiveaway (giveawayId, accountId, cooldownId, region, serverName, time, uuid) VALUES (?, ?, ?, ?, ?, now(), ?)"; private static final String LOAD_GIVEAWAY = "SELECT id, name, prettyName, header, message, max, notifyNetwork, notifyCooldown, canWinTwice FROM Account.giveaway WHERE enabled = TRUE"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/ignore/data/IgnoreRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/ignore/data/IgnoreRepository.java index 14e1918c4..f4ee78ab2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/ignore/data/IgnoreRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/ignore/data/IgnoreRepository.java @@ -3,14 +3,15 @@ package mineplex.core.ignore.data; import java.sql.ResultSet; import java.sql.SQLException; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -public class IgnoreRepository extends RepositoryBase +public class IgnoreRepository extends MinecraftRepository { private static String ADD_IGNORE_RECORD = "INSERT INTO accountIgnore (uuidIgnorer, uuidIgnored) SELECT fA.uuid AS uuidIgnorer, tA.uuid AS uuidIgnored FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;"; private static String DELETE_IGNORE_RECORD = "DELETE aF FROM accountIgnore AS aF INNER JOIN accounts as fA ON aF.uuidIgnorer = fA.uuid INNER JOIN accounts AS tA ON aF.uuidIgnored = tA.uuid WHERE fA.name = ? AND tA.name = ?;"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java index 018eb41e9..c13bd99e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java @@ -5,18 +5,19 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; 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.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.core.inventory.ClientInventory; import mineplex.core.inventory.ClientItem; -public class InventoryRepository extends RepositoryBase +public class InventoryRepository extends MinecraftRepository { private static String CREATE_INVENTORY_TABLE = "CREATE TABLE IF NOT EXISTS items (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), rarity INT, PRIMARY KEY (id), INDEX mameIndex (name));"; private static String CREATE_INVENTORY_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountInventory (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, itemId INT NOT NULL, count INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (itemId) REFERENCES items(id), UNIQUE INDEX accountItemIndex (accountId, itemId));"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StatEventsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StatEventsRepository.java index 5f0659c03..fab7b1cc2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StatEventsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StatEventsRepository.java @@ -1,9 +1,10 @@ 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; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.plugin.java.JavaPlugin; @@ -15,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin; * @author MrTwiggy * */ -public class StatEventsRepository extends RepositoryBase +public class StatEventsRepository extends MinecraftRepository { // Insert or update stat events query diff --git a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java index 56d689a77..a94be37fe 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/npc/NpcManager.java @@ -38,7 +38,7 @@ import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilPlayer; import mineplex.core.creature.Creature; import mineplex.core.creature.event.CreatureKillEntitiesEvent; -import mineplex.core.database.DBPool; +import mineplex.serverdata.database.DBPool; import mineplex.core.npc.command.NpcCommand; import mineplex.core.npc.event.NpcDamageByEntityEvent; import mineplex.core.npc.event.NpcInteractEntityEvent; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java index 40c2d2e1c..e607bd0c3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java @@ -2,21 +2,21 @@ package mineplex.core.pet.repository; import java.util.List; +import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; import com.google.gson.reflect.TypeToken; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.core.pet.repository.token.PetChangeToken; import mineplex.core.pet.repository.token.PetExtraToken; -import mineplex.core.pet.repository.token.PetSalesToken; import mineplex.core.server.remotecall.AsyncJsonWebCall; import mineplex.core.server.remotecall.JsonWebCall; -public class PetRepository extends RepositoryBase +public class PetRepository extends MinecraftRepository { private String _webAddress; @@ -31,7 +31,7 @@ public class PetRepository extends RepositoryBase { new AsyncJsonWebCall(_webAddress + "Pets/AddPet").Execute(token); - Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable() + getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() { public void run() { @@ -49,7 +49,7 @@ public class PetRepository extends RepositoryBase { new AsyncJsonWebCall(_webAddress + "Pets/RemovePet").Execute(token); - Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable() + getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() { public void run() { @@ -72,7 +72,7 @@ public class PetRepository extends RepositoryBase { new AsyncJsonWebCall(_webAddress + "Pets/UpdatePet").Execute(token); - Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable() + getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable() { public void run() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java index 9628a5c93..dbf24772d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollRepository.java @@ -6,18 +6,19 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import mineplex.core.database.MinecraftRepository; 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; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; /** * Created by Shaun on 8/16/2014. */ -public class PollRepository extends RepositoryBase +public class PollRepository extends MinecraftRepository { private static String CREATE_POLL_TABLE = "CREATE TABLE IF NOT EXISTS polls (id INT NOT NULL AUTO_INCREMENT, enabled BIT(1), question VARCHAR(256) NOT NULL, answerA VARCHAR(256) NOT NULL, answerB VARCHAR(256), answerC VARCHAR(256), answerD VARCHAR(256), coinReward INT NOT NULL, displayType INT DEFAULT 0 NOT NULL, PRIMARY KEY (id));"; private static String CREATE_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountPolls (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, pollId INT NOT NULL, value TINYINT(1) NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (pollId) REFERENCES polls(id), UNIQUE INDEX accountPollIndex (accountId, pollId));"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index 3c90a2cce..ac3b06ffe 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -6,14 +6,15 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map.Entry; +import mineplex.core.database.MinecraftRepository; 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.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnVarChar; -public class PreferencesRepository extends RepositoryBase +public class PreferencesRepository extends MinecraftRepository { // private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS // accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 7b550e058..87f2780ac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -1,22 +1,14 @@ package mineplex.core.report; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -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; -import mineplex.core.database.column.ColumnVarChar; -import mineplex.core.preferences.UserPreferences; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import org.bukkit.plugin.java.JavaPlugin; -public class ReportRepository extends RepositoryBase +public class ReportRepository extends MinecraftRepository { /* * *ReportTicket diff --git a/Plugins/Mineplex.Core/src/mineplex/core/spawn/SpawnRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/spawn/SpawnRepository.java index c6f4191a5..78fda20c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/spawn/SpawnRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/spawn/SpawnRepository.java @@ -5,14 +5,15 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; 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; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnVarChar; -public class SpawnRepository extends RepositoryBase +public class SpawnRepository extends MinecraftRepository { private static String CREATE_SPAWN_TABLE = "CREATE TABLE IF NOT EXISTS spawns (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(100), location VARCHAR(100), PRIMARY KEY (id), INDEX serverNameIndex (serverName));"; private static String RETRIEVE_SPAWNS = "SELECT location FROM spawns WHERE serverName = ?;"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java index e8ac03479..cb5ec1320 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsRepository.java @@ -7,10 +7,11 @@ import java.util.Collections; import java.util.List; 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; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.database.Tables; import org.bukkit.plugin.java.JavaPlugin; @@ -23,7 +24,7 @@ import org.jooq.Update; import org.jooq.impl.DSL; import org.jooq.types.ULong; -public class StatsRepository extends RepositoryBase +public class StatsRepository extends MinecraftRepository { private static String RETRIEVE_STATS = "SELECT id, name FROM stats;"; private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/task/repository/TaskRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/task/repository/TaskRepository.java index 51dfe5726..35766c91d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/task/repository/TaskRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/task/repository/TaskRepository.java @@ -5,17 +5,18 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; 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; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.core.task.Task; import mineplex.core.task.TaskClient; -public class TaskRepository extends RepositoryBase +public class TaskRepository extends MinecraftRepository { private static String ADD_ACCOUNT_TASK = "INSERT INTO accountTasks (accountId, taskId) VALUES (?, ?);"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titangiveaway/TitanGiveawayRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/titangiveaway/TitanGiveawayRepository.java index b6d29c68b..29c0d6a88 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titangiveaway/TitanGiveawayRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titangiveaway/TitanGiveawayRepository.java @@ -4,15 +4,16 @@ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.Types; +import mineplex.core.database.MinecraftRepository; 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; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.serverdata.Region; -public class TitanGiveawayRepository extends RepositoryBase +public class TitanGiveawayRepository extends MinecraftRepository { private static final String ADD_TITAN = "INSERT INTO titanGiveaway (accountId, region, serverName) VALUES (?, ?, ?)"; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftRepository.java index 39a9d4034..0115bd9a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/valentines/ValentinesGiftRepository.java @@ -1,11 +1,12 @@ package mineplex.core.valentines; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; import org.bukkit.plugin.java.JavaPlugin; -public class ValentinesGiftRepository extends RepositoryBase +public class ValentinesGiftRepository extends MinecraftRepository { private String GIVE_GIFT = "INSERT INTO accountValentinesGift (senderId, targetId) VALUES (?, ?);"; diff --git a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java index 2563df862..aebe2bdec 100644 --- a/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java +++ b/Plugins/Mineplex.DDoSProtectionSwitcher/src/mineplex/ddos/DnsMadeEasyRepository.java @@ -61,7 +61,7 @@ public class DnsMadeEasyRepository } } } - + public boolean switchToDDOSProt() { Connection connection = null; diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java index e96d4a42a..73cba9a30 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/TempRepository.java @@ -1,13 +1,14 @@ package mineplex.enjinTranslator; +import mineplex.core.database.MinecraftRepository; 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; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; -public class TempRepository extends RepositoryBase +public class TempRepository extends MinecraftRepository { 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);"; diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java index 1897f407e..8f52c28a4 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/PurchaseManager.java @@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.common.util.NautHashMap; -import mineplex.core.database.ResultSetCallable; +import mineplex.serverdata.database.ResultSetCallable; import mineplex.enjinTranslator.purchase.data.PurchaseRepository; import mineplex.enjinTranslator.purchase.data.Package; diff --git a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java index 048c1fc99..0c2fe000a 100644 --- a/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java +++ b/Plugins/Mineplex.EnjinTranslator/src/mineplex/enjinTranslator/purchase/data/PurchaseRepository.java @@ -5,16 +5,17 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; 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.ColumnBoolean; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnBoolean; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; -public class PurchaseRepository extends RepositoryBase +public class PurchaseRepository extends MinecraftRepository { private static String INSERT_ACCOUNT_PURCHASE = "INSERT INTO accountPurchases (accountId, packageId, amount, date, success) VALUES (?, ?, ?, now(), ?);"; diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java index 70f9d082b..8e2068a2d 100644 --- a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java @@ -11,14 +11,15 @@ import java.util.UUID; import mineplex.core.common.util.Callback; 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.Column; -import mineplex.core.database.column.ColumnBoolean; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnTimestamp; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.Column; +import mineplex.serverdata.database.column.ColumnBoolean; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnTimestamp; +import mineplex.serverdata.database.column.ColumnVarChar; import mineplex.database.tables.records.ClansRecord; import mineplex.game.clans.core.repository.tokens.ClanAllianceToken; import mineplex.game.clans.core.repository.tokens.ClanMemberToken; @@ -36,7 +37,7 @@ import org.jooq.DSLContext; import static mineplex.database.Tables.*; import static org.jooq.impl.DSL.*; -public class ClanRepository extends RepositoryBase +public class ClanRepository extends MinecraftRepository { private static String CREATE_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS clans (id INT NOT NULL AUTO_INCREMENT, serverId INT NOT NULL, name VARCHAR(100), description VARCHAR(140), home VARCHAR(140), admin BIT(1), dateCreated DATETIME, lastOnline DATETIME, energy INT, PRIMARY KEY (id), INDEX clanName (name));"; private static String CREATE_ACCOUNT_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS accountClan (id INT NOT NULL AUTO_INCREMENT, accountId INT, clanId INT, clanRole VARCHAR(140), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));"; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java index 5ec0f6fc0..287d3c1de 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/ClansBanRepository.java @@ -6,20 +6,21 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClient; import mineplex.core.common.util.Callback; import mineplex.core.common.util.NonFinalInteger; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.ResultSetCallable; -import mineplex.core.database.column.ColumnBoolean; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnTimestamp; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnBoolean; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnTimestamp; +import mineplex.serverdata.database.column.ColumnVarChar; -public class ClansBanRepository extends RepositoryBase +public class ClansBanRepository extends MinecraftRepository { private ClansBanManager _manager; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/repository/FieldRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/repository/FieldRepository.java index 2f36fd067..6e604d3f8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/repository/FieldRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/fields/repository/FieldRepository.java @@ -5,17 +5,18 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; 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; -import mineplex.core.database.column.ColumnDouble; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnByte; +import mineplex.serverdata.database.column.ColumnDouble; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnVarChar; -public class FieldRepository extends RepositoryBase +public class FieldRepository extends MinecraftRepository { private static String ALL_STRING = "ALL"; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java index cf07e0012..065728f36 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubRepository.java @@ -1,20 +1,12 @@ package mineplex.hub; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.database.DBPool; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import mineplex.serverdata.database.DBPool; public class HubRepository { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java index ae09e592f..7e7659b83 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailRepository.java @@ -4,10 +4,11 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; +import mineplex.core.database.MinecraftRepository; import org.bukkit.plugin.java.JavaPlugin; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; import mineplex.database.Tables; import mineplex.database.tables.records.MailRecord; @@ -15,7 +16,7 @@ import org.jooq.DSLContext; import org.jooq.Result; import org.jooq.impl.DSL; -public class MailRepository extends RepositoryBase +public class MailRepository extends MinecraftRepository { private MailManager _manager; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java index d0b0d0a91..217e4cd49 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/queue/QueueRepository.java @@ -1,14 +1,12 @@ package mineplex.hub.queue; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import mineplex.core.common.util.C; -import mineplex.core.database.DBPool; +import mineplex.serverdata.database.DBPool; public class QueueRepository { diff --git a/Plugins/Mineplex.ServerData/pom.xml b/Plugins/Mineplex.ServerData/pom.xml index b7e313ba5..b89ca0d8f 100644 --- a/Plugins/Mineplex.ServerData/pom.xml +++ b/Plugins/Mineplex.ServerData/pom.xml @@ -20,5 +20,10 @@ redis.clients jedis + + org.apache.commons + commons-dbcp2 + 2.0.1 + diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java similarity index 93% rename from Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java index ca6eaca75..d7c85e11a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/DBPool.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java @@ -1,4 +1,4 @@ -package mineplex.core.database; +package mineplex.serverdata.database; import javax.sql.DataSource; @@ -6,15 +6,10 @@ import java.io.File; import java.nio.charset.Charset; import java.nio.file.Files; import java.sql.Connection; -import java.util.ArrayList; import java.util.List; import org.apache.commons.dbcp2.BasicDataSource; -import mineplex.serverdata.redis.RedisConfig; -import mineplex.serverdata.servers.ConnectionData; -import mineplex.serverdata.servers.ConnectionData.ConnectionType; - public final class DBPool { private static DataSource ACCOUNT; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DatabaseRunnable.java similarity index 90% rename from Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DatabaseRunnable.java index f5d1899cd..4817a9dc4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DatabaseRunnable.java @@ -1,4 +1,4 @@ -package mineplex.core.database; +package mineplex.serverdata.database; public class DatabaseRunnable { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java similarity index 55% rename from Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java index 55acc83ed..daa668281 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java @@ -1,57 +1,31 @@ -package mineplex.core.database; +package mineplex.serverdata.database; -import java.sql.CallableStatement; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.Iterator; import javax.sql.DataSource; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.database.column.Column; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import org.jooq.DSLContext; -import org.jooq.SQLDialect; -import org.jooq.impl.DSL; +import mineplex.serverdata.database.column.Column; -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 { - // Queue for failed processes - private static Object _queueLock = new Object(); - private NautHashMap _failedQueue = new NautHashMap(); - 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) + public RepositoryBase(DataSource dataSource) { - Plugin = plugin; _dataSource = dataSource; - Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() - { - public void run() - { - initialize(); - update(); - } - }); - - plugin.getServer().getPluginManager().registerEvents(this, plugin); + new Thread(() -> { + initialize(); + update(); + }).start(); } protected abstract void initialize(); @@ -66,11 +40,6 @@ public abstract class RepositoryBase implements Listener return _dataSource; } - protected DSLContext jooq() - { - return DSL.using(DBPool.getAccount(), SQLDialect.MYSQL); - } - /** * Requirements: {@link Connection}s must be closed after usage so they may be returned to the pool! * @see Connection#close() @@ -178,58 +147,4 @@ public abstract class RepositoryBase implements Listener exception.printStackTrace(); } } - - protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage) - { - Thread asyncThread = new Thread(new Runnable() - { - public void run() - { - try - { - databaseRunnable.run(); - } - catch (Exception exception) - { - processFailedDatabaseCall(databaseRunnable, exception.getMessage(), errorMessage); - } - } - }); - - asyncThread.start(); - } - - protected void processFailedDatabaseCall(DatabaseRunnable databaseRunnable, String errorPreMessage, String runnableMessage) - { - if (databaseRunnable.getFailedCounts() < 4) - { - databaseRunnable.incrementFailCount(); - - synchronized (_queueLock) - { - _failedQueue.put(databaseRunnable, runnableMessage); - } - } - } - - @EventHandler - public void processDatabaseQueue(UpdateEvent event) - { - if (event.getType() != UpdateType.MIN_01) - return; - - processFailedQueue(); - } - - private void processFailedQueue() - { - synchronized (_queueLock) - { - for (Iterator runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();) - { - DatabaseRunnable databaseRunnable = runnablesIterator.next(); - handleDatabaseCall(databaseRunnable, _failedQueue.get(databaseRunnable)); - } - } - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/ResultSetCallable.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/ResultSetCallable.java similarity index 81% rename from Plugins/Mineplex.Core/src/mineplex/core/database/ResultSetCallable.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/ResultSetCallable.java index 2972d5f4a..adac7876d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/ResultSetCallable.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/ResultSetCallable.java @@ -1,4 +1,4 @@ -package mineplex.core.database; +package mineplex.serverdata.database; import java.sql.ResultSet; import java.sql.SQLException; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/Column.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/Column.java similarity index 92% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/Column.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/Column.java index d73d6da05..939e29a83 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/Column.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/Column.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnBoolean.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnBoolean.java index a7da34f61..4eb6a48c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnBoolean.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnByte.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnByte.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnByte.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnByte.java index 40464a318..9a92bdb38 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnByte.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnByte.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnDouble.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnDouble.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnDouble.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnDouble.java index 1163df926..2c7fe76c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnDouble.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnDouble.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnInt.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnInt.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnInt.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnInt.java index 25ed6a705..348aeb1dd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnInt.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnInt.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnLong.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnLong.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnLong.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnLong.java index d8c8815b5..d3eec3a95 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnLong.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnLong.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnTimestamp.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnTimestamp.java index 1efacd628..6ce17f633 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnTimestamp.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnVarChar.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnVarChar.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnVarChar.java rename to Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnVarChar.java index da5c484c1..a60b3b19d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnVarChar.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/column/ColumnVarChar.java @@ -1,4 +1,4 @@ -package mineplex.core.database.column; +package mineplex.serverdata.database.column; import java.sql.PreparedStatement; import java.sql.ResultSet; diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java index a85d42848..8f4566b0f 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/StatusHistoryRepository.java @@ -1,7 +1,6 @@ package mineplex.servermonitor; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; @@ -14,15 +13,13 @@ import mineplex.serverdata.data.BungeeServer; import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.data.DedicatedServer; import mineplex.serverdata.data.ServerGroup; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ServerManager; -public class StatusHistoryRepository +public class StatusHistoryRepository extends RepositoryBase { - private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/ServerStats"; - private String _userName = "root"; - private String _password = "tAbechAk3wR7tuTh"; - private static String CREATE_GROUP_TABLE = "CREATE TABLE IF NOT EXISTS ServerGroupStats (id INT NOT NULL AUTO_INCREMENT, serverGroup VARCHAR(100), updated LONG, players INT, maxPlayers INT, totalNetworkCpuUsage DOUBLE(4,2), totalNetworkRamUsage DOUBLE(4,2), totalCpu MEDIUMINT, totalRam MEDIUMINT, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id));"; private static String CREATE_DEDICATED_TABLE = "CREATE TABLE IF NOT EXISTS DedicatedServerStats (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(100), address VARCHAR(25), updated LONG, cpu TINYINT, ram MEDIUMINT, usedCpuPercent DOUBLE(4,2), usedRamPercent DOUBLE(4,2), US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id));"; private static String CREATE_BUNGEE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeStats (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(25), updated LONG, players INT, maxPlayers INT, alive BOOLEAN NOT NULL, online BOOLEAN NOT NULL, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id));"; @@ -33,38 +30,33 @@ public class StatusHistoryRepository private static String INSERT_BUNGEE_STATS = "INSERT INTO BungeeStats (address, updated, players, maxPlayers, alive, online, US) VALUES (?, now(), ?, ?, ?, ?, ?);"; private static String INSERT_NETWORK_STATS = "INSERT INTO NetworkStats (updated, players, totalNetworkCpuUsage, totalNetworkRamUsage, totalCpu, totalRam, US) VALUES (now(), ?, ?, ?, ?, ?, ?);"; - private static Connection _connection; - private static DataRepository _repository; public StatusHistoryRepository() { + super(DBPool.getStats()); + PreparedStatement preparedStatement = null; - - try + + try(Connection connection = getConnection()) { - Class.forName("com.mysql.jdbc.Driver"); - - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - // Create table - preparedStatement = _connection.prepareStatement(CREATE_GROUP_TABLE); + preparedStatement = connection.prepareStatement(CREATE_GROUP_TABLE); preparedStatement.execute(); preparedStatement.close(); // Create table - preparedStatement = _connection.prepareStatement(CREATE_DEDICATED_TABLE); + preparedStatement = connection.prepareStatement(CREATE_DEDICATED_TABLE); preparedStatement.execute(); preparedStatement.close(); // Create table - preparedStatement = _connection.prepareStatement(CREATE_BUNGEE_TABLE); + preparedStatement = connection.prepareStatement(CREATE_BUNGEE_TABLE); preparedStatement.execute(); preparedStatement.close(); // Create table - preparedStatement = _connection.prepareStatement(CREATE_NETWORKSTATS_TABLE); + preparedStatement = connection.prepareStatement(CREATE_NETWORKSTATS_TABLE); preparedStatement.execute(); preparedStatement.close(); @@ -95,12 +87,9 @@ public class StatusHistoryRepository { PreparedStatement preparedStatement = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(INSERT_SERVERGROUP_STATS); + preparedStatement = connection.prepareStatement(INSERT_SERVERGROUP_STATS); for (ServerGroup serverGroup : collection) { @@ -144,12 +133,9 @@ public class StatusHistoryRepository { PreparedStatement preparedStatement = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(INSERT_DEDICATEDSERVER_STATS); + preparedStatement = connection.prepareStatement(INSERT_DEDICATEDSERVER_STATS); for (DedicatedServer dedicatedServer : dedicatedServers) { @@ -204,12 +190,9 @@ public class StatusHistoryRepository PreparedStatement preparedStatement = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(INSERT_BUNGEE_STATS); + preparedStatement = connection.prepareStatement(INSERT_BUNGEE_STATS); for (BungeeServer bungeeStatusData : bungeeServers) { @@ -246,12 +229,9 @@ public class StatusHistoryRepository preparedStatement = null; - try + try(Connection connection = getConnection()) { - if (_connection == null || _connection.isClosed()) - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - - preparedStatement = _connection.prepareStatement(INSERT_NETWORK_STATS); + preparedStatement = connection.prepareStatement(INSERT_NETWORK_STATS); preparedStatement.setInt(1, totalPlayers); preparedStatement.setDouble(2, usedCpuPercent); preparedStatement.setDouble(3, usedRamPercent); @@ -280,4 +260,16 @@ public class StatusHistoryRepository } } } + + @Override + protected void initialize() + { + + } + + @Override + protected void update() + { + + } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java index 33b63e8a5..07fa746c1 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/password/PasswordRepository.java @@ -5,14 +5,15 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import mineplex.core.database.MinecraftRepository; 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; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.ResultSetCallable; +import mineplex.serverdata.database.column.ColumnVarChar; -public class PasswordRepository extends RepositoryBase +public class PasswordRepository extends MinecraftRepository { private static String CREATE_SERVER_PASSWORD_TABLE = "CREATE TABLE IF NOT EXISTS serverPassword (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(100), password VARCHAR(100), PRIMARY KEY (id));"; private static String RETRIEVE_SERVER_PASSWORD = "SELECT password FROM serverPassword WHERE server = ?;"; diff --git a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java index 4817371cb..23801e02d 100644 --- a/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java +++ b/Plugins/Mineplex.Votifier/src/mineplex/votifier/VotifierManager.java @@ -11,12 +11,11 @@ import com.vexsoftware.votifier.model.VotifierEvent; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.bonuses.BonusAmount; -import mineplex.core.bonuses.BonusClientData; import mineplex.core.bonuses.BonusManager; import mineplex.core.common.Pair; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UUIDFetcher; -import mineplex.core.database.DBPool; +import mineplex.serverdata.database.DBPool; import mineplex.core.donation.DonationManager; import mineplex.core.bonuses.redis.VotifierCommand; import mineplex.database.Tables; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/titangiveaway/TitanGiveawayRepository.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/titangiveaway/TitanGiveawayRepository.java index 3585b3586..49bc0601b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/titangiveaway/TitanGiveawayRepository.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/titangiveaway/TitanGiveawayRepository.java @@ -4,12 +4,13 @@ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.Types; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; +import mineplex.core.database.MinecraftRepository; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; import org.bukkit.plugin.java.JavaPlugin; -public class TitanGiveawayRepository extends RepositoryBase +public class TitanGiveawayRepository extends MinecraftRepository { private int _titanGiveawayCount;