Quellcode durchsuchen

Null check ALL the profiles.

We should probably find a more elegant way to do this, though.
GJ vor 13 Jahren
Ursprung
Commit
686bcd5308

+ 4 - 0
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;

+ 16 - 2
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();
+        }
     }
 
     /**

+ 9 - 2
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;

+ 8 - 0
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);