From 46fa30d224bf337845f89e244fa0874fce72a792 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Wed, 11 Jul 2018 12:46:37 +0300 Subject: [PATCH] PvP & PvE tab on Player inspect page --- .../plan/data/container/PlayerDeath.java | 31 ++++ .../plan/data/container/Session.java | 2 + .../plan/data/store/keys/CommonKeys.java | 2 + .../plan/data/store/keys/PerServerKeys.java | 2 + .../plan/data/store/keys/PlayerKeys.java | 2 + .../plan/data/store/keys/SessionKeys.java | 2 + .../data/store/mutators/PvpInfoMutator.java | 57 +++++++ .../data/store/mutators/SessionsMutator.java | 12 ++ .../formatting/PlaceholderReplacer.java | 5 - .../plan/data/store/objects/Nickname.java | 1 + .../databases/sql/operation/SQLFetchOps.java | 3 + .../databases/sql/tables/KillsTable.java | 39 +++++ .../databases/sql/tables/SessionsTable.java | 1 + .../webserver/pages/parsing/InspectPage.java | 95 ++++++++---- .../DateHolderRecentComparator.java | 18 +++ .../comparators/GeoInfoComparator.java | 11 +- .../comparators/PlayerKillComparator.java | 15 +- .../comparators/SessionStartComparator.java | 10 +- .../plan/utilities/html/HtmlStructure.java | 5 +- .../plan/utilities/html/icon/Icons.java | 2 +- .../utilities/html/tables/DeathsTable.java | 57 +++++++ .../utilities/html/tables/KillsTable.java | 3 +- Plan/src/main/resources/web/player.html | 141 +++++++++++++++++- Plan/src/main/resources/web/server.html | 2 +- 24 files changed, 445 insertions(+), 73 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PvpInfoMutator.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/comparators/DateHolderRecentComparator.java create mode 100644 Plan/src/main/java/com/djrapitops/plan/utilities/html/tables/DeathsTable.java diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java new file mode 100644 index 000000000..1eb7f35b5 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerDeath.java @@ -0,0 +1,31 @@ +package com.djrapitops.plan.data.container; + +import com.djrapitops.plan.data.store.objects.DateHolder; + +import java.util.UUID; + +public class PlayerDeath implements DateHolder { + + private final UUID killer; + private final long date; + private final String weapon; + + public PlayerDeath(UUID killer, String weapon, long date) { + this.killer = killer; + this.date = date; + this.weapon = weapon; + } + + public UUID getKiller() { + return killer; + } + + @Override + public long getDate() { + return date; + } + + public String getWeapon() { + return weapon; + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java index b9dacbb92..0166aacf7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java @@ -37,6 +37,7 @@ public class Session extends DataContainer implements DateHolder { putRawData(SessionKeys.START, sessionStart); putRawData(SessionKeys.WORLD_TIMES, new WorldTimes(world, gm)); putRawData(SessionKeys.PLAYER_KILLS, new ArrayList<>()); + putRawData(SessionKeys.PLAYER_DEATHS, new ArrayList<>()); putSupplier(SessionKeys.MOB_KILL_COUNT, () -> mobKills); putSupplier(SessionKeys.DEATH_COUNT, () -> deaths); putSupplier(SessionKeys.AFK_TIME, () -> afkTime); @@ -70,6 +71,7 @@ public class Session extends DataContainer implements DateHolder { putRawData(SessionKeys.END, sessionEnd); putRawData(SessionKeys.WORLD_TIMES, new WorldTimes(new HashMap<>())); putRawData(SessionKeys.PLAYER_KILLS, new ArrayList<>()); + putRawData(SessionKeys.PLAYER_DEATHS, new ArrayList<>()); putSupplier(SessionKeys.MOB_KILL_COUNT, () -> mobKills); putSupplier(SessionKeys.DEATH_COUNT, () -> deaths); putSupplier(SessionKeys.AFK_TIME, () -> afkTime); 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 e6aa3e651..a95619421 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 @@ -1,5 +1,6 @@ package com.djrapitops.plan.data.store.keys; +import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.Key; @@ -33,6 +34,7 @@ public class CommonKeys { public static final Key WORLD_TIMES = new Key<>(WorldTimes.class, "world_times"); public static final PlaceholderKey LAST_SEEN = new PlaceholderKey<>(Long.class, "lastSeen"); + public static final Key> PLAYER_DEATHS = new Key<>(new Type>() {}, "player_deaths"); 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"); public static final Key MOB_KILL_COUNT = new Key<>(Integer.class, "mob_kill_count"); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java index 8ffe81dc6..3327202cb 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.data.store.keys; +import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.Key; @@ -27,6 +28,7 @@ public class PerServerKeys { public static final Key WORLD_TIMES = CommonKeys.WORLD_TIMES; public static final Key> PLAYER_KILLS = CommonKeys.PLAYER_KILLS; + public static final Key> PLAYER_DEATHS = CommonKeys.PLAYER_DEATHS; public static final Key PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT; public static final Key MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT; public static final Key DEATH_COUNT = CommonKeys.DEATH_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 afcd4199a..4c8879384 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 @@ -1,6 +1,7 @@ package com.djrapitops.plan.data.store.keys; import com.djrapitops.plan.data.container.GeoInfo; +import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.Key; @@ -40,6 +41,7 @@ public class PlayerKeys { public static final Key WORLD_TIMES = CommonKeys.WORLD_TIMES; public static final Key> PLAYER_KILLS = CommonKeys.PLAYER_KILLS; + public static final Key> PLAYER_DEATHS = CommonKeys.PLAYER_DEATHS; public static final Key PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT; public static final Key MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT; public static final Key DEATH_COUNT = CommonKeys.DEATH_COUNT; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/SessionKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/SessionKeys.java index 055793ea0..4bcd3c1fd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/SessionKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/SessionKeys.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.data.store.keys; +import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.store.Key; import com.djrapitops.plan.data.time.WorldTimes; @@ -29,6 +30,7 @@ public class SessionKeys { public static final Key PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT; public static final Key MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT; public static final Key DEATH_COUNT = CommonKeys.DEATH_COUNT; + public static final Key> PLAYER_DEATHS = CommonKeys.PLAYER_DEATHS; private SessionKeys() { /* Static variable class */ diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PvpInfoMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PvpInfoMutator.java new file mode 100644 index 000000000..0341c7e3a --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PvpInfoMutator.java @@ -0,0 +1,57 @@ +package com.djrapitops.plan.data.store.mutators; + +import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.data.store.containers.DataContainer; + +import java.util.List; + +public class PvpInfoMutator { + + private final SessionsMutator sessionsMutator; + + private PvpInfoMutator(SessionsMutator sessionsMutator) { + this.sessionsMutator = sessionsMutator; + } + + public PvpInfoMutator(List sessions) { + this(new SessionsMutator(sessions)); + } + + public static PvpInfoMutator forContainer(DataContainer container) { + return new PvpInfoMutator(SessionsMutator.forContainer(container)); + } + + public static PvpInfoMutator forMutator(SessionsMutator sessionsMutator) { + return new PvpInfoMutator(sessionsMutator); + } + + public double killDeathRatio() { + int deathCount = sessionsMutator.toPlayerDeathCount(); + return sessionsMutator.toPlayerKillCount() * 1.0 / (deathCount != 0 ? deathCount : 1); + } + + public int mobCausedDeaths() { + return sessionsMutator.toDeathCount() - sessionsMutator.toPlayerDeathCount(); + } + + public double mobKillDeathRatio() { + int deathCount = mobCausedDeaths(); + return sessionsMutator.toMobKillCount() * 1.0 / (deathCount != 0 ? deathCount : 1); + } + + public int mobKills() { + return sessionsMutator.toMobKillCount(); + } + + public int playerKills() { + return sessionsMutator.toPlayerKillCount(); + } + + public int deaths() { + return sessionsMutator.toDeathCount(); + } + + public int playerCausedDeaths() { + return sessionsMutator.toPlayerDeathCount(); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java index 3b859d88f..266f190f8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.data.store.mutators; +import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.containers.DataContainer; @@ -67,6 +68,13 @@ public class SessionsMutator { .collect(Collectors.toList()); } + public List toPlayerDeathList() { + return sessions.stream() + .map(session -> session.getValue(SessionKeys.PLAYER_DEATHS).orElse(new ArrayList<>())) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + public int toMobKillCount() { return sessions.stream() .mapToInt(session -> session.getValue(SessionKeys.MOB_KILL_COUNT).orElse(0)) @@ -178,4 +186,8 @@ public class SessionsMutator { return (after <= start && start <= before) || (after <= end && end <= before); }; } + + public int toPlayerDeathCount() { + return toPlayerDeathList().size(); + } } \ No newline at end of file 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 a6f4afa4e..487dc4304 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 @@ -2,7 +2,6 @@ package com.djrapitops.plan.data.store.mutators.formatting; import com.djrapitops.plan.data.store.PlaceholderKey; import com.djrapitops.plan.data.store.containers.DataContainer; -import com.djrapitops.plugin.api.utility.log.Log; import org.apache.commons.text.StringSubstitutor; import java.io.Serializable; @@ -19,11 +18,7 @@ public class PlaceholderReplacer extends HashMap implement if (!container.supports(key)) { return; } - long ns = System.nanoTime(); - Log.debug(key.getPlaceholder()); put(key.getPlaceholder(), container.getSupplier(key).get().toString()); - ns = System.nanoTime() - ns; - Log.debug(key.getPlaceholder() + ": " + Formatters.benchmark().apply(ns)); } public void addAllPlaceholdersFrom(DataContainer container, PlaceholderKey... keys) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/objects/Nickname.java b/Plan/src/main/java/com/djrapitops/plan/data/store/objects/Nickname.java index a904a780f..60fa052d0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/objects/Nickname.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/objects/Nickname.java @@ -24,6 +24,7 @@ public class Nickname implements DateHolder { return name; } + @Override public long getDate() { return date; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index f34025eee..9e5a9fb26 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -236,6 +236,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { container.putSupplier(PerServerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen()); container.putSupplier(PerServerKeys.WORLD_TIMES, () -> SessionsMutator.forContainer(container).toTotalWorldTimes()); + container.putSupplier(PerServerKeys.PLAYER_DEATHS, () -> SessionsMutator.forContainer(container).toPlayerDeathList()); container.putSupplier(PerServerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList()); container.putSupplier(PerServerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PerServerKeys.PLAYER_KILLS).size()); container.putSupplier(PerServerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); @@ -279,6 +280,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen()); container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList()); + container.putSupplier(PlayerKeys.PLAYER_DEATHS, () -> SessionsMutator.forContainer(container).toPlayerDeathList()); container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PlayerKeys.PLAYER_KILLS).size()); container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount()); @@ -313,6 +315,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { container.putSupplier(PerServerKeys.WORLD_TIMES, () -> SessionsMutator.forContainer(container).toTotalWorldTimes()); container.putSupplier(PerServerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList()); + container.putSupplier(PerServerKeys.PLAYER_DEATHS, () -> SessionsMutator.forContainer(container).toPlayerDeathList()); container.putSupplier(PerServerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PerServerKeys.PLAYER_KILLS).size()); container.putSupplier(PerServerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); container.putSupplier(PerServerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount()); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java index 9a80e8cf7..2ab7f6665 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/KillsTable.java @@ -1,8 +1,10 @@ package com.djrapitops.plan.system.database.databases.sql.tables; import com.djrapitops.plan.api.exceptions.database.DBInitException; +import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.system.database.databases.sql.SQLDB; import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement; import com.djrapitops.plan.system.database.databases.sql.processing.QueryAllStatement; @@ -121,6 +123,43 @@ public class KillsTable extends UserIDTable { }); } + public void addDeathsToSessions(UUID uuid, Map sessions) { + String usersIDColumn = usersTable + "." + UsersTable.Col.ID; + String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as killer_uuid"; + String sql = "SELECT " + + Col.SESSION_ID + ", " + + Col.DATE + ", " + + Col.WEAPON + ", " + + usersUUIDColumn + + " FROM " + tableName + + " INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.KILLER_ID + + " WHERE " + Col.VICTIM_ID + "=" + usersTable.statementSelectID; + + query(new QueryStatement(sql, 50000) { + @Override + public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, uuid.toString()); + } + + @Override + public Object processResults(ResultSet set) throws SQLException { + while (set.next()) { + int sessionID = set.getInt(Col.SESSION_ID.get()); + Session session = sessions.get(sessionID); + if (session == null) { + continue; + } + String uuidS = set.getString("killer_uuid"); + UUID killer = UUID.fromString(uuidS); + long date = set.getLong(Col.DATE.get()); + String weapon = set.getString(Col.WEAPON.get()); + session.getUnsafe(SessionKeys.PLAYER_DEATHS).add(new PlayerDeath(killer, weapon, date)); + } + return null; + } + }); + } + public void savePlayerKills(UUID uuid, int sessionID, List playerKills) { if (Verify.isEmpty(playerKills)) { return; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java index 25dc94c23..799072b78 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/SessionsTable.java @@ -225,6 +225,7 @@ public class SessionsTable extends UserIDTable { Map allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(Session::getSessionID, Function.identity())); db.getKillsTable().addKillsToSessions(uuid, allSessions); + db.getKillsTable().addDeathsToSessions(uuid, allSessions); db.getWorldTimesTable().addWorldTimesToSessions(uuid, allSessions); return sessions; } 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 767fbe08f..1b67ab53c 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 @@ -11,6 +11,7 @@ import com.djrapitops.plan.data.store.containers.PlayerContainer; import com.djrapitops.plan.data.store.keys.PlayerKeys; import com.djrapitops.plan.data.store.mutators.ActivityIndex; import com.djrapitops.plan.data.store.mutators.PerServerDataMutator; +import com.djrapitops.plan.data.store.mutators.PvpInfoMutator; 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; @@ -34,9 +35,7 @@ import com.djrapitops.plan.utilities.html.graphs.pie.ServerPreferencePie; import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie; import com.djrapitops.plan.utilities.html.structure.ServerAccordion; import com.djrapitops.plan.utilities.html.structure.SessionAccordion; -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.plan.utilities.html.tables.*; import com.djrapitops.plugin.api.Benchmark; import com.djrapitops.plugin.api.TimeAmount; @@ -159,6 +158,38 @@ public class InspectPage implements Page { SessionsMutator weekSessionsMutator = sessionsMutator.filterSessionsBetween(weekAgo, now); SessionsMutator monthSessionsMutator = sessionsMutator.filterSessionsBetween(monthAgo, now); + sessionsAndPlaytime(replacer, sessionsMutator, daySessionsMutator, weekSessionsMutator, monthSessionsMutator); + + String punchCardData = new PunchCardGraph(allSessions).toHighChartsSeries(); + WorldTimes worldTimes = container.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>())); + + WorldPie worldPie = new WorldPie(worldTimes); + + replacer.put("worldPieSeries", worldPie.toHighChartsSeries()); + replacer.put("gmSeries", worldPie.toHighChartsDrilldown()); + + replacer.put("punchCardSeries", punchCardData); + + pvpAndPve(replacer, sessionsMutator, weekSessionsMutator, monthSessionsMutator); + + ActivityIndex activityIndex = container.getActivityIndex(now); + + replacer.put("activityIndexNumber", activityIndex.getFormattedValue()); + replacer.put("activityIndexColor", activityIndex.getColor()); + replacer.put("activityIndex", activityIndex.getGroup()); + + replacer.put("playerStatus", HtmlStructure.playerStatus(online, + container.getValue(PlayerKeys.BANNED).orElse(false), + container.getValue(PlayerKeys.OPERATOR).orElse(false))); + + if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable()) { + replacer.put("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_")); + } + + return replacer.apply(FileUtil.getStringFromResource("web/player.html")); + } + + private void sessionsAndPlaytime(PlaceholderReplacer replacer, SessionsMutator sessionsMutator, SessionsMutator daySessionsMutator, SessionsMutator weekSessionsMutator, SessionsMutator monthSessionsMutator) { long playtime = sessionsMutator.toPlaytime(); long playtimeDay = daySessionsMutator.toPlaytime(); long playtimeWeek = weekSessionsMutator.toPlaytime(); @@ -223,39 +254,41 @@ public class InspectPage implements Page { 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<>())); + private void pvpAndPve(PlaceholderReplacer replacer, SessionsMutator sessionsMutator, SessionsMutator weekSessionsMutator, SessionsMutator monthSessionsMutator) { + String playerKillsTable = new KillsTable(sessionsMutator.toPlayerKillList()).parseHtml(); + String playerDeathTable = new DeathsTable(sessionsMutator.toPlayerDeathList()).parseHtml(); - WorldPie worldPie = new WorldPie(worldTimes); + PvpInfoMutator pvpInfoMutator = PvpInfoMutator.forMutator(sessionsMutator); + PvpInfoMutator pvpInfoMutatorMonth = PvpInfoMutator.forMutator(monthSessionsMutator); + PvpInfoMutator pvpInfoMutatorWeek = PvpInfoMutator.forMutator(weekSessionsMutator); - replacer.put("worldPieSeries", worldPie.toHighChartsSeries()); - replacer.put("gmSeries", worldPie.toHighChartsDrilldown()); + replacer.put("tablePlayerKills", playerKillsTable); + replacer.put("tablePlayerDeaths", playerDeathTable); - replacer.put("punchCardSeries", punchCardData); + replacer.put("playerKillCount", pvpInfoMutator.playerKills()); + replacer.put("mobKillCount", pvpInfoMutator.mobKills()); + replacer.put("playerDeathCount", pvpInfoMutator.playerCausedDeaths()); + replacer.put("mobDeathCount", pvpInfoMutator.mobCausedDeaths()); + replacer.put("deathCount", pvpInfoMutator.deaths()); + replacer.put("KDR", FormatUtils.cutDecimals(pvpInfoMutator.killDeathRatio())); + replacer.put("mobKDR", FormatUtils.cutDecimals(pvpInfoMutator.mobKillDeathRatio())); - 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(); + replacer.put("playerKillCountMonth", pvpInfoMutatorMonth.playerKills()); + replacer.put("mobKillCountMonth", pvpInfoMutatorMonth.mobKills()); + replacer.put("playerDeathCountMonth", pvpInfoMutatorMonth.playerCausedDeaths()); + replacer.put("mobDeathCountMonth", pvpInfoMutatorMonth.mobCausedDeaths()); + replacer.put("deathCountMonth", pvpInfoMutatorMonth.deaths()); + replacer.put("KDRMonth", FormatUtils.cutDecimals(pvpInfoMutatorMonth.killDeathRatio())); + replacer.put("mobKDRMonth", FormatUtils.cutDecimals(pvpInfoMutatorMonth.mobKillDeathRatio())); - replacer.put("playerKillCount", playerKillCount); - replacer.put("mobKillCount", mobKillCount); - replacer.put("deathCount", deathCount); - - ActivityIndex activityIndex = container.getActivityIndex(now); - - replacer.put("activityIndexNumber", activityIndex.getFormattedValue()); - replacer.put("activityIndexColor", activityIndex.getColor()); - replacer.put("activityIndex", activityIndex.getGroup()); - - replacer.put("playerStatus", HtmlStructure.playerStatus(online, - container.getValue(PlayerKeys.BANNED).orElse(false), - container.getValue(PlayerKeys.OPERATOR).orElse(false))); - - if (!InfoSystem.getInstance().getConnectionSystem().isServerAvailable()) { - replacer.put("networkName", Settings.SERVER_NAME.toString().replaceAll("[^a-zA-Z0-9_\\s]", "_")); - } - - return replacer.apply(FileUtil.getStringFromResource("web/player.html")); + replacer.put("playerKillCountWeek", pvpInfoMutatorWeek.playerKills()); + replacer.put("mobKillCountWeek", pvpInfoMutatorWeek.mobKills()); + replacer.put("playerDeathCountWeek", pvpInfoMutatorWeek.playerCausedDeaths()); + replacer.put("mobDeathCountWeek", pvpInfoMutatorWeek.mobCausedDeaths()); + replacer.put("deathCountWeek", pvpInfoMutatorWeek.deaths()); + replacer.put("KDRWeek", FormatUtils.cutDecimals(pvpInfoMutatorWeek.killDeathRatio())); + replacer.put("mobKDRWeek", FormatUtils.cutDecimals(pvpInfoMutatorWeek.mobKillDeathRatio())); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/DateHolderRecentComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/DateHolderRecentComparator.java new file mode 100644 index 000000000..a0e940e9f --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/DateHolderRecentComparator.java @@ -0,0 +1,18 @@ +package com.djrapitops.plan.utilities.comparators; + +import com.djrapitops.plan.data.store.objects.DateHolder; + +import java.util.Comparator; + +/** + * Compares DateHolder objects so that most recent is first. + * + * @author Rsl1122 + */ +public class DateHolderRecentComparator implements Comparator { + + @Override + public int compare(DateHolder one, DateHolder two) { + return Long.compare(two.getDate(), one.getDate()); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/GeoInfoComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/GeoInfoComparator.java index 3633d397d..a6828febe 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/GeoInfoComparator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/GeoInfoComparator.java @@ -1,19 +1,10 @@ package com.djrapitops.plan.utilities.comparators; -import com.djrapitops.plan.data.container.GeoInfo; - -import java.util.Comparator; - /** * Comparator for comparing GeoInfo so that most recent is the first component. * * @author Rsl1122 */ -public class GeoInfoComparator implements Comparator { - - @Override - public int compare(GeoInfo o1, GeoInfo o2) { - return -Long.compare(o1.getDate(), o2.getDate()); - } +public class GeoInfoComparator extends DateHolderRecentComparator { } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PlayerKillComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PlayerKillComparator.java index 9507cb869..580937df4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PlayerKillComparator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/PlayerKillComparator.java @@ -1,17 +1,10 @@ package com.djrapitops.plan.utilities.comparators; -import com.djrapitops.plan.data.container.PlayerKill; - -import java.util.Comparator; - /** - * @author Fuzzlemann + * Compares PlayerKills so that most recent is first. + * + * @author Rsl1122 */ -public class PlayerKillComparator implements Comparator { - - @Override - public int compare(PlayerKill o1, PlayerKill o2) { - return Long.compare(o1.getDate(), o2.getDate()); - } +public class PlayerKillComparator extends DateHolderRecentComparator { } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java index 07302220d..c1c886439 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/comparators/SessionStartComparator.java @@ -1,18 +1,10 @@ package com.djrapitops.plan.utilities.comparators; -import com.djrapitops.plan.data.container.Session; - -import java.util.Comparator; - /** * Comparator for Sessions in descending start order (Most recent first). * * @author Rsl1122 */ -public class SessionStartComparator implements Comparator { +public class SessionStartComparator extends DateHolderRecentComparator { - @Override - public int compare(Session s1, Session s2) { - return -Long.compare(s1.getSessionStart(), s2.getSessionStart()); - } } 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 f05e66c30..7b23dbe9c 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 @@ -9,6 +9,7 @@ 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.utilities.FormatUtils; import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph; import com.djrapitops.plan.utilities.html.icon.Color; import com.djrapitops.plan.utilities.html.icon.Icon; @@ -98,7 +99,7 @@ public class HtmlStructure { ServerProperties properties = ServerInfo.getServerProperties(); int maxPlayers = properties.getMaxPlayers(); int online = properties.getOnlinePlayers(); - String refresh = "-"; + String refresh = FormatUtils.formatTimeStampClock(System.currentTimeMillis()); Server server = ServerInfo.getServer(); @@ -141,7 +142,7 @@ public class HtmlStructure { "

Type " + "" + serverType + "

" + "
" + - "

Last Refresh" + + "

Last Updated" + "" + refresh + "

" + "
" + "
@@ -633,12 +639,143 @@ + + ${pluginsTabs}
-
diff --git a/Plan/src/main/resources/web/server.html b/Plan/src/main/resources/web/server.html index c7b80fb5b..3a8d3b082 100644 --- a/Plan/src/main/resources/web/server.html +++ b/Plan/src/main/resources/web/server.html @@ -423,7 +423,7 @@ ${mobKillCount}
  • - Deaths + Deaths ${deaths}