From 38bd37e4fa53f453431d289bc84b89a21264a6bd Mon Sep 17 00:00:00 2001 From: QuarkTheAwesome Date: Wed, 21 Jan 2015 09:18:58 +1100 Subject: [PATCH] Fix issue #2417 Fixed the NPE on Spigot builds pointed out in #2417. --- .../util/scoreboards/ScoreboardManager.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java index e5a9cfa3f..4412b703f 100644 --- a/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java +++ b/src/main/java/com/gmail/nossr50/util/scoreboards/ScoreboardManager.java @@ -370,25 +370,34 @@ public class ScoreboardManager { */ public static Objective getPowerLevelObjective() { if (!Config.getInstance().getPowerLevelTagsEnabled()) { - Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); - - if (objective != null) { - objective.unregister(); - mcMMO.p.debug("Removed leftover scoreboard objects from Power Level Tags."); - } - + try { + Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); + if (objective != null) { + objective.unregister(); + mcMMO.p.debug("Removed leftover scoreboard objects from Power Level Tags."); + } + } catch (NullPointerException e) { + //It's already null + } + return null; } - - Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); - - if (powerObjective == null) { - powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy"); - powerObjective.setDisplayName(TAG_POWER_LEVEL); - powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME); + try { + Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); + if (powerObjective == null) { + powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy"); + powerObjective.setDisplayName(TAG_POWER_LEVEL); + powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME); + } + return powerObjective; + } catch (NullPointerException e) { + Objective powerObjective; + powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy"); + powerObjective.setDisplayName(TAG_POWER_LEVEL); + powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME); + return powerObjective; } - - return powerObjective; + } private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) {