From 2ca7d139fe2d73d9b0c88bee1cdd4a652e199ae1 Mon Sep 17 00:00:00 2001 From: GJ Date: Mon, 22 Apr 2013 23:19:26 -0400 Subject: [PATCH] Fix NPEs relating combat checks and world changing. Fixes #976, #979 --- .../java/com/gmail/nossr50/listeners/PlayerListener.java | 4 ++++ .../nossr50/runnables/commands/MctopCommandAsyncTask.java | 1 - .../java/com/gmail/nossr50/util/skills/CombatUtils.java | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 99dd790ca..630396691 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -128,6 +128,10 @@ public class PlayerListener implements Listener { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + if (mcMMOPlayer == null) { + return; + } + if (mcMMOPlayer.getGodMode() && !Permissions.mcgod(player)) { mcMMOPlayer.toggleGodMode(); player.sendMessage(LocaleLoader.getString("Commands.GodMode.Forbidden")); diff --git a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java index 3865896a1..3a79b05a8 100644 --- a/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/commands/MctopCommandAsyncTask.java @@ -29,5 +29,4 @@ public class MctopCommandAsyncTask extends BukkitRunnable { new MctopCommandDisplayTask(userslist, page, tablePrefix, sender).runTaskLater(mcMMO.p, 1); } - } diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 4efee054d..a17ad15c7 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -266,7 +266,7 @@ public final class CombatUtils { if (target instanceof Player) { Player player = (Player) target; - if (Misc.isNPCEntity(player)) { + if (Misc.isNPCEntity(player) || !player.isOnline()) { return; } @@ -291,6 +291,11 @@ public final class CombatUtils { } else if (attacker instanceof Player) { Player player = (Player) attacker; + + if (Misc.isNPCEntity(player)) { + return; + } + PlayerProfile profile = UserManager.getPlayer(player).getProfile(); if (Permissions.mobHealthDisplay(player) && profile.getMobHealthbarType() != MobHealthbarType.DISABLED) {