From 1ecffe18959432c0842228cfcbf3606bb0a9163b Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 8 Jan 2020 17:51:40 +0100 Subject: [PATCH] Fixed NPE when loading the chunks from database - Fixed NPE when getting the quests and null - Removed some deprecated methods --- .../jobs/CMILib/VersionChecker.java | 1 - src/main/java/com/gamingmesh/jobs/Jobs.java | 45 +------------------ .../com/gamingmesh/jobs/PlayerManager.java | 5 +-- .../gamingmesh/jobs/config/ConfigManager.java | 4 +- .../jobs/container/ExploreChunk.java | 15 ++++--- .../jobs/container/QuestProgression.java | 2 +- .../jobs/listeners/JobsPaymentListener.java | 3 ++ .../java/com/gamingmesh/jobs/stuff/Util.java | 1 - 8 files changed, 18 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java b/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java index 9f21fd96..be2cd1b3 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/VersionChecker.java @@ -12,7 +12,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.stuff.Debug; public class VersionChecker { private Jobs plugin; diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 47972053..036b9e40 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -113,19 +113,8 @@ public class Jobs extends JavaPlugin { private static Job noneJob = null; private static WeakHashMap usedSlots = new WeakHashMap<>(); private static HashMap jobsIds = new HashMap<>(); - /** - * Gets the actionbar toggle map - * @deprecated Moved to {@link ToggleBarHandling} - */ - @Deprecated - public static WeakHashMap actionbartoggle = new WeakHashMap<>(); - /** - * Gets the bossbar toggle map - * @deprecated Moved to {@link ToggleBarHandling} - */ - @Deprecated - public static WeakHashMap BossBartoggle = new WeakHashMap<>(); // public static WeakHashMap GlobalBoost = new WeakHashMap(); + private static BufferedEconomy economy = null; private static PermissionHandler permissionHandler = null; private static PermissionManager permissionManager = null; @@ -158,19 +147,6 @@ public class Jobs extends JavaPlugin { } } - /** - * Gets the {@link #McMMOManager} file - * - * @return McMMO Manager - * @deprecated Use instead {@link #getMcMMOManager()} - */ - @Deprecated - public static McMMOManager getMcMMOlistener() { - if (McMMOManager == null) - McMMOManager = new McMMOManager(); - return McMMOManager; - } - public static McMMOManager getMcMMOManager() { if (McMMOManager == null) McMMOManager = new McMMOManager(); @@ -390,24 +366,6 @@ public class Jobs extends JavaPlugin { return BBManager; } - /** - * Gets the actionbar toggle map - * @deprecated Moved to {@link ToggleBarHandling} - */ - @Deprecated - public static WeakHashMap getActionbarToggleList() { - return actionbartoggle; - } - - /** - * Gets the bossbar toggle map - * @deprecated Moved to {@link ToggleBarHandling} - */ - @Deprecated - public static WeakHashMap getBossBarToggleList() { - return BossBartoggle; - } - /** * Returns schedule manager * @return the schedule manager @@ -984,6 +942,7 @@ public class Jobs extends JavaPlugin { e.printStackTrace(); } shutdown(); + instance = null; consoleMsg("&e[Jobs] &2Plugin has been disabled successfully."); setEnabled(false); } diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index df050b23..cfc4d148 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -857,9 +857,7 @@ public class PlayerManager { } public BoostMultiplier getItemBoostNBT(Player player, Job prog) { - - HashMap cj = cache == null ? new HashMap() : cache.get(player.getUniqueId()); - + HashMap cj = cache.get(player.getUniqueId()); if (cj == null) { cj = new HashMap<>(); cache.put(player.getUniqueId(), cj); @@ -925,7 +923,6 @@ public class PlayerManager { Object itemName = Reflections.getNbt(item, JobsItemBoost); if (itemName == null || itemName.toString().isEmpty()) { - // Checking old boost items and converting to new format if needed if (Jobs.getReflections().hasNbt(item, JobsItemBoost)) { for (Job one : Jobs.getJobs()) { diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index 0b132557..b7a3bb10 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -168,7 +168,6 @@ public class ConfigManager { cfg.addComment(pt + ".maxDailyQuests", "You can use the custom player head:", "Item: player_head", " CustomSkull: Notch", - "", "Defines maximum amount of daily quests player can have from THIS job", "This will not have effect on overall quest amount player will have"); @@ -204,7 +203,7 @@ public class ConfigManager { cfg.addComment(pt + ".Quests.1.fromLevel", "Defines from which level you want to give option to get this quest", "You can use both limitations to have limited quests for particular job level ranges"); cfg.get(pt + ".Quests.1.fromLevel", 3); - + cfg.addComment(pt + ".Quests.1.toLevel", "Defines to which job level you want to give out this quest.", "Keep in mind that player will keep quest even if he is over level limit if he got new one while being under", "In example: player with level 2 takes quests and levels up to level 5, he still can finish this quest and after next quest reset (check general config file)", @@ -213,7 +212,6 @@ public class ConfigManager { cfg.save(); - } public void reload() throws IOException { diff --git a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java index 71b4fe74..a55ee023 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java +++ b/src/main/java/com/gamingmesh/jobs/container/ExploreChunk.java @@ -17,8 +17,8 @@ public class ExploreChunk { private boolean updated = false; public ExploreChunk(int playerId, int x, int z) { - this.x = x; - this.z = z; + this(x, z); + this.playerIds.add(playerId); } @@ -70,14 +70,15 @@ public class ExploreChunk { } public Set getPlayers() { - return playerIds == null ? new HashSet<>() : playerIds; + return playerIds == null ? new HashSet() : playerIds; } public String serializeNames() { - String s = ""; if (playerIds == null) return null; - for (Integer one : this.playerIds) { + + String s = ""; + for (Integer one : playerIds) { if (!s.isEmpty()) s += ";"; s += one; @@ -92,6 +93,10 @@ public class ExploreChunk { return; } + if (playerIds == null) { + playerIds = new HashSet(); + } + List split = Arrays.asList(names.split(";")); for (String one : split) { try { diff --git a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java index 96298023..310b8d02 100644 --- a/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java +++ b/src/main/java/com/gamingmesh/jobs/container/QuestProgression.java @@ -21,7 +21,7 @@ public class QuestProgression { } public Quest getQuest() { - return quest.getJob().getQuest(quest.getConfigName()); + return quest == null ? null : quest.getJob().getQuest(quest.getConfigName()); } public void setQuest(Quest quest) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 802cffc1..0453f6a3 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -946,6 +946,7 @@ public class JobsPaymentListener implements Listener { if (event.getItem() == null || event.getItem().getType() == Material.AIR) return; + Block block = null; switch (type.toLowerCase()) { @@ -960,6 +961,8 @@ public class JobsPaymentListener implements Listener { // This should be done in this way to have backwards compatibility block = ((org.bukkit.block.BlastFurnace) event.getDestination().getHolder()).getBlock(); break; + default: + break; } if (block == null) diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 3fff998d..8b9b80a8 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -36,7 +36,6 @@ public class Util { private static HashMap jobsEditorMap = new HashMap<>(); private static HashMap questsEditorMap = new HashMap<>(); - @Deprecated public static List confirmLeave = new ArrayList<>(); public static List leaveConfirm = new ArrayList<>(); private static HashMap jobsWorlds = new HashMap<>();