mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-29 04:18:05 +01:00
Merge flags into development build.
This commit is contained in:
commit
62189f0052
@ -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;
|
||||
@ -69,6 +72,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
|
||||
@ -122,6 +140,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);
|
||||
}
|
||||
});
|
||||
|
||||
@ -172,6 +193,10 @@ public class ChallengesAddon extends Addon {
|
||||
// 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);
|
||||
|
||||
// Register Request Handlers
|
||||
this.registerRequestHandler(new ChallengeListRequestHandler(this));
|
||||
this.registerRequestHandler(new LevelListRequestHandler(this));
|
||||
|
@ -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())))
|
||||
|
@ -315,4 +315,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: 7
|
||||
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: 8
|
Loading…
Reference in New Issue
Block a user