Deleted InformationManagers

This commit is contained in:
Rsl1122 2018-01-24 19:14:50 +02:00
parent 9b0d42587b
commit c786e7795a
28 changed files with 87 additions and 622 deletions

View File

@ -34,16 +34,14 @@ import com.djrapitops.plan.system.file.FileSystem;
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.processing.processors.importing.importers.OfflinePlayerImporter;
import com.djrapitops.plan.system.processing.importing.ImporterManager;
import com.djrapitops.plan.system.processing.importing.importers.OfflinePlayerImporter;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.settings.config.ConfigSystem;
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.systems.info.BukkitInformationManager;
import com.djrapitops.plan.systems.info.ImporterManager;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plan.utilities.metrics.BStats;
import com.djrapitops.plugin.BukkitPlugin;
@ -75,7 +73,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
private HookHandler hookHandler; // Manages 3rd party data sources
private BukkitInformationManager infoManager;
private BukkitServerInfo serverInfoManager;
private ServerProperties serverProperties;
@ -137,7 +134,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
Benchmark.start("WebServer Initialization");
serverInfoManager = new BukkitServerInfo(this);
infoManager = new BukkitInformationManager(this);
WebServerSystem.getInstance().enable();
if (!WebServerSystem.isWebServerEnabled()) {
if (Settings.WEBSERVER_DISABLED.isTrue()) {
@ -148,7 +144,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
}
}
serverInfoManager.updateServerInfo();
infoManager.updateConnection();
Benchmark.stop("Enable", "WebServer Initialization");
@ -270,11 +265,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
return serverInfoManager;
}
@Deprecated
public InformationManager getInfoManager() {
return infoManager;
}
public boolean isReloading() {
return reloading;
}

View File

