Преглед изворни кода

Fix possible NPE when using the PartyAPI to add a player to a party that
doesn't exist.

GJ пре 12 година
родитељ
комит
38a8a6f2ff
2 измењених фајлова са 11 додато и 1 уклоњено
  1. 1 0
      Changelog.txt
  2. 10 1
      src/main/java/com/gmail/nossr50/api/PartyAPI.java

+ 1 - 0
Changelog.txt

@@ -20,6 +20,7 @@ Version 1.3.13-dev
  + Added wooden button to the list of items that shouldn't trigger abilities
  + Added a new feature to fishing. Players will have +10% chance of finding enchanted items when fishing while it's raining
  + Added displaying bonus perks on skill commands
+ = Fix possible NPE when using the PartyAPI to add a player to a party that doesn't exist.
  = Fix mcremove command for mySQL
  = Impact now works with mobs wearing armor
  = Fixed issue with Tree Feller dropping player-placed blocks

+ 10 - 1
src/main/java/com/gmail/nossr50/api/PartyAPI.java

@@ -69,7 +69,16 @@ public final class PartyAPI {
      * @param partyName The party to add the player to
      */
     public static void addToParty(Player player, String partyName) {
-        PartyManager.getInstance().addToParty(player.getName(), Users.getProfile(player), PartyManager.getInstance().getParty(partyName)); //TODO this will throw a NPE if the party doesn't exist
+        Party party = PartyManager.getInstance().getParty(partyName);
+        String playerName = player.getName();
+
+        if (party == null) {
+            party = new Party();
+            party.setName(partyName);
+            party.setLeader(playerName);
+        }
+
+        PartyManager.getInstance().addToParty(playerName, Users.getProfile(player), party);
     }
 
     /**