Added defaults to getString for challenge import

This will avoid nulls if challenge lines like itemReward are missing.

Should help https://github.com/BentoBoxWorld/Challenges/issues/53
This commit is contained in:
tastybento 2019-01-29 14:38:26 -08:00
parent 44ab03819c
commit 78f924b7c3

View File

@ -89,7 +89,7 @@ public class ChallengesImportManager
// Check if there is a level reward // Check if there is a level reward
ConfigurationSection unlock = chal.getConfigurationSection("challenges.levelUnlock." + level); ConfigurationSection unlock = chal.getConfigurationSection("challenges.levelUnlock." + level);
if (unlock != null) { if (unlock != null) {
challengeLevel.setUnlockMessage(unlock.getString("message")); challengeLevel.setUnlockMessage(unlock.getString("message", ""));
challengeLevel.setRewardText(unlock.getString("rewardDesc","")); challengeLevel.setRewardText(unlock.getString("rewardDesc",""));
challengeLevel.setRewardItems(parseItems(unlock.getString("itemReward",""))); challengeLevel.setRewardItems(parseItems(unlock.getString("itemReward","")));
challengeLevel.setRewardMoney(unlock.getInt("moneyReward")); challengeLevel.setRewardMoney(unlock.getInt("moneyReward"));
@ -118,9 +118,9 @@ public class ChallengesImportManager
ConfigurationSection details = chals.getConfigurationSection(challenge); ConfigurationSection details = chals.getConfigurationSection(challenge);
newChallenge.setFriendlyName(details.getString("friendlyname", challenge)); newChallenge.setFriendlyName(details.getString("friendlyname", challenge));
newChallenge.setDescription(GuiUtils.stringSplit(details.getString("description", ""))); newChallenge.setDescription(GuiUtils.stringSplit(details.getString("description", "")));
newChallenge.setIcon(ItemParser.parse(details.getString("icon") + ":1")); newChallenge.setIcon(ItemParser.parse(details.getString("icon", "") + ":1"));
if (details.getString("type").equalsIgnoreCase("level")) if (details.getString("type", "").equalsIgnoreCase("level"))
{ {
// Fix for older version config // Fix for older version config
newChallenge.setChallengeType(Challenge.ChallengeType.OTHER); newChallenge.setChallengeType(Challenge.ChallengeType.OTHER);
@ -152,11 +152,11 @@ public class ChallengesImportManager
} else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) { } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) {
parseEntities(newChallenge, reqItems); parseEntities(newChallenge, reqItems);
} }
newChallenge.setRewardItems(parseItems(details.getString("itemReward"))); newChallenge.setRewardItems(parseItems(details.getString("itemReward", "")));
newChallenge.setRepeatItemReward(parseItems(details.getString("repeatItemReward"))); newChallenge.setRepeatItemReward(parseItems(details.getString("repeatItemReward", "")));
// Save // Save
this.addon.getChallengesManager().addChallengeToLevel(newChallenge, this.addon.getChallengesManager().addChallengeToLevel(newChallenge,
addon.getChallengesManager().getLevel(Util.getWorld(world).getName() + "_" + details.getString("level"))); addon.getChallengesManager().getLevel(Util.getWorld(world).getName() + "_" + details.getString("level", "")));
if (addon.getChallengesManager().loadChallenge(newChallenge, overwrite, user, false)) { if (addon.getChallengesManager().loadChallenge(newChallenge, overwrite, user, false)) {
size++; size++;