Pooled Friend/Ignore/Preferences/Poll/Elo repositories.
Removed ArcadeRepository as its unused. Removed target server check for RedisCommand because it breaks other commands.
This commit is contained in:
parent
5c738a2e3c
commit
09ecb994f6
@ -314,6 +314,33 @@
|
||||
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
|
||||
</jar>
|
||||
<copy file="../bin/ServerMonitor.jar" todir="../../Testing/ServerMonitor/"/>
|
||||
</target>
|
||||
<target name ="ChestConverter" description="ChestConverter">
|
||||
<jar jarfile="../bin/ChestConverter.jar">
|
||||
<fileset dir="../Mineplex.Core.Common/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
<fileset dir="../Mineplex.ChestConverter/bin">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
|
||||
<zipfileset src="../Libraries/mysql.zip" />
|
||||
|
||||
<manifest>
|
||||
<attribute name="Main-Class"
|
||||
value="mineplex.chestConverter.ChestConverter"/>
|
||||
</manifest>
|
||||
|
||||
<zipfileset src="../Libraries/httpclient-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpcore-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpclient-cache-4.2.jar" />
|
||||
<zipfileset src="../Libraries/httpmime-4.2.jar" />
|
||||
<zipfileset src="../Libraries/gson-2.2.1.jar" />
|
||||
<zipfileset src="../Libraries/commons-logging-1.1.1.jar" />
|
||||
<zipfileset src="../Libraries/commons-codec-1.6.jar" />
|
||||
<zipfileset src="../Libraries/commons-pool2-2.2.jar" />
|
||||
</jar>
|
||||
<copy file="../bin/ChestConverter.jar" todir="../../Testing/ChestConverter/"/>
|
||||
</target>
|
||||
<target name ="Queuer" description="Queuer">
|
||||
<jar jarfile="../bin/Queuer.jar">
|
||||
|
@ -23,8 +23,8 @@ public final class DBPool
|
||||
source.setUrl(url);
|
||||
source.setUsername(username);
|
||||
source.setPassword(password);
|
||||
source.setMaxTotal(10);
|
||||
source.setMaxIdle(3);
|
||||
source.setMaxTotal(2);
|
||||
source.setMaxIdle(2);
|
||||
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
|
||||
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
|
||||
|
||||
|
@ -8,6 +8,8 @@ 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;
|
||||
@ -33,6 +35,7 @@ public abstract class RepositoryBase implements Listener
|
||||
private String _password;
|
||||
|
||||
protected JavaPlugin Plugin;
|
||||
protected DataSource DataSource;
|
||||
|
||||
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
||||
{
|
||||
@ -57,6 +60,26 @@ public abstract class RepositoryBase implements Listener
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public RepositoryBase(JavaPlugin plugin, DataSource dataSource)
|
||||
{
|
||||
Plugin = plugin;
|
||||
DataSource = dataSource;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
initialize();
|
||||
update();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
protected abstract void initialize();
|
||||
|
||||
protected abstract void update();
|
||||
@ -73,8 +96,13 @@ public abstract class RepositoryBase implements Listener
|
||||
try
|
||||
{
|
||||
if (_connection == null || (validate && !_connection.isValid(2)))
|
||||
{
|
||||
if (DataSource != null)
|
||||
_connection = DataSource.getConnection();
|
||||
else
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
@ -97,8 +125,7 @@ public abstract class RepositoryBase implements Listener
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null)
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
getConnection(false);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
@ -114,19 +141,9 @@ public abstract class RepositoryBase implements Listener
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_connection.isValid(5))
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
getConnection(true);
|
||||
executeInsert(query, callable, columns);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
@ -166,19 +183,9 @@ public abstract class RepositoryBase implements Listener
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_connection.isValid(5))
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
getConnection(true);
|
||||
executeQuery(statement, callable, columns);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
@ -205,8 +212,7 @@ public abstract class RepositoryBase implements Listener
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null)
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
getConnection(false);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(query);
|
||||
|
||||
@ -214,19 +220,9 @@ public abstract class RepositoryBase implements Listener
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_connection.isValid(5))
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
getConnection(true);
|
||||
executeQuery(query, callable, columns);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
@ -262,19 +258,9 @@ public abstract class RepositoryBase implements Listener
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_connection.isValid(5))
|
||||
{
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
getConnection(true);
|
||||
executeUpdate(preparedStatement, columns);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
@ -337,15 +323,7 @@ public abstract class RepositoryBase implements Listener
|
||||
{
|
||||
synchronized (_connectionLock)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_connection == null || !_connection.isValid(5))
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
getConnection(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -5,6 +5,7 @@ import java.sql.SQLException;
|
||||
|
||||
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;
|
||||
@ -16,7 +17,7 @@ public class EloRepository extends RepositoryBase
|
||||
|
||||
public EloRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ 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;
|
||||
@ -22,7 +23,7 @@ public class FriendRepository extends RepositoryBase
|
||||
|
||||
public FriendRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ 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;
|
||||
|
||||
@ -16,8 +17,7 @@ public class IgnoreRepository extends RepositoryBase
|
||||
|
||||
public IgnoreRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10",
|
||||
"root", "tAbechAk3wR7tuTh");
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,28 +36,12 @@ public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
|
||||
{
|
||||
super("Preferences", plugin, clientManager);
|
||||
|
||||
setupConfigValues();
|
||||
|
||||
_repository = new PreferencesRepository(plugin, plugin.getConfig().getString("preferences.connectionurl"));
|
||||
_repository = new PreferencesRepository(plugin);
|
||||
_shop = new PreferencesShop(this, clientManager, donationManager);
|
||||
|
||||
addCommand(new PreferencesCommand(this));
|
||||
}
|
||||
|
||||
private void setupConfigValues()
|
||||
{
|
||||
try
|
||||
{
|
||||
getPlugin().getConfig().addDefault("preferences.connectionurl", "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
|
||||
getPlugin().getConfig().set("preferences.connectionurl", getPlugin().getConfig().getString("preferences.connectionurl"));
|
||||
getPlugin().saveConfig();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected UserPreferences AddPlayer(String player)
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ import java.util.Map.Entry;
|
||||
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;
|
||||
|
||||
@ -17,9 +18,9 @@ public class PreferencesRepository extends RepositoryBase
|
||||
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=?;";
|
||||
|
||||
public PreferencesRepository(JavaPlugin plugin, String connectionString)
|
||||
public PreferencesRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh");
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
@ -28,7 +29,7 @@ public class PollRepository extends RepositoryBase
|
||||
|
||||
public PollRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,9 +113,6 @@ public class ServerCommandManager
|
||||
Class<? extends ServerCommand> commandClazz = _commandTypes.get(commandType).getCommandType();
|
||||
final ServerCommand serverCommand = Utility.deserialize(serializedCommand, commandClazz);
|
||||
|
||||
if (!serverCommand.isTargetServer(_localServerName))
|
||||
return;
|
||||
|
||||
new Thread("Redis Command " + commandType)
|
||||
{
|
||||
public void run()
|
||||
@ -130,7 +127,7 @@ public class ServerCommandManager
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
private PartyManager _partyManager;
|
||||
|
||||
private TaskManager _taskManager;
|
||||
private ArcadeRepository _arcadeRepository;
|
||||
private PacketHandler _packetHandler;
|
||||
|
||||
|
||||
@ -261,7 +260,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
_idleManager = new IdleManager(this);
|
||||
//new HalloweenManager(this);
|
||||
|
||||
_arcadeRepository = new ArcadeRepository(plugin);
|
||||
// Game Addons
|
||||
new CompassAddon(plugin, this);
|
||||
new SoupAddon(plugin, this);
|
||||
@ -1038,11 +1036,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
||||
}
|
||||
}
|
||||
|
||||
public ArcadeRepository getArcadeRepository()
|
||||
{
|
||||
return _arcadeRepository;
|
||||
}
|
||||
|
||||
/*public void saveBasicStats(final Game game)
|
||||
{
|
||||
if (!IsTournamentServer())
|
||||
|
@ -1,107 +0,0 @@
|
||||
package nautilus.game.arcade;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.database.Tables;
|
||||
//import mineplex.database.tables.records.GamesRecord;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Query;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
public class ArcadeRepository extends RepositoryBase
|
||||
{
|
||||
private final String serverName;
|
||||
|
||||
public ArcadeRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
||||
|
||||
serverName = plugin.getConfig().getString("serverstatus.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*public void saveBasicStats(GameType type, boolean tournament, int duration, Map<UUID, Boolean> players)
|
||||
{
|
||||
DSLContext context;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
context = DSL.using(getConnection());
|
||||
}
|
||||
|
||||
GamesRecord record = context.newRecord(Tables.games);
|
||||
record.setDuration(duration);
|
||||
record.setTournament(tournament);
|
||||
record.setType(type.name());
|
||||
record.setServer(serverName);
|
||||
record.store();
|
||||
|
||||
List<Query> queryList = new ArrayList<>(players.size());
|
||||
|
||||
for (Map.Entry<UUID, Boolean> entry : players.entrySet())
|
||||
{
|
||||
Query query = context
|
||||
.insertInto(Tables.gamePlayers)
|
||||
.set(Tables.gamePlayers.gameId, record.getId())
|
||||
.set(Tables.gamePlayers.accountId, DSL.select(Tables.accounts.id)
|
||||
.from(Tables.accounts)
|
||||
.where(Tables.accounts.uuid.eq(entry.getKey().toString())))
|
||||
.set(Tables.gamePlayers.winner, entry.getValue());
|
||||
|
||||
queryList.add(query);
|
||||
}
|
||||
|
||||
context.batch(queryList).execute();
|
||||
}
|
||||
|
||||
public void saveLeaderboardStats(int tournamentId, int gameId, Map<UUID, Boolean> players)
|
||||
{
|
||||
DSLContext context;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
context = DSL.using(getConnection());
|
||||
}
|
||||
|
||||
List<Query> queryList = new ArrayList<>(players.size());
|
||||
|
||||
for (Map.Entry<UUID, Boolean> entry : players.entrySet())
|
||||
{
|
||||
int winIncrement = entry.getValue() ? 1 : 0;
|
||||
|
||||
Query query = context
|
||||
.insertInto(Tables.tournamentLeaderboard)
|
||||
.set(Tables.tournamentLeaderboard.tournamentId, tournamentId)
|
||||
.set(Tables.tournamentLeaderboard.gameId, gameId)
|
||||
.set(Tables.tournamentLeaderboard.accountId, DSL.select(Tables.accounts.id)
|
||||
.from(Tables.accounts)
|
||||
.where(Tables.accounts.uuid.eq(entry.getKey().toString())))
|
||||
.set(Tables.tournamentLeaderboard.wins, winIncrement)
|
||||
.set(Tables.tournamentLeaderboard.total, 1)
|
||||
.onDuplicateKeyUpdate()
|
||||
.set(Tables.tournamentLeaderboard.wins, Tables.tournamentLeaderboard.wins.plus(winIncrement))
|
||||
.set(Tables.tournamentLeaderboard.total, Tables.tournamentLeaderboard.total.plus(1));
|
||||
|
||||
queryList.add(query);
|
||||
}
|
||||
|
||||
context.batch(queryList).execute();
|
||||
}*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user