mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-29 03:21:25 +01:00
Introduced PageId for preventing PageCache identifier mistakes in the future
This commit is contained in:
parent
3fb21b1d1e
commit
9bf4a94510
@ -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.processing.Processor;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
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.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.response.*;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
|
||||||
@ -114,7 +115,7 @@ public class BukkitInformationManager extends InformationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PageCache.cachePage("inspectPage: " + uuid, () -> {
|
PageCache.cachePage(PageId.PLAYER.of(uuid), () -> {
|
||||||
try {
|
try {
|
||||||
return new InspectPageResponse(this, uuid);
|
return new InspectPageResponse(this, uuid);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
@ -188,7 +189,7 @@ public class BukkitInformationManager extends InformationManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pluginsTabContents.put(uuid, contents);
|
pluginsTabContents.put(uuid, contents);
|
||||||
Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
|
Response inspectResponse = PageCache.loadPage(PageId.PLAYER.of(uuid));
|
||||||
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
|
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
|
||||||
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(contents);
|
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(contents);
|
||||||
}
|
}
|
||||||
@ -231,7 +232,7 @@ public class BukkitInformationManager extends InformationManager {
|
|||||||
return isAnalysisCached(serverUUID);
|
return isAnalysisCached(serverUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PageCache.isCached("analysisPage:" + serverUUID);
|
return PageCache.isCached(PageId.SERVER.of(serverUUID));
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebAPIManager getWebAPI() {
|
private WebAPIManager getWebAPI() {
|
||||||
@ -306,7 +307,7 @@ public class BukkitInformationManager extends InformationManager {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
UUID serverUUID = Plan.getServerUUID();
|
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()) {
|
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
||||||
HtmlExport.exportServer(plugin, serverUUID);
|
HtmlExport.exportServer(plugin, serverUUID);
|
||||||
}
|
}
|
||||||
|
@ -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.BungeeServerInfoManager;
|
||||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
|
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.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.response.*;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalysisReadyWebAPI;
|
||||||
@ -233,11 +234,7 @@ public class BungeeInformationManager extends InformationManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isAnalysisCached(UUID serverUUID) {
|
public boolean isAnalysisCached(UUID serverUUID) {
|
||||||
if (PlanBungee.getServerUUID().equals(serverUUID)) {
|
return PageCache.isCached(PageId.SERVER.of(serverUUID));
|
||||||
return PageCache.isCached("networkPage");
|
|
||||||
} else {
|
|
||||||
return PageCache.isCached("analysisPage:" + serverUUID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,7 +247,7 @@ public class BungeeInformationManager extends InformationManager {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getPlayerHtml(UUID uuid) {
|
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"));
|
() -> new NotFoundResponse("No Bukkit Servers were online to process this request"));
|
||||||
if (response instanceof InspectPageResponse) {
|
if (response instanceof InspectPageResponse) {
|
||||||
((InspectPageResponse) response).setInspectPagePluginsTab(getPluginsTabContent(uuid));
|
((InspectPageResponse) response).setInspectPagePluginsTab(getPluginsTabContent(uuid));
|
||||||
@ -314,7 +311,7 @@ public class BungeeInformationManager extends InformationManager {
|
|||||||
Map<UUID, String[]> perServerPluginsTab = pluginsTabContent.getOrDefault(uuid, new HashMap<>());
|
Map<UUID, String[]> perServerPluginsTab = pluginsTabContent.getOrDefault(uuid, new HashMap<>());
|
||||||
perServerPluginsTab.put(serverUUID, html);
|
perServerPluginsTab.put(serverUUID, html);
|
||||||
pluginsTabContent.put(uuid, perServerPluginsTab);
|
pluginsTabContent.put(uuid, perServerPluginsTab);
|
||||||
Response inspectResponse = PageCache.loadPage("inspectPage: " + uuid);
|
Response inspectResponse = PageCache.loadPage(PageId.PLAYER.of(uuid));
|
||||||
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
|
if (inspectResponse != null && inspectResponse instanceof InspectPageResponse) {
|
||||||
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(getPluginsTabContent(uuid));
|
((InspectPageResponse) inspectResponse).setInspectPagePluginsTab(getPluginsTabContent(uuid));
|
||||||
}
|
}
|
||||||
@ -372,7 +369,7 @@ public class BungeeInformationManager extends InformationManager {
|
|||||||
@Override
|
@Override
|
||||||
public void updateNetworkPageContent() {
|
public void updateNetworkPageContent() {
|
||||||
UUID serverUUID = MiscUtils.getIPlan().getServerUuid();
|
UUID serverUUID = MiscUtils.getIPlan().getServerUuid();
|
||||||
PageCache.cachePage("analysisPage:" + serverUUID, () -> new AnalysisPageResponse(this));
|
PageCache.cachePage(PageId.SERVER.of(serverUUID), () -> new AnalysisPageResponse(this));
|
||||||
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
||||||
HtmlExport.exportServer(plugin, serverUUID);
|
HtmlExport.exportServer(plugin, serverUUID);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import main.java.com.djrapitops.plan.api.exceptions.ParseException;
|
|||||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||||
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
|
import main.java.com.djrapitops.plan.systems.cache.SessionCache;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
|
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
|
||||||
|
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -46,7 +47,7 @@ public abstract class InformationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCached(UUID uuid) {
|
public boolean isCached(UUID uuid) {
|
||||||
return PageCache.isCached("inspectPage: " + uuid);
|
return PageCache.isCached(PageId.PLAYER.of(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getPlayerHtml(UUID uuid) throws ParseException;
|
public abstract String getPlayerHtml(UUID uuid) throws ParseException;
|
||||||
|
@ -6,6 +6,7 @@ package main.java.com.djrapitops.plan.systems.webserver;
|
|||||||
|
|
||||||
import com.djrapitops.plugin.api.utility.log.Log;
|
import com.djrapitops.plugin.api.utility.log.Log;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
|
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.response.*;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
|
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
|
||||||
@ -40,29 +41,29 @@ public class APIResponseHandler {
|
|||||||
String[] args = target.split("/");
|
String[] args = target.split("/");
|
||||||
|
|
||||||
if ("/favicon.ico".equalsIgnoreCase(target)) {
|
if ("/favicon.ico".equalsIgnoreCase(target)) {
|
||||||
return PageCache.loadPage("Redirect: favicon", () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
|
return PageCache.loadPage(PageId.FAVICON_REDIRECT.id(), () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
|
||||||
}
|
}
|
||||||
if ("/debug".equalsIgnoreCase(target)) {
|
if ("/debug".equalsIgnoreCase(target)) {
|
||||||
return new DebugPageResponse();
|
return new DebugPageResponse();
|
||||||
}
|
}
|
||||||
if (target.endsWith(".css")) {
|
if (target.endsWith(".css")) {
|
||||||
return PageCache.loadPage(target + "css", () -> new CSSResponse(target));
|
return PageCache.loadPage(PageId.CSS.of(target), () -> new CSSResponse(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.endsWith(".js")) {
|
if (target.endsWith(".js")) {
|
||||||
return PageCache.loadPage(target + "js", () -> new JavaScriptResponse(target));
|
return PageCache.loadPage(PageId.JS.of(target), () -> new JavaScriptResponse(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length < 2 || !"api".equals(args[1])) {
|
if (args.length < 2 || !"api".equals(args[1])) {
|
||||||
String address = MiscUtils.getIPlan().getInfoManager().getWebServerAddress() + target;
|
String address = MiscUtils.getIPlan().getInfoManager().getWebServerAddress() + target;
|
||||||
String link = Html.LINK.parse(address, address);
|
String link = Html.LINK.parse(address, address);
|
||||||
return PageCache.loadPage("Non-API Request", () -> new NotFoundResponse("WebServer is in WebAPI-only mode, " +
|
return PageCache.loadPage(PageId.ERROR.of("Non-API Request"), () -> new NotFoundResponse("WebServer is in WebAPI-only mode, " +
|
||||||
"connect to the Bungee server instead: " + link));
|
"connect to the Bungee server instead: " + link));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
String error = "API Method not specified";
|
String error = "API Method not specified";
|
||||||
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
|
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
String method = args[2];
|
String method = args[2];
|
||||||
@ -74,7 +75,7 @@ public class APIResponseHandler {
|
|||||||
if (requestBody == null) {
|
if (requestBody == null) {
|
||||||
String error = "Error at reading the POST request." +
|
String error = "Error at reading the POST request." +
|
||||||
"Note that the Encoding must be ISO-8859-1.";
|
"Note that the Encoding must be ISO-8859-1.";
|
||||||
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
|
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> variables = WebAPI.readVariables(requestBody);
|
Map<String, String> variables = WebAPI.readVariables(requestBody);
|
||||||
@ -93,7 +94,7 @@ public class APIResponseHandler {
|
|||||||
if (!checkKey(sender)) {
|
if (!checkKey(sender)) {
|
||||||
String error = "Server Key not given or invalid";
|
String error = "Server Key not given or invalid";
|
||||||
Log.debug("Request had invalid Server key: " + sender);
|
Log.debug("Request had invalid Server key: " + sender);
|
||||||
return PageCache.loadPage(error, () -> {
|
return PageCache.loadPage(PageId.ERROR.of(error), () -> {
|
||||||
ForbiddenResponse forbidden = new ForbiddenResponse();
|
ForbiddenResponse forbidden = new ForbiddenResponse();
|
||||||
forbidden.setContent(error);
|
forbidden.setContent(error);
|
||||||
return forbidden;
|
return forbidden;
|
||||||
@ -103,7 +104,7 @@ public class APIResponseHandler {
|
|||||||
if (!webAPI.isAuthorized(accessKey)) {
|
if (!webAPI.isAuthorized(accessKey)) {
|
||||||
String error = "Access Key invalid";
|
String error = "Access Key invalid";
|
||||||
Log.debug("Request had invalid Access key: " + accessKey);
|
Log.debug("Request had invalid Access key: " + accessKey);
|
||||||
return PageCache.loadPage(error, () -> {
|
return PageCache.loadPage(PageId.ERROR.of(error), () -> {
|
||||||
ForbiddenResponse forbidden = new ForbiddenResponse();
|
ForbiddenResponse forbidden = new ForbiddenResponse();
|
||||||
forbidden.setContent(error);
|
forbidden.setContent(error);
|
||||||
return forbidden;
|
return forbidden;
|
||||||
@ -117,7 +118,7 @@ public class APIResponseHandler {
|
|||||||
if (api == null) {
|
if (api == null) {
|
||||||
String error = "API Method not found";
|
String error = "API Method not found";
|
||||||
Log.debug(error);
|
Log.debug(error);
|
||||||
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
|
return PageCache.loadPage(PageId.ERROR.of(error), () -> new BadRequestResponse(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
Response response = api.processRequest(MiscUtils.getIPlan(), variables);
|
Response response = api.processRequest(MiscUtils.getIPlan(), variables);
|
||||||
|
@ -11,6 +11,7 @@ import main.java.com.djrapitops.plan.api.exceptions.WebUserAuthException;
|
|||||||
import main.java.com.djrapitops.plan.data.WebUser;
|
import main.java.com.djrapitops.plan.data.WebUser;
|
||||||
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
|
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageCache;
|
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.response.*;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
|
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||||
@ -43,17 +44,17 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
String[] args = target.split("/");
|
String[] args = target.split("/");
|
||||||
try {
|
try {
|
||||||
if ("/favicon.ico".equals(target)) {
|
if ("/favicon.ico".equals(target)) {
|
||||||
return PageCache.loadPage("Redirect: favicon", () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
|
return PageCache.loadPage(PageId.FAVICON_REDIRECT.id(), () -> new RedirectResponse("https://puu.sh/tK0KL/6aa2ba141b.ico"));
|
||||||
}
|
}
|
||||||
if (request.isAPIRequest()) {
|
if (request.isAPIRequest()) {
|
||||||
return getAPIResponse(request);
|
return getAPIResponse(request);
|
||||||
}
|
}
|
||||||
if (target.endsWith(".css")) {
|
if (target.endsWith(".css")) {
|
||||||
return PageCache.loadPage(target + "css", () -> new CSSResponse(target));
|
return PageCache.loadPage(PageId.CSS.of(target), () -> new CSSResponse(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.endsWith(".js")) {
|
if (target.endsWith(".js")) {
|
||||||
return PageCache.loadPage(target + "js", () -> new JavaScriptResponse(target));
|
return PageCache.loadPage(PageId.JS.of(target), () -> new JavaScriptResponse(target));
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID serverUUID = MiscUtils.getIPlan().getServerUuid();
|
UUID serverUUID = MiscUtils.getIPlan().getServerUuid();
|
||||||
@ -82,7 +83,7 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
case "debug":
|
case "debug":
|
||||||
return new DebugPageResponse();
|
return new DebugPageResponse();
|
||||||
case "players":
|
case "players":
|
||||||
return PageCache.loadPage("players", PlayersPageResponse::new);
|
return PageCache.loadPage(PageId.PLAYERS.id(), PlayersPageResponse::new);
|
||||||
case "player":
|
case "player":
|
||||||
return playerResponse(args);
|
return playerResponse(args);
|
||||||
case "network":
|
case "network":
|
||||||
@ -103,7 +104,7 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (WebUserAuthException e) {
|
} catch (WebUserAuthException e) {
|
||||||
return PageCache.loadPage("promptAuthorization", PromptAuthorizationResponse::new);
|
return PageCache.loadPage(PageId.AUTH_PROMPT.id(), PromptAuthorizationResponse::new);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
return new InternalErrorResponse(e, request.getTarget());
|
return new InternalErrorResponse(e, request.getTarget());
|
||||||
@ -111,7 +112,7 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response forbiddenResponse(int required, int permLevel) {
|
private Response forbiddenResponse(int required, int permLevel) {
|
||||||
return PageCache.loadPage("forbidden", () ->
|
return PageCache.loadPage(PageId.FORBIDDEN.id(), () ->
|
||||||
new ForbiddenResponse("Unauthorized User.<br>"
|
new ForbiddenResponse("Unauthorized User.<br>"
|
||||||
+ "Make sure your user has the correct access level.<br>"
|
+ "Make sure your user has the correct access level.<br>"
|
||||||
+ "This page requires permission level of " + required + ",<br>"
|
+ "This page requires permission level of " + required + ",<br>"
|
||||||
@ -183,7 +184,7 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
case 0:
|
case 0:
|
||||||
return serverResponse(serverUUID);
|
return serverResponse(serverUUID);
|
||||||
case 1:
|
case 1:
|
||||||
return PageCache.loadPage("players", PlayersPageResponse::new);
|
return PageCache.loadPage(PageId.PLAYERS.id(), PlayersPageResponse::new);
|
||||||
case 2:
|
case 2:
|
||||||
return playerResponse(new String[]{"", "", user.getName()});
|
return playerResponse(new String[]{"", "", user.getName()});
|
||||||
default:
|
default:
|
||||||
@ -192,12 +193,12 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Response serverResponse(UUID serverUUID) {
|
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) {
|
private Response playerResponse(String[] args) {
|
||||||
if (args.length < 3) {
|
if (args.length < 3) {
|
||||||
return PageCache.loadPage("notFound", NotFoundResponse::new);
|
return PageCache.loadPage(PageId.NOT_FOUND.id(), NotFoundResponse::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
String playerName = args[2].trim();
|
String playerName = args[2].trim();
|
||||||
@ -205,22 +206,22 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
|
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
String error = "Player has no UUID";
|
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)) {
|
if (plugin.getDB().wasSeenBefore(uuid)) {
|
||||||
plugin.getInfoManager().cachePlayer(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.
|
// 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")) {
|
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 {
|
try {
|
||||||
return new InspectPageResponse(plugin.getInfoManager(), uuid);
|
return new InspectPageResponse(plugin.getInfoManager(), uuid);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
return new InternalErrorResponse(e, this.getClass().getName());
|
return new InternalErrorResponse(e, this.getClass().getName());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
response = PageCache.loadPage("inspectPage: " + uuid);
|
response = PageCache.loadPage(PageId.PLAYER.of(uuid));
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@ -229,7 +230,7 @@ public class ResponseHandler extends APIResponseHandler {
|
|||||||
|
|
||||||
private Response notFoundResponse() {
|
private Response notFoundResponse() {
|
||||||
String error = "404 Not Found";
|
String error = "404 Not Found";
|
||||||
return PageCache.loadPage("notFound: " + error, () -> {
|
return PageCache.loadPage(PageId.NOT_FOUND.of("Wrong Page"), () -> {
|
||||||
String url = plugin.getInfoManager().getWebServerAddress();
|
String url = plugin.getInfoManager().getWebServerAddress();
|
||||||
return new NotFoundResponse("Make sure you're accessing a link given by a command, Examples:</p>"
|
return new NotFoundResponse("Make sure you're accessing a link given by a command, Examples:</p>"
|
||||||
+ "<p>" + url + "/player/Playername<br>" +
|
+ "<p>" + url + "/player/Playername<br>" +
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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.api.exceptions.*;
|
||||||
import main.java.com.djrapitops.plan.settings.Settings;
|
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.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.NotFoundResponse;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
|
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
|
||||||
@ -165,11 +166,11 @@ public abstract class WebAPI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected Response success() {
|
protected Response success() {
|
||||||
return PageCache.loadPage("success", SuccessResponse::new);
|
return PageCache.loadPage(PageId.TRUE.id(), SuccessResponse::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Response fail(String reason) {
|
protected Response fail(String reason) {
|
||||||
return PageCache.loadPage("fail", () -> {
|
return PageCache.loadPage(PageId.FALSE.id(), () -> {
|
||||||
NotFoundResponse notFoundResponse = new NotFoundResponse("");
|
NotFoundResponse notFoundResponse = new NotFoundResponse("");
|
||||||
notFoundResponse.setContent(reason);
|
notFoundResponse.setContent(reason);
|
||||||
return notFoundResponse;
|
return notFoundResponse;
|
||||||
@ -177,7 +178,7 @@ public abstract class WebAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Response badRequest(String error) {
|
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() {
|
private String parseVariables() {
|
||||||
|
@ -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.settings.Settings;
|
||||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
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.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.AnalysisPageResponse;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse;
|
import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||||
@ -54,14 +55,14 @@ public class PostHtmlWebAPI extends WebAPI {
|
|||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString());
|
map.put("networkName", Settings.BUNGEE_NETWORK_NAME.toString());
|
||||||
|
|
||||||
PageCache.cachePage("inspectPage:" + uuid, () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), StrSubstitutor.replace(html, map)));
|
PageCache.cachePage(PageId.PLAYER.of(uuid), () -> new InspectPageResponse(infoManager, UUID.fromString(uuid), StrSubstitutor.replace(html, map)));
|
||||||
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
||||||
HtmlExport.exportPlayer(plugin, UUID.fromString(uuid));
|
HtmlExport.exportPlayer(plugin, UUID.fromString(uuid));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "analysisPage":
|
case "analysisPage":
|
||||||
String sender = variables.get("sender");
|
String sender = variables.get("sender");
|
||||||
PageCache.cachePage("analysisPage:" + sender, () -> new AnalysisPageResponse(html));
|
PageCache.cachePage(PageId.SERVER.of(sender), () -> new AnalysisPageResponse(html));
|
||||||
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
if (Settings.ANALYSIS_EXPORT.isTrue()) {
|
||||||
HtmlExport.exportServer(plugin, UUID.fromString(sender));
|
HtmlExport.exportServer(plugin, UUID.fromString(sender));
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
|||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.task.AbsRunnable;
|
||||||
import main.java.com.djrapitops.plan.settings.Settings;
|
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.PageCache;
|
||||||
|
import main.java.com.djrapitops.plan.systems.webserver.pagecache.PageId;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ public abstract class SpecificExport extends AbsRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void exportAvailablePlayerPage(UUID uuid, String name) throws IOException {
|
protected void exportAvailablePlayerPage(UUID uuid, String name) throws IOException {
|
||||||
Response response = PageCache.loadPage("inspectPage: " + uuid);
|
Response response = PageCache.loadPage(PageId.PLAYER.of(uuid));
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ public abstract class SpecificExport extends AbsRunnable {
|
|||||||
|
|
||||||
protected void exportAvailableServerPage(UUID serverUUID, String serverName) throws IOException {
|
protected void exportAvailableServerPage(UUID serverUUID, String serverName) throws IOException {
|
||||||
|
|
||||||
Response response = PageCache.loadPage("analysisPage:" + serverUUID);
|
Response response = PageCache.loadPage(PageId.SERVER.of(serverUUID));
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user