Fixed rest of Compile issues

This commit is contained in:
Rsl1122 2018-01-24 20:12:13 +02:00
parent ab87923420
commit 0d56a73125
45 changed files with 199 additions and 414 deletions

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.system.BukkitSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.importing.ImporterManager;
import com.djrapitops.plan.system.processing.importing.importers.OfflinePlayerImporter;
import com.djrapitops.plan.system.settings.locale.Locale;
@ -42,8 +41,6 @@ import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.UUID;
/**
* Main class for Bukkit that manages the plugin.
* <p>
@ -68,15 +65,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
return (Plan) StaticHolder.getInstance(Plan.class);
}
@Deprecated
public static UUID getServerUUID() {
return ServerInfo.getServerUUID();
}
public UUID getServerUuid() {
return ServerInfo.getServerUUID();
}
/**
* OnEnable method.
* <p>

View File

@ -8,20 +8,13 @@ import com.djrapitops.plan.command.PlanBungeeCommand;
import com.djrapitops.plan.system.BungeeSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.file.FileSystem;
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
import com.djrapitops.plan.system.info.server.ServerProperties;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.system.settings.theme.PlanColorScheme;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
@ -29,10 +22,8 @@ import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.task.RunnableFactory;
import java.io.InputStream;
import java.util.UUID;
/**
* Bungee Main class.
@ -53,28 +44,14 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return (PlanBungee) StaticHolder.getInstance(PlanBungee.class);
}
public static UUID getServerUUID() {
return getInstance().getServerUuid();
}
@Override
public void onEnable() {
super.onEnable();
try {
FileSystem.getInstance().enable();
ConfigSystem.getInstance().enable();
Log.setDebugMode(Settings.DEBUG.toString());
VersionCheckSystem.getInstance().enable();
variableHolder = new ServerProperties(getProxy());
new Locale().loadLocale();
Theme.getInstance().enable();
DBSystem.getInstance().enable();
system = new BungeeSystem(this);
system.enable();
// TODO BungeeServerInfo & move there.
String ip = variableHolder.getIp();
if ("0.0.0.0".equals(ip)) {
Log.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
@ -82,20 +59,7 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return;
}
Benchmark.start("WebServer Initialization");
serverInfoManager = new BungeeServerInfo(this);
WebServerSystem.getInstance().enable();
serverInfoManager.loadServerInfo();
TaskSystem.getInstance().enable();
Log.logDebug("Enable", "WebServer Initialization");
Log.info(Locale.get(Msg.ENABLED).toString());
if (Settings.ANALYSIS_EXPORT.isTrue()) {
RunnableFactory.createNew(new HtmlExport(this)).runTaskAsynchronously();
}
} catch (Exception e) {
Log.error("Plugin Failed to Initialize Correctly.");
Log.toLog(this.getClass().getName(), e);
@ -128,11 +92,8 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return DBSystem.getInstance().getActiveDatabase();
}
public BungeeServerInfo getServerInfoManager() {
return serverInfoManager;
}
@Override
@Deprecated
public WebServer getWebServer() {
return WebServerSystem.getInstance().getWebServer();
}
@ -147,18 +108,17 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return PlanColorScheme.create();
}
@Deprecated
public ServerProperties getVariable() {
return variableHolder;
}
public UUID getServerUuid() {
return serverInfoManager.getServerUUID();
}
@Deprecated
public boolean isSetupAllowed() {
return setupAllowed;
}
@Deprecated
public void setSetupAllowed(boolean setupAllowed) {
this.setupAllowed = setupAllowed;
}

View File

@ -12,7 +12,6 @@ import com.djrapitops.plugin.settings.ColorScheme;
import java.io.File;
import java.io.InputStream;
import java.util.UUID;
/**
* Abstraction interface for both Plan and PlanBungee.
@ -36,9 +35,6 @@ public interface PlanPlugin extends IPlugin {
@Deprecated
Database getDB();
@Deprecated
UUID getServerUuid();
@Deprecated
WebServer getWebServer();

View File

@ -1,6 +1,8 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
@ -10,7 +12,6 @@ import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import com.djrapitops.plugin.settings.ColorScheme;
import java.sql.SQLException;
import java.util.Map;
/**
@ -45,13 +46,13 @@ public class ListServersCommand extends SubCommand {
String tCol = colorScheme.getTertiaryColor();
try {
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString() + mCol + " Servers");
Map<Integer, String> serverNames = plugin.getDB().getServerTable().getServerNamesByID();
Map<Integer, String> serverNames = Database.getActive().fetch().getServerNamesByID();
for (Map.Entry<Integer, String> entry : serverNames.entrySet()) {
sender.sendMessage(" " + tCol + entry.getKey() + sCol + " : " + entry.getValue());
}
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
} catch (SQLException e) {
sender.sendMessage("§cSQLException occurred.");
} catch (DBException e) {
sender.sendMessage("§cDatabase Exception occurred.");
Log.toLog(this.getClass().getName(), e);
}
return true;

View File

@ -2,7 +2,7 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.sql.tables.SecurityTable;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
@ -121,12 +121,12 @@ public class RegisterCommand extends SubCommand {
final String userName = webUser.getName();
final String successMsg = "§aAdded a new user (" + userName + ") successfully!";
try {
SecurityTable securityTable = plugin.getDB().getSecurityTable();
boolean userExists = securityTable.userExists(userName);
Database database = Database.getActive();
boolean userExists = database.check().doesWebUserExists(userName);
if (!Condition.isTrue(!userExists, existsMsg, sender)) {
return;
}
securityTable.addNewUser(webUser);
database.save().webUser(webUser);
sender.sendMessage(successMsg);
Log.info("Registered new user: " + userName + " Perm level: " + webUser.getPermLevel());
} catch (Exception e) {

View File

@ -50,8 +50,8 @@ public class WebUserCommand extends TreeCommand<PlanPlugin> {
add(
new WebLevelCommand(plugin),
new WebListUsersCommand(plugin),
new WebCheckCommand(plugin),
new WebDeleteCommand(plugin)
new WebCheckCommand(),
new WebDeleteCommand()
);
}
}

View File

@ -3,11 +3,11 @@ package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
import com.djrapitops.plan.system.webserver.webapi.bungee.RequestSetupWebAPI;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.command.CommandType;
@ -66,8 +66,9 @@ public class ManageSetupCommand extends SubCommand {
try {
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
Settings.BUNGEE_COPY_CONFIG.set(true);
// plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address);
plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address);
InfoSystem.getInstance().requestSetUp(address);
sender.sendMessage("§eConnection successful, Plan may restart in a few seconds, if it doesn't something has gone wrong.");
} catch (ForbiddenException e) {
sender.sendMessage("§eConnection succeeded, but Bungee has set-up mode disabled - use '/planbungee setup' to enable it.");

View File

@ -1,8 +1,7 @@
package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.sql.tables.SecurityTable;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
@ -23,15 +22,12 @@ import org.bukkit.ChatColor;
*/
public class WebCheckCommand extends SubCommand {
private final PlanPlugin plugin;
public WebCheckCommand(PlanPlugin plugin) {
public WebCheckCommand() {
super("check",
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB_CHECK).toString(),
"<username>");
this.plugin = plugin;
}
@Override
@ -39,17 +35,17 @@ public class WebCheckCommand extends SubCommand {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
return true;
}
SecurityTable table = plugin.getDB().getSecurityTable();
Database database = Database.getActive();
String user = args[0];
RunnableFactory.createNew(new AbsRunnable("Webuser Check Task: " + user) {
@Override
public void run() {
try {
if (!Condition.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
if (!Condition.isTrue(database.check().doesWebUserExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
return;
}
WebUser info = table.getWebUser(user);
WebUser info = database.fetch().getWebUser(user);
sender.sendMessage(info.getName() + ": Permission level: " + info.getPermLevel());
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);

View File

@ -1,7 +1,6 @@
package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.databases.sql.tables.SecurityTable;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
@ -22,15 +21,12 @@ import net.md_5.bungee.api.ChatColor;
*/
public class WebDeleteCommand extends SubCommand {
private final PlanPlugin plugin;
public WebDeleteCommand(PlanPlugin plugin) {
public WebDeleteCommand() {
super("delete, remove",
CommandType.PLAYER_OR_ARGS,
Permissions.MANAGE_WEB.getPerm(),
Locale.get(Msg.CMD_USG_WEB_DELETE).toString(),
"<username>");
this.plugin = plugin;
}
@Override
@ -38,17 +34,17 @@ public class WebDeleteCommand extends SubCommand {
if (!Condition.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).parse() + " <username>", sender)) {
return true;
}
SecurityTable table = plugin.getDB().getSecurityTable();
Database database = Database.getActive();
String user = args[0];
RunnableFactory.createNew(new AbsRunnable("Webuser Delete Task: " + user) {
@Override
public void run() {
try {
if (!Condition.isTrue(table.userExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
if (!Condition.isTrue(database.check().doesWebUserExists(user), ChatColor.RED + "[Plan] User Doesn't exist.", sender)) {
return;
}
table.removeUser(user);
database.remove().webUser(user);
sender.sendMessage(Locale.get(Msg.MANAGE_INFO_SUCCESS).parse());
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.command.commands.webuser;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.settings.locale.Locale;
import com.djrapitops.plan.system.settings.locale.Msg;
@ -39,7 +40,7 @@ public class WebListUsersCommand extends SubCommand {
try {
ColorScheme cs = plugin.getColorScheme();
String mCol = cs.getMainColor();
List<WebUser> users = plugin.getDB().getSecurityTable().getUsers();
List<WebUser> users = Database.getActive().fetch().getWebUsers();
users.sort(new WebUserComparator());
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse() + mCol + " WebUsers (" + users.size() + ")");
for (WebUser user : users) {

View File

@ -4,13 +4,13 @@
*/
package com.djrapitops.plan.data;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.data.container.Action;
import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.element.ActivityIndex;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.comparators.ActionComparator;
import com.djrapitops.plan.utilities.comparators.GeoInfoComparator;
@ -335,7 +335,7 @@ public class PlayerProfile implements OfflinePlayer {
}
public void addActiveSession(Session activeSession) {
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
UUID serverUUID = ServerInfo.getServerUUID();
List<Session> sessions = getSessions(serverUUID);
sessions.add(activeSession);
this.sessions.put(serverUUID, sessions);
@ -478,7 +478,7 @@ public class PlayerProfile implements OfflinePlayer {
@Override
public long getLastPlayed() {
return getLastSeen(PlanPlugin.getInstance().getServerUuid());
return getLastSeen(ServerInfo.getServerUUID());
}
@Override
@ -498,7 +498,7 @@ public class PlayerProfile implements OfflinePlayer {
@Override
public boolean isOp() {
return oppedOnServers.contains(PlanPlugin.getInstance().getServerUuid());
return oppedOnServers.contains(ServerInfo.getServerUUID());
}
@Override
@ -507,7 +507,7 @@ public class PlayerProfile implements OfflinePlayer {
}
public void calculateWorldTimesPerServer() {
if (worldTimesMap.containsKey(PlanPlugin.getInstance().getServerUuid())) {
if (worldTimesMap.containsKey(ServerInfo.getServerUUID())) {
return;
}

View File

@ -78,4 +78,8 @@ public interface FetchOperations {
List<String> getNicknames(UUID uuid) throws DBException;
Map<UUID, Server> getBukkitServers() throws DBException;
List<WebUser> getWebUsers() throws DBException;
Map<Integer, String> getServerNamesByID() throws DBException;
}

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.system.database.databases.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.data.container.*;
import com.djrapitops.plan.system.info.server.Server;
@ -67,4 +68,6 @@ public interface SaveOperations {
void session(UUID uuid, Session session) throws DBException;
void serverInfoForThisServer(Server server) throws DBException;
void webUser(WebUser webUser) throws DBException;
}

View File

@ -361,4 +361,31 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public Map<UUID, Server> getBukkitServers() throws DBException {
try {
return serverTable.getBukkitServers();
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public List<WebUser> getWebUsers() throws DBException {
try {
return securityTable.getUsers();
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public Map<Integer, String> getServerNamesByID() throws DBException {
try {
return serverTable.getServerNamesByID();
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.data.container.*;
import com.djrapitops.plan.system.database.databases.operation.SaveOperations;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
@ -214,4 +215,13 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
throw SQLErrorUtil.getExceptionFor(e);
}
}
@Override
public void webUser(WebUser webUser) throws DBException {
try {
securityTable.addNewUser(webUser);
} catch (SQLException e) {
throw SQLErrorUtil.getExceptionFor(e);
}
}
}

View File

@ -4,7 +4,6 @@
*/
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.data.Actions;
import com.djrapitops.plan.data.container.Action;
@ -15,6 +14,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
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;
@ -86,7 +86,7 @@ public class ActionsTable extends UserIDTable {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
statement.setString(2, Plan.getServerUUID().toString());
statement.setString(2, ServerInfo.getServerUUID().toString());
statement.setInt(3, action.getDoneAction().getId());
statement.setLong(4, action.getDate());
statement.setString(5, action.getAdditionalInfo());

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
@ -9,6 +8,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
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;
@ -62,7 +62,7 @@ public class CommandUseTable extends Table {
* @throws SQLException DB Error
*/
public Map<String, Integer> getCommandUse() throws SQLException {
return getCommandUse(Plan.getServerUUID());
return getCommandUse(ServerInfo.getServerUUID());
}
/**
@ -110,7 +110,7 @@ public class CommandUseTable extends Table {
boolean updated = execute(new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, Plan.getServerUUID().toString());
statement.setString(1, ServerInfo.getServerUUID().toString());
statement.setString(2, command);
}
});
@ -125,7 +125,7 @@ public class CommandUseTable extends Table {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, command);
statement.setInt(2, 1);
statement.setString(3, Plan.getServerUUID().toString());
statement.setString(3, ServerInfo.getServerUUID().toString());
}
});
}

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
@ -8,6 +7,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStat
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
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;
@ -104,7 +104,7 @@ public class NicknamesTable extends UserIDTable {
* @throws SQLException when an error at retrieval happens
*/
public List<String> getNicknames(UUID uuid) throws SQLException {
return getNicknames(uuid, Plan.getServerUUID());
return getNicknames(uuid, ServerInfo.getServerUUID());
}
/**
@ -156,7 +156,7 @@ public class NicknamesTable extends UserIDTable {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
statement.setString(2, Plan.getServerUUID().toString());
statement.setString(2, ServerInfo.getServerUUID().toString());
statement.setString(3, displayName);
}
});

View File

@ -280,24 +280,25 @@ public class ServerTable extends Table {
});
}
public List<Server> getBukkitServers() throws SQLException {
public Map<UUID, Server> getBukkitServers() throws SQLException {
String sql = Select.from(tableName, "*")
.where(columnServerName + "!=?")
.toString();
return query(new QueryStatement<List<Server>>(sql, 100) {
return query(new QueryStatement<Map<UUID, Server>>(sql, 100) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, "BungeeCord");
}
@Override
public List<Server> processResults(ResultSet set) throws SQLException {
List<Server> servers = new ArrayList<>();
public Map<UUID, Server> processResults(ResultSet set) throws SQLException {
Map<UUID, Server> servers = new HashMap<>();
while (set.next()) {
servers.add(new Server(
UUID serverUUID = UUID.fromString(set.getString(columnServerUUID));
servers.put(serverUUID, new Server(
set.getInt(columnServerID),
UUID.fromString(set.getString(columnServerUUID)),
serverUUID,
set.getString(columnServerName),
set.getString(columnWebserverAddress),
set.getInt(columnMaxPlayers)));

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
@ -10,6 +9,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryStateme
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;
@ -105,7 +105,7 @@ public class SessionsTable extends UserIDTable {
statement.setLong(3, session.getSessionEnd());
statement.setInt(4, session.getDeaths());
statement.setInt(5, session.getMobKills());
statement.setString(6, Plan.getServerUUID().toString());
statement.setString(6, ServerInfo.getServerUUID().toString());
}
});
}
@ -204,7 +204,7 @@ public class SessionsTable extends UserIDTable {
* @throws SQLException DB Error
*/
public long getPlaytime(UUID uuid) throws SQLException {
return getPlaytime(uuid, Plan.getServerUUID());
return getPlaytime(uuid, ServerInfo.getServerUUID());
}
/**
@ -216,7 +216,7 @@ public class SessionsTable extends UserIDTable {
* @throws SQLException DB Error
*/
public long getPlaytime(UUID uuid, long afterDate) throws SQLException {
return getPlaytime(uuid, Plan.getServerUUID(), afterDate);
return getPlaytime(uuid, ServerInfo.getServerUUID(), afterDate);
}
/**
@ -321,7 +321,7 @@ public class SessionsTable extends UserIDTable {
* @throws SQLException DB Error
*/
public long getPlaytimeOfServer() throws SQLException {
return getPlaytimeOfServer(Plan.getServerUUID());
return getPlaytimeOfServer(ServerInfo.getServerUUID());
}
/**
@ -343,7 +343,7 @@ public class SessionsTable extends UserIDTable {
* @throws SQLException DB Error
*/
public long getPlaytimeOfServer(long afterDate) throws SQLException {
return getPlaytimeOfServer(Plan.getServerUUID(), afterDate);
return getPlaytimeOfServer(ServerInfo.getServerUUID(), afterDate);
}
/**
@ -398,7 +398,7 @@ public class SessionsTable extends UserIDTable {
* @throws SQLException DB Error
*/
public int getSessionCount(UUID uuid, long afterDate) throws SQLException {
return getSessionCount(uuid, Plan.getServerUUID(), afterDate);
return getSessionCount(uuid, ServerInfo.getServerUUID(), afterDate);
}
/**
@ -453,7 +453,7 @@ public class SessionsTable extends UserIDTable {
}
public Map<UUID, List<Session>> getSessionInfoOfServer() throws SQLException {
return getSessionInfoOfServer(Plan.getServerUUID());
return getSessionInfoOfServer(ServerInfo.getServerUUID());
}
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) throws SQLException {

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
@ -11,6 +10,7 @@ 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.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.utilities.Verify;
@ -77,7 +77,7 @@ public class TPSTable extends Table {
* @return @throws SQLException
*/
public List<TPS> getTPSData() throws SQLException {
return getTPSData(PlanPlugin.getInstance().getServerUuid());
return getTPSData(ServerInfo.getServerUUID());
}
public List<TPS> getTPSData(UUID serverUUID) throws SQLException {
@ -113,7 +113,7 @@ public class TPSTable extends Table {
execute(new ExecStatement(insertStatement) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, PlanPlugin.getInstance().getServerUuid().toString());
statement.setString(1, ServerInfo.getServerUUID().toString());
statement.setLong(2, tps.getDate());
statement.setDouble(3, tps.getTicksPerSecond());
statement.setInt(4, tps.getPlayers());
@ -163,7 +163,7 @@ public class TPSTable extends Table {
}
public Optional<TPS> getPeakPlayerCount(long afterDate) throws SQLException {
return getPeakPlayerCount(PlanPlugin.getInstance().getServerUuid(), afterDate);
return getPeakPlayerCount(ServerInfo.getServerUUID(), afterDate);
}
public Optional<TPS> getPeakPlayerCount(UUID serverUUID, long afterDate) throws SQLException {

View File

@ -4,8 +4,6 @@
*/
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.data.container.UserInfo;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
@ -16,6 +14,7 @@ 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.database.databases.sql.statements.Update;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.utilities.Verify;
import java.sql.PreparedStatement;
@ -76,13 +75,13 @@ public class UserInfoTable extends UserIDTable {
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, uuid.toString());
statement.setLong(2, registered);
statement.setString(3, Plan.getServerUUID().toString());
statement.setString(3, ServerInfo.getServerUUID().toString());
}
});
}
public boolean isRegistered(UUID uuid) throws SQLException {
return isRegistered(uuid, PlanPlugin.getInstance().getServerUuid());
return isRegistered(uuid, ServerInfo.getServerUUID());
}
public boolean isRegistered(UUID uuid, UUID serverUUID) throws SQLException {
@ -134,7 +133,7 @@ public class UserInfoTable extends UserIDTable {
}
public UserInfo getUserInfo(UUID uuid) throws SQLException {
return getAllUserInfo(uuid).get(PlanPlugin.getInstance().getServerUuid());
return getAllUserInfo(uuid).get(ServerInfo.getServerUUID());
}
public Map<UUID, UserInfo> getAllUserInfo(UUID uuid) throws SQLException {
@ -182,7 +181,7 @@ public class UserInfoTable extends UserIDTable {
* @return List of UserInfo objects.
*/
public List<UserInfo> getServerUserInfo() throws SQLException {
return getServerUserInfo(Plan.getServerUUID());
return getServerUserInfo(ServerInfo.getServerUUID());
}
public List<UserInfo> getServerUserInfo(UUID serverUUID) throws SQLException {

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
@ -8,6 +7,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStat
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
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;
@ -108,7 +108,7 @@ public class WorldTable extends Table {
}
public Set<String> getWorldNames() throws SQLException {
return getWorldNames(PlanPlugin.getInstance().getServerUuid());
return getWorldNames(ServerInfo.getServerUUID());
}
public Set<String> getWorldNames(UUID serverUUID) throws SQLException {

View File

@ -1,6 +1,5 @@
package com.djrapitops.plan.system.database.databases.sql.tables;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.time.GMTimes;
@ -11,6 +10,7 @@ import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStat
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
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;
@ -152,7 +152,7 @@ public class WorldTimesTable extends UserIDTable {
}
public WorldTimes getWorldTimesOfServer() throws SQLException {
return getWorldTimesOfServer(Plan.getServerUUID());
return getWorldTimesOfServer(ServerInfo.getServerUUID());
}
public WorldTimes getWorldTimesOfServer(UUID serverUUID) throws SQLException {

View File

@ -14,6 +14,7 @@ import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -140,7 +141,7 @@ public class BatchOperationTable extends Table {
}
Log.debug("Batch Copy Servers");
ServerTable serverTable = db.getServerTable();
List<Server> servers = serverTable.getBukkitServers();
List<Server> servers = new ArrayList<>(serverTable.getBukkitServers().values());
serverTable.getBungeeInfo().ifPresent(servers::add);
toDB.getDb().getServerTable().insertAllServers(servers);
}

View File

@ -4,10 +4,10 @@
*/
package com.djrapitops.plan.system.database.databases.sql.tables.move;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBCreateTableException;
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 com.djrapitops.plugin.api.Benchmark;
import java.sql.SQLException;
@ -26,7 +26,7 @@ public class Version8TransferTable extends Table {
public Version8TransferTable(SQLDB db) throws SQLException {
super("", db);
Optional<Integer> serverID = db.getServerTable().getServerID(Plan.getServerUUID());
Optional<Integer> serverID = db.getServerTable().getServerID(ServerInfo.getServerUUID());
if (!serverID.isPresent()) {
throw new IllegalStateException("Server UUID was not registered, try rebooting the plugin.");
}

View File

@ -4,7 +4,6 @@
*/
package com.djrapitops.plan.system.info;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.PlanSystem;
@ -13,6 +12,7 @@ import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
import com.djrapitops.plan.system.info.request.GenerateInspectPageRequest;
import com.djrapitops.plan.system.info.request.InfoRequest;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.utilities.NullCheck;
import com.djrapitops.plugin.api.utility.log.Log;
@ -44,12 +44,12 @@ public abstract class InfoSystem implements SubSystem {
}
public void generateAnalysisPageOfThisServer() throws WebException {
generateAnalysisPage(Plan.getServerUUID());
generateAnalysisPage(ServerInfo.getServerUUID());
}
public void generateAnalysisPage(UUID serverUUID) throws WebException {
GenerateAnalysisPageRequest request = new GenerateAnalysisPageRequest(serverUUID);
if (Plan.getServerUUID().equals(serverUUID)) {
if (ServerInfo.getServerUUID().equals(serverUUID)) {
runLocally(request);
} else {
sendRequest(request);
@ -86,4 +86,8 @@ public abstract class InfoSystem implements SubSystem {
}
public abstract void updateNetworkPage() throws WebException;
public void requestSetUp(String address) {
// TODO
}
}

View File

@ -6,18 +6,12 @@ package com.djrapitops.plan.system.info.server;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.tables.ServerTable;
import com.djrapitops.plan.system.webserver.webapi.bukkit.ConfigurationWebAPI;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plan.system.webserver.WebServerSystem;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.Optional;
import java.util.UUID;
/**
* Manages Server information on the Bungee instance.
@ -26,158 +20,47 @@ import java.util.stream.Collectors;
*/
public class BungeeServerInfo extends ServerInfo {
private final PlanBungee plugin;
private final Database db;
private final Map<UUID, Server> bukkitServers;
private final Set<UUID> onlineServers;
private Server server;
private ServerTable serverTable;
public BungeeServerInfo(PlanBungee plugin) {
this.plugin = plugin;
this.db = plugin.getDB();
serverTable = db.getServerTable();
bukkitServers = new HashMap<>();
onlineServers = new HashSet<>();
serverProperties = new ServerProperties(plugin.getProxy());
}
public void loadServerInfo() throws EnableException {
public Server loadServerInfo() throws EnableException {
try {
Optional<Server> bungeeInfo = db.getServerTable().getBungeeInfo();
Database db = Database.getActive();
Optional<Server> bungeeInfo = db.fetch().getBungeeInformation();
if (bungeeInfo.isPresent()) {
server = bungeeInfo.get();
String accessAddress = plugin.getWebServer().getAccessAddress();
String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
if (!accessAddress.equals(server.getWebAddress())) {
server.setWebAddress(accessAddress);
serverTable.saveCurrentServerInfo(server);
db.save().serverInfoForThisServer(server);
}
} else {
server = registerBungeeInfo();
server = registerBungeeInfo(db);
}
} catch (SQLException e) {
} catch (DBException e) {
throw new EnableException("Failed to read Database for Server");
}
return null;
}
private Server registerBungeeInfo() throws SQLException, EnableException {
ServerProperties variable = plugin.getVariable();
UUID serverUUID = generateNewUUID(variable);
String accessAddress = plugin.getWebServer().getAccessAddress();
private Server registerBungeeInfo(Database db) throws DBException, EnableException {
ServerProperties properties = ServerInfo.getServerProperties();
UUID serverUUID = generateNewUUID(properties);
String accessAddress = WebServerSystem.getInstance().getWebServer().getAccessAddress();
serverTable.saveCurrentServerInfo(
new Server(-1, serverUUID, "BungeeCord", accessAddress, variable.getMaxPlayers())
);
Server bungeeCord = new Server(-1, serverUUID, "BungeeCord", accessAddress, properties.getMaxPlayers());
db.save().serverInfoForThisServer(bungeeCord);
Optional<Server> bungeeInfo = db.getServerTable().getBungeeInfo();
Optional<Server> bungeeInfo = db.fetch().getBungeeInformation();
if (bungeeInfo.isPresent()) {
return bungeeInfo.get();
}
throw new EnableException("BungeeCord registration failed (DB)");
}
private UUID generateNewUUID(ServerProperties variableHolder) {
String seed = variableHolder.getName() + variableHolder.getIp() + variableHolder.getPort() + variableHolder.getVersion() + variableHolder.getImplVersion();
private UUID generateNewUUID(ServerProperties properties) {
String seed = properties.getName() + properties.getIp() + properties.getPort() + properties.getVersion() + properties.getImplVersion();
return UUID.nameUUIDFromBytes(seed.getBytes());
}
public UUID getServerUUID() {
return server.getUuid();
}
public boolean attemptConnection(Server server, String accessCode) {
if (server == null) {
Log.debug("Attempted a connection to a null Server");
return false;
}
try {
String webAddress = server.getWebAddress();
Log.debug("Attempting to connect to Bukkit server.. (" + webAddress + ")");
plugin.getWebServer().getWebAPI().getAPI(ConfigurationWebAPI.class).sendRequest(webAddress, server.getUuid(), accessCode);
connectedToServer(server);
return true;
} catch (WebException e) {
Log.debug(e.toString());
serverHasGoneOffline(server.getUuid());
return false;
}
}
public boolean attemptConnection(Server server) {
return attemptConnection(server, null);
}
public void sendConfigSettings(UUID serverUUID) {
String webAddress = null;
try {
Server server = bukkitServers.get(serverUUID);
if (server == null) {
return;
}
webAddress = server.getWebAddress();
Log.debug("Sending config settings to " + webAddress + "");
plugin.getWebServer().getWebAPI().getAPI(ConfigurationWebAPI.class).sendRequest(webAddress, serverUUID);
} catch (WebException e) {
Log.info("Connection to Bukkit (" + webAddress + ") did not succeed.");
serverHasGoneOffline(serverUUID);
}
}
public void connectedToServer(Server server) {
Log.info("Connection to Bukkit (" + server.getWebAddress() + ") OK");
bukkitServers.put(server.getUuid(), server);
onlineServers.add(server.getUuid());
}
public boolean serverConnected(UUID serverUUID) {
if (plugin.getServerUuid().equals(serverUUID)) {
return false;
}
Log.info("Received a connection from a Bukkit server..");
if (onlineServers.contains(serverUUID)) {
RunnableFactory.createNew("BukkitRebootedConnectionTask: " + serverUUID, new AbsRunnable() {
@Override
public void run() {
sendConfigSettings(serverUUID);
connectedToServer(bukkitServers.get(serverUUID));
this.cancel();
}
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 3L);
return true;
}
try {
Optional<Server> serverInfo = db.getServerTable().getServerInfo(serverUUID);
if (serverInfo.isPresent()) {
Server server = serverInfo.get();
Log.info("Server Info found from DB: " + server.getName());
RunnableFactory.createNew("BukkitConnectionTask: " + server.getName(), new AbsRunnable() {
@Override
public void run() {
attemptConnection(server);
sendConfigSettings(serverUUID);
this.cancel();
}
}).runTaskLaterAsynchronously(TimeAmount.SECOND.ticks() * 3L);
return true;
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
return false;
}
public Collection<Server> getOnlineBukkitServers() {
return bukkitServers.entrySet().stream()
.filter(entry -> onlineServers.contains(entry.getKey()))
.map(Map.Entry::getValue)
.collect(Collectors.toSet());
}
public Collection<Server> getBukkitServers() {
return bukkitServers.values();
}
public void serverHasGoneOffline(UUID serverUUID) {
onlineServers.remove(serverUUID);
}
}

View File

@ -8,6 +8,7 @@ import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.cache.DataCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.ProcessingQueue;
import com.djrapitops.plan.system.processing.processors.NewNickActionProcessor;
import com.djrapitops.plugin.api.utility.log.Log;
@ -59,7 +60,7 @@ public class NameProcessor extends PlayerProcessor {
}
private void cueNameChangeActionProcessor(UUID uuid, Database db) throws DBException {
List<String> nicknames = db.fetch().getNicknamesOfPlayerOnServer(uuid, Plan.getServerUUID());
List<String> nicknames = db.fetch().getNicknamesOfPlayerOnServer(uuid, ServerInfo.getServerUUID());
if (nicknames.contains(displayName)) {
return;
}

View File

@ -5,9 +5,11 @@
package com.djrapitops.plan.system.tasks;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.tasks.bukkit.NetworkPageRefreshTask;
import com.djrapitops.plan.system.tasks.bungee.BungeeTPSCountTimer;
import com.djrapitops.plan.system.tasks.bungee.EnableConnectionTask;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.api.TimeAmount;
/**
@ -17,8 +19,11 @@ import com.djrapitops.plugin.api.TimeAmount;
*/
public class BungeeTaskSystem extends TaskSystem {
private final PlanBungee plugin;
public BungeeTaskSystem(PlanBungee plugin) {
tpsCountTimer = new BungeeTPSCountTimer(plugin);
this.plugin = plugin;
}
@Override
@ -30,5 +35,8 @@ public class BungeeTaskSystem extends TaskSystem {
registerTask(new EnableConnectionTask()).runTaskAsynchronously();
registerTask(tpsCountTimer).runTaskTimerAsynchronously(1000, TimeAmount.SECOND.ticks());
registerTask(new NetworkPageRefreshTask()).runTaskTimerAsynchronously(1500, TimeAmount.MINUTE.ticks());
if (Settings.ANALYSIS_EXPORT.isTrue()) {
registerTask(new HtmlExport(plugin)).runTaskAsynchronously();
}
}
}

View File

@ -4,15 +4,17 @@
*/
package com.djrapitops.plan.system.webserver.pages;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.WebUserAuthException;
import com.djrapitops.plan.api.exceptions.database.DBException;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.Request;
import com.djrapitops.plan.system.webserver.auth.Authentication;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.List;
import java.util.Optional;
@ -32,7 +34,7 @@ public class ServerPageHandler extends PageHandler {
}
private UUID getServerUUID(List<String> target) {
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
UUID serverUUID = ServerInfo.getServerUUID();
if (!target.isEmpty()) {
try {
String serverName = target.get(0).replace("%20", " ");
@ -42,6 +44,8 @@ public class ServerPageHandler extends PageHandler {
}
} catch (IllegalArgumentException ignore) {
/*ignored*/
} catch (DBException e) {
Log.toLog(this.getClass(), e);
}
}
return serverUUID;

View File

@ -4,7 +4,6 @@
*/
package com.djrapitops.plan.system.webserver.pages.parsing;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.data.PlayerProfile;
import com.djrapitops.plan.data.container.Action;
@ -14,6 +13,7 @@ import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.settings.theme.ThemeVal;
@ -66,7 +66,7 @@ public class InspectPage extends Page {
if (profile == null) {
throw new IllegalStateException("Player profile was null!");
}
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
UUID serverUUID = ServerInfo.getServerUUID();
Map<UUID, String> serverNames = db.fetch().getServerNames();
Benchmark.stop("Inspect Parse, Fetch");

View File

@ -4,12 +4,10 @@
*/
package com.djrapitops.plan.system.webserver.response.pages;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.info.connection.ConnectionLog;
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.info.server.ServerProperties;
@ -18,7 +16,6 @@ import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.file.FileUtil;
import com.djrapitops.plan.utilities.html.Html;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.ErrorLogger;
import com.djrapitops.plugin.api.utility.log.Log;
@ -57,11 +54,6 @@ public class DebugPageResponse extends ErrorResponse {
appendServerInformation(content);
appendConnectionLog(content);
if (Check.isBungeeAvailable()) {
appendBungeeConfiguration(content);
}
appendLoggedErrors(content);
appendDebugLog(content);
appendBenchmarks(content);
@ -75,7 +67,7 @@ public class DebugPageResponse extends ErrorResponse {
Map<Server, Map<String, ConnectionLog.Entry>> logEntries = ConnectionLog.getLogEntries();
content.append("<pre>");
content.append("Server name | Request Type | Sent | Response<br>")
content.append("Server Address | Request Type | Sent | Response<br>")
.append("-- | -- | -- | --<br>");
for (Map.Entry<Server, Map<String, ConnectionLog.Entry>> entry : logEntries.entrySet()) {
Server server = entry.getKey();
@ -84,7 +76,7 @@ public class DebugPageResponse extends ErrorResponse {
String infoRequest = requestEntry.getKey();
ConnectionLog.Entry logEntry = requestEntry.getValue();
content.append(server.getName()).append(" | ")
content.append(server.getWebAddress()).append(" | ")
.append(infoRequest).append(" | ")
.append(logEntry.getResponseCode()).append(" | ")
.append(FormatUtils.formatTimeStampSecond(logEntry.getTimeSent())).append("<br>");
@ -165,35 +157,6 @@ public class DebugPageResponse extends ErrorResponse {
}
}
private void appendBungeeConfiguration(StringBuilder content) {
PlanBungee plugin = PlanBungee.getInstance();
BungeeServerInfo serverInfoManager = plugin.getServerInfoManager();
Collection<Server> online = serverInfoManager.getOnlineBukkitServers();
Collection<Server> bukkitServers = serverInfoManager.getBukkitServers();
if (!bukkitServers.isEmpty()) {
content.append("<p>If your issue is about Bungee-Bukkit connection relations, please include the following debug information of available servers as well:</p>");
for (Server info : bukkitServers) {
String link = Html.LINK.parse(info.getWebAddress() + "/debug", info.getWebAddress() + "/debug");
content.append("<p>").append(link).append("</p>");
}
}
content.append("<pre>### Bungee Configuration<br>");
content.append("Server name | Online | Address | UUID<br>")
.append("-- | -- | -- | --<br>");
for (Server info : bukkitServers) {
content.append(info.getName()).append(" | ")
.append(online.contains(info) ? "Online" : "Offline").append(" | ")
.append(info.getWebAddress()).append(" | ")
.append(info.getUuid()).append("<br>");
}
content.append("</pre>");
}
private void appendBenchmarks(StringBuilder content) {
content.append("<pre>### Benchmarks<br>&#96;&#96;&#96;<br>");
try {

View File

@ -6,6 +6,7 @@ package com.djrapitops.plan.system.webserver.webapi;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.*;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.api.BadRequestResponse;
@ -192,7 +193,7 @@ public abstract class WebAPI {
private String parseVariables() {
StringBuilder parameters = new StringBuilder();
String serverUUID = PlanPlugin.getInstance().getServerUuid().toString();
String serverUUID = ServerInfo.getServerUUID().toString();
parameters.append("sender=").append(serverUUID);
for (Map.Entry<String, String> entry : variables.entrySet()) {
parameters.append(";&variable;").append(entry.getKey()).append("=").append(entry.getValue());

View File

@ -6,16 +6,10 @@ package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.processing.processors.Processor;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
import com.djrapitops.plan.system.webserver.webapi.bukkit.RequestInspectPluginsTabBukkitWebAPI;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -58,23 +52,5 @@ public class RequestPluginsTabWebAPI extends WebAPI {
}
public void sendRequestsToBukkitServers(PlanPlugin plugin, UUID uuid) {
new Processor<UUID>(uuid) {
@Override
public void process() {
try {
List<Server> bukkitServers = plugin.getDB().getServerTable().getBukkitServers();
for (Server server : bukkitServers) {
String webAddress = server.getWebAddress();
try {
plugin.getWebServer().getWebAPI().getAPI(RequestInspectPluginsTabBukkitWebAPI.class).sendRequest(webAddress, uuid);
} catch (WebException ignore) {
/* ignored */
}
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
}
}.queue();
}
}

View File

@ -4,49 +4,26 @@
*/
package com.djrapitops.plan.system.webserver.webapi.bungee;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.errors.ForbiddenResponse;
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Map;
import java.util.UUID;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
@Deprecated
public class RequestSetupWebAPI extends WebAPI {
@Override
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
if (!Check.isBungeeAvailable()) {
return badRequest("Called a Bukkit server.");
}
if (!((PlanBungee) plugin).isSetupAllowed()) {
return new ForbiddenResponse("Setup mode disabled, use /planbungee setup to enable");
}
String serverUUIDS = variables.get("sender");
String webAddress = variables.get("webAddress");
String accessCode = variables.get("accessKey");
if (!Verify.notNull(serverUUIDS, webAddress, accessCode)) {
return badRequest("Variable was null");
}
Server server = new Server(-1, UUID.fromString(serverUUIDS), "", webAddress, 0);
((PlanBungee) plugin).getServerInfoManager().attemptConnection(server, accessCode);
return success();
return fail("Deprecated");
}
@Override
@ -56,11 +33,6 @@ public class RequestSetupWebAPI extends WebAPI {
}
Plan plugin = Plan.getInstance();
try {
addVariable("accessKey", plugin.getWebServer().getWebAPI().generateNewAccessKey());
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
}
addVariable("webAddress", plugin.getWebServer().getAccessAddress());
super.sendRequest(address);
}

View File

@ -9,6 +9,7 @@ import com.djrapitops.plan.data.element.ActivityIndex;
import com.djrapitops.plan.data.time.GMTimes;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.api.utility.log.Log;
@ -142,7 +143,7 @@ public class AnalysisUtils {
// Add 0 time for worlds not present.
Set<String> nonZeroWorlds = worldTimes.getWorldTimes().keySet();
PlanPlugin plugin = PlanPlugin.getInstance();
for (String world : Database.getActive().fetch().getWorldNames(plugin.getServerUuid())) {
for (String world : Database.getActive().fetch().getWorldNames(ServerInfo.getServerUUID())) {
if (nonZeroWorlds.contains(world)) {
continue;
}

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.utilities.file.export;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
@ -104,7 +105,7 @@ public abstract class SpecificExport extends AbsRunnable {
File htmlLocation = null;
if (usingBungee) {
if (serverUUID.equals(PlanPlugin.getInstance().getServerUuid())) {
if (serverUUID.equals(ServerInfo.getServerUUID())) {
htmlLocation = new File(outputFolder, "network");
} else {
htmlLocation = new File(getServerFolder(), serverName.replace(" ", "%20").replace(".", "%2E"));

View File

@ -1,12 +1,12 @@
package com.djrapitops.plan.utilities.html.tables;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.data.PlayerProfile;
import com.djrapitops.plan.data.element.ActivityIndex;
import com.djrapitops.plan.data.element.AnalysisContainer;
import com.djrapitops.plan.data.element.TableContainer;
import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.MiscUtils;
@ -37,7 +37,7 @@ public class PlayersTableCreator {
StringBuilder html = new StringBuilder();
long now = MiscUtils.getTime();
UUID serverUUID = PlanPlugin.getInstance().getServerUuid();
UUID serverUUID = ServerInfo.getServerUUID();
int i = 0;
int maxPlayers = Settings.MAX_PLAYERS.getNumber();

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.data.cache;
import com.djrapitops.plan.system.cache.CacheSystem;
import com.djrapitops.plan.system.cache.GeolocationCache;
import org.bukkit.plugin.java.JavaPlugin;
import org.junit.Before;
@ -26,7 +27,7 @@ public class GeolocationCacheTest {
@Before
public void setUp() throws Exception {
TestInit.init();
GeolocationCache.clearCache();
CacheSystem.getInstance().getGeolocationCache().clearCache();
ipsToCountries.put("8.8.8.8", "United States");
ipsToCountries.put("8.8.4.4", "United States");

View File

@ -1,7 +1,6 @@
package com.djrapitops.plan.data.cache;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.cache.PageLoader;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import org.junit.Test;
import test.utilities.RandomData;
@ -20,31 +19,20 @@ public class ResponseCacheTest {
return RESPONSE_STRING;
}
};
private final PageLoader LOADER = () -> RESPONSE;
@Test
public void testCreateResponse() {
String expResponse = RESPONSE.getResponse();
String response = LOADER.createResponse().getResponse();
assertEquals(expResponse, response);
}
@Test
public void testCache() {
Response expResponse = LOADER.createResponse();
assertFalse(ResponseCache.isCached(IDENTIFIER));
Response response = ResponseCache.loadResponse(IDENTIFIER, LOADER);
Response response = ResponseCache.loadResponse(IDENTIFIER, () -> RESPONSE);
assertTrue(ResponseCache.isCached(IDENTIFIER));
assertEquals(expResponse, response);
assertEquals(RESPONSE, response);
}
@Test
public void testClearCache() {
ResponseCache.cacheResponse(IDENTIFIER, LOADER);
ResponseCache.cacheResponse(IDENTIFIER, () -> RESPONSE);
assertTrue(ResponseCache.isCached(IDENTIFIER));
ResponseCache.clearCache();
@ -53,7 +41,7 @@ public class ResponseCacheTest {
@Test
public void testRemoveIf() {
ResponseCache.cacheResponse(IDENTIFIER, LOADER);
ResponseCache.cacheResponse(IDENTIFIER, () -> RESPONSE);
assertTrue(ResponseCache.isCached(IDENTIFIER));
ResponseCache.removeIf(identifier -> identifier.equals(IDENTIFIER));

View File

@ -17,6 +17,7 @@ import com.djrapitops.plan.system.database.databases.sql.SQLDB;
import com.djrapitops.plan.system.database.databases.sql.SQLiteDB;
import com.djrapitops.plan.system.database.databases.sql.tables.*;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.processors.player.RegisterProcessor;
import com.djrapitops.plan.utilities.ManageUtils;
import com.djrapitops.plan.utilities.MiscUtils;
@ -294,7 +295,7 @@ public class SQLiteTest {
assertEquals(expected, nicknames.get(0));
Map<UUID, List<String>> allNicknames = nickTable.getAllNicknames(uuid);
assertEquals(nicknames, allNicknames.get(Plan.getServerUUID()));
assertEquals(nicknames, allNicknames.get(ServerInfo.getServerUUID()));
}
@Test
@ -417,7 +418,7 @@ public class SQLiteTest {
System.out.println(" " + entry.getValue());
}
List<Session> savedSessions = sessions.get(Plan.getServerUUID());
List<Session> savedSessions = sessions.get(ServerInfo.getServerUUID());
assertNotNull(savedSessions);
assertEquals(1, savedSessions.size());
@ -449,7 +450,7 @@ public class SQLiteTest {
assertEquals(uuid, userInfo.getUuid());
assertEquals(123456789L, (long) usersTable.getRegisterDates().get(0));
assertEquals(123456789L, userInfo.getRegistered());
assertEquals(1, userInfoTable.getServerUserCount(Plan.getServerUUID()));
assertEquals(1, userInfoTable.getServerUserCount(ServerInfo.getServerUUID()));
assertEquals("Waiting for Update..", userInfo.getName());
assertFalse(userInfo.isBanned());
assertFalse(userInfo.isOpped());
@ -698,7 +699,7 @@ public class SQLiteTest {
testServerTableBungeeSave();
ServerTable serverTable = db.getServerTable();
List<Server> bukkitServers = serverTable.getBukkitServers();
Map<UUID, Server> bukkitServers = serverTable.getBukkitServers();
assertEquals(1, bukkitServers.size());
}
@ -821,7 +822,7 @@ public class SQLiteTest {
List<Session> sessions = new ArrayList<>();
sessions.add(session);
sessionMap.put(uuid, sessions);
map.put(Plan.getServerUUID(), sessionMap);
map.put(ServerInfo.getServerUUID(), sessionMap);
worldTimesTable.saveWorldTimes(map);
@ -844,7 +845,7 @@ public class SQLiteTest {
List<Session> sessions = new ArrayList<>();
sessions.add(session);
sessionMap.put(uuid, sessions);
UUID serverUUID = Plan.getServerUUID();
UUID serverUUID = ServerInfo.getServerUUID();
map.put(serverUUID, sessionMap);
sessionsTable.insertSessions(map, true);

View File

@ -25,8 +25,8 @@ public class WebServerTest {
public void setUp() throws Exception {
TestInit testInit = TestInit.init();
Plan plugin = testInit.getPlanMock();
webServer = new WebServer(plugin);
requestHandler = new RequestHandler(plugin, webServer);
webServer = new WebServer();
requestHandler = new RequestHandler(webServer);
}
@Test

View File

@ -1,6 +1,6 @@
package com.djrapitops.plan.utilities.export;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.utilities.file.export.Hastebin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.utility.log.Log;

View File

@ -2,7 +2,6 @@ package test.utilities;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.system.info.server.BukkitServerInfo;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.info.server.ServerProperties;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.locale.Locale;
@ -132,8 +131,6 @@ public class TestInit {
// };
// when(planMock.getDataCache()).thenReturn(dataCache);
when(ServerInfo.getServerUUID()).thenReturn(serverUUID);
when(planMock.getServerUuid()).thenReturn(serverUUID);
ColorScheme cs = new ColorScheme(ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK, ChatColor.BLACK);
when(planMock.getColorScheme()).thenReturn(cs);
initLocale(null);