Fixed the NPE on Spigot builds pointed out in #2417.
This commit is contained in:
QuarkTheAwesome 2015-01-21 09:18:58 +11:00
parent 385fe1bb05
commit 38bd37e4fa

View File

@ -370,25 +370,34 @@ public class ScoreboardManager {
*/ */
public static Objective getPowerLevelObjective() { public static Objective getPowerLevelObjective() {
if (!Config.getInstance().getPowerLevelTagsEnabled()) { if (!Config.getInstance().getPowerLevelTagsEnabled()) {
try {
Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); Objective objective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if (objective != null) { if (objective != null) {
objective.unregister(); objective.unregister();
mcMMO.p.debug("Removed leftover scoreboard objects from Power Level Tags."); mcMMO.p.debug("Removed leftover scoreboard objects from Power Level Tags.");
} }
} catch (NullPointerException e) {
//It's already null
}
return null; return null;
} }
try {
Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE); Objective powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().getObjective(POWER_OBJECTIVE);
if (powerObjective == null) { if (powerObjective == null) {
powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy"); powerObjective = mcMMO.p.getServer().getScoreboardManager().getMainScoreboard().registerNewObjective(POWER_OBJECTIVE, "dummy");
powerObjective.setDisplayName(TAG_POWER_LEVEL); powerObjective.setDisplayName(TAG_POWER_LEVEL);
powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME); powerObjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
} }
return powerObjective; 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;
}
} }
private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) { private static void changeScoreboard(ScoreboardWrapper wrapper, int displayTime) {