Calculating server times from sessions is now possible

This commit is contained in:
Rsl1122 2017-11-20 16:44:04 +02:00
parent f618a2466e
commit 5577771231
3 changed files with 35 additions and 1 deletions

View File

@ -107,7 +107,7 @@ public class PlayerProfile implements OfflinePlayer {
UUID maxServer = null;
for (Map.Entry<UUID, WorldTimes> entry : getWorldTimesPerServer().entrySet()) {
long playTime = entry.getValue().getTotal();
if (playTime < max) {
if (playTime > max) {
max = playTime;
maxServer = entry.getKey();
}
@ -499,4 +499,23 @@ public class PlayerProfile implements OfflinePlayer {
public void setOp(boolean b) {
/* Do nothing */
}
public void calculateWorldTimesPerServer() {
if (worldTimesMap.containsKey(MiscUtils.getIPlan().getServerUuid())) {
return;
}
for (Map.Entry<UUID, List<Session>> entry : sessions.entrySet()) {
UUID serverUUID = entry.getKey();
List<Session> sessions = entry.getValue();
WorldTimes times = worldTimesMap.getOrDefault(serverUUID, new WorldTimes(new HashMap<>()));
for (Session session : sessions) {
WorldTimes worldTimes = session.getWorldTimes();
times.add(worldTimes);
}
worldTimesMap.put(serverUUID, times);
}
}
}

View File

@ -158,4 +158,18 @@ public class WorldTimes {
public String getCurrentWorld() {
return currentWorld;
}
public void add(WorldTimes toAdd) {
Map<String, GMTimes> times = toAdd.getWorldTimes();
for (Map.Entry<String, GMTimes> entry : times.entrySet()) {
String worldName = entry.getKey();
GMTimes gmTimes = entry.getValue();
GMTimes currentGMTimes = getGMTimes(worldName);
for (String gm : GMTimes.getGMKeyArray()) {
currentGMTimes.addTime(gm, gmTimes.getTime(gm));
}
worldTimes.put(worldName, currentGMTimes);
}
}
}

View File

@ -257,6 +257,7 @@ public abstract class SQLDB extends Database {
Map<UUID, List<Session>> sessions = sessionsTable.getSessions(uuid);
profile.setSessions(sessions);
profile.calculateWorldTimesPerServer();
profile.setTotalWorldTimes(worldTimesTable.getWorldTimesOfUser(uuid));
return profile;