diff --git a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java index 59cfc4b8c..07954423e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/ShutdownHook.java @@ -85,10 +85,9 @@ public class ShutdownHook extends Thread { UUID uuid = entry.getKey(); Session session = entry.getValue(); long sessionEnd = session.getSessionEnd(); - if (sessionEnd != -1) { - continue; + if (sessionEnd == -1) { + session.endSession(now); } - session.endSession(now); try { Log.debug("Shutdown: Saving a session: " + session.getSessionStart()); db.save().session(uuid, session); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java index e1bffd464..e6887b00a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java @@ -80,15 +80,11 @@ public class PlayerProfile implements OfflinePlayer { } public static long getPlaytime(Stream s) { - return s.map(Session::getLength) - .mapToLong(i -> i) - .sum(); + return s.mapToLong(Session::getLength).sum(); } public static long getLongestSession(Stream s) { - OptionalLong longestSession = s.map(Session::getLength) - .mapToLong(i -> i) - .max(); + OptionalLong longestSession = s.mapToLong(Session::getLength).max(); if (longestSession.isPresent()) { return longestSession.getAsLong(); } 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 8b265b705..fb5a21349 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 @@ -67,18 +67,6 @@ public class Session { this.deaths = deaths; } - /** - * Starts a new Session. - * - * @param time Time the session started. - * @param world World the session started in. - * @param gm GameMode the session started in. - * @return a new Session object. - */ - public static Session start(long time, String world, String gm) { - return new Session(time, world, gm); - } - /** * Ends the session with given end point. *

diff --git a/Plan/src/main/java/com/djrapitops/plan/data/element/ActivityIndex.java b/Plan/src/main/java/com/djrapitops/plan/data/element/ActivityIndex.java index bbd773da8..833ee8c2d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/element/ActivityIndex.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/element/ActivityIndex.java @@ -17,8 +17,12 @@ public class ActivityIndex { value = calculate(player, date); } - private static long loadSetting(long value) { - return value < 0 ? 1 : value; + private long loadSetting(long value) { + return value <= 0 ? 1 : value; + } + + private int loadSetting(int value) { + return value <= 0 ? 1 : value; } public static String[] getGroups() { @@ -31,14 +35,8 @@ public class ActivityIndex { long twoWeeksAgo = date - 2L * week; long threeWeeksAgo = date - 3L * week; - long activePlayThreshold = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms(); - if (activePlayThreshold <= 0) { - activePlayThreshold = 1; - } - int activeLoginThreshold = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber(); - if (activeLoginThreshold <= 0) { - activeLoginThreshold = 1; - } + long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms()); + int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber()); List sessionsWeek = player.getSessions(weekAgo, date).collect(Collectors.toList()); List sessionsWeek2 = player.getSessions(twoWeeksAgo, weekAgo).collect(Collectors.toList()); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index 712bdb8d2..ea7b134c4 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -94,7 +94,7 @@ public class PlayerOnlineListener implements Listener { int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline(); - SessionCache.getInstance().cacheSession(uuid, Session.start(time, world, gm)); + SessionCache.getInstance().cacheSession(uuid, new Session(time, world, gm)); Processor.queueMany( new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline, diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java index 3e9750a0a..e0e420dc5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/response/pages/PlayersPageResponse.java @@ -35,7 +35,6 @@ public class PlayersPageResponse extends Response { super.setHeader("HTTP/1.1 200 OK"); try { PlanSystem system = PlanSystem.getInstance(); - PlanPlugin plugin = PlanPlugin.getInstance(); Database db = system.getDatabaseSystem().getActiveDatabase(); List names = new ArrayList<>(db.fetch().getPlayerNames().values()); @@ -101,8 +100,8 @@ public class PlayersPageResponse extends Response { List sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>()); int sessionCount = sessions.size(); - long playtime = sessionCount != 0 ? sessions.stream().map(Session::getLength) - .mapToLong(p -> p) + long playtime = sessionCount != 0 ? sessions.stream() + .mapToLong(Session::getLength) .sum() : 0L; long registered = userInfo.getRegistered(); long lastSeen = lastSeenForAllPlayers.getOrDefault(uuid, 0L);