@ -21,13 +21,10 @@ 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.systems.info.BungeeInformationManager;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.BungeePlugin;
import com.djrapitops.plugin.StaticHolder;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.config.Config;
import com.djrapitops.plugin.api.systems.TaskCenter;
import com.djrapitops.plugin.api.utility.log.DebugLog;
import com.djrapitops.plugin.api.utility.log.Log;
@ -47,7 +44,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
private BungeeSystem system;
private BungeeServerInfo serverInfoManager;
private BungeeInformationManager infoManager;
private ServerProperties variableHolder;
@Deprecated
@ -89,7 +85,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
Benchmark.start("WebServer Initialization");
serverInfoManager = new BungeeServerInfo(this);
infoManager = new BungeeInformationManager(this);
WebServerSystem.getInstance().enable();
serverInfoManager.loadServerInfo();
@ -137,12 +132,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return serverInfoManager;
}
@Override
@Deprecated
public InformationManager getInfoManager() {
return infoManager;
}
@Override
public WebServer getWebServer() {
return WebServerSystem.getInstance().getWebServer();
@ -153,11 +142,6 @@ public class PlanBungee extends BungeePlugin implements PlanPlugin {
return getResourceAsStream(resource);
}
@Override
public Config getMainConfig() {
return ConfigSystem.getInstance().getConfig();
}
@Override
public ColorScheme getColorScheme() {
return PlanColorScheme.create();

View File

@ -7,7 +7,6 @@ package com.djrapitops.plan;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.server.ServerProperties;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plugin.IPlugin;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.settings.ColorScheme;
@ -44,9 +43,6 @@ public interface PlanPlugin extends IPlugin {
@Deprecated
UUID getServerUuid();
@Deprecated
InformationManager getInfoManager();
@Deprecated
WebServer getWebServer();

View File

@ -1,8 +1,8 @@
package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
@ -43,7 +43,7 @@ public class ListCommand extends SubCommand {
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse());
// Link
String url = PlanPlugin.getInstance().getInfoManager().getLinkTo("/players/");
String url = ConnectionSystem.getAddress() + "/players/";
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
boolean console = !CommandUtils.isPlayer(sender);
if (console) {

View File

@ -3,6 +3,7 @@ package com.djrapitops.plan.command.commands;
import com.djrapitops.plan.PlanPlugin;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.CommandUtils;
@ -42,7 +43,7 @@ public class NetworkCommand extends SubCommand {
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).parse());
// Link
String url = plugin.getInfoManager().getLinkTo("/network/");
String url = ConnectionSystem.getAddress() + "/network/";
String message = Locale.get(Msg.CMD_INFO_LINK).toString();
boolean console = !CommandUtils.isPlayer(sender);
if (console) {

View File

@ -3,8 +3,8 @@ package com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.processing.importing.ImporterManager;
import com.djrapitops.plan.system.settings.Permissions;
import com.djrapitops.plan.systems.info.ImporterManager;
import com.djrapitops.plan.utilities.Condition;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;

View File

@ -14,6 +14,7 @@ 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.utilities.NullCheck;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.UUID;
@ -67,6 +68,12 @@ public abstract class InfoSystem implements SubSystem {
@Override
public void enable() throws EnableException {
connectionSystem.enable();
try {
updateNetworkPage();
} catch (WebException e) {
// TODO Exception handling
Log.toLog(this.getClass().getName(), e);
}
}
@Override

View File

@ -2,9 +2,9 @@
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.systems.info;
package com.djrapitops.plan.system.processing.importing;
import com.djrapitops.plan.system.processing.processors.importing.importers.Importer;
import com.djrapitops.plan.system.processing.importing.importers.Importer;
import java.util.ArrayList;
import java.util.List;

View File

@ -2,7 +2,7 @@
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.processing.processors.importing;
package com.djrapitops.plan.system.processing.importing;
import com.djrapitops.plan.data.container.TPS;

View File

@ -2,7 +2,7 @@
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.processing.processors.importing;
package com.djrapitops.plan.system.processing.importing;
import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.time.GMTimes;

View File

@ -2,7 +2,7 @@
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.processing.processors.importing;
package com.djrapitops.plan.system.processing.importing;
import com.djrapitops.plan.Plan;
import com.djrapitops.plugin.api.Benchmark;

View File

@ -2,7 +2,7 @@
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.processing.processors.importing.importers;
package com.djrapitops.plan.system.processing.importing.importers;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.database.DBException;
@ -12,9 +12,10 @@ import com.djrapitops.plan.data.container.UserInfo;
import com.djrapitops.plan.data.time.WorldTimes;
import com.djrapitops.plan.system.cache.GeolocationCache;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.processing.processors.importing.ServerImportData;
import com.djrapitops.plan.system.processing.processors.importing.UserImportData;
import com.djrapitops.plan.system.processing.processors.importing.UserImportRefiner;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.importing.ServerImportData;
import com.djrapitops.plan.system.processing.importing.UserImportData;
import com.djrapitops.plan.system.processing.importing.UserImportRefiner;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log;
@ -95,7 +96,7 @@ public abstract class Importer {
}
Plan plugin = Plan.getInstance();
UUID uuid = plugin.getServerInfoManager().getServerUUID();
UUID uuid = ServerInfo.getServerUUID();
Database db = plugin.getDB();
ExecutorService service = Executors.newCachedThreadPool();
@ -151,7 +152,7 @@ public abstract class Importer {
UserImportRefiner userImportRefiner = new UserImportRefiner(plugin, userImportData);
userImportData = userImportRefiner.refineData();
UUID serverUUID = plugin.getServerInfoManager().getServerUUID();
UUID serverUUID = ServerInfo.getServerUUID();
Database db = plugin.getDB();
Set<UUID> existingUUIDs = db.fetch().getSavedUUIDs();

View File

@ -2,10 +2,10 @@
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.system.processing.processors.importing.importers;
package com.djrapitops.plan.system.processing.importing.importers;
import com.djrapitops.plan.system.processing.processors.importing.ServerImportData;
import com.djrapitops.plan.system.processing.processors.importing.UserImportData;
import com.djrapitops.plan.system.processing.importing.ServerImportData;
import com.djrapitops.plan.system.processing.importing.UserImportData;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

View File

@ -1,8 +1,12 @@
package com.djrapitops.plan.system.tasks.bukkit;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.settings.locale.Locale;
import com.djrapitops.plan.settings.locale.Msg;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.utilities.analysis.Analysis;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.AbsRunnable;
@ -16,7 +20,11 @@ public class BootAnalysisTask extends AbsRunnable {
public void run() {
String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString();
Log.info(bootAnalysisRunMsg);
Plan.getInstance().getInfoManager().refreshAnalysis(Plan.getServerUUID());
if (!Analysis.isAnalysisBeingRun()) {
WebExceptionLogger.logIfOccurs(this.getClass(), () ->
InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID()))
);
}
cancel();
}
}

View File

@ -1,6 +1,10 @@
package com.djrapitops.plan.system.tasks.bukkit;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.utilities.analysis.Analysis;
import com.djrapitops.plugin.task.AbsRunnable;
public class PeriodicAnalysisTask extends AbsRunnable {
@ -11,6 +15,10 @@ public class PeriodicAnalysisTask extends AbsRunnable {
@Override
public void run() {
Plan.getInstance().getInfoManager().refreshAnalysis(Plan.getServerUUID());
if (!Analysis.isAnalysisBeingRun()) {
WebExceptionLogger.logIfOccurs(this.getClass(), () ->
InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID()))
);
}
}
}

View File

@ -1,7 +1,5 @@
package com.djrapitops.plan.system.tasks.bungee;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.systems.info.BungeeInformationManager;
import com.djrapitops.plugin.task.AbsRunnable;
public class EnableConnectionTask extends AbsRunnable {
@ -12,9 +10,9 @@ public class EnableConnectionTask extends AbsRunnable {
@Override
public void run() {
BungeeInformationManager infoManager = (BungeeInformationManager) PlanBungee.getInstance().getInfoManager();
infoManager.attemptConnection();
infoManager.sendConfigSettings();
// TODO Config InfoRequests.
// infoManager.attemptConnection();
// infoManager.sendConfigSettings();
cancel();
}
}

View File

@ -28,9 +28,7 @@ public class ServerPageHandler extends PageHandler {
@Override
public Response getResponse(Request request, List<String> target) {
UUID serverUUID = getServerUUID(target);
return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID),
() -> new AnalysisPageResponse(PlanPlugin.getInstance().getInfoManager())
);
return ResponseCache.loadResponse(PageId.SERVER.of(serverUUID), AnalysisPageResponse::refreshNow);
}
private UUID getServerUUID(List<String> target) {

View File

@ -1,13 +1,10 @@
package com.djrapitops.plan.system.webserver.response.pages;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.AnalysisData;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.webserver.response.Response;
import com.djrapitops.plan.system.webserver.response.errors.ErrorResponse;
import com.djrapitops.plan.systems.info.BukkitInformationManager;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plugin.task.AbsRunnable;
import com.djrapitops.plugin.task.RunnableFactory;
import com.djrapitops.plugin.api.utility.log.Log;
/**
* @author Rsl1122
@ -15,35 +12,14 @@ import com.djrapitops.plugin.task.RunnableFactory;
*/
public class AnalysisPageResponse extends Response {
/**
* Constructor.
*
* @param informationManager InformationManager to use for getting the Html
* @throws NullPointerException if AnalysisData has not been cached after 1 second.
*/
public AnalysisPageResponse(InformationManager informationManager) {
super.setHeader("HTTP/1.1 200 OK");
if (informationManager instanceof BukkitInformationManager) {
AnalysisData analysisData = ((BukkitInformationManager) informationManager).getAnalysisData();
if (analysisData == null) {
RunnableFactory.createNew("OnRequestAnalysisRefreshTask", new AbsRunnable() {
@Override
public void run() {
informationManager.refreshAnalysis(Plan.getServerUUID());
}
}).runTaskAsynchronously();
ErrorResponse analysisRefreshPage = new ErrorResponse();
analysisRefreshPage.setTitle("Analysis is being refreshed..");
analysisRefreshPage.setParagraph("<i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
analysisRefreshPage.replacePlaceholders();
super.setContent(analysisRefreshPage.getContent());
return;
}
public static AnalysisPageResponse refreshNow() {
try {
InfoSystem.getInstance().generateAnalysisPageOfThisServer();
} catch (WebException e) {
// TODO Exception handling
Log.toLog(AnalysisPageResponse.class, e);
}
super.setContent(informationManager.getAnalysisHtml());
return new AnalysisPageResponse(getRefreshingHtml());
}
public AnalysisPageResponse(String html) {

View File

@ -15,16 +15,11 @@ import java.util.UUID;
/**
* @author Rsl1122
*/
@Deprecated
public class AnalysisReadyWebAPI extends WebAPI {
@Override
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
String serverUUIDS = variables.get("serverUUID");
if (serverUUIDS == null) {
return badRequest("serverUUID was not present");
}
UUID serverUUID = UUID.fromString(serverUUIDS);
plugin.getInfoManager().analysisReady(serverUUID);
return success();
return fail("Deprecated");
}
@Override

View File

@ -15,16 +15,11 @@ import java.util.UUID;
/**
* @author Rsl1122
*/
@Deprecated
public class AnalyzeWebAPI extends WebAPI {
@Override
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
String serverUUIDS = variables.get("serverUUID");
if (serverUUIDS == null) {
return badRequest("serverUUID was not present");
}
UUID serverUUID = UUID.fromString(serverUUIDS);
plugin.getInfoManager().refreshAnalysis(serverUUID);
return success();
return fail("Deprecated");
}
@Override

View File

@ -6,19 +6,9 @@ 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.settings.Settings;
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.plan.system.webserver.response.pages.InspectPageResponse;
import com.djrapitops.plan.system.webserver.webapi.WebAPI;
import com.djrapitops.plan.systems.info.InformationManager;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.api.utility.log.Log;
import org.apache.commons.lang3.text.StrSubstitutor;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -27,53 +17,12 @@ import java.util.UUID;
*
* @author Rsl1122
*/
@Deprecated
public class PostHtmlWebAPI extends WebAPI {
@Override
public Response onRequest(PlanPlugin plugin, Map<String, String> variables) {
try {
String htmlVariable = variables.get("html");
if (htmlVariable == null) {
return badRequest("Html was null");
}
if (!htmlVariable.startsWith("<!DOCTYPE html>")) {
String[] split = htmlVariable.split("<!DOCTYPE html>", 2);
if (split.length <= 1) {
Log.debug(htmlVariable);
return badRequest("Html did not start with <!DOCTYPE html>");
}
htmlVariable = "<!DOCTYPE html>" + split[1];
}
String html = htmlVariable;
String target = variables.get("target");
InformationManager infoManager = plugin.getInfoManager();
switch (target) {
case "inspectPage":
String uuid = variables.get("uuid");
Map<String, String> map = new HashMap<>();
map.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString());
ResponseCache.cacheResponse(PageId.PLAYER.of(uuid), () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), StrSubstitutor.replace(html, map)));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportPlayer(UUID.fromString(uuid));
}
break;
case "analysisPage":
String sender = variables.get("sender");
ResponseCache.cacheResponse(PageId.SERVER.of(sender), () -> new AnalysisPageResponse(html));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportServer(UUID.fromString(sender));
}
break;
default:
return badRequest("Faulty Target");
}
return success();
} catch (NullPointerException e) {
return badRequest(e.toString());
}
return fail("Deprecated");
}
@Override

View File

@ -1,204 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.systems.info;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.api.exceptions.connection.WebFailException;
import com.djrapitops.plan.data.AnalysisData;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.system.webserver.WebServer;
import com.djrapitops.plan.system.webserver.WebServerSystem;
import com.djrapitops.plan.system.webserver.pages.parsing.AnalysisPage;
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.errors.ErrorResponse;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
import com.djrapitops.plan.system.webserver.webapi.WebAPIManager;
import com.djrapitops.plan.system.webserver.webapi.bukkit.AnalysisReadyWebAPI;
import com.djrapitops.plan.system.webserver.webapi.bukkit.AnalyzeWebAPI;
import com.djrapitops.plan.system.webserver.webapi.bungee.PostHtmlWebAPI;
import com.djrapitops.plan.system.webserver.webapi.bungee.PostOriginalBukkitSettingsWebAPI;
import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plan.utilities.analysis.Analysis;
import com.djrapitops.plan.utilities.file.export.HtmlExport;
import com.djrapitops.plugin.api.utility.log.Log;
import java.util.HashSet;
import java.util.Optional;
import java.util.UUID;
/**
* Manages the Information going to the ResponseCache.
* <p>
* This means Inspect and Analysis pages as well as managing what is sent to Bungee WebServer when one is in use.
*
* @author Rsl1122
*/
@Deprecated
public class BukkitInformationManager extends InformationManager {
private final Plan plugin;
private final Analysis analysis;
private AnalysisData analysisData;
public BukkitInformationManager(Plan plugin) {
this.plugin = plugin;
analysis = new Analysis(plugin);
usingAnotherWebServer = false;
}
public void updateConnection() {
Optional<String> bungeeConnectionAddress = plugin.getServerInfoManager().getBungeeConnectionAddress();
if (bungeeConnectionAddress.isPresent() && Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
webServerAddress = bungeeConnectionAddress.get();
attemptConnection();
} else {
usingAnotherWebServer = false;
}
}
@Override
public void refreshAnalysis(UUID serverUUID) {
if (Plan.getServerUUID().equals(serverUUID)) {
analysis.runAnalysis();
} else if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(AnalyzeWebAPI.class).sendRequest(webServerAddress, serverUUID);
} catch (WebFailException e) {
Log.error("Failed to request Analysis refresh from Bungee.");
} catch (WebException e) {
attemptConnection();
refreshAnalysis(serverUUID);
}
}
}
private WebAPIManager getWebAPI() {
return plugin.getWebServer().getWebAPI();
}
/**
* Get the HTML for analysis page of this server.
*
* @return Html for Analysis page
* @throws NullPointerException if AnalysisData has not been cached.
*/
@Override
public String getAnalysisHtml() {
if (analysisData == null) {
analysis.runAnalysis();
ErrorResponse analysisRefreshPage = new ErrorResponse();
analysisRefreshPage.setTitle("Analysis is being refreshed..");
analysisRefreshPage.setParagraph("<meta http-equiv=\"refresh\" content=\"25\" /><i class=\"fa fa-refresh fa-spin\" aria-hidden=\"true\"></i> Analysis is being run, refresh the page after a few seconds.. (F5)");
analysisRefreshPage.replacePlaceholders();
return analysisRefreshPage.getContent();
}
try {
return Theme.replaceColors(new AnalysisPage(analysisData, plugin).toHtml());
} catch (ParseException e) {
return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent();
}
}
public void cacheAnalysisData(AnalysisData analysisData) {
this.analysisData = analysisData;
refreshDate = MiscUtils.getTime();
cacheAnalysisHtml();
UUID serverUUID = Plan.getServerUUID();
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(AnalysisReadyWebAPI.class).sendRequest(webServerAddress, serverUUID);
// updateNetworkPageContent();
return;
} catch (WebFailException ignored) {
Log.error("Failed to notify Bungee of Analysis Completion.");
} catch (WebException e) {
attemptConnection();
}
}
analysisReady(serverUUID);
}
private void cacheAnalysisHtml() {
cacheAnalysisHtml(getAnalysisHtml());
}
@Deprecated
public void cacheAnalysisHtml(String html) {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(PostHtmlWebAPI.class).sendAnalysisHtml(webServerAddress, html);
} catch (WebFailException e) {
Log.error("Failed to send Analysis HTML to Bungee Server.");
} catch (WebException e) {
attemptConnection();
cacheAnalysisHtml(html);
}
} else {
UUID serverUUID = Plan.getServerUUID();
ResponseCache.cacheResponse(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(html));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportServer(serverUUID);
}
}
}
public AnalysisData getAnalysisData() {
return analysisData;
}
@Override
public boolean attemptConnection() {
boolean webServerIsEnabled = WebServerSystem.isWebServerEnabled();
boolean previousState = usingAnotherWebServer;
try {
Log.info("Attempting Bungee Connection.. (" + webServerAddress + ")");
// PingWebAPI api = getWebAPI().getAPI(PingWebAPI.class);
try {
// api.sendRequest(webServerAddress);
getWebAPI().getAPI(PostOriginalBukkitSettingsWebAPI.class).sendRequest(webServerAddress);
Log.info("Bungee Connection OK");
plugin.getServerInfoManager().resetConnectionFails();
usingAnotherWebServer = true;
return true;
} catch (ConnectionFailException e) {
plugin.getServerInfoManager().markConnectionFail();
} catch (NotFoundException e) {
Log.info("Bungee reported that UUID of this server is not in the MySQL-database. Try using '/plan m setup " + webServerAddress + "' again");
} catch (WebException e) {
Log.toLog(this.getClass().getName(), e);
}
Log.info("Bungee Connection Failed.");
usingAnotherWebServer = false;
return false;
} finally {
boolean changedState = previousState != usingAnotherWebServer;
if (webServerIsEnabled && changedState) {
WebServer webServer = WebServerSystem.getInstance().getWebServer();
webServer.stop();
webServer.initServer();
}
}
}
@Override
public String getWebServerAddress() {
return webServerAddress != null ? webServerAddress : plugin.getWebServer().getAccessAddress();
}
@Override
public void analysisReady(UUID serverUUID) {
analysisNotification.getOrDefault(serverUUID, new HashSet<>()).clear();
}
}

