diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index f27b6db..c15427f 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -1462,6 +1462,20 @@ public class ChallengesManager if (this.levelCacheData.containsKey(challengeLevel.getUniqueId())) { this.levelCacheData.remove(challengeLevel.getUniqueId()); + + // Remove challenge level from challenges object. + if (!challengeLevel.getChallenges().isEmpty()) + { + challengeLevel.getChallenges().forEach(challengeID -> { + Challenge challenge = this.getChallenge(challengeID); + + if (challenge != null) + { + challenge.setLevel(ChallengesManager.FREE); + } + }); + } + this.levelDatabase.deleteObject(challengeLevel); } } diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index a061962..219a2be 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -298,8 +298,19 @@ public abstract class CommonGUI { case 'l': { - result.add(this.user.getTranslation("challenges.gui.challenge-description.level", - "[level]", manager.getLevel(challenge).getFriendlyName())); + ChallengeLevel level = manager.getLevel(challenge); + + if (level == null) + { + result.add(this.user.getTranslation("challenges.errors.missing-level", + "[level]", challenge.getLevel())); + } + else + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.level", + "[level]", level.getFriendlyName())); + } + break; } case 's': diff --git a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java index cf7e060..ca915a8 100644 --- a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java @@ -359,12 +359,13 @@ public class TryToComplete // Mark as complete this.manager.setChallengeComplete(this.user, this.world, this.challenge, result.getFactor()); - // Check level completion. - if (!result.wasCompleted()) + // Check level completion for non-free challenges + if (!result.wasCompleted() && + !this.challenge.getLevel().equals(ChallengesManager.FREE)) { ChallengeLevel level = this.manager.getLevel(this.challenge); - if (!this.manager.isLevelCompleted(this.user, this.world, level)) + if (level != null && !this.manager.isLevelCompleted(this.user, this.world, level)) { if (this.manager.validateLevelCompletion(this.user, this.world, level)) { diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 22706b0..7b3dc26 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -364,6 +364,7 @@ challenges: defaults-file-exist: '&cdefault.json already exists. Use overwrite mode to replace it!' defaults-file-error: '&cThere was an error while creating default.json file! Check console!' no-challenges: '&cChallenges are not implemented in current world!' + missing-level: '&cChallenge Level [level] is not defined in database. It may case some errors!' protection: flags: CHALLENGES_ISLAND_PROTECTION: