Skip to content

Commit

Permalink
Implement Challenges protection flags.
Browse files Browse the repository at this point in the history
Create a new Flag Challenges Protection (#93), that allows to define which users can complete challenges on island.
Create a new Flag Challenges Island Limitation (#95), that allows to disable check for users to be on their islands for completing challenge.
  • Loading branch information
BONNe committed Feb 19, 2019
1 parent 8649409 commit 9328f43
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@


import org.bukkit.Bukkit;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.List;
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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -121,6 +139,9 @@ public void onEnable() {
new Challenges(this, gameModeAddon.getAdminCommand().get());
this.hooked = true;
}

CHALLENGES_WORLD_PROTECTION.addGameModeAddon(gameModeAddon);
CHALLENGES_ISLAND_PROTECTION.addGameModeAddon(gameModeAddon);
}
});

Expand Down Expand Up @@ -170,6 +191,10 @@ public void onEnable() {
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);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/world/bentobox/challenges/panel/TryToComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,20 @@ else if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) ||
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())))
Expand Down
12 changes: 11 additions & 1 deletion src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-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

0 comments on commit 9328f43

Please sign in to comment.