Cleaned up some session related stuff while attempting to find a bug

This commit is contained in:
Rsl1122 2018-01-24 12:35:00 +02:00
parent 4d76671bc8
commit 097958c416
6 changed files with 15 additions and 35 deletions

View File

@ -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);

View File

@ -80,15 +80,11 @@ public class PlayerProfile implements OfflinePlayer {
}
public static long getPlaytime(Stream<Session> s) {
return s.map(Session::getLength)
.mapToLong(i -> i)
.sum();
return s.mapToLong(Session::getLength).sum();
}
public static long getLongestSession(Stream<Session> s) {
OptionalLong longestSession = s.map(Session::getLength)
.mapToLong(i -> i)
.max();
OptionalLong longestSession = s.mapToLong(Session::getLength).max();
if (longestSession.isPresent()) {
return longestSession.getAsLong();
}

View File

@ -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.
* <p>

View File

@ -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<Session> sessionsWeek = player.getSessions(weekAgo, date).collect(Collectors.toList());
List<Session> sessionsWeek2 = player.getSessions(twoWeeksAgo, weekAgo).collect(Collectors.toList());

View File

@ -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,

View File

@ -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<String> names = new ArrayList<>(db.fetch().getPlayerNames().values());
@ -101,8 +100,8 @@ public class PlayersPageResponse extends Response {
List<Session> 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);