From ef4e5d6d66e432eeab2c5002b1c8bb5fee9a30e2 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 7 Jul 2018 17:28:56 +0300 Subject: [PATCH] Prevented multiple concurrent analysis --- .../plan/command/commands/AnalyzeCommand.java | 6 +- .../store/containers/AnalysisContainer.java | 2 +- .../plan/data/store/keys/CommonKeys.java | 5 +- .../plan/data/store/keys/PlayerKeys.java | 5 +- .../formatting/PlaceholderReplacer.java | 6 +- .../tables/move/Version18TransferTable.java | 2 +- .../request/GenerateAnalysisPageRequest.java | 15 +- .../system/tasks/server/BootAnalysisTask.java | 1 - .../tasks/server/PeriodicAnalysisTask.java | 1 - .../webserver/pages/parsing/AnalysisPage.java | 4 +- .../webserver/pages/parsing/InspectPage.java | 133 +++++++++--------- .../webserver/pages/parsing/NetworkPage.java | 2 +- .../system/webserver/pages/parsing/Page.java | 21 +-- .../webserver/pages/parsing/PlayersPage.java | 2 +- .../html/graphs/calendar/PlayerCalendar.java | 11 +- .../AnalysisPluginsTabContentCreator.java | 9 +- 16 files changed, 111 insertions(+), 114 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java index a210289a4..6fd95436c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/AnalyzeCommand.java @@ -46,10 +46,8 @@ public class AnalyzeCommand extends CommandNode { Server server = getServer(args).orElseGet(ServerInfo::getServer); UUID serverUUID = server.getUuid(); - // TODO Create a new system to prevent multiple concurrent Analysis - if (!ServerInfo.getServerUUID().equals(serverUUID)) { - InfoSystem.getInstance().generateAnalysisPage(serverUUID); - } + + InfoSystem.getInstance().generateAnalysisPage(serverUUID); sendWebUserNotificationIfNecessary(sender); sendLink(server, sender); } catch (DBOpException | WebException e) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java index 6a2769592..0d8bcde2f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java @@ -377,7 +377,7 @@ public class AnalysisContainer extends DataContainer { // TODO Refactor into a system that supports running the analysis on Bungee Key navAndTabs = new Key<>(new Type() {}, "NAV_AND_TABS"); putSupplier(navAndTabs, () -> - AnalysisPluginsTabContentCreator.createContent(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).uuids()) + AnalysisPluginsTabContentCreator.createContent(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) ); putSupplier(AnalysisKeys.PLUGINS_TAB_NAV, () -> getUnsafe(navAndTabs)[0]); putSupplier(AnalysisKeys.PLUGINS_TAB, () -> getUnsafe(navAndTabs)[1]); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java index 19efaa924..e6aa3e651 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java @@ -3,6 +3,7 @@ package com.djrapitops.plan.data.store.keys; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.Key; +import com.djrapitops.plan.data.store.PlaceholderKey; import com.djrapitops.plan.data.store.Type; import com.djrapitops.plan.data.store.mutators.PlayersMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator; @@ -26,11 +27,11 @@ public class CommonKeys { public static final Key UUID = new Key<>(UUID.class, "uuid"); public static final Key SERVER_UUID = new Key<>(UUID.class, "server_uuid"); public static final Key NAME = new Key<>(String.class, "name"); - public static final Key REGISTERED = new Key<>(Long.class, "registered"); + public static final PlaceholderKey REGISTERED = new PlaceholderKey<>(Long.class, "registered"); public static final Key> SESSIONS = new Key<>(new Type>() {}, "sessions"); public static final Key WORLD_TIMES = new Key<>(WorldTimes.class, "world_times"); - public static final Key LAST_SEEN = new Key<>(Long.class, "last_seen"); + public static final PlaceholderKey LAST_SEEN = new PlaceholderKey<>(Long.class, "lastSeen"); public static final Key> PLAYER_KILLS = new Key<>(new Type>() {}, "player_kills"); public static final Key PLAYER_KILL_COUNT = new Key<>(Integer.class, "player_kill_count"); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java index d331add7d..afcd4199a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java @@ -4,6 +4,7 @@ import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.Key; +import com.djrapitops.plan.data.store.PlaceholderKey; import com.djrapitops.plan.data.store.Type; import com.djrapitops.plan.data.store.containers.PerServerContainer; import com.djrapitops.plan.data.store.objects.Nickname; @@ -29,7 +30,7 @@ public class PlayerKeys { public static final Key NAME = CommonKeys.NAME; public static final Key> NICKNAMES = new Key<>(new Type>() {}, "nicknames"); - public static final Key REGISTERED = CommonKeys.REGISTERED; + public static final PlaceholderKey REGISTERED = CommonKeys.REGISTERED; public static final Key KICK_COUNT = new Key<>(Integer.class, "kick_count"); public static final Key> GEO_INFO = new Key<>(new Type>() {}, "geo_info"); @@ -43,7 +44,7 @@ public class PlayerKeys { public static final Key MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT; public static final Key DEATH_COUNT = CommonKeys.DEATH_COUNT; public static final Key PER_SERVER = new Key<>(PerServerContainer.class, "per_server_data"); - public static final Key LAST_SEEN = CommonKeys.LAST_SEEN; + public static final PlaceholderKey LAST_SEEN = CommonKeys.LAST_SEEN; public static final Key BANNED = CommonKeys.BANNED; public static final Key OPERATOR = CommonKeys.OPERATOR; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/PlaceholderReplacer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/PlaceholderReplacer.java index c8289e3b9..c1726ebf3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/PlaceholderReplacer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/formatting/PlaceholderReplacer.java @@ -32,7 +32,7 @@ public class PlaceholderReplacer extends HashMap implement } } - public void addAllPlaceholderFrom(DataContainer container, Formatter formatter, PlaceholderKey key) { + public void addPlaceholderFrom(DataContainer container, Formatter formatter, PlaceholderKey key) { if (!container.supports(key)) { return; } @@ -43,9 +43,9 @@ public class PlaceholderReplacer extends HashMap implement Log.debug(key.getPlaceholder() + ": " + Formatters.benchmark().apply(ns)); } - public void addPlaceholdersFrom(DataContainer container, Formatter formatter, PlaceholderKey... keys) { + public void addAllPlaceholdersFrom(DataContainer container, Formatter formatter, PlaceholderKey... keys) { for (PlaceholderKey key : keys) { - addAllPlaceholderFrom(container, formatter, key); + addPlaceholderFrom(container, formatter, key); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/move/Version18TransferTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/move/Version18TransferTable.java index 6990cadb3..b0ac0ca5c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/move/Version18TransferTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/move/Version18TransferTable.java @@ -31,7 +31,7 @@ public class Version18TransferTable extends TransferTable { db.getGeoInfoTable().createTable(); execute("INSERT INTO plan_ips (" + "user_id, ip, ip_hash, geolocation, last_used" + - ") SELECT user_id, ip, ip_hash, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip_hash, user_id"); + ") SELECT user_id, ip, ip_hash, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip_hash, user_id, ip, geolocation"); dropTable(tempTableName); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java index 6669674cd..48f50a71f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/request/GenerateAnalysisPageRequest.java @@ -18,6 +18,7 @@ import com.djrapitops.plan.system.webserver.response.Response; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.utilities.Verify; +import java.util.Collections; import java.util.Map; import java.util.UUID; @@ -28,6 +29,7 @@ import java.util.UUID; */ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implements GenerateRequest { + private boolean runningAnalysis = false; private final UUID serverUUID; public GenerateAnalysisPageRequest(UUID serverUUID) { @@ -52,8 +54,9 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem throw new BadRequestException("Requested Analysis page from wrong server."); } - // TODO Create a new system to prevent multiple concurrent Analysis - generateAndCache(serverUUID); + if (!runningAnalysis) { + generateAndCache(serverUUID); + } return DefaultResponses.SUCCESS.get(); } @@ -66,11 +69,15 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem @Override public void runLocally() throws WebException { - generateAndCache(serverUUID); + // Get the handler from ConnectionSystem and run the request. + InfoSystem.getInstance().getConnectionSystem() + .getInfoRequest(this.getClass().getSimpleName()) + .handleRequest(Collections.singletonMap("server", serverUUID.toString())); } private String analyseAndGetHtml() throws InternalErrorException { try { + runningAnalysis = true; UUID serverUUID = ServerInfo.getServerUUID(); Database db = Database.getActive(); @@ -84,6 +91,8 @@ public class GenerateAnalysisPageRequest extends InfoRequestWithVariables implem } catch (Exception e) { Log.toLog(this.getClass(), e); throw new InternalErrorException("Analysis failed due to exception", e); + } finally { + runningAnalysis = false; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java index daa910777..beb14d174 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/BootAnalysisTask.java @@ -21,7 +21,6 @@ public class BootAnalysisTask extends AbsRunnable { try { String bootAnalysisRunMsg = Locale.get(Msg.ENABLE_BOOT_ANALYSIS_RUN_INFO).toString(); Log.info(bootAnalysisRunMsg); - // TODO Create a new system to prevent multiple concurrent Analysis WebExceptionLogger.logIfOccurs(this.getClass(), () -> InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID())) ); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java index c7d05c98b..9beed5578 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/tasks/server/PeriodicAnalysisTask.java @@ -17,7 +17,6 @@ public class PeriodicAnalysisTask extends AbsRunnable { @Override public void run() { try { - // TODO Create a new system to prevent multiple concurrent Analysis WebExceptionLogger.logIfOccurs(this.getClass(), () -> InfoSystem.getInstance().sendRequest(new GenerateAnalysisPageRequest(ServerInfo.getServerUUID())) ); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/AnalysisPage.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/AnalysisPage.java index ad9824b2b..5395cf4ee 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/AnalysisPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/AnalysisPage.java @@ -20,7 +20,7 @@ import static com.djrapitops.plan.data.store.keys.AnalysisKeys.*; * * @author Rsl1122 */ -public class AnalysisPage extends Page { +public class AnalysisPage implements Page { private final AnalysisContainer analysisContainer; @@ -76,7 +76,7 @@ public class AnalysisPage extends Page { WORLD_MAP_SERIES, ACTIVITY_STACK_SERIES, ACTIVITY_STACK_CATEGORIES, ACTIVITY_PIE_SERIES, CALENDAR_SERIES ); - placeholderReplacer.addPlaceholdersFrom(analysisContainer, FormatUtils::cutDecimals, + placeholderReplacer.addAllPlaceholdersFrom(analysisContainer, FormatUtils::cutDecimals, AVG_TPS_MONTH, AVG_TPS_WEEK, AVG_TPS_DAY, AVG_CPU_MONTH, AVG_CPU_WEEK, AVG_CPU_DAY, AVG_RAM_MONTH, AVG_RAM_WEEK, AVG_RAM_DAY, diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java index 78d15958b..7213e66ae 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java @@ -14,6 +14,7 @@ import com.djrapitops.plan.data.store.mutators.PerServerDataMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.mutators.formatting.Formatter; import com.djrapitops.plan.data.store.mutators.formatting.Formatters; +import com.djrapitops.plan.data.store.mutators.formatting.PlaceholderReplacer; import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.databases.Database; @@ -27,7 +28,6 @@ import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.comparators.SessionStartComparator; import com.djrapitops.plan.utilities.file.FileUtil; import com.djrapitops.plan.utilities.html.HtmlStructure; -import com.djrapitops.plan.utilities.html.HtmlUtils; import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph; import com.djrapitops.plan.utilities.html.graphs.calendar.PlayerCalendar; import com.djrapitops.plan.utilities.html.graphs.pie.ServerPreferencePie; @@ -42,14 +42,13 @@ import com.djrapitops.plugin.api.TimeAmount; import java.io.IOException; import java.util.*; -import java.util.stream.Collectors; /** * Used for parsing Inspect page out of database data and the html. * * @author Rsl1122 */ -public class InspectPage extends Page { +public class InspectPage implements Page { private final UUID uuid; @@ -83,9 +82,11 @@ public class InspectPage extends Page { public String parse(PlayerContainer container, UUID serverUUID, Map serverNames) throws IOException { long now = System.currentTimeMillis(); - addValue("refresh", FormatUtils.formatTimeStampClock(now)); - addValue("version", MiscUtils.getPlanVersion()); - addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); + PlaceholderReplacer replacer = new PlaceholderReplacer(); + + replacer.put("refresh", FormatUtils.formatTimeStampClock(now)); + replacer.put("version", MiscUtils.getPlanVersion()); + replacer.put("timeZone", MiscUtils.getTimeZoneOffsetHours()); String online = "Offline"; Optional activeSession = SessionCache.getCachedSession(uuid); @@ -97,36 +98,31 @@ public class InspectPage extends Page { } String playerName = container.getValue(PlayerKeys.NAME).orElse("Unknown"); - long registered = container.getValue(PlayerKeys.REGISTERED).orElse(-1L); int timesKicked = container.getValue(PlayerKeys.KICK_COUNT).orElse(0); - long lastSeen = container.getValue(PlayerKeys.LAST_SEEN).orElse(-1L); - addValue("registered", Formatters.year().apply(() -> registered)); - addValue("playerName", playerName); - addValue("kickCount", timesKicked); + replacer.addAllPlaceholdersFrom(container, Formatters.yearLongValue(), + PlayerKeys.REGISTERED, PlayerKeys.LAST_SEEN + ); - addValue("lastSeen", Formatters.year().apply(() -> lastSeen)); + replacer.put("playerName", playerName); + replacer.put("kickCount", timesKicked); PerServerContainer perServerContainer = container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer()); PerServerDataMutator perServerDataMutator = new PerServerDataMutator(perServerContainer); Map worldTimesPerServer = perServerDataMutator.worldTimesPerServer(); - addValue("serverPieSeries", new ServerPreferencePie(serverNames, worldTimesPerServer).toHighChartsSeries()); - addValue("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE)); - addValue("gmPieColors", Theme.getValue(ThemeVal.GRAPH_GM_PIE)); - addValue("serverPieColors", Theme.getValue(ThemeVal.GRAPH_SERVER_PREF_PIE)); + replacer.put("serverPieSeries", new ServerPreferencePie(serverNames, worldTimesPerServer).toHighChartsSeries()); + replacer.put("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE)); + replacer.put("gmPieColors", Theme.getValue(ThemeVal.GRAPH_GM_PIE)); + replacer.put("serverPieColors", Theme.getValue(ThemeVal.GRAPH_SERVER_PREF_PIE)); String favoriteServer = serverNames.getOrDefault(perServerDataMutator.favoriteServer(), "Unknown"); - addValue("favoriteServer", favoriteServer); + replacer.put("favoriteServer", favoriteServer); - addValue("tableBodyNicknames", new NicknameTable( + replacer.put("tableBodyNicknames", new NicknameTable( container.getValue(PlayerKeys.NICKNAMES).orElse(new ArrayList<>()), serverNames) .parseBody()); - addValue("tableBodyIPs", new GeoInfoTable(container.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).parseBody()); - - Map> sessions = perServerDataMutator.sessionsPerServer(); - Map> sessionsByServerName = sessions.entrySet().stream() - .collect(Collectors.toMap(entry -> serverNames.get(entry.getKey()), Map.Entry::getValue)); + replacer.put("tableBodyIPs", new GeoInfoTable(container.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>())).parseBody()); List allSessions = container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()); SessionsMutator sessionsMutator = SessionsMutator.forContainer(container); @@ -134,27 +130,26 @@ public class InspectPage extends Page { String sessionAccordionViewScript = ""; if (allSessions.isEmpty()) { - addValue("accordionSessions", "
" + "

No Sessions

" + "
"); + replacer.put("accordionSessions", "
" + "

No Sessions

" + "
"); } else { if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { - addValue("accordionSessions", new PlayerSessionTable(playerName, allSessions).parseHtml()); + replacer.put("accordionSessions", new PlayerSessionTable(playerName, allSessions).parseHtml()); } else { SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames); - addValue("accordionSessions", sessionAccordion.toHtml()); + replacer.put("accordionSessions", sessionAccordion.toHtml()); sessionAccordionViewScript = sessionAccordion.toViewScript(); } } - // TODO Session table if setting is enabled ServerAccordion serverAccordion = new ServerAccordion(container, serverNames); - PlayerCalendar playerCalendar = new PlayerCalendar(allSessions, registered); + PlayerCalendar playerCalendar = new PlayerCalendar(container); - addValue("calendarSeries", playerCalendar.toCalendarSeries()); - addValue("firstDay", 1); + replacer.put("calendarSeries", playerCalendar.toCalendarSeries()); + replacer.put("firstDay", 1); - addValue("accordionServers", serverAccordion.toHtml()); - addValue("sessionTabGraphViewFunctions", sessionAccordionViewScript + serverAccordion.toViewScript()); + replacer.put("accordionServers", serverAccordion.toHtml()); + replacer.put("sessionTabGraphViewFunctions", sessionAccordionViewScript + serverAccordion.toViewScript()); long dayAgo = now - TimeAmount.DAY.ms(); long weekAgo = now - TimeAmount.WEEK.ms(); @@ -197,70 +192,70 @@ public class InspectPage extends Page { long sessionAverageMonth = monthSessionsMutator.toAverageSessionLength(); Formatter formatter = Formatters.timeAmount(); - addValue("playtimeTotal", formatter.apply(playtime)); - addValue("playtimeDay", formatter.apply(playtimeDay)); - addValue("playtimeWeek", formatter.apply(playtimeWeek)); - addValue("playtimeMonth", formatter.apply(playtimeMonth)); + replacer.put("playtimeTotal", formatter.apply(playtime)); + replacer.put("playtimeDay", formatter.apply(playtimeDay)); + replacer.put("playtimeWeek", formatter.apply(playtimeWeek)); + replacer.put("playtimeMonth", formatter.apply(playtimeMonth)); - addValue("activeTotal", formatter.apply(activeTotal)); + replacer.put("activeTotal", formatter.apply(activeTotal)); - addValue("afkTotal", formatter.apply(afk)); - addValue("afkDay", formatter.apply(afkDay)); - addValue("afkWeek", formatter.apply(afkWeek)); - addValue("afkMonth", formatter.apply(afkMonth)); + replacer.put("afkTotal", formatter.apply(afk)); + replacer.put("afkDay", formatter.apply(afkDay)); + replacer.put("afkWeek", formatter.apply(afkWeek)); + replacer.put("afkMonth", formatter.apply(afkMonth)); - addValue("sessionLengthLongest", formatter.apply(longestSession)); - addValue("sessionLongestDay", formatter.apply(longestSessionDay)); - addValue("sessionLongestWeek", formatter.apply(longestSessionWeek)); - addValue("sessionLongestMonth", formatter.apply(longestSessionMonth)); + replacer.put("sessionLengthLongest", formatter.apply(longestSession)); + replacer.put("sessionLongestDay", formatter.apply(longestSessionDay)); + replacer.put("sessionLongestWeek", formatter.apply(longestSessionWeek)); + replacer.put("sessionLongestMonth", formatter.apply(longestSessionMonth)); - addValue("sessionLengthMedian", formatter.apply(sessionMedian)); - addValue("sessionMedianDay", formatter.apply(sessionMedianDay)); - addValue("sessionMedianWeek", formatter.apply(sessionMedianWeek)); - addValue("sessionMedianMonth", formatter.apply(sessionMedianMonth)); + replacer.put("sessionLengthMedian", formatter.apply(sessionMedian)); + replacer.put("sessionMedianDay", formatter.apply(sessionMedianDay)); + replacer.put("sessionMedianWeek", formatter.apply(sessionMedianWeek)); + replacer.put("sessionMedianMonth", formatter.apply(sessionMedianMonth)); - addValue("sessionAverage", formatter.apply(sessionAverage)); - addValue("sessionAverageDay", formatter.apply(sessionAverageDay)); - addValue("sessionAverageWeek", formatter.apply(sessionAverageWeek)); - addValue("sessionAverageMonth", formatter.apply(sessionAverageMonth)); + replacer.put("sessionAverage", formatter.apply(sessionAverage)); + replacer.put("sessionAverageDay", formatter.apply(sessionAverageDay)); + replacer.put("sessionAverageWeek", formatter.apply(sessionAverageWeek)); + replacer.put("sessionAverageMonth", formatter.apply(sessionAverageMonth)); - addValue("sessionCount", sessionCount); - addValue("sessionCountDay", sessionCountDay); - addValue("sessionCountWeek", sessionCountWeek); - addValue("sessionCountMonth", sessionCountMonth); + replacer.put("sessionCount", sessionCount); + replacer.put("sessionCountDay", sessionCountDay); + replacer.put("sessionCountWeek", sessionCountWeek); + replacer.put("sessionCountMonth", sessionCountMonth); String punchCardData = new PunchCardGraph(allSessions).toHighChartsSeries(); WorldTimes worldTimes = container.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>())); WorldPie worldPie = new WorldPie(worldTimes); - addValue("worldPieSeries", worldPie.toHighChartsSeries()); - addValue("gmSeries", worldPie.toHighChartsDrilldown()); + replacer.put("worldPieSeries", worldPie.toHighChartsSeries()); + replacer.put("gmSeries", worldPie.toHighChartsDrilldown()); - addValue("punchCardSeries", punchCardData); + replacer.put("punchCardSeries", punchCardData); long playerKillCount = allSessions.stream().map(Session::getPlayerKills).mapToLong(Collection::size).sum(); long mobKillCount = allSessions.stream().mapToLong(Session::getMobKills).sum(); long deathCount = allSessions.stream().mapToLong(Session::getDeaths).sum(); - addValue("playerKillCount", playerKillCount); - addValue("mobKillCount", mobKillCount); - addValue("deathCount", deathCount); + replacer.put("playerKillCount", playerKillCount); + replacer.put("mobKillCount", mobKillCount); + replacer.put("deathCount", deathCount); ActivityIndex activityIndex = container.getActivityIndex(now); - addValue("activityIndexNumber", activityIndex.getFormattedValue()); - addValue("activityIndexColor", activityIndex.getColor()); - addValue("activityIndex", activityIndex.getGroup()); + replacer.put("activityIndexNumber", activityIndex.getFormattedValue()); + replacer.put("activityIndexColor", activityIndex.getColor()); + replacer.put("activityIndex", activityIndex.getGroup()); - addValue("playerStatus", HtmlStructure.playerStatus(online, + replacer.put("playerStatus", HtmlStructure.playerStatus(online, container.getValue(PlayerKeys.BANNED).orElse(false), container.getValue(PlayerKeys.OPERATOR).orElse(false))); if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable()) { - addValue("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_")); + replacer.put("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_")); } - return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("web/player.html"), placeHolders); + return replacer.apply(FileUtil.getStringFromResource("web/player.html")); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java index b30b1bd29..ba2a504d1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java @@ -20,7 +20,7 @@ import static com.djrapitops.plan.data.store.keys.NetworkKeys.*; * * @author Rsl1122 */ -public class NetworkPage extends Page { +public class NetworkPage implements Page { @Override public String toHtml() throws ParseException { diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/Page.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/Page.java index 24c9cdb7e..de800be8e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/Page.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/Page.java @@ -6,27 +6,12 @@ package com.djrapitops.plan.system.webserver.pages.parsing; import com.djrapitops.plan.api.exceptions.ParseException; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - /** - * Abstract class that is responsible for parsing data and html together into a String. + * Interface for parsing page HTML. * * @author Rsl1122 */ -public abstract class Page { +public interface Page { - protected final Map placeHolders; - - public Page() { - this.placeHolders = new HashMap<>(); - } - - @Deprecated - protected void addValue(String placeholder, Serializable value) { - placeHolders.put(placeholder, value); - } - - public abstract String toHtml() throws ParseException; + String toHtml() throws ParseException; } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/PlayersPage.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/PlayersPage.java index 4950d3122..f2211dbbc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/PlayersPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/PlayersPage.java @@ -20,7 +20,7 @@ import java.util.List; * * @author Rsl1122 */ -public class PlayersPage extends Page { +public class PlayersPage implements Page { @Override public String toHtml() throws ParseException { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/calendar/PlayerCalendar.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/calendar/PlayerCalendar.java index 2a298e3ce..95b6d4b17 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/calendar/PlayerCalendar.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/calendar/PlayerCalendar.java @@ -6,6 +6,8 @@ package com.djrapitops.plan.utilities.html.graphs.calendar; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.data.store.containers.PlayerContainer; +import com.djrapitops.plan.data.store.keys.PlayerKeys; import com.djrapitops.plan.data.store.mutators.formatting.Formatter; import com.djrapitops.plan.data.store.mutators.formatting.Formatters; import com.djrapitops.plan.system.settings.theme.Theme; @@ -28,7 +30,14 @@ public class PlayerCalendar { private final List allSessions; private final long registered; - public PlayerCalendar(List allSessions, long registered) { + public PlayerCalendar(PlayerContainer container) { + this( + container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()), + container.getValue(PlayerKeys.REGISTERED).orElse(0L) + ); + } + + private PlayerCalendar(List allSessions, long registered) { this.allSessions = allSessions; this.registered = registered; } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java index a78e69922..63cadd7ac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java @@ -9,6 +9,7 @@ import com.djrapitops.plan.data.element.AnalysisContainer; import com.djrapitops.plan.data.element.InspectContainer; import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.data.store.mutators.PlayersMutator; import com.djrapitops.plan.utilities.comparators.PluginDataNameComparator; import com.djrapitops.plan.utilities.html.tables.PluginPlayersTable; import com.djrapitops.plugin.StaticHolder; @@ -24,11 +25,12 @@ import java.util.*; */ public class AnalysisPluginsTabContentCreator { - public static String[] createContent(List uuids) { - if (uuids.isEmpty()) { + public static String[] createContent(PlayersMutator mutator) { + if (mutator.all().isEmpty()) { return new String[]{"
  • No Data
  • ", ""}; } + List uuids = mutator.uuids(); Map containers = analyzeAdditionalPluginData(uuids); List order = new ArrayList<>(containers.keySet()); @@ -77,8 +79,7 @@ public class AnalysisPluginsTabContentCreator { "
    " + "

    Plugin Data

    " + "
    " + - // TODO Start using ServerContainer and PlayerContainers instead - new PluginPlayersTable(containers, new ArrayList<>()).parseHtml() + + new PluginPlayersTable(containers, mutator.all()).parseHtml() + "
    " + "";