From 686bcd5308ea076cb0dd06079e9c669d1288ef63 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 10 Jul 2012 14:02:48 -0400 Subject: [PATCH] Null check ALL the profiles. We should probably find a more elegant way to do this, though. --- .../nossr50/listeners/EntityListener.java | 4 ++++ .../nossr50/listeners/PlayerListener.java | 18 ++++++++++++++++-- .../com/gmail/nossr50/party/PartyManager.java | 11 +++++++++-- .../java/com/gmail/nossr50/util/Skills.java | 8 ++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 2e3f43000..f26eb9e2c 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -130,6 +130,10 @@ public class EntityListener implements Listener { PlayerProfile profile = Users.getProfile(player); + if (profile == null) { + return; + } + if (profile.getGodMode()) { event.setCancelled(true); return; diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 816b0c4fd..4e96dcdcb 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -59,6 +59,10 @@ public class PlayerListener implements Listener { Player player = event.getPlayer(); PlayerProfile profile = Users.getProfile(player); + if (profile == null) { + return; + } + if (profile.getGodMode()) { if (!Permissions.getInstance().mcgod(player)) { profile.toggleGodMode(); @@ -110,7 +114,13 @@ public class PlayerListener implements Listener { */ @EventHandler(ignoreCancelled = true) public void onPlayerPickupItem(PlayerPickupItemEvent event) { - if (Users.getProfile(event.getPlayer()).getAbilityMode(AbilityType.BERSERK)) { + PlayerProfile profile = Users.getProfile(event.getPlayer()); + + if (profile == null) { + return; + } + + if (profile.getAbilityMode(AbilityType.BERSERK)) { event.setCancelled(true); } } @@ -190,7 +200,11 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerRespawn(PlayerRespawnEvent event) { - Users.getProfile(event.getPlayer()).actualizeRespawnATS(); + PlayerProfile profile = Users.getProfile(event.getPlayer()); + + if (profile != null) { + profile.actualizeRespawnATS(); + } } /** diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index c92ba83b1..a21864d7c 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -41,8 +41,15 @@ public class PartyManager { * @return true if they are in the same party, false otherwise */ public boolean inSameParty(Player firstPlayer, Player secondPlayer) { - Party firstParty = Users.getProfile(firstPlayer).getParty(); - Party secondParty = Users.getProfile(secondPlayer).getParty(); + PlayerProfile firstProfile = Users.getProfile(firstPlayer); + PlayerProfile secondProfile = Users.getProfile(secondPlayer); + + if (firstProfile == null || secondProfile == null) { + return false; + } + + Party firstParty = firstProfile.getParty(); + Party secondParty = secondProfile.getParty(); if (firstParty == null || secondParty == null || firstParty != secondParty) { return false; diff --git a/src/main/java/com/gmail/nossr50/util/Skills.java b/src/main/java/com/gmail/nossr50/util/Skills.java index 6682fb12f..f31549a3e 100644 --- a/src/main/java/com/gmail/nossr50/util/Skills.java +++ b/src/main/java/com/gmail/nossr50/util/Skills.java @@ -107,6 +107,10 @@ public class Skills { } /* Check if any abilities are active */ + if (profile == null) { + return; + } + if (!profile.getAbilityUse()) { return; } @@ -151,6 +155,10 @@ public class Skills { ToolType tool = skill.getTool(); AbilityType ability = skill.getAbility(); + if (profile == null) { + return; + } + if (profile.getToolPreparationMode(tool) && curTime - (profile.getToolPreparationATS(tool) * TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) { profile.setToolPreparationMode(tool, false);