diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/DataContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/DataContainer.java index 656d82ada..c73a1a289 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/DataContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/DataContainer.java @@ -71,7 +71,7 @@ public class DataContainer extends HashMap { public T getUnsafe(Key key) { Supplier supplier = get(key); if (supplier == null) { - throw new IllegalArgumentException("Unsupported Key"); + throw new IllegalArgumentException("Unsupported Key: " + key.getKeyName()); } return (T) supplier.get(); } 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 0c924c731..90fbaa382 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 @@ -39,6 +39,7 @@ import com.djrapitops.plan.utilities.html.structure.SessionAccordion; import com.djrapitops.plan.utilities.html.tables.ActionsTable; import com.djrapitops.plan.utilities.html.tables.GeoInfoTable; import com.djrapitops.plan.utilities.html.tables.NicknameTable; +import com.djrapitops.plan.utilities.html.tables.PlayerSessionTable; import com.djrapitops.plugin.api.Benchmark; import com.djrapitops.plugin.api.TimeAmount; @@ -134,7 +135,19 @@ public class InspectPage extends Page { SessionsMutator allSessionsMutator = new SessionsMutator(allSessions); allSessions.sort(new SessionStartComparator()); - SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames); + String sessionAccordionViewScript = ""; + if (allSessions.isEmpty()) { + addValue("accordionSessions", "
" + "

No Sessions

" + "
"); + } else { + if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { + addValue("accordionSessions", new PlayerSessionTable(playerName, allSessions).parseHtml()); + } else { + SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames); + addValue("accordionSessions", sessionAccordion.toHtml()); + sessionAccordionViewScript = sessionAccordion.toViewScript(); + } + } + // TODO Session table if setting is enabled ServerAccordion serverAccordion = new ServerAccordion(container, serverNames); @@ -143,9 +156,8 @@ public class InspectPage extends Page { addValue("calendarSeries", playerCalendar.toCalendarSeries()); addValue("firstDay", 1); - addValue("accordionSessions", sessionAccordion.toHtml()); addValue("accordionServers", serverAccordion.toHtml()); - addValue("sessionTabGraphViewFunctions", sessionAccordion.toViewScript() + serverAccordion.toViewScript()); + addValue("sessionTabGraphViewFunctions", sessionAccordionViewScript + serverAccordion.toViewScript()); long dayAgo = now - TimeAmount.DAY.ms(); long weekAgo = now - TimeAmount.WEEK.ms(); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java index 9da868562..0c378dce9 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java @@ -4,9 +4,11 @@ import com.djrapitops.plan.data.PlayerProfile; import com.djrapitops.plan.data.calculation.ActivityIndex; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.StickyData; +import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.data.time.GMTimes; import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.system.settings.WorldAliasSettings; +import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plugin.api.TimeAmount; import java.util.*; @@ -258,4 +260,33 @@ public class AnalysisUtils { return new StickyData(averageIndex, averageMessagesSent, averagePlayersOnline); } + + public static String getLongestWorldPlayed(Session session) { + Map aliases = WorldAliasSettings.getAliases(); + if (!session.supports(SessionKeys.WORLD_TIMES)) { + return "No World Time Data"; + } + if (!session.supports(SessionKeys.END)) { + return "Current: " + aliases.get(session.getUnsafe(SessionKeys.WORLD_TIMES).getCurrentWorld()); + } + + WorldTimes worldTimes = session.getUnsafe(SessionKeys.WORLD_TIMES); + Map playtimePerAlias = getPlaytimePerAlias(worldTimes); + long total = worldTimes.getTotal(); + + long longest = 0; + String theWorld = "-"; + for (Map.Entry entry : playtimePerAlias.entrySet()) { + String world = entry.getKey(); + long time = entry.getValue(); + if (time > longest) { + longest = time; + theWorld = world; + } + } + + double percentage = longest * 100.0 / total; + + return theWorld + " (" + FormatUtils.cutDecimals(percentage) + "%)"; + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java index de90531fd..27bfc9ea2 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/HtmlStructure.java @@ -5,17 +5,13 @@ package com.djrapitops.plan.utilities.html; import com.djrapitops.plan.api.exceptions.database.DBOpException; -import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.info.server.ServerProperties; -import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.analysis.Analysis; import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph; -import com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator; -import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.utilities.Verify; @@ -61,19 +57,6 @@ public class HtmlStructure { return builder.toString(); } - @Deprecated - public static String[] createSessionsTabContentInspectPage(Map> sessions, List allSessions, UUID uuid) { - if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) { - Map> sessionsByPlayer = new HashMap<>(); - sessionsByPlayer.put(uuid, allSessions); - return new String[]{Html.TABLE_SESSIONS.parse("", "", "", SessionsTableCreator.createTable(sessionsByPlayer, allSessions)[0]), ""}; - } else { - Map>> map = new HashMap<>(); - map.put(uuid, sessions); - return SessionTabStructureCreator.createStructure(map, allSessions, false); - } - } - public static String[] createInspectPageTabContentCalculating() { String tab = "
" + "
" + diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java index e9c14f01a..bcf7ac039 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionAccordion.java @@ -10,10 +10,10 @@ import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.theme.Theme; import com.djrapitops.plan.system.settings.theme.ThemeVal; +import com.djrapitops.plan.utilities.analysis.AnalysisUtils; import com.djrapitops.plan.utilities.html.HtmlStructure; import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie; import com.djrapitops.plan.utilities.html.tables.KillsTable; -import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator; import java.util.*; import java.util.function.Supplier; @@ -107,7 +107,7 @@ public class SessionAccordion extends AbstractAccordion { int deaths = session.getValue(SessionKeys.DEATH_COUNT).orElse(0); String info = appendWorldPercentage - ? HtmlStructure.separateWithDots(sessionStart, SessionsTableCreator.getLongestWorldPlayed(session)) + ? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session)) : sessionStart; String title = HtmlStructure.separateWithDots(playerName, info) + "" + length + ""; String htmlID = "" + session.getValue(SessionKeys.START).orElse(0L) + i; @@ -178,7 +178,7 @@ public class SessionAccordion extends AbstractAccordion { int deaths = session.getValue(SessionKeys.DEATH_COUNT).orElse(0); String info = appendWorldPercentage - ? HtmlStructure.separateWithDots(sessionStart, SessionsTableCreator.getLongestWorldPlayed(session)) + ? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session)) : sessionStart; String title = HtmlStructure.separateWithDots(serverName, info) + "" + length + ""; String htmlID = "" + session.getValue(SessionKeys.START).orElse(0L) + i; diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java index 46f312932..ace8eca53 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/SessionTabStructureCreator.java @@ -14,6 +14,7 @@ import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.theme.Theme; import com.djrapitops.plan.system.settings.theme.ThemeVal; +import com.djrapitops.plan.utilities.analysis.AnalysisUtils; import com.djrapitops.plan.utilities.html.Html; import com.djrapitops.plan.utilities.html.HtmlStructure; import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie; @@ -79,7 +80,7 @@ public class SessionTabStructureCreator { String link = PlanAPI.getInstance().getPlayerInspectPageLink(name); String info = appendWorldPercentage - ? HtmlStructure.separateWithDots(sessionStart, SessionsTableCreator.getLongestWorldPlayed(session)) + ? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session)) : sessionStart; String nameAndInfo = appendName ? HtmlStructure.separateWithDots(name, info) : diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayerSessionTable.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayerSessionTable.java new file mode 100644 index 000000000..635152790 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/PlayerSessionTable.java @@ -0,0 +1,60 @@ +package com.djrapitops.plan.utilities.html.tables; + +import com.djrapitops.plan.api.PlanAPI; +import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.data.element.TableContainer; +import com.djrapitops.plan.data.store.keys.SessionKeys; +import com.djrapitops.plan.data.store.mutators.formatting.Formatters; +import com.djrapitops.plan.system.settings.Settings; +import com.djrapitops.plan.utilities.analysis.AnalysisUtils; +import com.djrapitops.plan.utilities.html.Html; + +import java.util.List; + +/** + * TableContainer for a Session table for a single player. + * + * @author Rsl1122 + */ +public class PlayerSessionTable extends TableContainer { + + private final String playerName; + private final List sessions; + + public PlayerSessionTable(String playerName, List sessions) { + super("Player", "Start", "Length", "World"); + this.playerName = playerName; + this.sessions = sessions; + + addRows(); + } + + private void addRows() { + int maxSessions = Settings.MAX_SESSIONS.getNumber(); + if (maxSessions <= 0) { + maxSessions = 50; + } + + String inspectUrl = PlanAPI.getInstance().getPlayerInspectPageLink(playerName); + + int i = 0; + for (Session session : sessions) { + if (i >= maxSessions) { + break; + } + + String start = Formatters.year().apply(session); + String length = session.supports(SessionKeys.END) + ? Formatters.timeAmount().apply(session.getValue(SessionKeys.LENGTH).orElse(0L)) + : "Online"; + String world = AnalysisUtils.getLongestWorldPlayed(session); + + String toolTip = "Session ID: " + session.getValue(SessionKeys.DB_ID) + .map(id -> Integer.toString(id)) + .orElse("Not Saved."); + addRow(Html.LINK_TOOLTIP.parse(inspectUrl, playerName, toolTip), start, length, world); + + i++; + } + } +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java index 7fc08c0c1..82abbc732 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/SessionsTableCreator.java @@ -7,12 +7,9 @@ package com.djrapitops.plan.utilities.html.tables; import com.djrapitops.plan.api.PlanAPI; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.mutators.formatting.Formatters; -import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.system.cache.DataCache; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.settings.Settings; -import com.djrapitops.plan.system.settings.WorldAliasSettings; -import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.analysis.AnalysisUtils; import com.djrapitops.plan.utilities.comparators.SessionStartComparator; import com.djrapitops.plan.utilities.html.Html; @@ -79,7 +76,7 @@ public class SessionsTableCreator { String name = dataCache.getName(uuid); String start = Formatters.year().apply(session); String length = session.getSessionEnd() != -1 ? Formatters.timeAmount().apply(session.getLength()) : "Online"; - String world = getLongestWorldPlayed(session); + String world = AnalysisUtils.getLongestWorldPlayed(session); String inspectUrl = PlanAPI.getInstance().getPlayerInspectPageLink(name); String toolTip = "Session ID: " + (session.isFetchedFromDB() ? session.getSessionID() : "Not Saved."); @@ -104,29 +101,4 @@ public class SessionsTableCreator { return new String[]{sessionTableBuilder.toString(), recentLoginsBuilder.toString()}; } - public static String getLongestWorldPlayed(Session session) { - Map aliases = WorldAliasSettings.getAliases(); - if (session.getSessionEnd() == -1) { - return "Current: " + aliases.get(session.getWorldTimes().getCurrentWorld()); - } - - WorldTimes worldTimes = session.getWorldTimes(); - Map playtimePerAlias = AnalysisUtils.getPlaytimePerAlias(worldTimes); - long total = worldTimes.getTotal(); - - long longest = 0; - String theWorld = "-"; - for (Map.Entry entry : playtimePerAlias.entrySet()) { - String world = entry.getKey(); - long time = entry.getValue(); - if (time > longest) { - longest = time; - theWorld = world; - } - } - - double percentage = longest * 100.0 / total; - - return theWorld + " (" + FormatUtils.cutDecimals(percentage) + "%)"; - } } \ No newline at end of file