From aeaab43f444c7097c250d452b998b783f1e18be8 Mon Sep 17 00:00:00 2001 From: Glitchfinder Date: Sun, 4 Aug 2013 12:15:01 -0700 Subject: [PATCH] Fixing a multitude of reported NPEs. --- src/main/java/com/gmail/nossr50/api/PartyAPI.java | 9 ++++++++- .../com/gmail/nossr50/listeners/EntityListener.java | 4 ++++ .../com/gmail/nossr50/listeners/PlayerListener.java | 9 +++++++++ .../com/gmail/nossr50/util/skills/CombatUtils.java | 10 ++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/api/PartyAPI.java b/src/main/java/com/gmail/nossr50/api/PartyAPI.java index 9dc078b54..f73f9d622 100644 --- a/src/main/java/com/gmail/nossr50/api/PartyAPI.java +++ b/src/main/java/com/gmail/nossr50/api/PartyAPI.java @@ -9,6 +9,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.party.Party; +import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.player.UserManager; @@ -40,7 +41,13 @@ public final class PartyAPI { * @return true if the player is in a party, false otherwise */ public static boolean inParty(Player player) { - return UserManager.getPlayer(player).inParty(); + McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + + if (mcMMOPlayer == null) { + return false; + } + + return mcMMOPlayer.inParty(); } /** diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 8f6d11b1a..945e82880 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -215,6 +215,10 @@ public class EntityListener implements Listener { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + if (mcMMOPlayer == null) { + return; + } + /* Check for invincibility */ if (mcMMOPlayer.getGodMode()) { event.setCancelled(true); diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 2d90e58a6..e33d385c8 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -299,6 +299,11 @@ public class PlayerListener implements Listener { } McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + + if (mcMMOPlayer == null) { + return; + } + Item drop = event.getItem(); ItemStack dropStack = drop.getItemStack(); @@ -341,6 +346,10 @@ public class PlayerListener implements Listener { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + if (mcMMOPlayer == null) { + return; + } + mcMMOPlayer.resetAbilityMode(); BleedTimerTask.bleedOut(player); mcMMOPlayer.getProfile().save(); 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 77c747bff..103b37459 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -139,6 +139,11 @@ public final class CombatUtils { private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + + if (mcMMOPlayer == null) { + return; + } + ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager(); if (archeryManager.canSkillShot()) { @@ -312,6 +317,11 @@ public final class CombatUtils { Player player = (Player) target; McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); + + if (mcMMOPlayer == null) { + return; + } + AcrobaticsManager acrobaticsManager = mcMMOPlayer.getAcrobaticsManager(); if (acrobaticsManager.canDodge(damager)) {