From 1456d78bd4cee1227328800796c9d51cae01fa7c Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 5 Aug 2018 22:02:52 +0300 Subject: [PATCH] Removed unnecessary use of getValue inside Session --- .../djrapitops/plan/data/container/GeoInfo.java | 6 +++--- .../plan/data/container/PlayerKill.java | 3 ++- .../djrapitops/plan/data/container/Session.java | 6 ------ .../com/djrapitops/plan/data/time/TimeKeeper.java | 15 +++++---------- .../com/djrapitops/plan/data/time/WorldTimes.java | 3 ++- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java index bff37d252..2ed38a28d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/GeoInfo.java @@ -10,7 +10,7 @@ import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.SHA256Hash; import com.google.common.base.Objects; -import java.io.UnsupportedEncodingException; +import java.io.Serializable; import java.net.InetAddress; import java.security.NoSuchAlgorithmException; @@ -19,7 +19,7 @@ import java.security.NoSuchAlgorithmException; * * @author Rsl1122 */ -public class GeoInfo implements DateHolder { +public class GeoInfo implements DateHolder, Serializable { private final String ip; private final String geolocation; @@ -27,7 +27,7 @@ public class GeoInfo implements DateHolder { private final long date; public GeoInfo(InetAddress address, String geolocation, long lastUsed) - throws UnsupportedEncodingException, NoSuchAlgorithmException { + throws NoSuchAlgorithmException { this(FormatUtils.formatIP(address), geolocation, lastUsed, new SHA256Hash(address.getHostAddress()).create()); } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java index f7e3067ff..7eece6d25 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/PlayerKill.java @@ -2,6 +2,7 @@ package com.djrapitops.plan.data.container; import com.djrapitops.plan.data.store.objects.DateHolder; +import java.io.Serializable; import java.util.Objects; import java.util.UUID; @@ -11,7 +12,7 @@ import java.util.UUID; * * @author Rsl1122 */ -public class PlayerKill implements DateHolder { +public class PlayerKill implements DateHolder, Serializable { private final UUID victim; private final long date; 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 a6ab9953a..77822cbc8 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 @@ -107,8 +107,6 @@ public class Session extends DataContainer implements DateHolder { */ public void endSession(long endOfSession) { putRawData(SessionKeys.END, endOfSession); - WorldTimes worldTimes = getValue(SessionKeys.WORLD_TIMES) - .orElseThrow(() -> new IllegalStateException("World times have not been defined")); worldTimes.updateState(endOfSession); } @@ -120,14 +118,10 @@ public class Session extends DataContainer implements DateHolder { * @param time Epoch ms of the event. */ public void changeState(String world, String gm, long time) { - WorldTimes worldTimes = getValue(SessionKeys.WORLD_TIMES) - .orElseThrow(() -> new IllegalStateException("World times is not defined")); worldTimes.updateState(world, gm, time); } public void playerKilled(PlayerKill kill) { - List playerKills = getValue(SessionKeys.PLAYER_KILLS) - .orElseThrow(() -> new IllegalStateException("Player kills is not defined.")); playerKills.add(kill); } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/time/TimeKeeper.java b/Plan/src/main/java/com/djrapitops/plan/data/time/TimeKeeper.java index 3a6b7583d..f2d608c72 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/time/TimeKeeper.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/time/TimeKeeper.java @@ -2,25 +2,20 @@ package com.djrapitops.plan.data.time; import com.djrapitops.plugin.utilities.Verify; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.Objects; /** * Abstract class for keeping track of time spent in each state. + * + * @author Rsl1122 */ -public abstract class TimeKeeper { - /** - * Keeps time of states. - */ +public abstract class TimeKeeper implements Serializable { + protected Map times; - /** - * Last State seen in - */ protected String state; - /** - * Relates to Playtime Milliseconds. - */ protected long lastStateChange; public TimeKeeper(Map times, String lastState, long lastStateChange) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java index 096387071..1fed088ed 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java @@ -1,5 +1,6 @@ package com.djrapitops.plan.data.time; +import java.io.Serializable; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -10,7 +11,7 @@ import java.util.Objects; * @author Rsl1122 * @since 4.0.0 */ -public class WorldTimes { +public class WorldTimes implements Serializable { private final Map worldTimes; private String currentWorld;