From 70e94f893e6e8b9eac3281dd2ff69676fdb1ec39 Mon Sep 17 00:00:00 2001 From: Fuzzlemann Date: Wed, 30 Aug 2017 13:33:55 +0200 Subject: [PATCH] Update GraphTest Add OnlinePlayersWebAPI Update InspectWebAPI, AnalyzeWebAPI & AnalyticsWebAPI --- .../webapi/bukkit/AnalyticsWebAPI.java | 8 +++--- .../systems/webapi/bukkit/AnalyzeWebAPI.java | 2 +- .../systems/webapi/bukkit/InspectWebAPI.java | 2 +- .../webapi/bukkit/OnlinePlayersWebAPI.java | 25 +++++++++++++++++++ .../plan/systems/webserver/WebServer.java | 6 ++--- .../plan/utilities/analysis/Analysis.java | 2 -- .../utilities/html/HtmlStructureTest.java | 2 +- .../djrapitops/plan/ui/graphs/GraphTest.java | 6 ++--- 8 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/OnlinePlayersWebAPI.java diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyticsWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyticsWebAPI.java index 2914b9f7c..b6e55b2e5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyticsWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyticsWebAPI.java @@ -5,10 +5,12 @@ package main.java.com.djrapitops.plan.systems.webapi.bukkit; import main.java.com.djrapitops.plan.Plan; +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.webserver.PageCache; 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.JsonResponse; import java.util.Map; @@ -18,12 +20,12 @@ import java.util.Map; public class AnalyticsWebAPI implements WebAPI { @Override public Response onResponse(Plan plan, Map variables) { - String identifier = "analysisJson"; + InformationManager infoManager = plan.getInfoManager(); - if (!PageCache.isCached(identifier)) { + if (!infoManager.isAnalysisCached()) { return PageCache.loadPage("No Analysis Data", () -> new BadRequestResponse("No analysis data available")); } - return PageCache.loadPage(identifier); + return new JsonResponse(infoManager.getAnalysisHtml()); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyzeWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyzeWebAPI.java index 9451f9171..066fb26ba 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyzeWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/AnalyzeWebAPI.java @@ -18,7 +18,7 @@ import java.util.Map; public class AnalyzeWebAPI implements WebAPI { @Override public Response onResponse(Plan plan, Map variables) { - // TODO plan.getAnalysisCache().updateCache(); + plan.getInfoManager().refreshAnalysis(); return PageCache.loadPage("success", SuccessResponse::new); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/InspectWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/InspectWebAPI.java index 4c413e8b4..19d05fac1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/InspectWebAPI.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/InspectWebAPI.java @@ -35,7 +35,7 @@ public class InspectWebAPI implements WebAPI { return PageCache.loadPage(error, () -> new BadRequestResponse(error)); } - // TODO plan.getInspectCache().cache(uuid); + plan.getInfoManager().cachePlayer(uuid); return PageCache.loadPage("success", SuccessResponse::new); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/OnlinePlayersWebAPI.java b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/OnlinePlayersWebAPI.java new file mode 100644 index 000000000..d3f2c506b --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webapi/bukkit/OnlinePlayersWebAPI.java @@ -0,0 +1,25 @@ +/* + * 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.webapi.bukkit; + +import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.systems.webapi.WebAPI; +import main.java.com.djrapitops.plan.systems.webserver.response.Response; +import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse; +import org.bukkit.Server; + +import java.util.Map; + +/** + * @author Fuzzlemann + */ +public class OnlinePlayersWebAPI implements WebAPI { + @Override + public Response onResponse(Plan plan, Map variables) { + Server server = plan.getServer(); + + return new JsonResponse(server.getOnlinePlayers() + "/" + server.getMaxPlayers()); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java index f333c0ae6..b298c3666 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/webserver/WebServer.java @@ -13,10 +13,7 @@ import main.java.com.djrapitops.plan.locale.Msg; 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.webapi.bukkit.AnalyticsWebAPI; -import main.java.com.djrapitops.plan.systems.webapi.bukkit.AnalyzeWebAPI; -import main.java.com.djrapitops.plan.systems.webapi.bukkit.ConfigureWebAPI; -import main.java.com.djrapitops.plan.systems.webapi.bukkit.InspectWebAPI; +import main.java.com.djrapitops.plan.systems.webapi.bukkit.*; 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; @@ -74,6 +71,7 @@ public class WebServer { WebAPIManager.registerNewAPI("analyze", new AnalyzeWebAPI()); WebAPIManager.registerNewAPI("configure", new ConfigureWebAPI()); WebAPIManager.registerNewAPI("inspect", new InspectWebAPI()); + WebAPIManager.registerNewAPI("onlineplayers", new OnlinePlayersWebAPI()); } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index deb14d9a6..504ccb875 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -22,7 +22,6 @@ import main.java.com.djrapitops.plan.systems.info.InformationManager; import main.java.com.djrapitops.plan.systems.webserver.PageCache; import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse; import main.java.com.djrapitops.plan.systems.webserver.response.PlayersPageResponse; -import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse; import main.java.com.djrapitops.plan.utilities.Benchmark; import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.html.HtmlUtils; @@ -153,7 +152,6 @@ public class Analysis { PageCache.removeIf(identifier -> identifier.startsWith("inspectPage: ") || identifier.startsWith("inspectionJson: ")); PageCache.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getInfoManager())); - PageCache.cachePage("analysisJson", () -> new JsonResponse(analysisData)); PageCache.cachePage("players", PlayersPageResponse::new); // TODO Export diff --git a/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java b/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java index 0586dd227..3e567cd7d 100644 --- a/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java +++ b/Plan/test/main/java/com/djrapitops/plan/utilities/html/HtmlStructureTest.java @@ -1,7 +1,7 @@ package main.java.com.djrapitops.plan.utilities.html; import main.java.com.djrapitops.plan.data.Session; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.bukkit.plugin.java.JavaPlugin; import org.junit.Before; import org.junit.Test; diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/GraphTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/GraphTest.java index 4f5591d8a..8f9c8a529 100644 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/GraphTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/ui/graphs/GraphTest.java @@ -6,6 +6,7 @@ package test.java.main.java.com.djrapitops.plan.ui.graphs; import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.TPS; +import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.utilities.analysis.Point; import main.java.com.djrapitops.plan.utilities.html.graphs.*; import org.junit.Before; @@ -24,7 +25,7 @@ public class GraphTest { private final List tpsList = new ArrayList<>(); private final List sessionList = new ArrayList<>(); private final Map geoList = new HashMap<>(); - private final Map worldTimes = new HashMap<>(); + private final WorldTimes worldTimes = new WorldTimes("WORLD", "SURVIVAL"); private List points = new ArrayList<>(); @@ -34,7 +35,6 @@ public class GraphTest { tpsList.add(new TPS(i, i, i, i, i, i, i)); sessionList.add(new Session(i, (long) i, (long) i, i, i)); geoList.put(String.valueOf(i), i); - worldTimes.put(String.valueOf(i), (long) i); } points = RandomData.randomPoints(); @@ -50,7 +50,7 @@ public class GraphTest { assertEquals("[[0,0.0],[9,9.0]]", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsList)); assertEquals("[[0,0.0],[9,9.0]]", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsList)); assertEquals("[{'code':'1','value':1},{'code':'2','value':2},{'code':'3','value':3},{'code':'4','value':4},{'code':'5','value':5},{'code':'6','value':6},{'code':'7','value':7},{'code':'8','value':8},{'code':'9','value':9}]", WorldMapCreator.createDataSeries(geoList)); - //assertEquals(WorldPieCreator.createSeriesData(worldTimes), "[{name:'0',y:0},{name:'1',y:1, sliced: true, selected: true},{name:'2',y:2},{name:'3',y:3},{name:'4',y:4},{name:'5',y:5},{name:'6',y:6},{name:'7',y:7},{name:'8',y:8},{name:'9',y:9}]"); + assertEquals(Arrays.toString(WorldPieCreator.createSeriesData(worldTimes)), "[[{name:'WORLD',y:0,drilldown: 'WORLD'}], {name:'WORLD', id:'WORLD',data: []}]"); } @Test