diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java
index 325d1abda..843482ab3 100644
--- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java
+++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java
@@ -21,6 +21,7 @@ import main.java.com.djrapitops.plan.systems.info.parsing.InspectPageParser;
import main.java.com.djrapitops.plan.systems.processing.Processor;
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
+import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
@@ -114,7 +115,7 @@ public class BukkitInformationManager extends InformationManager {
}
}
} else {
- PageCache.cachePage("inspectPage: " + uuid, () -> {
+ PageCache.cachePage(PageId.PLAYER.of(uuid), () -> {
try {
return new InspectPageResponse(this, uuid);
} catch (ParseException e) {
@@ -188,7 +189,7 @@ public class BukkitInformationManager extends InformationManager {
}
} else {
pluginsTabContents.put(uuid, contents);
- Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
+ Response inspectResponse = PageCache.loadPage(PageId.PLAYER.of(uuid));
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(contents);
}
@@ -231,7 +232,7 @@ public class BukkitInformationManager extends InformationManager {
return isAnalysisCached(serverUUID);
}
}
- return PageCache.isCached("analysisPage:" + serverUUID);
+ return PageCache.isCached(PageId.SERVER.of(serverUUID));
}
private WebAPIManager getWebAPI() {
@@ -306,7 +307,7 @@ public class BukkitInformationManager extends InformationManager {
}
} else {
UUID serverUUID = Plan.getServerUUID();
- PageCache.cachePage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(html));
+ PageCache.cachePage(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(html));
if (Settings.ANALYSIS_EXPORT.isTrue()) {
HtmlExport.exportServer(plugin, serverUUID);
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java
index 4b8dd202d..3a16b44d5 100644
--- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java
+++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BungeeInformationManager.java
@@ -17,6 +17,7 @@ import main.java.com.djrapitops.plan.systems.info.parsing.NetworkPageParser;
import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
+import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.*;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
@@ -233,11 +234,7 @@ public class BungeeInformationManager extends InformationManager {
*/
@Override
public boolean isAnalysisCached(UUID serverUUID) {
- if (PlanBungee.getServerUUID().equals(serverUUID)) {
- return PageCache.isCached("networkPage");
- } else {
- return PageCache.isCached("analysisPage:" + serverUUID);
- }
+ return PageCache.isCached(PageId.SERVER.of(serverUUID));
}
/**
@@ -250,7 +247,7 @@ public class BungeeInformationManager extends InformationManager {
*/
@Override
public String getPlayerHtml(UUID uuid) {
- Response response = PageCache.copyPage("inspectPage:" + uuid,
+ Response response = PageCache.copyPage(PageId.PLAYER.of(uuid),
() -> new NotFoundResponse("No Bukkit Servers were online to process this request"));
if (response instanceof InspectPageResponse) {
((InspectPageResponse) response).setInspectPagePluginsTab(getPluginsTabContent(uuid));
@@ -314,7 +311,7 @@ public class BungeeInformationManager extends InformationManager {
Map
"
+ "Make sure your user has the correct access level.
"
+ "This page requires permission level of " + required + ",
"
@@ -183,7 +184,7 @@ public class ResponseHandler extends APIResponseHandler {
case 0:
return serverResponse(serverUUID);
case 1:
- return PageCache.loadPage("players", PlayersPageResponse::new);
+ return PageCache.loadPage(PageId.PLAYERS.id(), PlayersPageResponse::new);
case 2:
return playerResponse(new String[]{"", "", user.getName()});
default:
@@ -192,12 +193,12 @@ public class ResponseHandler extends APIResponseHandler {
}
private Response serverResponse(UUID serverUUID) {
- return PageCache.loadPage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(plugin.getInfoManager()));
+ return PageCache.loadPage(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(plugin.getInfoManager()));
}
private Response playerResponse(String[] args) {
if (args.length < 3) {
- return PageCache.loadPage("notFound", NotFoundResponse::new);
+ return PageCache.loadPage(PageId.NOT_FOUND.id(), NotFoundResponse::new);
}
String playerName = args[2].trim();
@@ -205,22 +206,22 @@ public class ResponseHandler extends APIResponseHandler {
if (uuid == null) {
String error = "Player has no UUID";
- return PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
+ return PageCache.loadPage(PageId.NOT_FOUND.of(error), () -> new NotFoundResponse(error));
}
if (plugin.getDB().wasSeenBefore(uuid)) {
plugin.getInfoManager().cachePlayer(uuid);
- Response response = PageCache.loadPage("inspectPage: " + uuid);
+ Response response = PageCache.loadPage(PageId.PLAYER.of(uuid));
// TODO Create a new method that places NotFoundResponse to PageCache instead.
if (response == null || response.getContent().contains("No Bukkit Servers were online to process this request")) {
- PageCache.cachePage("inspectPage: " + uuid, () -> {
+ PageCache.cachePage(PageId.PLAYER.of(uuid), () -> {
try {
return new InspectPageResponse(plugin.getInfoManager(), uuid);
} catch (ParseException e) {
return new InternalErrorResponse(e, this.getClass().getName());
}
});
- response = PageCache.loadPage("inspectPage: " + uuid);
+ response = PageCache.loadPage(PageId.PLAYER.of(uuid));
}
return response;
}
@@ -229,7 +230,7 @@ public class ResponseHandler extends APIResponseHandler {
private Response notFoundResponse() {
String error = "404 Not Found";
- return PageCache.loadPage("notFound: " + error, () -> {
+ return PageCache.loadPage(PageId.NOT_FOUND.of("Wrong Page"), () -> {
String url = plugin.getInfoManager().getWebServerAddress();
return new NotFoundResponse("Make sure you're accessing a link given by a command, Examples:
" + url + "/player/Playername
" +
diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/pagecache/PageId.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/pagecache/PageId.java
new file mode 100644
index 000000000..48021fab5
--- /dev/null
+++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/pagecache/PageId.java
@@ -0,0 +1,50 @@
+/*
+ * 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.systems.webserver.pagecache;
+
+import java.util.UUID;
+
+/**
+ * Enum class for "magic" PageCache identifier values.
+ *
+ * @author Rsl1122
+ */
+public enum PageId {
+
+ SERVER("serverPage:"),
+ PLAYER("playerPage:"),
+ PLAYERS("playersPage"),
+ //
+ ERROR("error:"),
+ FORBIDDEN(ERROR.of("Forbidden")),
+ NOT_FOUND(ERROR.of("Not Found")),
+ TRUE("true"),
+ FALSE("false"),
+ //
+ JS("js:"),
+ CSS("css:"),
+ //
+ FAVICON_REDIRECT("Redirect:Favicon"),
+ AUTH_PROMPT("PromptAuth")
+ ;
+
+ private final String id;
+
+ PageId(String id) {
+ this.id = id;
+ }
+
+ public String of(String additionalInfo) {
+ return id + additionalInfo;
+ }
+
+ public String of(UUID uuid) {
+ return of(uuid.toString());
+ }
+
+ public String id() {
+ return id;
+ }
+}
\ No newline at end of file
diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java
index 0c91a42a2..170bfd004 100644
--- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java
+++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/WebAPI.java
@@ -10,6 +10,7 @@ import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.*;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
+import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.NotFoundResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
@@ -165,11 +166,11 @@ public abstract class WebAPI {
};
protected Response success() {
- return PageCache.loadPage("success", SuccessResponse::new);
+ return PageCache.loadPage(PageId.TRUE.id(), SuccessResponse::new);
}
protected Response fail(String reason) {
- return PageCache.loadPage("fail", () -> {
+ return PageCache.loadPage(PageId.FALSE.id(), () -> {
NotFoundResponse notFoundResponse = new NotFoundResponse("");
notFoundResponse.setContent(reason);
return notFoundResponse;
@@ -177,7 +178,7 @@ public abstract class WebAPI {
}
protected Response badRequest(String error) {
- return PageCache.loadPage(error, () -> new BadRequestResponse(error));
+ return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
}
private String parseVariables() {
diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java
index 175998a34..7c131d498 100644
--- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java
+++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/webapi/bungee/PostHtmlWebAPI.java
@@ -10,6 +10,7 @@ import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.settings.Settings;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
+import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
@@ -54,14 +55,14 @@ public class PostHtmlWebAPI extends WebAPI {
Map