From 355074dffdb165437b5b9215ebe895d1edc74609 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 14 Aug 2019 14:09:32 +0200 Subject: [PATCH 1/2] We don't need the x, y, z methods, it can be get from location --- .../com/gamingmesh/jobs/Signs/SignUtil.java | 9 +++---- .../com/gamingmesh/jobs/Signs/jobsSign.java | 24 ------------------- .../com/gamingmesh/jobs/stuff/blockLoc.java | 24 ------------------- 3 files changed, 5 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index a2c2bdcf..4a0e004f 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -23,7 +23,6 @@ import com.gamingmesh.jobs.CMILib.VersionChecker.Version; import com.gamingmesh.jobs.config.CommentedYamlConfiguration; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.TopList; -import com.gamingmesh.jobs.stuff.Debug; public class SignUtil { @@ -99,9 +98,9 @@ public class SignUtil { jobsSign newTemp = new jobsSign(); if (NameSection.isString("World")) { newTemp.setWorldName(NameSection.getString("World")); - newTemp.setX((int) NameSection.getDouble("X")); - newTemp.setY((int) NameSection.getDouble("Y")); - newTemp.setZ((int) NameSection.getDouble("Z")); + newTemp.getLocation().setX((int) NameSection.getDouble("X")); + newTemp.getLocation().setY((int) NameSection.getDouble("Y")); + newTemp.getLocation().setZ((int) NameSection.getDouble("Z")); } else { newTemp.setLoc(NameSection.getString("Loc")); } @@ -228,6 +227,8 @@ public class SignUtil { temp.put(SignJobName, PlayerList); } break; + default: + break; } if (PlayerList.isEmpty()) diff --git a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java index a24a16c8..ca41295b 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/jobsSign.java @@ -44,30 +44,6 @@ public class jobsSign { return worldName; } - public void setX(int x) { - this.x = x; - } - - public double getX() { - return x; - } - - public void setY(int y) { - this.y = y; - } - - public double getY() { - return y; - } - - public void setZ(int z) { - this.z = z; - } - - public double getZ() { - return z; - } - public Location getLocation() { if (loc != null) return loc; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/blockLoc.java b/src/main/java/com/gamingmesh/jobs/stuff/blockLoc.java index cf81b8e0..7aa52005 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/blockLoc.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/blockLoc.java @@ -24,30 +24,6 @@ public class blockLoc { worldName = loc.getWorld().getName(); } - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public int getZ() { - return z; - } - - public void setZ(int z) { - this.z = z; - } - public String getWorldName() { return worldName; } From d1417cc35a4f3b5d52988ae0331ebe4f822803d6 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 14 Aug 2019 14:13:15 +0200 Subject: [PATCH 2/2] Some null checks in playerManager --- .../java/com/gamingmesh/jobs/PlayerManager.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index fda0cd5c..c1247804 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -104,24 +104,28 @@ public class PlayerManager { } public void addPlayerToCache(JobsPlayer jPlayer) { - if (jPlayer.getUserName() != null) + if (jPlayer.getUserName() != null && playersCache.get(jPlayer.getUserName().toLowerCase()) == null) playersCache.put(jPlayer.getUserName().toLowerCase(), jPlayer); - if (jPlayer.getPlayerUUID() != null) + if (jPlayer.getPlayerUUID() != null && playersUUIDCache.get(jPlayer.getPlayerUUID()) == null) playersUUIDCache.put(jPlayer.getPlayerUUID(), jPlayer); } public void addPlayer(JobsPlayer jPlayer) { - if (jPlayer.getUserName() != null) + if (jPlayer.getUserName() != null && players.get(jPlayer.getUserName().toLowerCase()) == null) players.put(jPlayer.getUserName().toLowerCase(), jPlayer); - if (jPlayer.getPlayerUUID() != null) + if (jPlayer.getPlayerUUID() != null && playersUUID.get(jPlayer.getPlayerUUID()) == null) playersUUID.put(jPlayer.getPlayerUUID(), jPlayer); } public JobsPlayer removePlayer(Player player) { if (player == null) return null; - players.remove(player.getName().toLowerCase()); - JobsPlayer jPlayer = playersUUID.remove(player.getUniqueId()); + + if (players.get(player.getName()) != null) + players.remove(player.getName().toLowerCase()); + + JobsPlayer jPlayer = playersUUID.get(player.getUniqueId()) != null ? + playersUUID.remove(player.getUniqueId()) : null; return jPlayer; } @@ -197,6 +201,7 @@ public class PlayerManager { JobsPlayer jPlayer = getJobsPlayer(player); if (jPlayer == null) return; + if (Jobs.getGCManager().saveOnDisconnect()) { jPlayer.onDisconnect(); jPlayer.save();