mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 09:27:45 +01:00
[Debt] Removed ServerInfo.getServerUUID() method
Most uses of this method were already handled, but database related were not. Dependency was met by adding a Supplier<UUID> to SQLDB class. Patch and Table classes have getServerUUID() method that use supplier in SQLDB. UserImportDataBuilder required the dependency, and it was provided via UserImportData#builder(UUID).
This commit is contained in:
parent
a48b660a05
commit
9b9443adf4
@ -1,7 +1,5 @@
|
||||
package com.djrapitops.plan.system.database.databases.operation;
|
||||
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface CheckOperations {
|
||||
@ -12,10 +10,7 @@ public interface CheckOperations {
|
||||
|
||||
boolean doesWebUserExists(String username);
|
||||
|
||||
@Deprecated
|
||||
default boolean isPlayerRegisteredOnThisServer(UUID player) {
|
||||
return isPlayerRegistered(player, ServerInfo.getServerUUID_Old());
|
||||
}
|
||||
boolean isPlayerRegisteredOnThisServer(UUID player);
|
||||
|
||||
boolean isServerInDatabase(UUID serverUUID);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.system.database.databases.sql;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
@ -14,6 +15,7 @@ import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.sql.DataSource;
|
||||
@ -34,12 +36,13 @@ public class MySQLDB extends SQLDB {
|
||||
public MySQLDB(
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger pluginLogger,
|
||||
Timings timings,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(locale, config, runnableFactory, pluginLogger, timings, errorHandler);
|
||||
super(() -> serverInfo.get().getServerUUID(), locale, config, runnableFactory, pluginLogger, timings, errorHandler);
|
||||
}
|
||||
|
||||
private static synchronized void increment() {
|
||||
|
@ -31,6 +31,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -41,6 +42,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public abstract class SQLDB extends Database {
|
||||
|
||||
private final Supplier<UUID> serverUUIDSupplier;
|
||||
|
||||
protected final Locale locale;
|
||||
protected final PlanConfig config;
|
||||
protected final RunnableFactory runnableFactory;
|
||||
@ -75,6 +78,7 @@ public abstract class SQLDB extends Database {
|
||||
private PluginTask dbCleanTask;
|
||||
|
||||
public SQLDB(
|
||||
Supplier<UUID> serverUUIDSupplier,
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
RunnableFactory runnableFactory,
|
||||
@ -82,6 +86,7 @@ public abstract class SQLDB extends Database {
|
||||
Timings timings,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.serverUUIDSupplier = serverUUIDSupplier;
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.runnableFactory = runnableFactory;
|
||||
@ -463,4 +468,8 @@ public abstract class SQLDB extends Database {
|
||||
public int hashCode() {
|
||||
return Objects.hash(getName());
|
||||
}
|
||||
|
||||
public Supplier<UUID> getServerUUIDSupplier() {
|
||||
return serverUUIDSupplier;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.system.database.databases.sql;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
@ -13,6 +14,7 @@ import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
import com.djrapitops.plugin.task.PluginTask;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
@ -29,16 +31,17 @@ public class SQLiteDB extends SQLDB {
|
||||
private Connection connection;
|
||||
private PluginTask connectionPingTask;
|
||||
|
||||
public SQLiteDB(
|
||||
private SQLiteDB(
|
||||
File databaseFile,
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger logger,
|
||||
Timings timings,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(locale, config, runnableFactory, logger, timings, errorHandler);
|
||||
super(() -> serverInfo.get().getServerUUID(), locale, config, runnableFactory, logger, timings, errorHandler);
|
||||
dbName = databaseFile.getName();
|
||||
this.databaseFile = databaseFile;
|
||||
}
|
||||
@ -179,6 +182,7 @@ public class SQLiteDB extends SQLDB {
|
||||
|
||||
private final Locale locale;
|
||||
private final PlanConfig config;
|
||||
private final Lazy<ServerInfo> serverInfo;
|
||||
private final RunnableFactory runnableFactory;
|
||||
private final PluginLogger logger;
|
||||
private final Timings timings;
|
||||
@ -190,6 +194,7 @@ public class SQLiteDB extends SQLDB {
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
PlanFiles planFiles,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger logger,
|
||||
Timings timings,
|
||||
@ -198,6 +203,7 @@ public class SQLiteDB extends SQLDB {
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.planFiles = planFiles;
|
||||
this.serverInfo = serverInfo;
|
||||
this.runnableFactory = runnableFactory;
|
||||
this.logger = logger;
|
||||
this.timings = timings;
|
||||
@ -213,7 +219,7 @@ public class SQLiteDB extends SQLDB {
|
||||
}
|
||||
|
||||
public SQLiteDB usingFile(File databaseFile) {
|
||||
return new SQLiteDB(databaseFile, locale, config, runnableFactory, logger, timings, errorHandler);
|
||||
return new SQLiteDB(databaseFile, locale, config, serverInfo, runnableFactory, logger, timings, errorHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.djrapitops.plan.system.database.databases.sql;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
@ -8,6 +9,7 @@ import com.djrapitops.plugin.benchmarking.Timings;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.task.RunnableFactory;
|
||||
import dagger.Lazy;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.service.sql.SqlService;
|
||||
|
||||
@ -27,12 +29,13 @@ public class SpongeMySQLDB extends MySQLDB {
|
||||
public SpongeMySQLDB(
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
RunnableFactory runnableFactory,
|
||||
PluginLogger pluginLogger,
|
||||
Timings timings,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(locale, config, runnableFactory, pluginLogger, timings, errorHandler);
|
||||
super(locale, config, serverInfo, runnableFactory, pluginLogger, timings, errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,11 @@ public class SQLCheckOps extends SQLOps implements CheckOperations {
|
||||
return userInfoTable.isRegistered(player, server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerRegisteredOnThisServer(UUID player) {
|
||||
return userInfoTable.isRegisteredOnThisServer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesWebUserExists(String username) {
|
||||
return securityTable.userExists(username);
|
||||
|
@ -8,6 +8,7 @@ import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlPars
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class Patch {
|
||||
|
||||
@ -91,4 +92,7 @@ public abstract class Patch {
|
||||
db.execute(sql);
|
||||
}
|
||||
|
||||
protected UUID getServerUUID() {
|
||||
return db.getServerUUIDSupplier().get();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.*;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -24,7 +23,7 @@ public class Version10Patch extends Patch {
|
||||
@Override
|
||||
public void apply() {
|
||||
try {
|
||||
Optional<Integer> fetchedServerID = db.getServerTable().getServerID(ServerInfo.getServerUUID_Old());
|
||||
Optional<Integer> fetchedServerID = db.getServerTable().getServerID(getServerUUID());
|
||||
if (!fetchedServerID.isPresent()) {
|
||||
throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin.");
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -94,7 +93,7 @@ public class CommandUseTable extends Table {
|
||||
* @return command - times used Map
|
||||
*/
|
||||
public Map<String, Integer> getCommandUse() {
|
||||
return getCommandUse(ServerInfo.getServerUUID_Old());
|
||||
return getCommandUse(getServerUUID());
|
||||
}
|
||||
|
||||
public void commandUsed(String command) {
|
||||
@ -110,7 +109,7 @@ public class CommandUseTable extends Table {
|
||||
boolean updated = execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(1, getServerUUID().toString());
|
||||
statement.setString(2, command);
|
||||
}
|
||||
});
|
||||
@ -144,7 +143,7 @@ public class CommandUseTable extends Table {
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, command);
|
||||
statement.setInt(2, 1);
|
||||
statement.setString(3, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(3, getServerUUID().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -183,7 +182,7 @@ public class KillsTable extends UserIDTable {
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, victim.toString());
|
||||
statement.setString(3, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(3, getServerUUID().toString());
|
||||
statement.setInt(4, sessionID);
|
||||
statement.setLong(5, date);
|
||||
statement.setString(6, weapon);
|
||||
|
@ -9,7 +9,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -111,7 +110,7 @@ public class NicknamesTable extends UserIDTable {
|
||||
* @return The nicknames of the User
|
||||
*/
|
||||
public List<String> getNicknames(UUID uuid) {
|
||||
return getNicknames(uuid, ServerInfo.getServerUUID_Old());
|
||||
return getNicknames(uuid, getServerUUID());
|
||||
}
|
||||
|
||||
public Map<UUID, Map<UUID, List<Nickname>>> getAllNicknames() {
|
||||
@ -167,7 +166,7 @@ public class NicknamesTable extends UserIDTable {
|
||||
statement.setLong(1, name.getDate());
|
||||
statement.setString(2, name.getName());
|
||||
statement.setString(3, uuid.toString());
|
||||
statement.setString(4, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(4, getServerUUID().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -177,7 +176,7 @@ public class NicknamesTable extends UserIDTable {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(2, getServerUUID().toString());
|
||||
statement.setString(3, name.getName());
|
||||
statement.setLong(4, name.getDate());
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -73,7 +72,7 @@ public class PingTable extends UserIDTable {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(2, getServerUUID().toString());
|
||||
statement.setLong(3, ping.getDate());
|
||||
statement.setInt(4, ping.getMin());
|
||||
statement.setInt(5, ping.getMax());
|
||||
|
@ -11,7 +11,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -134,7 +133,7 @@ public class SessionsTable extends UserIDTable {
|
||||
statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT));
|
||||
statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT));
|
||||
statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME));
|
||||
statement.setString(7, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(7, getServerUUID().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -239,7 +238,7 @@ public class SessionsTable extends UserIDTable {
|
||||
* @return Milliseconds played on THIS server. 0 if player or server not found.
|
||||
*/
|
||||
public long getPlaytime(UUID uuid) {
|
||||
return getPlaytime(uuid, ServerInfo.getServerUUID_Old());
|
||||
return getPlaytime(uuid, getServerUUID());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,7 +249,7 @@ public class SessionsTable extends UserIDTable {
|
||||
* @return Milliseconds played on THIS server. 0 if player or server not found.
|
||||
*/
|
||||
public long getPlaytime(UUID uuid, long afterDate) {
|
||||
return getPlaytime(uuid, ServerInfo.getServerUUID_Old(), afterDate);
|
||||
return getPlaytime(uuid, getServerUUID(), afterDate);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,7 +356,7 @@ public class SessionsTable extends UserIDTable {
|
||||
* @return How many sessions player has. 0 if player or server not found.
|
||||
*/
|
||||
public int getSessionCount(UUID uuid, long afterDate) {
|
||||
return getSessionCount(uuid, ServerInfo.getServerUUID_Old(), afterDate);
|
||||
return getSessionCount(uuid, getServerUUID(), afterDate);
|
||||
}
|
||||
|
||||
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) {
|
||||
@ -404,7 +403,7 @@ public class SessionsTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public Map<UUID, List<Session>> getSessionInfoOfServer() {
|
||||
return getSessionInfoOfServer(ServerInfo.getServerUUID_Old());
|
||||
return getSessionInfoOfServer(getServerUUID());
|
||||
}
|
||||
|
||||
public Map<UUID, Long> getLastSeenForAllPlayers() {
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plan.system.database.databases.sql.statements.Select;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -105,7 +104,7 @@ public class TPSTable extends Table {
|
||||
* @return @throws SQLException
|
||||
*/
|
||||
public List<TPS> getTPSData() {
|
||||
return getTPSData(ServerInfo.getServerUUID_Old());
|
||||
return getTPSData(getServerUUID());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,7 +137,7 @@ public class TPSTable extends Table {
|
||||
execute(new ExecStatement(insertStatement) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(1, getServerUUID().toString());
|
||||
statement.setLong(2, tps.getDate());
|
||||
statement.setDouble(3, tps.getTicksPerSecond());
|
||||
statement.setInt(4, tps.getPlayers());
|
||||
@ -194,7 +193,7 @@ public class TPSTable extends Table {
|
||||
}
|
||||
|
||||
public Optional<TPS> getPeakPlayerCount(long afterDate) {
|
||||
return getPeakPlayerCount(ServerInfo.getServerUUID_Old(), afterDate);
|
||||
return getPeakPlayerCount(getServerUUID(), afterDate);
|
||||
}
|
||||
|
||||
public Map<UUID, List<TPS>> getAllTPS() {
|
||||
|
@ -10,6 +10,7 @@ import com.google.common.base.Objects;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Abstract representation of a SQL database table.
|
||||
@ -44,11 +45,8 @@ public abstract class Table {
|
||||
}
|
||||
}
|
||||
|
||||
protected void renameTable(String to) {
|
||||
String sql = usingMySQL ?
|
||||
"RENAME TABLE " + tableName + " TO " + to :
|
||||
"ALTER TABLE " + tableName + " RENAME TO " + to;
|
||||
execute(sql);
|
||||
protected UUID getServerUUID() {
|
||||
return db.getServerUUIDSupplier().get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -90,7 +89,7 @@ public class TransferTable extends Table {
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(1, getServerUUID().toString());
|
||||
statement.setString(2, "onlineStatus");
|
||||
}
|
||||
});
|
||||
@ -100,7 +99,7 @@ public class TransferTable extends Table {
|
||||
execute(new ExecStatement(insertStatementNoParts) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(1, getServerUUID().toString());
|
||||
statement.setLong(2, System.currentTimeMillis() + TimeAmount.HOUR.ms());
|
||||
statement.setString(3, "configSettings");
|
||||
statement.setString(4, null);
|
||||
|
@ -11,7 +11,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatemen
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.*;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -69,7 +68,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setLong(2, registered);
|
||||
statement.setString(3, ServerInfo.getServerUUID_Old().toString());
|
||||
statement.setString(3, getServerUUID().toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -95,7 +94,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public boolean isRegistered(UUID uuid) {
|
||||
return isRegistered(uuid, ServerInfo.getServerUUID_Old());
|
||||
return isRegistered(uuid, getServerUUID());
|
||||
}
|
||||
|
||||
public void updateOpStatus(UUID uuid, boolean op) {
|
||||
@ -166,7 +165,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo(UUID uuid) {
|
||||
return getAllUserInfo(uuid).get(ServerInfo.getServerUUID_Old());
|
||||
return getAllUserInfo(uuid).get(getServerUUID());
|
||||
}
|
||||
|
||||
public List<UserInfo> getServerUserInfo(UUID serverUUID) {
|
||||
@ -213,7 +212,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
* @return List of UserInfo objects.
|
||||
*/
|
||||
public List<UserInfo> getServerUserInfo() {
|
||||
return getServerUserInfo(ServerInfo.getServerUUID_Old());
|
||||
return getServerUserInfo(getServerUUID());
|
||||
}
|
||||
|
||||
public Map<UUID, List<UserInfo>> getAllUserInfo() {
|
||||
@ -312,6 +311,10 @@ public class UserInfoTable extends UserIDTable {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isRegisteredOnThisServer(UUID player) {
|
||||
return isRegistered(player, getServerUUID());
|
||||
}
|
||||
|
||||
public enum Col implements Column {
|
||||
USER_ID(UserIDTable.Col.USER_ID.get()),
|
||||
SERVER_ID("server_id"),
|
||||
|
@ -8,7 +8,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -73,7 +72,7 @@ public class WorldTable extends Table {
|
||||
}
|
||||
|
||||
public List<String> getWorlds() {
|
||||
return getWorlds(ServerInfo.getServerUUID_Old());
|
||||
return getWorlds(getServerUUID());
|
||||
}
|
||||
|
||||
public List<String> getWorlds(UUID serverUUID) {
|
||||
@ -100,7 +99,7 @@ public class WorldTable extends Table {
|
||||
}
|
||||
|
||||
public void saveWorlds(Collection<String> worlds) {
|
||||
saveWorlds(worlds, ServerInfo.getServerUUID_Old());
|
||||
saveWorlds(worlds, getServerUUID());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,7 +12,6 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -143,7 +142,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
GMTimes gmTimes = entry.getValue();
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, worldName);
|
||||
String serverUUID = ServerInfo.getServerUUID_Old().toString();
|
||||
String serverUUID = getServerUUID().toString();
|
||||
statement.setString(3, serverUUID);
|
||||
statement.setString(4, serverUUID);
|
||||
statement.setInt(5, sessionID);
|
||||
|
@ -7,7 +7,6 @@ package com.djrapitops.plan.system.importing.data;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -49,8 +48,8 @@ public class UserImportData {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
public static UserImportDataBuilder builder() {
|
||||
return new UserImportDataBuilder();
|
||||
public static UserImportDataBuilder builder(UUID serverUUID) {
|
||||
return new UserImportDataBuilder(serverUUID);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -150,6 +149,8 @@ public class UserImportData {
|
||||
}
|
||||
|
||||
public static final class UserImportDataBuilder {
|
||||
private final UUID serverUUID;
|
||||
|
||||
private final List<Nickname> nicknames = new ArrayList<>();
|
||||
private final List<String> ips = new ArrayList<>();
|
||||
private final Map<String, GMTimes> worldTimes = new HashMap<>();
|
||||
@ -163,8 +164,8 @@ public class UserImportData {
|
||||
private int mobKills;
|
||||
private int deaths;
|
||||
|
||||
private UserImportDataBuilder() {
|
||||
/* Private Constructor */
|
||||
private UserImportDataBuilder(UUID serverUUID) {
|
||||
this.serverUUID = serverUUID;
|
||||
}
|
||||
|
||||
public UserImportDataBuilder name(String name) {
|
||||
@ -197,7 +198,6 @@ public class UserImportData {
|
||||
|
||||
public UserImportDataBuilder nicknames(String... nicknames) {
|
||||
long time = System.currentTimeMillis();
|
||||
UUID serverUUID = ServerInfo.getServerUUID_Old();
|
||||
|
||||
Arrays.stream(nicknames)
|
||||
.map(nick -> new Nickname(nick, time, serverUUID))
|
||||
|
@ -38,7 +38,7 @@ public abstract class Importer {
|
||||
|
||||
private final GeolocationCache geolocationCache;
|
||||
private final Database database;
|
||||
private final UUID serverUUID;
|
||||
protected final UUID serverUUID;
|
||||
|
||||
private final String name;
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class OfflinePlayerImporter extends Importer {
|
||||
Set<OfflinePlayer> banned = Bukkit.getBannedPlayers();
|
||||
|
||||
Arrays.stream(Bukkit.getOfflinePlayers()).parallel().forEach(player -> {
|
||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder();
|
||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder(serverUUID);
|
||||
builder.name(player.getName())
|
||||
.uuid(player.getUniqueId())
|
||||
.registered(player.getFirstPlayed());
|
||||
|
@ -5,7 +5,6 @@
|
||||
package com.djrapitops.plan.system.info.server;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.SubSystem;
|
||||
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
@ -28,18 +27,6 @@ public abstract class ServerInfo implements SubSystem {
|
||||
this.serverProperties = serverProperties;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ServerInfo getInstance() {
|
||||
ServerInfo serverInfo = PlanSystem.getInstance().getServerInfo();
|
||||
Verify.nullCheck(serverInfo, () -> new IllegalStateException("ServerInfo was not initialized."));
|
||||
return serverInfo;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static UUID getServerUUID_Old() {
|
||||
return getInstance().server.getUuid();
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class SQLiteTest {
|
||||
db.remove().everything();
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20));
|
||||
// assertEquals(ServerInfo.getServerUUID_Old(), TestConstants.SERVER_UUID); TODO check if assertion is required
|
||||
assertEquals(db.getServerUUIDSupplier().get(), TestConstants.SERVER_UUID);
|
||||
System.out.println("-- Clear Complete --\n");
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ImportBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyUserBuilder() {
|
||||
UserImportData data = UserImportData.builder().build();
|
||||
UserImportData data = UserImportData.builder(TestConstants.SERVER_UUID).build();
|
||||
|
||||
assertEquals(0, data.getRegistered());
|
||||
assertEquals(0, data.getTimesKicked());
|
||||
@ -122,7 +122,7 @@ public class ImportBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testUserDataBuilder() {
|
||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder();
|
||||
UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
PlayerKill playerKill = new PlayerKill(uuid, randomString, 1);
|
||||
|
@ -10,6 +10,8 @@ import org.junit.rules.TemporaryFolder;
|
||||
import utilities.TestConstants;
|
||||
import utilities.mocks.SystemMockUtil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class NetworkSettingsTest {
|
||||
|
||||
@ClassRule
|
||||
@ -43,7 +45,7 @@ public class NetworkSettingsTest {
|
||||
db.remove().everything();
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
serverTable.saveCurrentServerInfo(new Server(-1, TestConstants.SERVER_UUID, "ServerName", "", 20));
|
||||
// assertEquals(ServerInfo.getServerUUID_Old(), TestConstants.SERVER_UUID); TODO check if assert is necessary.
|
||||
assertEquals(db.getServerUUIDSupplier().get(), TestConstants.SERVER_UUID);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user