[#1009] Reduced reliance on class exist checks:

- Check.is _Platform_ Available() methods were causing issues, and has
  been generally known to cause issues for some time now, so its usage
  was reduced by moving to use Server#isProxy and Server#isNotProxy that
  do not depend on class checks
This commit is contained in:
Rsl1122 2019-04-23 12:51:34 +03:00
parent 44266d06fc
commit 14584065fb
14 changed files with 54 additions and 55 deletions

View File

@ -32,7 +32,6 @@ import com.djrapitops.plan.system.locale.lang.ManageLang;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.command.ColorScheme;
import com.djrapitops.plugin.command.CommandNode;
import com.djrapitops.plugin.command.CommandType;
@ -82,7 +81,7 @@ public class ManageConDebugCommand extends CommandNode {
this.webServer = webServer;
this.dbSystem = dbSystem;
setShortHelp(locale.getString(Check.isBungeeAvailable() || Check.isVelocityAvailable() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
setShortHelp(locale.getString(serverInfo.getServer().isProxy() ? CmdHelpLang.CON : CmdHelpLang.MANAGE_CON));
setInDepthHelp(locale.getArray(DeepHelpLang.MANAGE_CON));
}

View File

@ -18,10 +18,10 @@ package com.djrapitops.plan.system.export;
import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.ExportSettings;
import com.djrapitops.plugin.api.Check;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -35,6 +35,7 @@ import javax.inject.Singleton;
public class ExportSystem implements SubSystem {
private final PlanConfig config;
private final ServerInfo serverInfo;
private final Processing processing;
private final HtmlExport htmlExport;
private final ConnectionSystem connectionSystem;
@ -42,11 +43,13 @@ public class ExportSystem implements SubSystem {
@Inject
public ExportSystem(
PlanConfig config,
ServerInfo serverInfo,
Processing processing,
HtmlExport htmlExport,
ConnectionSystem connectionSystem
) {
this.config = config;
this.serverInfo = serverInfo;
this.processing = processing;
this.htmlExport = htmlExport;
this.connectionSystem = connectionSystem;
@ -54,7 +57,7 @@ public class ExportSystem implements SubSystem {
@Override
public void enable() {
if (Check.isBukkitAvailable() && connectionSystem.isServerAvailable()) {
if (serverInfo.getServer().isNotProxy() && connectionSystem.isServerAvailable()) {
return;
}
if (config.isTrue(ExportSettings.JS_AND_CSS)) {

View File

@ -34,7 +34,6 @@ import com.djrapitops.plan.system.settings.theme.Theme;
import com.djrapitops.plan.system.settings.theme.ThemeVal;
import com.djrapitops.plan.utilities.html.pages.InspectPage;
import com.djrapitops.plan.utilities.html.pages.PageFactory;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import com.djrapitops.plugin.utilities.Verify;
@ -93,7 +92,7 @@ public class HtmlExport extends SpecificExport {
}
public void exportServer(UUID serverUUID) {
if (Check.isBukkitAvailable() && connectionSystem.isServerAvailable()) {
if (!usingProxy && connectionSystem.isServerAvailable()) {
return;
}
dbSystem.getDatabase().query(ServerQueries.fetchServerMatchingIdentifier(serverUUID))
@ -122,7 +121,7 @@ public class HtmlExport extends SpecificExport {
}
public void exportCachedPlayerPage(UUID playerUUID) {
if (Check.isBukkitAvailable() && connectionSystem.isServerAvailable()) {
if (!usingProxy && connectionSystem.isServerAvailable()) {
return;
}

View File

@ -21,7 +21,6 @@ import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.cache.PageId;
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plugin.api.Check;
import java.io.File;
import java.io.IOException;
@ -43,7 +42,7 @@ public abstract class SpecificExport {
private final PlanFiles files;
private final ServerInfo serverInfo;
private final boolean usingProxy;
protected final boolean usingProxy;
protected SpecificExport(
PlanFiles files,
@ -51,7 +50,7 @@ public abstract class SpecificExport {
) {
this.files = files;
this.serverInfo = serverInfo;
usingProxy = Check.isBungeeAvailable() || Check.isVelocityAvailable();
usingProxy = serverInfo.getServer().isProxy();
}
protected File getFolder() {

View File

@ -29,7 +29,6 @@ import com.djrapitops.plan.system.info.request.InfoRequestFactory;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.logging.console.PluginLogger;
import dagger.Lazy;
@ -159,11 +158,8 @@ public abstract class InfoSystem implements SubSystem {
* @throws WebException If fails.
*/
public void requestSetUp(String addressToRequestServer) throws WebException {
if (Check.isBungeeAvailable()) {
throw new BadRequestException("Method not available on Bungee.");
}
if (Check.isVelocityAvailable()) {
throw new BadRequestException("Method not available on Velocity.");
if (serverInfo.getServer().isProxy()) {
throw new BadRequestException("Method not available on a Proxy server.");
}
Server bungee = new Server(-1, null, "Bungee", addressToRequestServer, -1);
String addressOfThisServer = webServer.get().getAccessAddress();

View File

@ -22,9 +22,9 @@ import com.djrapitops.plan.api.exceptions.connection.GatewayException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.utilities.Verify;
import java.util.Map;
@ -37,9 +37,11 @@ import java.util.UUID;
*/
public class CheckConnectionRequest extends InfoRequestWithVariables {
private final ServerInfo serverInfo;
private final ConnectionSystem connectionSystem;
CheckConnectionRequest(String webServerAddress, ConnectionSystem connectionSystem) {
CheckConnectionRequest(String webServerAddress, ServerInfo serverInfo, ConnectionSystem connectionSystem) {
this.serverInfo = serverInfo;
this.connectionSystem = connectionSystem;
Verify.nullCheck(webServerAddress, () -> new IllegalArgumentException("webServerAddress can not be null."));
@ -47,7 +49,8 @@ public class CheckConnectionRequest extends InfoRequestWithVariables {
variables.put("continue", "yes");
}
CheckConnectionRequest(ConnectionSystem connectionSystem) {
CheckConnectionRequest(ServerInfo serverInfo, ConnectionSystem connectionSystem) {
this.serverInfo = serverInfo;
this.connectionSystem = connectionSystem;
}
@ -60,7 +63,7 @@ public class CheckConnectionRequest extends InfoRequestWithVariables {
public Response handleRequest(Map<String, String> variables) throws WebException {
// Available variables: sender, address
if (Check.isBungeeAvailable() || Check.isVelocityAvailable()) {
if (serverInfo.getServer().isProxy()) {
attemptConnection(variables);
}
@ -82,7 +85,7 @@ public class CheckConnectionRequest extends InfoRequestWithVariables {
Server bukkit = new Server(-1, serverUUID, "", address, -1);
try {
connectionSystem.sendInfoRequest(new CheckConnectionRequest(connectionSystem), bukkit);
connectionSystem.sendInfoRequest(new CheckConnectionRequest(serverInfo, connectionSystem), bukkit);
} catch (ConnectionFailException e) {
throw new GatewayException(e.getMessage());
}

View File

@ -123,15 +123,15 @@ public class InfoRequestFactory {
}
public SaveDBSettingsRequest saveDBSettingsRequest() {
return new SaveDBSettingsRequest(plugin.get(), config.get(), logger.get(), runnableFactory.get());
return new SaveDBSettingsRequest(plugin.get(), config.get(), serverInfo.get(), logger.get(), runnableFactory.get());
}
public SetupRequest sendDBSettingsRequest(String addressOfThisServer) {
return new SendDBSettingsRequest(addressOfThisServer, this, connectionSystem.get());
return new SendDBSettingsRequest(addressOfThisServer, serverInfo.get(), this, connectionSystem.get());
}
public CheckConnectionRequest checkConnectionRequest(String webAddress) {
return new CheckConnectionRequest(webAddress, connectionSystem.get());
return new CheckConnectionRequest(webAddress, serverInfo.get(), connectionSystem.get());
}
@Singleton
@ -169,7 +169,7 @@ public class InfoRequestFactory {
}
CheckConnectionRequest checkConnectionRequest() {
return new CheckConnectionRequest(factory.connectionSystem.get());
return new CheckConnectionRequest(factory.serverInfo.get(), factory.connectionSystem.get());
}
GenerateRequest generateAnalysisPageRequest() {
@ -204,6 +204,7 @@ public class InfoRequestFactory {
return new SaveDBSettingsRequest(
factory.plugin.get(),
factory.config.get(),
factory.serverInfo.get(),
factory.logger.get(),
factory.runnableFactory.get()
);
@ -211,6 +212,7 @@ public class InfoRequestFactory {
SetupRequest sendDBSettingsRequest() {
return new SendDBSettingsRequest(
factory.serverInfo.get(),
factory,
factory.connectionSystem.get()
);

View File

@ -20,13 +20,13 @@ import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.api.exceptions.connection.BadRequestException;
import com.djrapitops.plan.api.exceptions.connection.InternalErrorException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
import com.djrapitops.plan.system.settings.paths.PluginSettings;
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.task.AbsRunnable;
@ -46,17 +46,19 @@ public class SaveDBSettingsRequest extends InfoRequestWithVariables implements S
private final PlanPlugin plugin;
private final PlanConfig config;
private final ServerInfo serverInfo;
private final PluginLogger logger;
private final RunnableFactory runnableFactory;
SaveDBSettingsRequest(
PlanPlugin plugin,
PlanConfig config,
PluginLogger logger,
ServerInfo serverInfo, PluginLogger logger,
RunnableFactory runnableFactory
) {
this.plugin = plugin;
this.config = config;
this.serverInfo = serverInfo;
this.logger = logger;
this.runnableFactory = runnableFactory;
@ -75,11 +77,8 @@ public class SaveDBSettingsRequest extends InfoRequestWithVariables implements S
@Override
public Response handleRequest(Map<String, String> variables) throws WebException {
if (Check.isBungeeAvailable()) {
return new BadRequestResponse("Not supposed to be called on a Bungee server");
}
if (Check.isVelocityAvailable()) {
return new BadRequestResponse("Not supposed to be called on a Velocity server");
if (serverInfo.getServer().isProxy()) {
return new BadRequestResponse("Not supposed to be called on a proxy server");
}
if (config.isFalse(PluginSettings.BUNGEE_COPY_CONFIG)) {
return new BadRequestResponse("Bungee config settings overridden on this server.");

View File

@ -22,10 +22,10 @@ import com.djrapitops.plan.api.exceptions.connection.GatewayException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.response.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.errors.BadRequestResponse;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.utilities.Verify;
import java.net.SocketException;
@ -39,20 +39,23 @@ import java.util.UUID;
*/
public class SendDBSettingsRequest extends InfoRequestWithVariables implements SetupRequest {
private final ServerInfo serverInfo;
private final InfoRequestFactory infoRequestFactory;
private final ConnectionSystem connectionSystem;
SendDBSettingsRequest(
InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
ServerInfo serverInfo, InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
) {
this.serverInfo = serverInfo;
this.infoRequestFactory = infoRequestFactory;
this.connectionSystem = connectionSystem;
}
SendDBSettingsRequest(
String webServerAddress,
InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
ServerInfo serverInfo, InfoRequestFactory infoRequestFactory, ConnectionSystem connectionSystem
) {
this.serverInfo = serverInfo;
this.infoRequestFactory = infoRequestFactory;
this.connectionSystem = connectionSystem;
@ -68,11 +71,8 @@ public class SendDBSettingsRequest extends InfoRequestWithVariables implements S
@Override
public Response handleRequest(Map<String, String> variables) throws WebException {
// Available variables: sender, address
if (Check.isBukkitAvailable()) {
return new BadRequestResponse("Not supposed to be called on a Bukkit server");
}
if (Check.isSpongeAvailable()) {
return new BadRequestResponse("Not supposed to be called on a Sponge server");
if (serverInfo.getServer().isNotProxy()) {
return new BadRequestResponse("Not supposed to be called on a non proxy server");
}
String address = variables.get("address");

View File

@ -35,7 +35,7 @@ public enum PluginLang implements Lang {
ENABLE_FAIL_DB("Enable FAIL - Database", "${0}-Database Connection failed: ${1}"),
ENABLE_FAIL_WRONG_DB("Enable FAIL - Wrong Database Type", "${0} is not a supported Database"),
ENABLE_FAIL_DB_PATCH("Enable FAIL - Database Patch", "Database Patching failed, plugin has to be disabled. Please report this issue"),
ENABLE_FAIL_NO_WEB_SERVER_BUNGEE("Enable FAIL - WebServer (Bungee)", "WebServer did not initialize!"),
ENABLE_FAIL_NO_WEB_SERVER_PROXY("Enable FAIL - WebServer (Bungee)", "WebServer did not initialize!"),
ENABLE_FAIL_GEODB_WRITE("Enable FAIL - GeoDB Write", "Something went wrong saving the downloaded GeoLite2 Geolocation database"),
WEB_SERVER_FAIL_PORT_BIND("WebServer FAIL - Port Bind", "WebServer was not initialized successfully. Is the port (${0}) in use?"),

View File

@ -19,12 +19,12 @@ package com.djrapitops.plan.system.webserver;
import com.djrapitops.plan.api.exceptions.EnableException;
import com.djrapitops.plan.system.SubSystem;
import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.info.server.properties.ServerProperties;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.locale.lang.PluginLang;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.PluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
@ -58,6 +58,7 @@ public class WebServer implements SubSystem {
private final Locale locale;
private final PlanFiles files;
private final PlanConfig config;
private final ServerInfo serverInfo;
private final ServerProperties serverProperties;
private final RequestHandler requestHandler;
@ -76,7 +77,7 @@ public class WebServer implements SubSystem {
Locale locale,
PlanFiles files,
PlanConfig config,
ServerProperties serverProperties,
ServerInfo serverInfo,
PluginLogger logger,
ErrorHandler errorHandler,
RequestHandler requestHandler
@ -84,7 +85,8 @@ public class WebServer implements SubSystem {
this.locale = locale;
this.files = files;
this.config = config;
this.serverProperties = serverProperties;
this.serverInfo = serverInfo;
this.serverProperties = serverInfo.getServerProperties();
this.requestHandler = requestHandler;
@ -99,8 +101,8 @@ public class WebServer implements SubSystem {
initServer();
if (!isEnabled()) {
if (Check.isBungeeAvailable() || Check.isVelocityAvailable()) {
throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_NO_WEB_SERVER_BUNGEE));
if (serverInfo.getServer().isProxy()) {
throw new EnableException(locale.getString(PluginLang.ENABLE_FAIL_NO_WEB_SERVER_PROXY));
}
if (config.isTrue(WebserverSettings.DISABLED)) {
logger.warn(locale.getString(PluginLang.ENABLE_NOTIFY_WEB_SERVER_DISABLED));
@ -116,7 +118,7 @@ public class WebServer implements SubSystem {
* Starts up the WebServer in a new Thread Pool.
*/
private void initServer() {
if (!(Check.isBungeeAvailable() || Check.isVelocityAvailable()) && config.isTrue(WebserverSettings.DISABLED)) {
if (serverInfo.getServer().isNotProxy() && config.isTrue(WebserverSettings.DISABLED)) {
// Bukkit WebServer has been disabled.
return;
}

View File

@ -34,7 +34,6 @@ import com.djrapitops.plan.system.webserver.cache.PageId;
import com.djrapitops.plan.system.webserver.cache.ResponseCache;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.ResponseFactory;
import com.djrapitops.plugin.api.Check;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -87,7 +86,7 @@ public class ServerPageHandler implements PageHandler {
return response;
} else {
checkDBState();
if ((Check.isBungeeAvailable() || Check.isVelocityAvailable()) && serverInfo.getServerUUID().equals(serverUUID)) {
if (serverInfo.getServer().isProxy() && serverInfo.getServerUUID().equals(serverUUID)) {
return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID), responseFactory::networkPageResponse);
}
return refreshNow(serverUUID);

View File

@ -48,7 +48,6 @@ import com.djrapitops.plan.utilities.html.structure.Accordions;
import com.djrapitops.plan.utilities.html.structure.ServerAccordion;
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.benchmarking.Timings;
@ -259,7 +258,7 @@ public class InspectPage implements Page {
: serverName
);
if (Check.isBungeeAvailable() || Check.isVelocityAvailable()) {
if (serverInfo.getServer().isProxy()) {
replacer.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 {
replacer.put("backButton", "<li><a title=\"to Server page\" href=\"/server\"><i class=\"material-icons\">arrow_back</i><i class=\"material-icons\">storage</i></a></li>");

View File

@ -28,7 +28,6 @@ import com.djrapitops.plan.system.settings.paths.ProxySettings;
import com.djrapitops.plan.system.update.VersionCheckSystem;
import com.djrapitops.plan.utilities.formatting.PlaceholderReplacer;
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.benchmarking.Timings;
import java.util.List;
@ -75,10 +74,10 @@ public class PlayersPage implements Page {
placeholderReplacer.put("version", versionCheckSystem.getCurrentVersion());
placeholderReplacer.put("update", versionCheckSystem.getUpdateHtml().orElse(""));
if (Check.isBukkitAvailable()) {
placeholderReplacer.put("networkName", config.get(PluginSettings.SERVER_NAME));
} else {
if (serverInfo.getServer().isProxy()) {
placeholderReplacer.put("networkName", config.get(ProxySettings.NETWORK_NAME));
} else {
placeholderReplacer.put("networkName", config.get(PluginSettings.SERVER_NAME));
}
timings.start("Players page players table parsing");