diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java index 518ec828..f9d2982f 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java @@ -74,7 +74,8 @@ public ChallengeLevel() @ConfigComment("") @ConfigComment("The number of undone challenges that can be left on this level before") - @ConfigComment("unlocking next level.") + @ConfigComment("unlocking next level. Give players more with the permission") + @ConfigComment("[gamemode].challenges.waiver-add.x where x is a number") @Expose private int waiverAmount = 1; diff --git a/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java b/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java index 89036cef..7ae75e50 100644 --- a/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java @@ -1121,8 +1121,9 @@ private void resetAllChallenges(@NonNull String storageDataID, @NonNull String g * @return Level status - how many challenges still to do on which level */ @NonNull - private List getAllChallengeLevelStatus(String storageDataID, String gameMode) + private List getAllChallengeLevelStatus(User user, World world, String gameMode) { + String storageDataID = this.getDataUniqueID(user, Util.getWorld(world)); this.addPlayerData(storageDataID); ChallengesPlayerData playerData = this.playerCacheData.get(storageDataID); @@ -1135,6 +1136,14 @@ private List getAllChallengeLevelStatus(String storageDataID, Strin int doneChallengeCount = 0; boolean previousUnlocked = true; + // Get user's waiver add from permission + // Get per-user waiver amount + int waiverAdd = user + .getPermissionValue(addon.getPlugin().getIWM().getPermissionPrefix(world) + "challenges.waiver-add", 0); + if (waiverAdd < 0) { + waiverAdd = 0; + } + // For each challenge level, check how many the storageDataID has done for (ChallengeLevel level : challengeLevelList) { @@ -1147,7 +1156,7 @@ private List getAllChallengeLevelStatus(String storageDataID, Strin this.getLevelChallenges(previousLevel); int challengesToDo = previousLevel == null ? 0 : - (previousChallengeList.size() - doneChallengeCount - previousLevel.getWaiverAmount()); + (previousChallengeList.size() - doneChallengeCount - (previousLevel.getWaiverAmount() + waiverAdd)); List challengeList = this.getLevelChallenges(level); @@ -1177,14 +1186,15 @@ private List getAllChallengeLevelStatus(String storageDataID, Strin /** * This method returns LevelStatus object for given challenge level. - * @param storageDataID User which level status must be acquired. + * @param user User which level status must be acquired. * @param world World where level is living. * @param level Level which status must be calculated. * @return LevelStatus of given level. */ @Nullable - private LevelStatus getChallengeLevelStatus(@NonNull String storageDataID, World world, @NonNull ChallengeLevel level) + private LevelStatus getChallengeLevelStatus(User user, World world, @NonNull ChallengeLevel level) { + String storageDataID = this.getDataUniqueID(user.getUniqueId(), Util.getWorld(world)); this.addPlayerData(storageDataID); ChallengesPlayerData playerData = this.playerCacheData.get(storageDataID); @@ -1651,11 +1661,9 @@ public boolean isLevelCompleted(User user, World world, ChallengeLevel level) */ public boolean isLevelUnlocked(User user, World world, ChallengeLevel level) { - String storageDataID = this.getDataUniqueID(user, Util.getWorld(world)); - this.addPlayerData(storageDataID); - - return this.islandWorldManager.getAddon(world).filter(gameMode -> this.getAllChallengeLevelStatus(storageDataID, gameMode.getDescription().getName()). - stream(). + return this.islandWorldManager.getAddon(world).filter(gameMode -> this + .getAllChallengeLevelStatus(user, world, gameMode.getDescription().getName()) + .stream(). filter(LevelStatus::isUnlocked). anyMatch(lv -> lv.getLevel().equals(level))). isPresent(); @@ -1709,7 +1717,8 @@ public boolean validateLevelCompletion(User user, World world, ChallengeLevel le @Nullable public LevelStatus getChallengeLevelStatus(UUID uniqueId, World world, ChallengeLevel level) { - return this.getChallengeLevelStatus(this.getDataUniqueID(uniqueId, Util.getWorld(world)), world, level); + User user = User.getInstance(uniqueId); + return this.getChallengeLevelStatus(user, world, level); } @@ -1725,9 +1734,8 @@ public List getAllChallengeLevelStatus(User user, World world) { return this.islandWorldManager.getAddon(world).map(gameMode -> this.getAllChallengeLevelStatus( - this.getDataUniqueID(user, Util.getWorld(world)), - gameMode.getDescription().getName())). - orElse(Collections.emptyList()); + user, world, gameMode.getDescription().getName())) + .orElse(Collections.emptyList()); } diff --git a/src/main/java/world/bentobox/challenges/panel/CommonPanel.java b/src/main/java/world/bentobox/challenges/panel/CommonPanel.java index 5a5b95b4..86118768 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonPanel.java @@ -13,7 +13,6 @@ import java.util.stream.Collectors; import org.bukkit.Material; -import org.bukkit.Statistic; import org.bukkit.World; import org.bukkit.inventory.ItemStack; import org.eclipse.jdt.annotation.NonNull; @@ -743,10 +742,17 @@ protected List generateLevelDescription(ChallengeLevel level) { // my eye :) // Get status in single string String status = ""; + // Get per-user waiver amount + int waiverAdd = user.getPermissionValue( + addon.getPlugin().getIWM().getPermissionPrefix(world) + "challenges.waiver-add", 0); + if (waiverAdd < 0) { + waiverAdd = 0; + } + waiverAdd += level.getWaiverAmount(); // Get requirements in single string String waiver = this.manager.isLastLevel(level, this.world) ? "" : this.user.getTranslationOrNothing(reference + "waiver", "[number]", - String.valueOf(level.getWaiverAmount())); + String.valueOf(waiverAdd)); // Get rewards in single string String rewards = this.generateReward(level); @@ -776,11 +782,18 @@ protected List generateLevelDescription(LevelStatus levelStatus, User us // my eye :) // Get status in single string String status = this.generateLevelStatus(levelStatus); + // Get per-user waiver amount + int waiverAdd = user + .getPermissionValue(addon.getPlugin().getIWM().getPermissionPrefix(world) + "challenges.waiver-add", 0); + if (waiverAdd < 0) { + waiverAdd = 0; + } + waiverAdd += level.getWaiverAmount(); // Get requirements in single string String waiver = this.manager.isLastLevel(level, this.world) || !levelStatus.isUnlocked() || levelStatus.isComplete() ? "" : this.user.getTranslationOrNothing(reference + "waiver", "[number]", - String.valueOf(level.getWaiverAmount())); + String.valueOf(waiverAdd)); // Get rewards in single string String rewards = !levelStatus.isUnlocked() ? "" : this.generateReward(level); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelPanel.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelPanel.java index 0b3dcedd..2ab24700 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelPanel.java @@ -758,7 +758,7 @@ private PanelItem createButton(Button button) } case WAIVER_AMOUNT -> { description.add(this.user.getTranslation(reference + "value", - Constants.PARAMETER_NUMBER, String.valueOf(this.challengeLevel.getWaiverAmount()))); + Constants.PARAMETER_NUMBER, String.valueOf(this.challengeLevel.getWaiverAmount()))); icon = new ItemStack(Material.HOPPER, Math.max(1, this.challengeLevel.getWaiverAmount())); clickHandler = (panel, user, clickType, i) -> {