View File

@ -1,185 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.systems.info;
import com.djrapitops.plan.PlanBungee;
import com.djrapitops.plan.api.exceptions.ParseException;
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.system.info.server.BungeeServerInfo;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.webserver.pages.parsing.NetworkPage;
import com.djrapitops.plan.system.webserver.response.errors.InternalErrorResponse;
import com.djrapitops.plan.system.webserver.webapi.WebAPIManager;
import com.djrapitops.plan.system.webserver.webapi.bukkit.AnalysisReadyWebAPI;
import com.djrapitops.plan.system.webserver.webapi.bukkit.AnalyzeWebAPI;
import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Manages information going to the ResponseCache from Bukkit servers.
*
* @author Rsl1122
*/
@Deprecated
public class BungeeInformationManager extends InformationManager {
private final PlanBungee plugin;
private final BungeeServerInfo serverInfoManager;
private Map<UUID, Server> bukkitServers;
public BungeeInformationManager(PlanBungee plugin) {
usingAnotherWebServer = false;
this.plugin = plugin;
serverInfoManager = plugin.getServerInfoManager();
refreshBukkitServerMap();
}
/**
* Refreshes the Offline Bukkit server Map (UUID - Server Address Map) from DB.
*
* @throws SQLException If DB Error occurs.
*/
private void refreshBukkitServerMap() {
bukkitServers = plugin.getDB().getServerTable().getBukkitServers().stream().collect(Collectors.toMap(Server::getUuid, Function.identity()));
}
/**
* Sends a "Refresh Analysis" WebAPI call to the appropriate Bukkit server.
* <p>
* if server is not online, api request will not be made.
*
* @param serverUUID Server UUID of the server in question.
*/
@Override
public void refreshAnalysis(UUID serverUUID) {
if (PlanBungee.getServerUUID().equals(serverUUID)) {
return;
}
Server server = getOnlineServerInfo(serverUUID);
if (server == null) {
return;
}
AnalyzeWebAPI api = plugin.getWebServer().getWebAPI().getAPI(AnalyzeWebAPI.class);
try {
api.sendRequest(server.getWebAddress(), serverUUID);
} catch (ConnectionFailException e) {
attemptConnection();
} catch (WebException e) {
Log.toLog(this.getClass().getName(), e);
}
}
/**
* Attempts to get info of a server that is online.
* <p>
* Returns null if server doesn't exist.
*
* @param serverUUID UUID of server
* @return Online Server or null
*/
private Server getOnlineServerInfo(UUID serverUUID) {
Server server = bukkitServers.get(serverUUID);
if (server == null) {
try {
refreshBukkitServerMap();
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
server = bukkitServers.get(serverUUID);
}
if (server == null) {
return null;
}
if (serverInfoManager.getOnlineBukkitServers().contains(server) || serverInfoManager.attemptConnection(server)) {
return server;
}
return null;
}
/**
* Attempts a connection to every Bukkit server in the database.
*
* @return true (always)
*/
@Override
public boolean attemptConnection() {
try {
List<Server> bukkitServers = plugin.getDB().getServerTable().getBukkitServers();
for (Server server : bukkitServers) {
serverInfoManager.attemptConnection(server);
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
return true;
}
/**
* Get the Network page html.
*
* @return Html string (Full page)
*/
@Override
public String getAnalysisHtml() {
try {
return new NetworkPage(plugin).toHtml();
} catch (ParseException e) {
return new InternalErrorResponse(e, this.getClass().getSimpleName()).getContent();
}
}
/**
* Shortcut for getting WebAPIManager
*
* @return WebAPIManager
*/
private WebAPIManager getWebAPI() {
return plugin.getWebServer().getWebAPI();
}
/**
* Get address of Bungee WebServer.
*
* @return URL String
*/
@Override
public String getWebServerAddress() {
return plugin.getWebServer().getAccessAddress();
}
/**
* Send notification of analysis being ready to all online bukkit servers via WebAPI.
*
* @param serverUUID UUID of a server which analysis is ready.
*/
@Override
public void analysisReady(UUID serverUUID) {
AnalysisReadyWebAPI api = getWebAPI().getAPI(AnalysisReadyWebAPI.class);
for (Server server : serverInfoManager.getOnlineBukkitServers()) {
try {
api.sendRequest(server.getWebAddress(), serverUUID);
} catch (WebException ignored) {
/*Ignored*/
}
}
}
public void sendConfigSettings() {
Collection<Server> online = serverInfoManager.getOnlineBukkitServers();
online.stream().map(Server::getUuid)
.forEach(serverInfoManager::sendConfigSettings);
}
}

View File

@ -1,61 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package com.djrapitops.plan.systems.info;
import com.djrapitops.plugin.command.ISender;
import java.util.*;
/**
* Abstract layer for Bukkit and Bungee Information managers.
* <p>
* Manages analysis notification sending.
*
* @author Rsl1122
*/
@Deprecated
public abstract class InformationManager {
boolean usingAnotherWebServer;
String webServerAddress;
Map<UUID, Set<ISender>> analysisNotification;
public InformationManager() {
analysisNotification = new HashMap<>();
}
public abstract boolean attemptConnection();
public String getLinkTo(String target) {
return getWebServerAddress() + target;
}
public abstract void refreshAnalysis(UUID serverUUID);
/**
* Used for /server on Bukkit and /network on Bungee
*
* @return Html of a page.
*/
public abstract String getAnalysisHtml();
public void addAnalysisNotification(ISender sender, UUID serverUUID) {
Set<ISender> notify = analysisNotification.getOrDefault(serverUUID, new HashSet<>());
notify.add(sender);
analysisNotification.put(serverUUID, notify);
}
public boolean isUsingAnotherWebServer() {
return usingAnotherWebServer;
}
public abstract String getWebServerAddress();
public boolean isAuthRequired() {
return getWebServerAddress().startsWith("https");
}
public abstract void analysisReady(UUID serverUUID);
}

View File

@ -10,9 +10,11 @@ import com.djrapitops.plan.data.container.UserInfo;
import com.djrapitops.plan.settings.theme.Theme;
import com.djrapitops.plan.settings.theme.ThemeVal;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.webserver.response.pages.PlayersPageResponse;
import com.djrapitops.plan.system.webserver.webapi.bungee.PostHtmlWebAPI;
import com.djrapitops.plan.utilities.file.FileUtil;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.task.RunnableFactory;
@ -57,8 +59,7 @@ public class HtmlExport extends SpecificExport {
@Override
public void run() {
try {
boolean usingAnotherWebServer = plugin.getInfoManager().isUsingAnotherWebServer();
if (usingAnotherWebServer) {
if (Check.isBukkitAvailable() && ConnectionSystem.getInstance().isServerAvailable()) {
return;
}

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.utilities.metrics;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.Check;
import com.djrapitops.plugin.api.utility.log.Log;
@ -53,7 +54,7 @@ public class BStats {
map.put("HTTPS", isEnabled("HTTPS".equals(plugin.getWebServer().getProtocol().toUpperCase())));
map.put("HTML Export", isEnabled(Settings.ANALYSIS_EXPORT.isTrue()));
boolean isConnectedToBungee = plugin.getInfoManager().isUsingAnotherWebServer();
boolean isConnectedToBungee = ConnectionSystem.getInstance().isServerAvailable();
map.put("BungeeCord Connected", isEnabled(isConnectedToBungee));
if (isConnectedToBungee) {
map.put("Copy Bungee Config Values", isEnabled(Settings.BUNGEE_COPY_CONFIG.isTrue()));

View File

@ -7,11 +7,14 @@ import com.djrapitops.plan.data.AnalysisData;
import com.djrapitops.plan.data.plugin.PluginData;
import com.djrapitops.plan.system.database.databases.Database;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plan.system.info.request.GenerateAnalysisPageRequest;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.webserver.pages.DefaultResponses;
import com.djrapitops.plan.system.webserver.response.cache.PageId;
import com.djrapitops.plan.system.webserver.response.cache.ResponseCache;
import com.djrapitops.plan.systems.info.BukkitInformationManager;
import com.djrapitops.plan.system.webserver.response.pages.AnalysisPageResponse;
import com.djrapitops.plan.utilities.analysis.Analysis;
import com.djrapitops.plan.utilities.uuid.UUIDUtility;
import com.djrapitops.plugin.api.utility.log.Log;
import com.djrapitops.plugin.utilities.Verify;
@ -182,7 +185,11 @@ public class API {
*/
@Deprecated
public void updateAnalysisCache() {
plugin.getInfoManager().refreshAnalysis(plugin.getServerUuid());
if (!Analysis.isAnalysisBeingRun()) {
WebExceptionLogger.logIfOccurs(this.getClass(), () ->
InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID()))
);
}
}
/**
@ -195,7 +202,7 @@ public class API {
*/
@Deprecated
public String getAnalysisHtmlAsString() {
return plugin.getInfoManager().getAnalysisHtml();
return ResponseCache.loadResponse(PageId.SERVER.of(ServerInfo.getServerUUID()), AnalysisPageResponse::refreshNow).getContent();
}
/**
@ -208,7 +215,7 @@ public class API {
*/
@Deprecated
public AnalysisData getAnalysisDataFromCache() {
return ((BukkitInformationManager) plugin.getInfoManager()).getAnalysisData();
return new AnalysisData();
}
/**

View File

@ -7,8 +7,8 @@ package com.djrapitops.plan.data.additional.importer;
import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.time.GMTimes;
import com.djrapitops.plan.system.processing.processors.importing.ServerImportData;
import com.djrapitops.plan.system.processing.processors.importing.UserImportData;
import com.djrapitops.plan.system.processing.importing.ServerImportData;
import com.djrapitops.plan.system.processing.importing.UserImportData;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import test.utilities.RandomData;