diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index c1c25d4..ecdef6c 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -2,6 +2,7 @@ package world.bentobox.challenges; import org.bukkit.Bukkit; +import org.bukkit.Material; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -9,7 +10,9 @@ import java.util.Optional; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.configuration.Config; +import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.hooks.VaultHook; +import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.commands.ChallengesUserCommand; import world.bentobox.challenges.commands.admin.Challenges; @@ -68,6 +71,21 @@ public class ChallengesAddon extends Addon { */ private static final String PERMISSION_PREFIX = "addon"; + /** + * This flag allows to complete challenges in any part of the world. It will not limit + * player to their island. Useful for skygrid without protection flags. + */ + public static Flag CHALLENGES_WORLD_PROTECTION = + new Flag.Builder("CHALLENGES_WORLD_PROTECTION", Material.GRASS_BLOCK).type(Flag.Type.WORLD_SETTING).defaultSetting(true).build(); + + /** + * This flag allows to define which users can complete challenge. F.e. it can be set + * that only Island owner can complete challenge. + * By default it is set to Visitor. + */ + public static Flag CHALLENGES_ISLAND_PROTECTION = + new Flag.Builder("CHALLENGES_ISLAND_PROTECTION", Material.COMMAND_BLOCK).defaultRank(RanksManager.VISITOR_RANK).build(); + // --------------------------------------------------------------------- // Section: Methods @@ -121,6 +139,9 @@ public class ChallengesAddon extends Addon { new Challenges(this, gameModeAddon.getAdminCommand().get()); this.hooked = true; } + + CHALLENGES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon); + CHALLENGES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon); } }); @@ -170,6 +191,10 @@ public class ChallengesAddon extends Addon { this.registerListener(new ResetListener(this)); // Register the autosave listener. this.registerListener(new SaveListener(this)); + + // Register Flags + this.getPlugin().getFlagsManager().registerFlag(CHALLENGES_ISLAND_PROTECTION); + this.getPlugin().getFlagsManager().registerFlag(CHALLENGES_WORLD_PROTECTION); } else { this.logError("Challenges could not hook into AcidIsland or BSkyBlock so will not do anything!"); this.setState(State.DISABLED); diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 808e975..63569a9 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -350,11 +350,20 @@ public class TryToComplete result = EMPTY_RESULT; } // Player is not on island - else if (!this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user)) + else if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.world) && + !this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user)) { this.user.sendMessage("challenges.errors.not-on-island"); result = EMPTY_RESULT; } + // Check player permission + else if (!this.addon.getIslands().getIslandAt(this.user.getLocation()). + map(i -> i.isAllowed(this.user, ChallengesAddon.CHALLENGES_ISLAND_PROTECTION)). + orElse(false)) + { + this.user.sendMessage("challenges.errors.no-rank"); + result = EMPTY_RESULT; + } // Check if user has unlocked challenges level. else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) && !this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel()))) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 42c318c..bed76e7 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -307,4 +307,14 @@ challenges: import-no-file: '&cCould not find challenges.yml file to import!' no-load: '&cError: Could not load challenges.yml. [message]' load-error: '&cError: Cannot load [value].' -version: 6 \ No newline at end of file + no-rank: "&cYou do not have rank to do that." +protection: + flags: + CHALLENGES_ISLAND_PROTECTION: + description: "&5&oToggle who can\n&5&ocomplete challenges" + name: "Challenges protection" + CHALLENGES_WORLD_PROTECTION: + description: "&5&oThis allows to enable/disable\n&5&orequirement for players to\n&5&obe on their island to\n&5&ocomplete a challenge." + name: "Challenges Island limitation" + hint: "No challenges outside island" +version: 7 \ No newline at end of file