diff --git a/Plan/.idea/sonarIssues.xml b/Plan/.idea/sonarIssues.xml index a1e0211b4..06d0c3f39 100644 --- a/Plan/.idea/sonarIssues.xml +++ b/Plan/.idea/sonarIssues.xml @@ -78,6 +78,11 @@ + + + + + @@ -103,6 +108,11 @@ + + + + + @@ -283,6 +293,11 @@ + + + + + diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java index a5319bce8..28bd57410 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/DataCacheHandler.java @@ -265,7 +265,7 @@ public class DataCacheHandler extends SessionCache { UUID uuid = p.getUuid(); endSession(uuid); String worldName = ((Player) p.getWrappedPlayerClass()).getWorld().getName(); - toProcess.add(new LogoutInfo(uuid, time, p.isBanned(), p.getGamemode(), getSession(uuid), worldName)); + toProcess.add(new LogoutInfo(uuid, time, p.isBanned(), p.getGamemode().name(), getSession(uuid), worldName)); } Log.debug("ToProcess size_AFTER: " + toProcess.size() + " DataCache size: " + dataCache.keySet().size()); toProcess.sort(new HandlingInfoTimeComparator()); @@ -388,7 +388,7 @@ public class DataCacheHandler extends SessionCache { long time = MiscUtils.getTime(); UUID uuid = p.getUuid(); String worldName = ((Player) p.getWrappedPlayerClass()).getWorld().getName(); - ReloadInfo info = new ReloadInfo(uuid, time, p.getAddress().getAddress(), p.isBanned(), p.getDisplayName(), p.getGamemode(), worldName); + ReloadInfo info = new ReloadInfo(uuid, time, p.getAddress().getAddress(), p.isBanned(), p.getDisplayName(), p.getGamemode().name(), worldName); if (!pool) { UserData data = dataCache.get(uuid); if (data != null) { diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/GamemodeHandling.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/GamemodeHandling.java deleted file mode 100644 index 5c816bc10..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/GamemodeHandling.java +++ /dev/null @@ -1,45 +0,0 @@ -package main.java.com.djrapitops.plan.data.handling; - -import com.djrapitops.plugin.utilities.player.Gamemode; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.time.GMTimes; - -/** - * Class containing static methods for processing information contained in a - * GamemodeChangeEvent. - * - * @author Rsl1122 - * @since 3.0.0 - */ -public class GamemodeHandling { - - /** - * Utility Class, hides constructor. - */ - private GamemodeHandling() { - throw new IllegalStateException("Utility Class."); - } - - /** - * Processes the information of the Event and changes UserData object - * accordingly. - * - * @param data UserData of the player. - * @param time Epoch ms the event occurred. - * @param newGM The Gamemode the player changed to. - */ - public static void processGamemodeInfo(UserData data, long time, Gamemode newGM) { - if (newGM == null) { - return; - } - final String newGamemode = newGM.name(); - - long diff = time - data.getLastPlayed(); - long playTime = data.getPlayTime() + diff; - data.setPlayTime(playTime); - data.setLastPlayed(time); - - GMTimes gmTimes = data.getGmTimes(); - gmTimes.changeState(newGamemode, playTime); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/PlaytimeHandling.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/PlaytimeHandling.java new file mode 100644 index 000000000..3a7e301d2 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/PlaytimeHandling.java @@ -0,0 +1,25 @@ +package main.java.com.djrapitops.plan.data.handling; + +import main.java.com.djrapitops.plan.data.UserData; +import main.java.com.djrapitops.plan.data.time.GMTimes; +import main.java.com.djrapitops.plan.data.time.WorldTimes; + +public class PlaytimeHandling { + + public static void processPlaytimeDependentInfo(UserData data, long time, String gamemode, String worldName) { + long diff = time - data.getLastPlayed(); + long playTime = data.getPlayTime() + diff; + data.setPlayTime(playTime); + data.setLastPlayed(time); + + GMTimes gmTimes = data.getGmTimes(); + if (gamemode != null) { + gmTimes.changeState(gamemode, playTime); + } else { + gmTimes.changeState(gmTimes.getState(), playTime); + } + + WorldTimes worldTimes = data.getWorldTimes(); + worldTimes.changeState(worldName, playTime); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/WorldTimeHandling.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/WorldTimeHandling.java deleted file mode 100644 index f40add258..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/WorldTimeHandling.java +++ /dev/null @@ -1,42 +0,0 @@ -package main.java.com.djrapitops.plan.data.handling; - -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.time.WorldTimes; - -/** - * Class for processing World Time related changes. - * - * @author Rsl1122 - * @since 3.6.0 - */ -public class WorldTimeHandling { - - /** - * Utility Class, hides constructor. - */ - private WorldTimeHandling() { - throw new IllegalStateException("Utility Class."); - } - - /** - * Processes the information of the Event and changes UserData object - * accordingly. - * - * @param data UserData of the player. - * @param time Epoch ms the event occurred. - * @param worldName The World the player changed to. - */ - public static void processWorldChangeInfo(UserData data, long time, String worldName) { - if (worldName == null) { - return; - } - - long diff = time - data.getLastPlayed(); - long playTime = data.getPlayTime() + diff; - data.setPlayTime(playTime); - data.setLastPlayed(time); - - WorldTimes worldTimes = data.getWorldTimes(); - worldTimes.changeState(worldName, playTime); - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfo.java deleted file mode 100644 index 44f85af70..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfo.java +++ /dev/null @@ -1,42 +0,0 @@ -package main.java.com.djrapitops.plan.data.handling.info; - -import com.djrapitops.plugin.utilities.player.Gamemode; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.handling.GamemodeHandling; - -import java.util.UUID; - -/** - * HandlingInfo Class for GamemodeChangeEvent information. - * - * @author Rsl1122 - * @since 3.0.0 - */ -public class GamemodeInfo extends HandlingInfo { - - private final Gamemode currentGamemode; - - /** - * Constructor. - * - * @param uuid UUID of the player. - * @param time Epoch ms of the event. - * @param gm Gamemode the player changed to. - */ - public GamemodeInfo(UUID uuid, long time, Gamemode gm) { - super(uuid, InfoType.GM, time); - currentGamemode = gm; - } - - @Override - public boolean process(UserData uData) { - if (currentGamemode == null) { - return false; - } - if (!uData.getUuid().equals(uuid)) { - return false; - } - GamemodeHandling.processGamemodeInfo(uData, time, currentGamemode); - return true; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LoginInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LoginInfo.java index 3d379bc76..954b2cc6f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LoginInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LoginInfo.java @@ -1,6 +1,5 @@ package main.java.com.djrapitops.plan.data.handling.info; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.data.handling.LoginHandling; @@ -18,8 +17,7 @@ public class LoginInfo extends HandlingInfo { private final InetAddress ip; private final boolean banned; private final String nickname; - private final GamemodeInfo gmInfo; - private final WorldInfo worldInfo; + private final PlaytimeDependentInfo playtimeDependentInfo; private final int loginTimes; /** @@ -33,19 +31,18 @@ public class LoginInfo extends HandlingInfo { * @param gm current gamemode of the player * @param loginTimes number the loginTimes should be incremented with. */ - public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, Gamemode gm, int loginTimes, String worldName) { + public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, String gm, int loginTimes, String worldName) { super(uuid, InfoType.LOGIN, time); this.ip = ip; this.banned = banned; this.nickname = nickname; - this.gmInfo = new GamemodeInfo(uuid, time, gm); - worldInfo = new WorldInfo(uuid, time, worldName); + this.playtimeDependentInfo = new PlaytimeDependentInfo(uuid, InfoType.OTHER, time, gm, worldName); this.loginTimes = loginTimes; } /** * Constructor for not incrementing the loginTimes. - * + *

* This constructor is used only by ReloadInfo * * @param uuid UUID of the player. @@ -55,13 +52,12 @@ public class LoginInfo extends HandlingInfo { * @param nickname Nickname of the player * @param gm current gamemode of the player */ - public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, Gamemode gm, String worldName) { + public LoginInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, String gm, String worldName) { super(uuid, InfoType.RELOAD, time); this.ip = ip; this.banned = banned; this.nickname = nickname; - this.gmInfo = new GamemodeInfo(uuid, time, gm); - worldInfo = new WorldInfo(uuid, time, worldName); + this.playtimeDependentInfo = new PlaytimeDependentInfo(uuid, InfoType.OTHER, time, gm, worldName); this.loginTimes = 0; } @@ -71,8 +67,7 @@ public class LoginInfo extends HandlingInfo { return false; } LoginHandling.processLoginInfo(uData, time, ip, banned, nickname, loginTimes); - gmInfo.process(uData); - worldInfo.process(uData); + playtimeDependentInfo.process(uData); return true; } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LogoutInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LogoutInfo.java index f7545c212..c591190b3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LogoutInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/LogoutInfo.java @@ -1,6 +1,5 @@ package main.java.com.djrapitops.plan.data.handling.info; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.data.handling.LogoutHandling; @@ -17,8 +16,7 @@ public class LogoutInfo extends HandlingInfo { private final boolean banned; private final SessionData sData; - private final GamemodeInfo gmInfo; - private final WorldInfo worldInfo; + private final PlaytimeDependentInfo playtimeDependentInfo; /** * Constructor. @@ -30,12 +28,11 @@ public class LogoutInfo extends HandlingInfo { * @param sData session that has been ended at the moment of the logout * event. */ - public LogoutInfo(UUID uuid, long time, boolean banned, Gamemode gm, SessionData sData, String worldName) { + public LogoutInfo(UUID uuid, long time, boolean banned, String gm, SessionData sData, String worldName) { super(uuid, InfoType.LOGOUT, time); this.banned = banned; this.sData = sData; - this.gmInfo = new GamemodeInfo(uuid, time, gm); - worldInfo = new WorldInfo(uuid, time, worldName); + this.playtimeDependentInfo = new PlaytimeDependentInfo(uuid, InfoType.OTHER, time, gm, worldName); } @Override @@ -45,8 +42,7 @@ public class LogoutInfo extends HandlingInfo { } uData.addSession(sData); LogoutHandling.processLogoutInfo(uData, time, banned); - gmInfo.process(uData); - worldInfo.process(uData); + playtimeDependentInfo.process(uData); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/PlaytimeDependentInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/PlaytimeDependentInfo.java new file mode 100644 index 000000000..757c4e88f --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/PlaytimeDependentInfo.java @@ -0,0 +1,27 @@ +package main.java.com.djrapitops.plan.data.handling.info; + +import main.java.com.djrapitops.plan.data.UserData; +import main.java.com.djrapitops.plan.data.handling.PlaytimeHandling; + +import java.util.UUID; + +public class PlaytimeDependentInfo extends HandlingInfo { + + private final String gamemode; + private final String worldName; + + public PlaytimeDependentInfo(UUID uuid, InfoType type, long time, String gm, String worldName) { + super(uuid, type, time); + this.worldName = worldName; + this.gamemode = gm; + } + + @Override + public boolean process(UserData uData) { + if (!uuid.equals(uData.getUuid())) { + return false; + } + PlaytimeHandling.processPlaytimeDependentInfo(uData, time, gamemode, worldName); + return true; + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/ReloadInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/ReloadInfo.java index e9c8fed67..3b289fd08 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/ReloadInfo.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/ReloadInfo.java @@ -1,7 +1,5 @@ package main.java.com.djrapitops.plan.data.handling.info; -import com.djrapitops.plugin.utilities.player.Gamemode; - import java.net.InetAddress; import java.util.UUID; @@ -23,7 +21,7 @@ public class ReloadInfo extends LoginInfo { * @param nickname Nickname of the player * @param gm current gamemode of the player */ - public ReloadInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, Gamemode gm, String worldName) { + public ReloadInfo(UUID uuid, long time, InetAddress ip, boolean banned, String nickname, String gm, String worldName) { super(uuid, time, ip, banned, nickname, gm, worldName); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/WorldInfo.java b/Plan/src/main/java/com/djrapitops/plan/data/handling/info/WorldInfo.java deleted file mode 100644 index 43405a9cd..000000000 --- a/Plan/src/main/java/com/djrapitops/plan/data/handling/info/WorldInfo.java +++ /dev/null @@ -1,38 +0,0 @@ -package main.java.com.djrapitops.plan.data.handling.info; - -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.handling.WorldTimeHandling; - -import java.util.UUID; - -/** - * HandlingInfo Class for PlayerChangedWorldEvent information. - * - * @author Rsl1122 - * @since 3.6.0 - */ -public class WorldInfo extends HandlingInfo { - - private final String currentWorld; - - /** - * Constructor. - * - * @param uuid UUID of the player related to the info. - * @param time Time the event occurred - * @param currentWorld World the player is currently in. - */ - public WorldInfo(UUID uuid, long time, String currentWorld) { - super(uuid, InfoType.WORLD, time); - this.currentWorld = currentWorld; - } - - @Override - public boolean process(UserData uData) { - if (!uData.getUuid().equals(uuid)) { - return false; - } - WorldTimeHandling.processWorldChangeInfo(uData, time, currentWorld); - return true; - } -} diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java index 331ae1042..4a21103e5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanGamemodeChangeListener.java @@ -1,10 +1,9 @@ package main.java.com.djrapitops.plan.data.listeners; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; -import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo; -import main.java.com.djrapitops.plan.data.handling.info.WorldInfo; +import main.java.com.djrapitops.plan.data.handling.info.InfoType; +import main.java.com.djrapitops.plan.data.handling.info.PlaytimeDependentInfo; import main.java.com.djrapitops.plan.utilities.MiscUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -46,7 +45,6 @@ public class PlanGamemodeChangeListener implements Listener { Player p = event.getPlayer(); UUID uuid = p.getUniqueId(); long time = MiscUtils.getTime(); - handler.addToPool(new GamemodeInfo(uuid, time, Gamemode.wrap(event.getNewGameMode()))); - handler.addToPool(new WorldInfo(uuid, time, p.getWorld().getName())); + handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.GM, time, event.getNewGameMode().name(), p.getWorld().getName())); } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java index c5c8669fd..e57d54790 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanPlayerListener.java @@ -74,7 +74,7 @@ public class PlanPlayerListener implements Listener { InetAddress ip = player.getAddress().getAddress(); boolean banned = player.isBanned(); String displayName = player.getDisplayName(); - Gamemode gm = Gamemode.wrap(player.getGameMode()); + String gm = player.getGameMode().name(); String worldName = player.getWorld().getName(); LoginInfo loginInfo = new LoginInfo(uuid, time, ip, banned, displayName, gm, 1, worldName); @@ -114,7 +114,7 @@ public class PlanPlayerListener implements Listener { Gamemode gm = Gamemode.wrap(player.getGameMode()); String worldName = player.getWorld().getName(); - handler.addToPool(new LogoutInfo(uuid, time, banned, gm, handler.getSession(uuid), worldName)); + handler.addToPool(new LogoutInfo(uuid, time, banned, gm.name(), handler.getSession(uuid), worldName)); handler.saveCachedData(uuid); Log.debug(uuid + ": PlayerQuitEvent_END"); } @@ -140,7 +140,7 @@ public class PlanPlayerListener implements Listener { Gamemode gm = Gamemode.wrap(player.getGameMode()); String worldName = player.getWorld().getName(); - handler.addToPool(new LogoutInfo(uuid, time, banned, gm, handler.getSession(uuid), worldName)); + handler.addToPool(new LogoutInfo(uuid, time, banned, gm.name(), handler.getSession(uuid), worldName)); handler.addToPool(new KickInfo(uuid)); handler.saveCachedData(uuid); Log.debug(uuid + ": PlayerKickEvent_END"); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanWorldChangeListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanWorldChangeListener.java index 3c0326a24..d3903c9ce 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanWorldChangeListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanWorldChangeListener.java @@ -1,10 +1,9 @@ package main.java.com.djrapitops.plan.data.listeners; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.cache.DataCacheHandler; -import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo; -import main.java.com.djrapitops.plan.data.handling.info.WorldInfo; +import main.java.com.djrapitops.plan.data.handling.info.InfoType; +import main.java.com.djrapitops.plan.data.handling.info.PlaytimeDependentInfo; import main.java.com.djrapitops.plan.utilities.MiscUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -31,7 +30,6 @@ public class PlanWorldChangeListener implements Listener { } UUID uuid = p.getUniqueId(); long time = MiscUtils.getTime(); - handler.addToPool(new GamemodeInfo(uuid, time, Gamemode.wrap(p.getGameMode()))); - handler.addToPool(new WorldInfo(uuid, time, worldName)); + handler.addToPool(new PlaytimeDependentInfo(uuid, InfoType.GM, time, p.getGameMode().name(), p.getWorld().getName())); } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/GamemodeHandlingTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/GamemodeHandlingTest.java deleted file mode 100644 index d33b17b27..000000000 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/GamemodeHandlingTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package test.java.main.java.com.djrapitops.plan.data.handling; - -import com.djrapitops.plugin.utilities.player.Gamemode; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.handling.GamemodeHandling; -import main.java.com.djrapitops.plan.data.time.GMTimes; -import org.junit.Before; -import org.junit.Test; -import test.java.utils.MockUtils; - -import static org.junit.Assert.assertTrue; - -/** - * @author Rsl1122 - */ -public class GamemodeHandlingTest { - - /** - * - */ - public GamemodeHandlingTest() { - } - - /** - * - */ - @Before - public void setUp() throws Exception { - } - - /** - * - */ - @Test - public void testProcessGamemodeInfo() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes("CREATIVE", 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeHandling.processGamemodeInfo(data, time, Gamemode.SURVIVAL); - Long result = data.getGmTimes().getTime("CREATIVE"); - assertTrue("Gamemode time was " + result, result == 1050L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 1100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 2000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Survival", lastGM.equals("SURVIVAL")); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 1100L); - } - - /** - * - */ - @Test - public void testProcessGamemodeInfoSameGM() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes("SURVIVAL", 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeHandling.processGamemodeInfo(data, time, Gamemode.SURVIVAL); - Long result = data.getGmTimes().getTime("SURVIVAL"); - assertTrue("Gamemode time was " + result, result == 1050L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 1100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 2000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Survival", "SURVIVAL".equals(lastGM)); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 1100L); - } - - /** - * - */ - @Test - public void testProcessGamemodeInfoNullNewGM() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes("SURVIVAL", 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeHandling.processGamemodeInfo(data, time, null); - Long result = data.getGmTimes().getTime("SURVIVAL"); - assertTrue("Gamemode time was " + result, result == 0L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 1000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Survival", "SURVIVAL".equals(lastGM)); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 50L); - } - - /** - * - */ - @Test - public void testProcessGamemodeInfoNullOldGM() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes(null, 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeHandling.processGamemodeInfo(data, time, Gamemode.SURVIVAL); - Long result = data.getGmTimes().getTime(Gamemode.SURVIVAL.name()); - assertTrue("Gamemode time was " + result, result == 1050L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 1100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 2000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Survival", "SURVIVAL".equals(lastGM)); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 1100L); - } -} diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfoTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfoTest.java deleted file mode 100644 index ef240b6e5..000000000 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/GamemodeInfoTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package test.java.main.java.com.djrapitops.plan.data.handling.info; - -import com.djrapitops.plugin.utilities.player.Gamemode; -import main.java.com.djrapitops.plan.data.UserData; -import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo; -import main.java.com.djrapitops.plan.data.time.GMTimes; -import org.junit.Before; -import org.junit.Test; -import test.java.utils.MockUtils; - -import static org.junit.Assert.assertTrue; - -/** - * @author Rsl1122 - */ -public class GamemodeInfoTest { - - /** - * - */ - public GamemodeInfoTest() { - } - - /** - * - */ - @Before - public void setUp() throws Exception { - } - - /** - * - */ - @Test - public void testProcess() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes("CREATIVE", 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeInfo i = new GamemodeInfo(data.getUuid(), time, Gamemode.SURVIVAL); - assertTrue(i.process(data)); - Long result = data.getGmTimes().getTime(Gamemode.CREATIVE.name()); - assertTrue("Gamemode time was " + result, result == 1050L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 1100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 2000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Survival", "SURVIVAL".equals(lastGM)); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 1100L); - } - - /** - * - */ - @Test - public void testProcessWrongUUID() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes("CREATIVE", 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeInfo i = new GamemodeInfo(null, time, Gamemode.SURVIVAL); - assertTrue(!i.process(data)); - Long result = data.getGmTimes().getTime(Gamemode.CREATIVE.name()); - assertTrue("Gamemode time was " + result, result == 0L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 1000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Creative", "CREATIVE".equals(lastGM)); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 50L); - } - - /** - * - */ - @Test - public void testProcessNullGM() { - UserData data = MockUtils.mockUser(); - data.setPlayTime(100L); - data.setGmTimes(new GMTimes("CREATIVE", 50L)); - data.setLastPlayed(1000L); - long time = 2000L; - GamemodeInfo i = new GamemodeInfo(data.getUuid(), time, null); - assertTrue(!i.process(data)); - Long result = data.getGmTimes().getTime(Gamemode.CREATIVE.name()); - assertTrue("Gamemode time was " + result, result == 0L); - result = data.getPlayTime(); - assertTrue("Playtime was" + result, result == 100L); - result = data.getLastPlayed(); - assertTrue("Last Played was" + result, result == 1000L); - String lastGM = data.getLastGamemode(); - assertTrue("Last gm not Creative", "CREATIVE".equals(lastGM)); - result = data.getLastGmSwapTime(); - assertTrue("Last swaptime was " + result, result == 50L); - } - -} diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java index b2a86926f..3daccf064 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LoginInfoTest.java @@ -5,7 +5,6 @@ */ package test.java.main.java.com.djrapitops.plan.data.handling.info; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.data.handling.info.LoginInfo; import org.bukkit.plugin.java.JavaPlugin; @@ -54,7 +53,7 @@ public class LoginInfoTest { long time = 10L; int loginTimes = data.getLoginTimes(); String nick = "TestProcessLoginInfo"; - LoginInfo i = new LoginInfo(data.getUuid(), time, ip, true, nick, Gamemode.CREATIVE, 1, "World"); + LoginInfo i = new LoginInfo(data.getUuid(), time, ip, true, nick, "CREATIVE", 1, "World"); assertTrue(i.process(data)); assertTrue("LastPlayed wrong: " + data.getLastPlayed(), data.getLastPlayed() == time); assertTrue("Ip not added", data.getIps().contains(ip)); @@ -77,7 +76,7 @@ public class LoginInfoTest { InetAddress ip = InetAddress.getByName("137.19.188.146"); long time = 10L; String nick = "TestProcessLoginInfo"; - LoginInfo i = new LoginInfo(null, time, ip, true, nick, Gamemode.CREATIVE, 1, "World"); + LoginInfo i = new LoginInfo(null, time, ip, true, nick, "CREATIVE", 1, "World"); assertTrue(!i.process(data)); } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java index 82c6769cf..bd83488cf 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/LogoutInfoTest.java @@ -5,7 +5,6 @@ */ package test.java.main.java.com.djrapitops.plan.data.handling.info; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.data.SessionData; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.data.handling.info.LogoutInfo; @@ -44,7 +43,7 @@ public class LogoutInfoTest { data.updateBanned(false); long time = 20L; data.getGmTimes().setState("SURVIVAL"); - LogoutInfo i = new LogoutInfo(data.getUuid(), time, true, Gamemode.CREATIVE, new SessionData(0, 1), "World"); + LogoutInfo i = new LogoutInfo(data.getUuid(), time, true, "CREATIVE", new SessionData(0, 1), "World"); assertTrue(i.process(data)); assertTrue("Last Played wrong", data.getLastPlayed() == 20L); assertTrue("Playtime wrong", data.getPlayTime() == 10L); @@ -64,7 +63,7 @@ public class LogoutInfoTest { data.updateBanned(false); long time = 20L; Exception ex = null; - LogoutInfo i = new LogoutInfo(null, time, true, Gamemode.CREATIVE, new SessionData(0, 1), "World"); + LogoutInfo i = new LogoutInfo(null, time, true, "CREATIVE", new SessionData(0, 1), "World"); assertTrue(!i.process(data)); } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java index 2c1f978bf..3dae0caf0 100644 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java +++ b/Plan/src/test/java/main/java/com/djrapitops/plan/data/handling/info/ReloadInfoTest.java @@ -5,7 +5,6 @@ */ package test.java.main.java.com.djrapitops.plan.data.handling.info; -import com.djrapitops.plugin.utilities.player.Gamemode; import main.java.com.djrapitops.plan.data.UserData; import main.java.com.djrapitops.plan.data.handling.info.ReloadInfo; import main.java.com.djrapitops.plan.utilities.MiscUtils; @@ -55,7 +54,7 @@ public class ReloadInfoTest { long time = MiscUtils.getTime(); int loginTimes = data.getLoginTimes(); String nick = "TestProcessLoginInfo"; - ReloadInfo i = new ReloadInfo(data.getUuid(), time, ip, true, nick, Gamemode.CREATIVE, "World"); + ReloadInfo i = new ReloadInfo(data.getUuid(), time, ip, true, nick, "CREATIVE", "World"); assertTrue(i.process(data)); assertTrue("LastPlayed wrong: " + data.getLastPlayed(), data.getLastPlayed() == time); assertTrue("Ip not added", data.getIps().contains(ip)); @@ -77,7 +76,7 @@ public class ReloadInfoTest { InetAddress ip = InetAddress.getByName("137.19.188.146"); long time = 10L; String nick = "TestProcessLoginInfo"; - ReloadInfo i = new ReloadInfo(null, time, ip, true, nick, Gamemode.CREATIVE, "World"); + ReloadInfo i = new ReloadInfo(null, time, ip, true, nick, "CREATIVE", "World"); assertTrue(!i.process(data)); } } diff --git a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/HandlingInfoTimeComparatorTest.java b/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/HandlingInfoTimeComparatorTest.java deleted file mode 100644 index 5d0f10cd7..000000000 --- a/Plan/src/test/java/main/java/com/djrapitops/plan/utilities/comparators/HandlingInfoTimeComparatorTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package test.java.main.java.com.djrapitops.plan.utilities.comparators; - -import com.djrapitops.plugin.utilities.player.Gamemode; -import main.java.com.djrapitops.plan.data.handling.info.GamemodeInfo; -import main.java.com.djrapitops.plan.data.handling.info.HandlingInfo; -import main.java.com.djrapitops.plan.utilities.comparators.HandlingInfoTimeComparator; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * @author Rsl1122 - */ -public class HandlingInfoTimeComparatorTest { - - /** - * - */ - public HandlingInfoTimeComparatorTest() { - } - - /** - * - */ - @Test - public void testCompare() { - List i = new ArrayList<>(); - GamemodeInfo one = new GamemodeInfo(null, 500L, Gamemode.CREATIVE); - i.add(one); - GamemodeInfo two = new GamemodeInfo(null, 400L, Gamemode.CREATIVE); - i.add(two); - GamemodeInfo three = new GamemodeInfo(null, 100L, Gamemode.CREATIVE); - i.add(three); - GamemodeInfo four = new GamemodeInfo(null, 700L, Gamemode.CREATIVE); - i.add(four); - i.sort(new HandlingInfoTimeComparator()); - assertEquals(three, i.get(0)); - assertEquals(two, i.get(1)); - assertEquals(one, i.get(2)); - assertEquals(four, i.get(3)); - - } - -}