Removed ConnectionSystem

This commit is contained in:
Rsl1122 2019-07-27 10:26:24 +03:00
parent e46ab76173
commit a68ac696c4
29 changed files with 127 additions and 443 deletions

View File

@ -1,35 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.api.exceptions.connection;
import com.djrapitops.plan.system.webserver.response.ResponseCode;
/**
* Thrown when Connection fails to connect to an address.
*
* @author Rsl1122
*/
public class ConnectionFailException extends WebException {
public ConnectionFailException(String message, Throwable cause) {
super(message, cause, ResponseCode.CONNECTION_REFUSED);
}
public ConnectionFailException(Throwable cause) {
super(cause, ResponseCode.CONNECTION_REFUSED);
}
}

View File

@ -23,7 +23,7 @@ import com.djrapitops.plan.system.webserver.response.ResponseCode;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class ForbiddenException extends WebFailException { public class ForbiddenException extends WebException {
public ForbiddenException(String url) { public ForbiddenException(String url) {
super("Forbidden: " + url, ResponseCode.FORBIDDEN); super("Forbidden: " + url, ResponseCode.FORBIDDEN);
} }

View File

@ -23,7 +23,7 @@ import com.djrapitops.plan.system.webserver.response.ResponseCode;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class InternalErrorException extends WebFailException { public class InternalErrorException extends WebException {
public InternalErrorException() { public InternalErrorException() {
super("Internal Error occurred on receiving server", ResponseCode.INTERNAL_ERROR); super("Internal Error occurred on receiving server", ResponseCode.INTERNAL_ERROR);
} }

View File

@ -1,37 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.api.exceptions.connection;
/**
* Thrown when ConnectionSystem can not find any servers to send request to.
*
* @author Rsl1122
*/
public class NoServersException extends WebException {
public NoServersException(String message) {
super(message);
}
public NoServersException(String message, Throwable cause) {
super(message, cause);
}
public NoServersException(Throwable cause) {
super(cause);
}
}

View File

@ -23,7 +23,7 @@ import com.djrapitops.plan.system.webserver.response.ResponseCode;
* *
* @author Rsl1122 * @author Rsl1122
*/ */
public class NotFoundException extends WebFailException { public class NotFoundException extends WebException {
public NotFoundException(String message) { public NotFoundException(String message) {
super(message, ResponseCode.NOT_FOUND); super(message, ResponseCode.NOT_FOUND);
} }

View File

@ -1,43 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.api.exceptions.connection;
import com.djrapitops.plan.system.webserver.response.ResponseCode;
/**
* Group of WebExceptions that can be considered a failed connection state on some occasions.
*
* @author Rsl1122
*/
public class WebFailException extends WebException {
public WebFailException(String message, Throwable cause) {
super(message, cause);
}
public WebFailException(String message, ResponseCode responseCode) {
super(message, responseCode);
}
public WebFailException(String message, Throwable cause, ResponseCode responseCode) {
super(message, cause, responseCode);
}
public WebFailException(Throwable cause, ResponseCode responseCode) {
super(cause, responseCode);
}
}

View File

@ -20,9 +20,9 @@ import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries; import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.db.access.queries.objects.WebUserQueries; import com.djrapitops.plan.db.access.queries.objects.WebUserQueries;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.export.HtmlExport; import com.djrapitops.plan.system.export.HtmlExport;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
@ -57,7 +57,6 @@ public class AnalyzeCommand extends CommandNode {
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final WebServer webServer; private final WebServer webServer;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ConnectionSystem connectionSystem;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@Inject @Inject
@ -66,7 +65,6 @@ public class AnalyzeCommand extends CommandNode {
Processing processing, Processing processing,
HtmlExport export, HtmlExport export,
ServerInfo serverInfo, ServerInfo serverInfo,
ConnectionSystem connectionSystem,
WebServer webServer, WebServer webServer,
DBSystem dbSystem, DBSystem dbSystem,
ErrorHandler errorHandler ErrorHandler errorHandler
@ -77,7 +75,6 @@ public class AnalyzeCommand extends CommandNode {
this.processing = processing; this.processing = processing;
this.export = export; this.export = export;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.connectionSystem = connectionSystem;
this.webServer = webServer; this.webServer = webServer;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
@ -89,7 +86,8 @@ public class AnalyzeCommand extends CommandNode {
@Override @Override
public void onCommand(Sender sender, String commandLabel, String[] args) { public void onCommand(Sender sender, String commandLabel, String[] args) {
Database.State dbState = dbSystem.getDatabase().getState(); Database database = dbSystem.getDatabase();
Database.State dbState = database.getState();
if (dbState != Database.State.OPEN) { if (dbState != Database.State.OPEN) {
sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name())); sender.sendMessage(locale.getString(CommandLang.FAIL_DATABASE_NOT_OPEN, dbState.name()));
return; return;
@ -97,11 +95,9 @@ public class AnalyzeCommand extends CommandNode {
processing.submitNonCritical(() -> { processing.submitNonCritical(() -> {
try { try {
Server server = getServer(args).orElseGet(serverInfo::getServer); Server server = getServer(args);
sendWebUserNotificationIfNecessary(sender); sendWebUserNotificationIfNecessary(sender);
if (connectionSystem.isServerAvailable()) { export.exportServer(server.getUuid());
export.exportServer(server.getUuid());
}
sendLink(server, sender); sendLink(server, sender);
} catch (DBOpException e) { } catch (DBOpException e) {
sender.sendMessage("§cError occurred: " + e.toString()); sender.sendMessage("§cError occurred: " + e.toString());
@ -112,7 +108,8 @@ public class AnalyzeCommand extends CommandNode {
private void sendLink(Server server, Sender sender) { private void sendLink(Server server, Sender sender) {
String target = "/server/" + server.getName(); String target = "/server/" + server.getName();
String url = connectionSystem.getMainAddress() + target; String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + target;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS)); sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
// Link // Link
@ -134,22 +131,24 @@ public class AnalyzeCommand extends CommandNode {
} }
} }
private Optional<Server> getServer(String[] args) { private Server getServer(String[] args) {
if (args.length >= 1 && connectionSystem.isServerAvailable()) { return getGivenIdentifier(args)
String serverIdentifier = getGivenIdentifier(args); .flatMap(serverIdentifier -> dbSystem.getDatabase()
return dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverIdentifier)) .query(ServerQueries.fetchServerMatchingIdentifier(serverIdentifier))
.filter(server -> !server.isProxy()); ).filter(server -> !server.isProxy())
} .orElseGet(serverInfo::getServer);
return Optional.empty();
} }
private String getGivenIdentifier(String[] args) { private Optional<String> getGivenIdentifier(String[] args) {
if (args.length < 1) {
return Optional.empty();
}
StringBuilder idBuilder = new StringBuilder(args[0]); StringBuilder idBuilder = new StringBuilder(args[0]);
if (args.length > 1) { if (args.length > 1) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
idBuilder.append(" ").append(args[i]); idBuilder.append(" ").append(args[i]);
} }
} }
return idBuilder.toString(); return Optional.of(idBuilder.toString());
} }
} }

View File

@ -18,8 +18,8 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
@ -42,7 +42,6 @@ public class InfoCommand extends CommandNode {
private final PlanPlugin plugin; private final PlanPlugin plugin;
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ConnectionSystem connectionSystem;
private final VersionCheckSystem versionCheckSystem; private final VersionCheckSystem versionCheckSystem;
@Inject @Inject
@ -50,7 +49,6 @@ public class InfoCommand extends CommandNode {
PlanPlugin plugin, PlanPlugin plugin,
Locale locale, Locale locale,
DBSystem dbSystem, DBSystem dbSystem,
ConnectionSystem connectionSystem,
VersionCheckSystem versionCheckSystem VersionCheckSystem versionCheckSystem
) { ) {
super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE); super("info", Permissions.INFO.getPermission(), CommandType.CONSOLE);
@ -58,7 +56,6 @@ public class InfoCommand extends CommandNode {
this.plugin = plugin; this.plugin = plugin;
this.locale = locale; this.locale = locale;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.connectionSystem = connectionSystem;
this.versionCheckSystem = versionCheckSystem; this.versionCheckSystem = versionCheckSystem;
setShortHelp(locale.get(CmdHelpLang.INFO).toString()); setShortHelp(locale.get(CmdHelpLang.INFO).toString());
@ -69,18 +66,19 @@ public class InfoCommand extends CommandNode {
String yes = locale.getString(GenericLang.YES); String yes = locale.getString(GenericLang.YES);
String no = locale.getString(GenericLang.NO); String no = locale.getString(GenericLang.NO);
String updateAvailable = versionCheckSystem.isNewVersionAvailable() ? yes : no;
String connectedToBungee = connectionSystem.isServerAvailable() ? yes : no;
Database database = dbSystem.getDatabase(); Database database = dbSystem.getDatabase();
String updateAvailable = versionCheckSystem.isNewVersionAvailable() ? yes : no;
String proxyAvailable = database.query(ServerQueries.fetchProxyServerInformation()).isPresent() ? yes : no;
String[] messages = { String[] messages = {
locale.getString(CommandLang.HEADER_INFO), locale.getString(CommandLang.HEADER_INFO),
"", "",
locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()), locale.getString(CommandLang.INFO_VERSION, plugin.getVersion()),
locale.getString(CommandLang.INFO_UPDATE, updateAvailable), locale.getString(CommandLang.INFO_UPDATE, updateAvailable),
locale.getString(CommandLang.INFO_DATABASE, database.getType().getName() + " (" + database.getState().name() + ")"), locale.getString(CommandLang.INFO_DATABASE, database.getType().getName() + " (" + database.getState().name() + ")"),
locale.getString(CommandLang.INFO_PROXY_CONNECTION, connectedToBungee), locale.getString(CommandLang.INFO_PROXY_CONNECTION, proxyAvailable),
"", "",
">" ">"
}; };

View File

@ -20,14 +20,13 @@ import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.PlayerFetchQueries; import com.djrapitops.plan.db.access.queries.PlayerFetchQueries;
import com.djrapitops.plan.db.access.queries.objects.WebUserQueries; import com.djrapitops.plan.db.access.queries.objects.WebUserQueries;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.processing.processors.info.InfoProcessors;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer; import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
@ -52,27 +51,21 @@ public class InspectCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final WebServer webServer; private final WebServer webServer;
private final InfoProcessors processorFactory;
private final Processing processing; private final Processing processing;
private final ConnectionSystem connectionSystem;
private final UUIDUtility uuidUtility; private final UUIDUtility uuidUtility;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@Inject @Inject
public InspectCommand( public InspectCommand(
Locale locale, Locale locale,
InfoProcessors processorFactory,
Processing processing, Processing processing,
DBSystem dbSystem, DBSystem dbSystem,
WebServer webServer, WebServer webServer,
ConnectionSystem connectionSystem,
UUIDUtility uuidUtility, UUIDUtility uuidUtility,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS); super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
this.processorFactory = processorFactory;
this.processing = processing; this.processing = processing;
this.connectionSystem = connectionSystem;
setArguments("<player>"); setArguments("<player>");
this.locale = locale; this.locale = locale;
@ -138,7 +131,8 @@ public class InspectCommand extends CommandNode {
private void sendInspectMsg(Sender sender, String playerName) { private void sendInspectMsg(Sender sender, String playerName) {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName)); sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
String url = connectionSystem.getMainAddress() + "/player/" + playerName; String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + "/player/" + playerName;
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);

View File

@ -16,12 +16,14 @@
*/ */
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
@ -37,14 +39,20 @@ import javax.inject.Inject;
public class ListPlayersCommand extends CommandNode { public class ListPlayersCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem; private final DBSystem dbSystem;
private final WebServer webServer;
@Inject @Inject
public ListPlayersCommand(Locale locale, ConnectionSystem connectionSystem) { public ListPlayersCommand(
Locale locale,
DBSystem dbSystem,
WebServer webServer
) {
super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE); super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE);
this.locale = locale; this.locale = locale;
this.connectionSystem = connectionSystem; this.dbSystem = dbSystem;
this.webServer = webServer;
setShortHelp(locale.getString(CmdHelpLang.PLAYERS)); setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS)); setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
@ -59,7 +67,8 @@ public class ListPlayersCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS)); sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
// Link // Link
String url = connectionSystem.getMainAddress() + "/players/"; String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + "/players/";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -16,12 +16,14 @@
*/ */
package com.djrapitops.plan.command.commands; package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils; import com.djrapitops.plugin.command.CommandUtils;
@ -37,14 +39,20 @@ import javax.inject.Inject;
public class NetworkCommand extends CommandNode { public class NetworkCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem; private final DBSystem dbSystem;
private final WebServer webServer;
@Inject @Inject
public NetworkCommand(Locale locale, ConnectionSystem connectionSystem) { public NetworkCommand(
Locale locale,
DBSystem dbSystem,
WebServer webServer
) {
super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE); super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
this.locale = locale; this.locale = locale;
this.connectionSystem = connectionSystem; this.dbSystem = dbSystem;
this.webServer = webServer;
setShortHelp(locale.getString(CmdHelpLang.NETWORK)); setShortHelp(locale.getString(CmdHelpLang.NETWORK));
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK)); setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
@ -59,7 +67,8 @@ public class NetworkCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK)); sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
// Link // Link
String url = connectionSystem.getMainAddress() + "/network/"; String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + "/network/";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -21,14 +21,15 @@ import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.WebUserQueries; import com.djrapitops.plan.db.access.queries.objects.WebUserQueries;
import com.djrapitops.plan.db.access.transactions.commands.RegisterWebUserTransaction; import com.djrapitops.plan.db.access.transactions.commands.RegisterWebUserTransaction;
import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.PassEncryptUtil; import com.djrapitops.plan.utilities.PassEncryptUtil;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
@ -61,7 +62,7 @@ public class RegisterCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final Processing processing; private final Processing processing;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final ConnectionSystem connectionSystem; private final WebServer webServer;
private final PluginLogger logger; private final PluginLogger logger;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@ -70,7 +71,7 @@ public class RegisterCommand extends CommandNode {
Locale locale, Locale locale,
Processing processing, Processing processing,
DBSystem dbSystem, DBSystem dbSystem,
ConnectionSystem connectionSystem, WebServer webServer,
PluginLogger logger, PluginLogger logger,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
@ -79,7 +80,7 @@ public class RegisterCommand extends CommandNode {
this.locale = locale; this.locale = locale;
this.processing = processing; this.processing = processing;
this.connectionSystem = connectionSystem; this.webServer = webServer;
this.logger = logger; this.logger = logger;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
@ -181,7 +182,7 @@ public class RegisterCommand extends CommandNode {
} }
private void sendLink(Sender sender) { private void sendLink(Sender sender) {
String url = connectionSystem.getMainAddress(); String url = PlanSystem.getMainAddress(webServer, dbSystem);
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
// Link // Link
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);

View File

@ -16,12 +16,14 @@
*/ */
package com.djrapitops.plan.command.commands.manage; package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.CmdHelpLang; import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
import com.djrapitops.plan.system.locale.lang.CommandLang; import com.djrapitops.plan.system.locale.lang.CommandLang;
import com.djrapitops.plan.system.locale.lang.DeepHelpLang; import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.CommandType;
@ -41,14 +43,16 @@ import java.util.Arrays;
public class ManageRawDataCommand extends CommandNode { public class ManageRawDataCommand extends CommandNode {
private final Locale locale; private final Locale locale;
private final ConnectionSystem connectionSystem; private final DBSystem dbSystem;
private final WebServer webServer;
@Inject @Inject
public ManageRawDataCommand(Locale locale, ConnectionSystem connectionSystem) { public ManageRawDataCommand(Locale locale, DBSystem dbSystem, WebServer webServer) {
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS); super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
this.locale = locale; this.locale = locale;
this.connectionSystem = connectionSystem; this.dbSystem = dbSystem;
this.webServer = webServer;
setArguments("<player>"); setArguments("<player>");
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA)); setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
@ -64,7 +68,8 @@ public class ManageRawDataCommand extends CommandNode {
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName)); sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
// Link // Link
String url = connectionSystem.getMainAddress() + "/player/" + playerName + "/raw"; String address = PlanSystem.getMainAddress(webServer, dbSystem);
String url = address + "/player/" + playerName + "/raw";
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX); String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
boolean console = !CommandUtils.isPlayer(sender); boolean console = !CommandUtils.isPlayer(sender);
if (console) { if (console) {

View File

@ -22,8 +22,6 @@ import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.database.ProxyDBSystem; import com.djrapitops.plan.system.database.ProxyDBSystem;
import com.djrapitops.plan.system.importing.EmptyImportSystem; import com.djrapitops.plan.system.importing.EmptyImportSystem;
import com.djrapitops.plan.system.importing.ImportSystem; import com.djrapitops.plan.system.importing.ImportSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.connection.ProxyConnectionSystem;
import com.djrapitops.plan.system.settings.ConfigSystem; import com.djrapitops.plan.system.settings.ConfigSystem;
import com.djrapitops.plan.system.settings.ProxyConfigSystem; import com.djrapitops.plan.system.settings.ProxyConfigSystem;
import dagger.Binds; import dagger.Binds;
@ -49,7 +47,4 @@ public interface ProxySuperClassBindingModule {
@Binds @Binds
ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem); ImportSystem bindImportSystem(EmptyImportSystem emptyImportSystem);
@Binds
ConnectionSystem bindServerConnectionSystem(ProxyConnectionSystem connectionSystem);
} }

View File

@ -18,8 +18,6 @@ package com.djrapitops.plan.modules;
import com.djrapitops.plan.api.CommonAPI; import com.djrapitops.plan.api.CommonAPI;
import com.djrapitops.plan.api.PlanAPI; import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.connection.ServerConnectionSystem;
import dagger.Binds; import dagger.Binds;
import dagger.Module; import dagger.Module;
@ -34,7 +32,4 @@ public interface ServerSuperClassBindingModule {
@Binds @Binds
PlanAPI bindServerPlanAPI(CommonAPI serverAPI); PlanAPI bindServerPlanAPI(CommonAPI serverAPI);
@Binds
ConnectionSystem bindServerConnectionSystem(ServerConnectionSystem connectionSystem);
} }

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.api.PlanAPI;
import com.djrapitops.plan.api.exceptions.EnableException; import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.capability.CapabilityServiceImplementation; import com.djrapitops.plan.capability.CapabilityServiceImplementation;
import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.extension.ExtensionService; import com.djrapitops.plan.extension.ExtensionService;
import com.djrapitops.plan.extension.ExtensionServiceImplementation; import com.djrapitops.plan.extension.ExtensionServiceImplementation;
import com.djrapitops.plan.query.QueryServiceImplementation; import com.djrapitops.plan.query.QueryServiceImplementation;
@ -28,6 +29,7 @@ import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.export.ExportSystem; import com.djrapitops.plan.system.export.ExportSystem;
import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.importing.ImportSystem; import com.djrapitops.plan.system.importing.ImportSystem;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.listeners.ListenerSystem; import com.djrapitops.plan.system.listeners.ListenerSystem;
import com.djrapitops.plan.system.locale.LocaleSystem; import com.djrapitops.plan.system.locale.LocaleSystem;
@ -35,6 +37,7 @@ import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.ConfigSystem; import com.djrapitops.plan.system.settings.ConfigSystem;
import com.djrapitops.plan.system.tasks.TaskSystem; import com.djrapitops.plan.system.tasks.TaskSystem;
import com.djrapitops.plan.system.update.VersionCheckSystem; 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.system.webserver.WebServerSystem;
import com.djrapitops.plugin.logging.L; import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler; import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -119,6 +122,16 @@ public class PlanSystem implements SubSystem {
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
} }
public static String getMainAddress(WebServer webServer, DBSystem dbSystem) {
return dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation())
.map(Server::getWebAddress)
.orElse(webServer.getAccessAddress());
}
public String getMainAddress() {
return PlanSystem.getMainAddress(webServerSystem.getWebServer(), databaseSystem);
}
@Override @Override
public void enable() throws EnableException { public void enable() throws EnableException {
CapabilityServiceImplementation.initialize(); CapabilityServiceImplementation.initialize();

View File

@ -16,8 +16,10 @@
*/ */
package com.djrapitops.plan.system.export; package com.djrapitops.plan.system.export;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.system.SubSystem; import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.config.PlanConfig;
@ -35,31 +37,34 @@ import javax.inject.Singleton;
public class ExportSystem implements SubSystem { public class ExportSystem implements SubSystem {
private final PlanConfig config; private final PlanConfig config;
private final DBSystem dbSystem;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final Processing processing; private final Processing processing;
private final HtmlExport htmlExport; private final HtmlExport htmlExport;
private final ConnectionSystem connectionSystem;
@Inject @Inject
public ExportSystem( public ExportSystem(
PlanConfig config, PlanConfig config,
DBSystem dbSystem,
ServerInfo serverInfo, ServerInfo serverInfo,
Processing processing, Processing processing,
HtmlExport htmlExport, HtmlExport htmlExport
ConnectionSystem connectionSystem
) { ) {
this.config = config; this.config = config;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.processing = processing; this.processing = processing;
this.htmlExport = htmlExport; this.htmlExport = htmlExport;
this.connectionSystem = connectionSystem;
} }
@Override @Override
public void enable() { public void enable() {
if (serverInfo.getServer().isNotProxy() && connectionSystem.isServerAvailable()) { Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return; return;
} }
if (config.isTrue(ExportSettings.JS_AND_CSS)) { if (config.isTrue(ExportSettings.JS_AND_CSS)) {
processing.submitNonCritical(htmlExport::exportJs); processing.submitNonCritical(htmlExport::exportJs);
processing.submitNonCritical(htmlExport::exportCss); processing.submitNonCritical(htmlExport::exportCss);

View File

@ -19,12 +19,12 @@ package com.djrapitops.plan.system.export;
import com.djrapitops.plan.api.exceptions.ParseException; import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.BaseUser; import com.djrapitops.plan.data.container.BaseUser;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.BaseUserQueries; import com.djrapitops.plan.db.access.queries.objects.BaseUserQueries;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries; import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.db.access.queries.objects.UserIdentifierQueries; import com.djrapitops.plan.db.access.queries.objects.UserIdentifierQueries;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.json.JSONFactory; import com.djrapitops.plan.system.json.JSONFactory;
@ -63,7 +63,6 @@ public class HtmlExport extends SpecificExport {
private final PlanFiles files; private final PlanFiles files;
private final DBSystem dbSystem; private final DBSystem dbSystem;
private final PageFactory pageFactory; private final PageFactory pageFactory;
private final ConnectionSystem connectionSystem;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@Inject @Inject
@ -75,7 +74,6 @@ public class HtmlExport extends SpecificExport {
PageFactory pageFactory, PageFactory pageFactory,
JSONFactory jsonFactory, JSONFactory jsonFactory,
ServerInfo serverInfo, ServerInfo serverInfo,
ConnectionSystem connectionSystem,
ErrorHandler errorHandler ErrorHandler errorHandler
) { ) {
super(files, jsonFactory, serverInfo); super(files, jsonFactory, serverInfo);
@ -84,7 +82,6 @@ public class HtmlExport extends SpecificExport {
this.files = files; this.files = files;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.pageFactory = pageFactory; this.pageFactory = pageFactory;
this.connectionSystem = connectionSystem;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;
} }
@ -94,10 +91,12 @@ public class HtmlExport extends SpecificExport {
} }
public void exportServer(UUID serverUUID) { public void exportServer(UUID serverUUID) {
if (serverInfo.getServer().isNotProxy() && connectionSystem.isServerAvailable()) { Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return; return;
} }
dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)) database.query(ServerQueries.fetchServerMatchingIdentifier(serverUUID))
.map(Server::getName) .map(Server::getName)
.ifPresent(serverName -> { .ifPresent(serverName -> {
try { try {
@ -123,11 +122,13 @@ public class HtmlExport extends SpecificExport {
} }
public void exportCachedPlayerPage(UUID playerUUID) { public void exportCachedPlayerPage(UUID playerUUID) {
if (serverInfo.getServer().isNotProxy() && connectionSystem.isServerAvailable()) { Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return; return;
} }
dbSystem.getDatabase().query(UserIdentifierQueries.fetchPlayerNameOf(playerUUID)) database.query(UserIdentifierQueries.fetchPlayerNameOf(playerUUID))
.ifPresent(playerName -> { .ifPresent(playerName -> {
try { try {
exportAvailablePlayerPage(playerUUID, playerName); exportAvailablePlayerPage(playerUUID, playerName);

View File

@ -1,44 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.system.info.server.ServerInfo;
/**
* ConnectionSystem manages proxy server status.
*
* @author Rsl1122
* @deprecated Usage should be replaced with Database query {@link ServerQueries#fetchProxyServerInformation()}
*/
@Deprecated
public abstract class ConnectionSystem {
protected final ServerInfo serverInfo;
public ConnectionSystem(
ServerInfo serverInfo
) {
this.serverInfo = serverInfo;
}
@Deprecated
public abstract boolean isServerAvailable();
@Deprecated
public abstract String getMainAddress();
}

View File

@ -1,55 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.WebServer;
import dagger.Lazy;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* ConnectionSystem for proxy servers.
*
* @author Rsl1122
*/
@Singleton
public class ProxyConnectionSystem extends ConnectionSystem {
private final Lazy<WebServer> webServer;
@Inject
public ProxyConnectionSystem(
Lazy<WebServer> webServer,
ServerInfo serverInfo
) {
super(serverInfo);
this.webServer = webServer;
}
@Override
public boolean isServerAvailable() {
return true;
}
@Override
public String getMainAddress() {
return webServer.get().getAccessAddress();
}
}

View File

@ -1,89 +0,0 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.system.info.connection;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
* Connection system for Bukkit servers.
*
* @author Rsl1122
*/
@Singleton
public class ServerConnectionSystem extends ConnectionSystem {
private final Processing processing;
private final DBSystem dbSystem;
private long latestServerMapRefresh;
private Server mainServer;
@Inject
public ServerConnectionSystem(
Processing processing,
DBSystem dbSystem,
ServerInfo serverInfo
) {
super(serverInfo);
this.processing = processing;
this.dbSystem = dbSystem;
latestServerMapRefresh = 0;
}
private void refreshServerMap() {
processing.submitNonCritical(() -> {
if (latestServerMapRefresh < System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(15L)) {
Database database = dbSystem.getDatabase();
Map<UUID, Server> servers = database.query(ServerQueries.fetchPlanServerInformation());
Optional<Server> proxy = servers.values().stream()
.filter(Server::isProxy)
.findFirst();
mainServer = proxy.orElse(null);
proxy.ifPresent(proxyServer -> servers.remove(proxyServer.getUuid()));
latestServerMapRefresh = System.currentTimeMillis();
}
});
}
@Override
public boolean isServerAvailable() {
refreshServerMap();
return mainServer != null;
}
@Override
public String getMainAddress() {
refreshServerMap();
return isServerAvailable() ? mainServer.getWebAddress() : serverInfo.getServer().getWebAddress();
}
}

View File

@ -172,9 +172,10 @@ public class PlayerJSONParser {
int worstPing = ping.max(); int worstPing = ping.max();
int bestPing = ping.min(); int bestPing = ping.min();
info.put("average_ping", averagePing != -1.0 ? decimals.apply(averagePing) + " ms" : "Unavailable"); String unavailable = "Unavailable";
info.put("worst_ping", worstPing != -1.0 ? worstPing + " ms" : "Unavailable"); info.put("average_ping", averagePing != -1.0 ? decimals.apply(averagePing) + " ms" : unavailable);
info.put("best_ping", bestPing != -1.0 ? bestPing + " ms" : "Unavailable"); info.put("worst_ping", worstPing != -1.0 ? worstPing + " ms" : unavailable);
info.put("best_ping", bestPing != -1.0 ? bestPing + " ms" : unavailable);
info.put("registered", player.getValue(PlayerKeys.REGISTERED).map(year).orElse("-")); info.put("registered", player.getValue(PlayerKeys.REGISTERED).map(year).orElse("-"));
info.put("last_seen", player.getValue(PlayerKeys.LAST_SEEN).map(year).orElse("-")); info.put("last_seen", player.getValue(PlayerKeys.LAST_SEEN).map(year).orElse("-"));

View File

@ -94,7 +94,7 @@ public class ResponseHandler extends TreePageHandler {
public Response getResponse(Request request) { public Response getResponse(Request request) {
try { try {
return tryToGetResponse(request); return tryToGetResponse(request);
} catch (NoServersException | NotFoundException e) { } catch (NotFoundException e) {
return responseFactory.notFound404(e.getMessage()); return responseFactory.notFound404(e.getMessage());
} catch (WebUserAuthException e) { } catch (WebUserAuthException e) {
return responseFactory.basicAuthFail(e); return responseFactory.basicAuthFail(e);

View File

@ -57,4 +57,5 @@ public class WebServerSystem implements SubSystem {
public WebServer getWebServer() { public WebServer getWebServer() {
return webServer; return webServer;
} }
} }

View File

@ -18,11 +18,9 @@ package com.djrapitops.plan.system.webserver.pages;
import com.djrapitops.plan.api.exceptions.WebUserAuthException; import com.djrapitops.plan.api.exceptions.WebUserAuthException;
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException; import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
import com.djrapitops.plan.api.exceptions.connection.WebException; import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.data.WebUser; import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.PlayerFetchQueries;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.Request;
import com.djrapitops.plan.system.webserver.RequestTarget; import com.djrapitops.plan.system.webserver.RequestTarget;
@ -67,37 +65,22 @@ public class PlayerPageHandler implements PageHandler {
} }
String playerName = target.get(0); String playerName = target.get(0);
UUID uuid = uuidUtility.getUUIDOf(playerName); UUID playerUUID = uuidUtility.getUUIDOf(playerName);
boolean raw = target.size() >= 2 && target.get(1).equalsIgnoreCase("raw"); boolean raw = target.size() >= 2 && target.get(1).equalsIgnoreCase("raw");
if (uuid == null) { if (playerUUID == null) {
return responseFactory.uuidNotFound404(); return responseFactory.uuidNotFound404();
} }
try { Database.State dbState = dbSystem.getDatabase().getState();
Database.State dbState = dbSystem.getDatabase().getState(); if (dbState != Database.State.OPEN) {
if (dbState != Database.State.OPEN) { throw new ForbiddenException("Database is " + dbState.name() + " - Please try again later. You can check database status with /plan info");
throw new ForbiddenException("Database is " + dbState.name() + " - Please try again later. You can check database status with /plan info");
}
// TODO Move this Database dependency to PlayerPage generation in PageFactory instead.
if (dbSystem.getDatabase().query(PlayerFetchQueries.isPlayerRegistered(uuid))) {
if (raw) {
return ResponseCache.loadResponse(PageId.RAW_PLAYER.of(uuid), () -> responseFactory.rawPlayerPageResponse(uuid));
}
return playerResponseOrNotFound(uuid);
} else {
return responseFactory.playerNotFound404();
}
} catch (NoServersException e) {
ResponseCache.loadResponse(PageId.PLAYER.of(uuid), () -> responseFactory.notFound404(e.getMessage()));
} }
return responseFactory.serverNotFound404(); if (raw) {
} return ResponseCache.loadResponse(PageId.RAW_PLAYER.of(playerUUID), () -> responseFactory.rawPlayerPageResponse(playerUUID));
}
private Response playerResponseOrNotFound(UUID playerUUID) throws WebException { return ResponseCache.loadResponse(PageId.PLAYER.of(playerUUID),
Response response = ResponseCache.loadResponse(PageId.PLAYER.of(playerUUID),
() -> responseFactory.playerPageResponse(playerUUID)); () -> responseFactory.playerPageResponse(playerUUID));
return response != null ? response : responseFactory.playerNotFound404();
} }
@Override @Override

View File

@ -22,7 +22,6 @@ import com.djrapitops.plan.data.store.objects.DateHolder;
import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.cache.SessionCache;
import com.djrapitops.plan.system.file.FileResource; import com.djrapitops.plan.system.file.FileResource;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.info.server.properties.ServerProperties; import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.webserver.cache.ResponseCache; import com.djrapitops.plan.system.webserver.cache.ResponseCache;
@ -55,7 +54,6 @@ public class DebugPage implements Page {
private final Database database; private final Database database;
private final ServerInfo serverInfo; private final ServerInfo serverInfo;
private final ConnectionSystem connectionSystem;
private final CombineDebugLogger debugLogger; private final CombineDebugLogger debugLogger;
private final Timings timings; private final Timings timings;
private final ErrorHandler errorHandler; private final ErrorHandler errorHandler;
@ -66,7 +64,6 @@ public class DebugPage implements Page {
DebugPage( DebugPage(
Database database, Database database,
ServerInfo serverInfo, ServerInfo serverInfo,
ConnectionSystem connectionSystem,
Formatters formatters, Formatters formatters,
DebugLogger debugLogger, DebugLogger debugLogger,
Timings timings, Timings timings,
@ -74,7 +71,6 @@ public class DebugPage implements Page {
) { ) {
this.database = database; this.database = database;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.connectionSystem = connectionSystem;
this.debugLogger = (CombineDebugLogger) debugLogger; this.debugLogger = (CombineDebugLogger) debugLogger;
this.timings = timings; this.timings = timings;
this.errorHandler = errorHandler; this.errorHandler = errorHandler;

View File

@ -27,7 +27,6 @@ import com.djrapitops.plan.extension.implementation.results.player.ExtensionPlay
import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery; import com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery;
import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.config.PlanConfig;
@ -35,8 +34,6 @@ import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.update.VersionCheckSystem; import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent; import com.djrapitops.plan.system.webserver.response.pages.parts.InspectPagePluginsContent;
import com.djrapitops.plan.utilities.formatting.Formatters; import com.djrapitops.plan.utilities.formatting.Formatters;
import com.djrapitops.plan.utilities.html.graphs.Graphs;
import com.djrapitops.plan.utilities.html.structure.Accordions;
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator; import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
import com.djrapitops.plan.utilities.html.tables.HtmlTables; import com.djrapitops.plan.utilities.html.tables.HtmlTables;
import com.djrapitops.plugin.benchmarking.Timings; import com.djrapitops.plugin.benchmarking.Timings;
@ -62,10 +59,7 @@ public class PageFactory {
private final Lazy<Theme> theme; private final Lazy<Theme> theme;
private final Lazy<DBSystem> dbSystem; private final Lazy<DBSystem> dbSystem;
private final Lazy<ServerInfo> serverInfo; private final Lazy<ServerInfo> serverInfo;
private final Lazy<ConnectionSystem> connectionSystem;
private final Lazy<Graphs> graphs;
private final Lazy<HtmlTables> tables; private final Lazy<HtmlTables> tables;
private final Lazy<Accordions> accordions;
private final Lazy<Formatters> formatters; private final Lazy<Formatters> formatters;
private final Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator; private final Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator;
private final Lazy<HookHandler> hookHandler; private final Lazy<HookHandler> hookHandler;
@ -81,10 +75,7 @@ public class PageFactory {
Lazy<Theme> theme, Lazy<Theme> theme,
Lazy<DBSystem> dbSystem, Lazy<DBSystem> dbSystem,
Lazy<ServerInfo> serverInfo, Lazy<ServerInfo> serverInfo,
Lazy<ConnectionSystem> connectionSystem,
Lazy<Graphs> graphs,
Lazy<HtmlTables> tables, Lazy<HtmlTables> tables,
Lazy<Accordions> accordions,
Lazy<Formatters> formatters, Lazy<Formatters> formatters,
Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator, Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator,
Lazy<HookHandler> hookHandler, Lazy<HookHandler> hookHandler,
@ -98,10 +89,7 @@ public class PageFactory {
this.theme = theme; this.theme = theme;
this.dbSystem = dbSystem; this.dbSystem = dbSystem;
this.serverInfo = serverInfo; this.serverInfo = serverInfo;
this.connectionSystem = connectionSystem;
this.graphs = graphs;
this.tables = tables; this.tables = tables;
this.accordions = accordions;
this.formatters = formatters; this.formatters = formatters;
this.analysisPluginsTabContentCreator = analysisPluginsTabContentCreator; this.analysisPluginsTabContentCreator = analysisPluginsTabContentCreator;
this.hookHandler = hookHandler; this.hookHandler = hookHandler;
@ -112,7 +100,7 @@ public class PageFactory {
public DebugPage debugPage() { public DebugPage debugPage() {
return new DebugPage( return new DebugPage(
dbSystem.get().getDatabase(), serverInfo.get(), connectionSystem.get(), formatters.get(), dbSystem.get().getDatabase(), serverInfo.get(), formatters.get(),
debugLogger.get(), timings.get(), errorHandler.get() debugLogger.get(), timings.get(), errorHandler.get()
); );
} }
@ -129,7 +117,6 @@ public class PageFactory {
server, server,
config.get(), config.get(),
theme.get(), theme.get(),
connectionSystem.get(),
versionCheckSystem.get(), versionCheckSystem.get(),
fileSystem.get(), fileSystem.get(),
formatters.get() formatters.get()

View File

@ -76,11 +76,10 @@ public class PlayerPage implements Page {
@Override @Override
public String toHtml() throws ParseException { public String toHtml() throws ParseException {
if (!player.getValue(PlayerKeys.REGISTERED).isPresent()) {
throw new IllegalStateException("Player is not registered");
}
try { try {
if (!player.getValue(PlayerKeys.REGISTERED).isPresent()) {
throw new IllegalStateException("Player is not registered");
}
return parse(player); return parse(player);
} catch (Exception e) { } catch (Exception e) {
throw new ParseException(e); throw new ParseException(e);

View File

@ -21,7 +21,6 @@ import com.djrapitops.plan.data.store.containers.DataContainer;
import com.djrapitops.plan.data.store.containers.RawDataContainer; import com.djrapitops.plan.data.store.containers.RawDataContainer;
import com.djrapitops.plan.data.store.keys.AnalysisKeys; import com.djrapitops.plan.data.store.keys.AnalysisKeys;
import com.djrapitops.plan.system.file.PlanFiles; import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.DisplaySettings; import com.djrapitops.plan.system.settings.paths.DisplaySettings;
@ -45,7 +44,6 @@ public class ServerPage implements Page {
private final Server server; private final Server server;
private PlanConfig config; private PlanConfig config;
private Theme theme; private Theme theme;
private final ConnectionSystem connectionSystem;
private final VersionCheckSystem versionCheckSystem; private final VersionCheckSystem versionCheckSystem;
private final PlanFiles files; private final PlanFiles files;
private Formatters formatters; private Formatters formatters;
@ -54,7 +52,6 @@ public class ServerPage implements Page {
Server server, Server server,
PlanConfig config, PlanConfig config,
Theme theme, Theme theme,
ConnectionSystem connectionSystem,
VersionCheckSystem versionCheckSystem, VersionCheckSystem versionCheckSystem,
PlanFiles files, PlanFiles files,
Formatters formatters Formatters formatters
@ -62,7 +59,6 @@ public class ServerPage implements Page {
this.server = server; this.server = server;
this.config = config; this.config = config;
this.theme = theme; this.theme = theme;
this.connectionSystem = connectionSystem;
this.versionCheckSystem = versionCheckSystem; this.versionCheckSystem = versionCheckSystem;
this.files = files; this.files = files;
this.formatters = formatters; this.formatters = formatters;
@ -113,7 +109,7 @@ public class ServerPage implements Page {
AVG_PING_COLOR, MAX_PING_COLOR, MIN_PING_COLOR AVG_PING_COLOR, MAX_PING_COLOR, MIN_PING_COLOR
); );
if (connectionSystem.isServerAvailable()) { if (server.isProxy()) {
placeholderReplacer.put("backButton", "<li><a title=\"to Network page\" href=\"/network\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">cloud</i></a></li>"); placeholderReplacer.put("backButton", "<li><a title=\"to Network page\" href=\"/network\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">cloud</i></a></li>");
} else { } else {
placeholderReplacer.put("backButton", ""); placeholderReplacer.put("backButton", "");