mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
ServerUUID usage with Analysis page
This commit is contained in:
parent
8ffcd302df
commit
f77944f3f6
@ -139,7 +139,7 @@ public class API {
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean isAnalysisCached() {
|
||||
return plugin.getInfoManager().isAnalysisCached();
|
||||
return plugin.getInfoManager().isAnalysisCached(Plan.getServerUUID());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,7 @@ import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Bungee Main class.
|
||||
@ -158,4 +159,8 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
|
||||
public ServerVariableHolder getVariable() {
|
||||
return variableHolder;
|
||||
}
|
||||
|
||||
public static UUID getServerUUID() {
|
||||
return getInstance().serverInfoManager.getServerUUID();
|
||||
}
|
||||
}
|
@ -322,4 +322,25 @@ public class ServerTable extends Table {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<UUID> getServerUUID(String serverName) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
statement = prepareStatement(Select.from(tableName,
|
||||
columnServerUUID)
|
||||
.where(columnServerName + "=?")
|
||||
.toString());
|
||||
statement.setString(1, serverName);
|
||||
set = statement.executeQuery();
|
||||
if (set.next()) {
|
||||
return Optional.of(UUID.fromString(set.getString(columnServerUUID)));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -150,10 +150,10 @@ public class BukkitInformationManager extends InformationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnalysisCached() {
|
||||
public boolean isAnalysisCached(UUID serverUUID) {
|
||||
if (usingBungeeWebServer) {
|
||||
try {
|
||||
return getWebAPI().getAPI(IsCachedWebAPI.class).isAnalysisCached(webServerAddress);
|
||||
return getWebAPI().getAPI(IsCachedWebAPI.class).isAnalysisCached(webServerAddress, serverUUID);
|
||||
} catch (WebAPIException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalyzeWebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.RequestPluginsTabWebAPI;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
@ -92,8 +93,12 @@ public class BungeeInformationManager extends InformationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnalysisCached() {
|
||||
return PageCache.isCached("networkPage");
|
||||
public boolean isAnalysisCached(UUID serverUUID) {
|
||||
if (PlanBungee.getServerUUID().equals(serverUUID)) {
|
||||
return PageCache.isCached("networkPage");
|
||||
} else {
|
||||
return PageCache.isCached("analysisPage:" + serverUUID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,7 +113,16 @@ public class BungeeInformationManager extends InformationManager {
|
||||
|
||||
@Override
|
||||
public String getPluginsTabContent(UUID uuid) {
|
||||
return null;
|
||||
Map<UUID, String> pluginsTab = pluginsTabContent.get(uuid);
|
||||
if (pluginsTab == null) {
|
||||
return HtmlStructure.createInspectPageTabContentCalculating();
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String tab : pluginsTab.values()) {
|
||||
builder.append(tab);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void cachePluginsTabContent(UUID serverUUID, UUID uuid, String html) {
|
||||
|
@ -59,7 +59,7 @@ public abstract class InformationManager {
|
||||
*
|
||||
* @return Is page cached.
|
||||
*/
|
||||
public abstract boolean isAnalysisCached();
|
||||
public abstract boolean isAnalysisCached(UUID serverUUID);
|
||||
|
||||
/**
|
||||
* Used for /server on Bukkit and /network on Bungee
|
||||
|
@ -9,12 +9,14 @@ import main.java.com.djrapitops.plan.api.exceptions.WebUserAuthException;
|
||||
import main.java.com.djrapitops.plan.data.WebUser;
|
||||
import main.java.com.djrapitops.plan.database.tables.SecurityTable;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.*;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Base64;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -54,6 +56,9 @@ public class ResponseHandler extends APIResponseHandler {
|
||||
String fileName = args[args.length - 1];
|
||||
return PageCache.loadPage(target + "js", () -> new JavaScriptResponse(fileName));
|
||||
}
|
||||
|
||||
UUID serverUUID = MiscUtils.getIPlan().getServerInfoManager().getServerUUID();
|
||||
|
||||
if (usingHttps) {
|
||||
if (!request.hasAuth()) {
|
||||
throw new WebUserAuthException("No Authorization");
|
||||
@ -67,7 +72,7 @@ public class ResponseHandler extends APIResponseHandler {
|
||||
return forbiddenResponse(required, permLevel);
|
||||
}
|
||||
if (args.length < 2) {
|
||||
return rootPageResponse(user);
|
||||
return rootPageResponse(user, serverUUID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,8 +82,19 @@ public class ResponseHandler extends APIResponseHandler {
|
||||
return PageCache.loadPage("players", PlayersPageResponse::new);
|
||||
case "player":
|
||||
return playerResponse(args);
|
||||
case "network":
|
||||
case "server":
|
||||
return serverResponse();
|
||||
if (args.length > 2) {
|
||||
try {
|
||||
Optional<UUID> serverUUIDOptional = plugin.getDB().getServerTable().getServerUUID(args[2]);
|
||||
if (serverUUIDOptional.isPresent()) {
|
||||
serverUUID = serverUUIDOptional.get();
|
||||
}
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
/*ignored*/
|
||||
}
|
||||
}
|
||||
return serverResponse(serverUUID);
|
||||
default:
|
||||
return notFoundResponse();
|
||||
}
|
||||
@ -154,14 +170,14 @@ public class ResponseHandler extends APIResponseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Response rootPageResponse(WebUser user) {
|
||||
private Response rootPageResponse(WebUser user, UUID serverUUID) {
|
||||
if (user == null) {
|
||||
return notFoundResponse();
|
||||
}
|
||||
|
||||
switch (user.getPermLevel()) {
|
||||
case 0:
|
||||
return serverResponse();
|
||||
return serverResponse(serverUUID);
|
||||
case 1:
|
||||
return PageCache.loadPage("players", PlayersPageResponse::new);
|
||||
case 2:
|
||||
@ -171,8 +187,8 @@ public class ResponseHandler extends APIResponseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private Response serverResponse() {
|
||||
if (!plugin.getInfoManager().isAnalysisCached()) {
|
||||
private Response serverResponse(UUID serverUUID) {
|
||||
if (!plugin.getInfoManager().isAnalysisCached(serverUUID)) {
|
||||
String error = "Analysis Data was not cached.<br>Use /plan analyze to cache the Data.";
|
||||
PageCache.loadPage("notFound: " + error, () -> new NotFoundResponse(error));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class IsCachedWebAPI extends WebAPI {
|
||||
}
|
||||
break;
|
||||
case "analysisPage":
|
||||
if (infoManager.isAnalysisCached()) {
|
||||
if (infoManager.isAnalysisCached(UUID.fromString(variables.get("serverUUID")))) {
|
||||
cached = true;
|
||||
}
|
||||
break;
|
||||
@ -78,7 +78,8 @@ public class IsCachedWebAPI extends WebAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAnalysisCached(String address) throws WebAPIException {
|
||||
public boolean isAnalysisCached(String address, UUID serverUUID) throws WebAPIException {
|
||||
addVariable("serverUUID", serverUUID.toString());
|
||||
addVariable("target", "analysisPage");
|
||||
try {
|
||||
super.sendRequest(address);
|
||||
|
Loading…
Reference in New Issue
Block a user