Removed DataRequesthandler, Plan uiServer -> webServer

This commit is contained in:
Rsl1122 2017-08-25 09:37:29 +03:00
parent dd4642980b
commit 47f500c3c3
14 changed files with 48 additions and 109 deletions

View File

@ -79,7 +79,7 @@ public class Plan extends BukkitPlugin<Plan> {
private Database db;
private Set<Database> databases;
private WebServer uiServer;
private WebServer webServer;
private InformationManager infoManager;
private ServerInfoManager serverInfoManager;
@ -160,16 +160,17 @@ public class Plan extends BukkitPlugin<Plan> {
Benchmark.stop("Enable", "Init Database");
Benchmark.start("WebServer Initialization");
uiServer = new WebServer(this);
webServer = new WebServer(this);
registerWebAPIs(); // TODO Move to WebServer class
uiServer.initServer();
webServer.initServer();
if (!uiServer.isEnabled()) {
if (!webServer.isEnabled()) {
Log.error("WebServer was not successfully initialized.");
}
serverInfoManager = new ServerInfoManager(this);
infoManager = new InformationManager(this);
webServer.setInfoManager(infoManager);
registerListeners();
registerTasks();
@ -272,8 +273,8 @@ public class Plan extends BukkitPlugin<Plan> {
PageCache.clearCache();
// Stop the UI Server
if (uiServer != null) {
uiServer.stop();
if (webServer != null) {
webServer.stop();
}
getServer().getScheduler().cancelTasks(this);
@ -371,8 +372,8 @@ public class Plan extends BukkitPlugin<Plan> {
*
* @return the Webserver
*/
public WebServer getUiServer() {
return uiServer;
public WebServer getWebServer() {
return webServer;
}
/**

View File

@ -46,7 +46,7 @@ public class PlanCommand extends TreeCommand<Plan> {
commands.add(new ManageCommand(plugin));
commands.add(new StatusCommand<>(plugin, Permissions.MANAGE.getPermission()));
if (plugin.getUiServer().isEnabled()) {
if (plugin.getWebServer().isEnabled()) {
commands.add(new ListCommand());
RegisterCommand registerCommand = new RegisterCommand(plugin);
commands.add(registerCommand);

View File

@ -55,7 +55,7 @@ public class AnalyzeCommand extends SubCommand {
// }
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
if (plugin.getUiServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
if (plugin.getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
plugin.getRunnableFactory().createNew(new AbsRunnable("WebUser exist check task") {
@Override
public void run() {

View File

@ -81,7 +81,7 @@ public class InspectCommand extends SubCommand {
return;
}
sender.sendMessage(Locale.get(Msg.CMD_INFO_FETCH_DATA).toString());
if (CommandUtils.isPlayer(sender) && plugin.getUiServer().isAuthRequired()) {
if (CommandUtils.isPlayer(sender) && plugin.getWebServer().isAuthRequired()) {
boolean senderHasWebUser = plugin.getDB().getSecurityTable().userExists(sender.getName());
if (!senderHasWebUser) {
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");

View File

@ -67,7 +67,7 @@ public class ServerInfoManager {
return;
}
String name = Settings.SERVER_NAME.toString();
String webAddress = plugin.getUiServer().getAccessAddress();
String webAddress = plugin.getWebServer().getAccessAddress();
if ("plan".equalsIgnoreCase(name)) {
name = "Server" + serverID.get();
}
@ -81,7 +81,7 @@ public class ServerInfoManager {
}
private void registerServer(UUID serverUUID) throws SQLException, IOException {
String webAddress = plugin.getUiServer().getAccessAddress();
String webAddress = plugin.getWebServer().getAccessAddress();
String name = Settings.SERVER_NAME.toString();
serverInfo = new ServerInfo(-1, serverUUID, name, webAddress);
serverTable.saveCurrentServerInfo(serverInfo);

View File

@ -10,12 +10,12 @@ import main.java.com.djrapitops.plan.database.tables.SecurityTable;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.cache.PageCache;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
import main.java.com.djrapitops.plan.systems.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
import main.java.com.djrapitops.plan.ui.html.DataRequestHandler;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
@ -44,7 +44,8 @@ import java.util.zip.GZIPOutputStream;
public class WebServer {
private final Plan plugin;
private final DataRequestHandler dataReqHandler;
private InformationManager infoManager;
private final int port;
private boolean enabled = false;
private HttpServer server;
@ -53,15 +54,16 @@ public class WebServer {
/**
* Class Constructor.
* <p>
* Initializes DataRequestHandler
*
* @param plugin Current instance of Plan
*/
public WebServer(Plan plugin) {
this.plugin = plugin;
this.port = Settings.WEBSERVER_PORT.getNumber();
dataReqHandler = new DataRequestHandler(plugin);
}
public void setInfoManager(InformationManager infoManager) {
this.infoManager = infoManager;
}
/**
@ -445,12 +447,12 @@ public class WebServer {
}
private Response serverResponse() {
if (!dataReqHandler.checkIfAnalysisIsCached()) {
if (!infoManager.isAnalysisCached()) {
String error = "Analysis Data was not cached.<br>Use /plan analyze to cache the Data.";
PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
}
return PageCache.loadPage("analysisPage", () -> new AnalysisPageResponse(dataReqHandler));
return PageCache.loadPage("analysisPage", () -> new AnalysisPageResponse(infoManager));
}
private Response playerResponse(String[] args) {
@ -466,12 +468,12 @@ public class WebServer {
return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
}
if (!dataReqHandler.checkIfCached(uuid)) {
if (!infoManager.isCached(uuid)) {
String error = "Player's data was not cached.<br>Use /plan inspect " + playerName + " to cache the Data.";
return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
}
return PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(dataReqHandler, uuid));
return PageCache.loadPage("inspectPage: " + uuid, () -> new InspectPageResponse(infoManager, uuid));
}
private Response notFoundResponse() {
@ -504,15 +506,6 @@ public class WebServer {
}
}
/**
* Used to get the handler for Html content requests.
*
* @return DataRequestHandler used by the WebServer.
*/
public DataRequestHandler getDataReqHandler() {
return dataReqHandler;
}
private int getRequiredPermLevel(String target, String user) {
String[] t = target.split("/");
if (t.length < 2) {

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.systems.webserver.response;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
import main.java.com.djrapitops.plan.ui.html.DataRequestHandler;
/**
* @author Rsl1122
@ -9,8 +9,8 @@ import main.java.com.djrapitops.plan.ui.html.DataRequestHandler;
*/
public class AnalysisPageResponse extends Response {
public AnalysisPageResponse(DataRequestHandler h) {
public AnalysisPageResponse(InformationManager informationManager) {
super.setHeader("HTTP/1.1 200 OK");
super.setContent(Theme.replaceColors(h.getServerHtml()));
super.setContent(Theme.replaceColors(informationManager.getAnalysisHtml()));
}
}

View File

@ -1,7 +1,7 @@
package main.java.com.djrapitops.plan.systems.webserver.response;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.theme.Theme;
import main.java.com.djrapitops.plan.ui.html.DataRequestHandler;
import java.util.UUID;
@ -11,8 +11,8 @@ import java.util.UUID;
*/
public class InspectPageResponse extends Response {
public InspectPageResponse(DataRequestHandler h, UUID uuid) {
public InspectPageResponse(InformationManager infoManager, UUID uuid) {
super.setHeader("HTTP/1.1 200 OK");
super.setContent(Theme.replaceColors(h.getInspectHtml(uuid)));
super.setContent(Theme.replaceColors(infoManager.getPlayerHtml(uuid)));
}
}

View File

@ -1,68 +0,0 @@
package main.java.com.djrapitops.plan.ui.html;
import main.java.com.djrapitops.plan.Plan;
import java.util.UUID;
/**
* @author Rsl1122
*/
@Deprecated //TODO Make an utility class for parsing files to give to the page cache.
public class DataRequestHandler {
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
@Deprecated
public DataRequestHandler(Plan plugin) {
}
/**
* Checks if the Players data is in the inspect cache.
*
* @param uuid UUID of Player
* @return true if cached.
*/
@Deprecated
public boolean checkIfCached(UUID uuid) {
// TODO Check from PageCache
return false;
}
/**
* Returns the player.html as string with replaced placeholders.
*
* @param uuid UUID of player, whose UserInfo is used to replace
* placeholders with
* @return The html
*/
@Deprecated
public String getInspectHtml(UUID uuid) {
// TODO Get from PageCache
return "";
}
/**
* Returns the server.html as string with replaced placeholders.
*
* @return the html
*/
@Deprecated
public String getServerHtml() {
// TODO Get from PageCache
return "";
}
/**
* Checks if the AnalysisData is cached.
*
* @return true if cached.
*/
@Deprecated
public boolean checkIfAnalysisIsCached() {
// TODO Check from PageCache
return false;
}
}

View File

@ -151,7 +151,7 @@ public class Analysis {
Log.info(Locale.get(Msg.ANALYSIS_FINISHED).parse(String.valueOf(time), HtmlUtils.getServerAnalysisUrlWithProtocol()));
PageCache.removeIf(identifier -> identifier.startsWith("inspectPage: ") || identifier.startsWith("inspectionJson: "));
PageCache.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler()));
PageCache.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getInfoManager()));
PageCache.cachePage("analysisJson", () -> new JsonResponse(analysisData));
PageCache.cachePage("players", () -> new PlayersPageResponse(plugin));

View File

@ -198,7 +198,7 @@ public class DumpUtils {
* @param plan The Plan instance
*/
private static void addConfigurationDetails(DumpLog log, Plan plan) {
boolean usingHTTPS = plan.getUiServer().isUsingHTTPS();
boolean usingHTTPS = plan.getWebServer().isUsingHTTPS();
boolean analysisExport = Settings.ANALYSIS_EXPORT.isTrue();
boolean usingAlternativeServerIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();

View File

@ -0,0 +1,13 @@
/*
* 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 main.java.com.djrapitops.plan.utilities.html;
/**
* Class for parsing layout components of the websites.
*
* @author Rsl1122
*/
public class HtmlStructure {
}

View File

@ -79,7 +79,7 @@ public class HtmlUtils {
}
public static String getProtocol() {
WebServer uiServer = Plan.getInstance().getUiServer();
WebServer uiServer = Plan.getInstance().getWebServer();
return uiServer.isEnabled() ? uiServer.getProtocol() : Settings.EXTERNAL_WEBSERVER_LINK_PROTOCOL.toString();
}

View File

@ -33,7 +33,7 @@ public class BStats {
addStringSettingPie("server_type", serverType);
addStringSettingPie("database_type", databaseType);
addStringSettingPie("web_protocol", plugin.getUiServer().getProtocol().toUpperCase());
addStringSettingPie("web_protocol", plugin.getWebServer().getProtocol().toUpperCase());
}
private void addEnabledDisabledPie(String id, boolean setting) {