mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-24 11:36:53 +01:00
Challenges reset when island is reset.
Fixed locale duplication. https://github.com/BentoBoxWorld/addon-challenges/issues/2 https://github.com/BentoBoxWorld/addon-challenges/issues/3
This commit is contained in:
parent
97bec0f870
commit
5f7581f09c
2
pom.xml
2
pom.xml
@ -66,7 +66,7 @@
|
||||
<dependency>
|
||||
<groupId>world.bentobox</groupId>
|
||||
<artifactId>bentobox</artifactId>
|
||||
<version>0.12.0-SNAPSHOT</version>
|
||||
<version>0.15.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,21 +1,19 @@
|
||||
package bentobox.addon.challenges;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import bentobox.addon.challenges.commands.ChallengesCommand;
|
||||
import bentobox.addon.challenges.commands.admin.Challenges;
|
||||
import bentobox.addon.challenges.listeners.ResetListener;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.level.event.IslandLevelCalculatedEvent;
|
||||
|
||||
/**
|
||||
* Add-on to BSkyBlock that enables challenges
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class ChallengesAddon extends Addon implements Listener {
|
||||
public class ChallengesAddon extends Addon {
|
||||
|
||||
private ChallengesManager challengesManager;
|
||||
private String permissionPrefix = "addon";
|
||||
@ -27,15 +25,9 @@ public class ChallengesAddon extends Addon implements Listener {
|
||||
// Save default config.yml
|
||||
saveDefaultConfig();
|
||||
}
|
||||
@EventHandler
|
||||
public void onIslandLevelChange(IslandLevelCalculatedEvent event)
|
||||
{
|
||||
event.getResults();
|
||||
Bukkit.getLogger().info("DEBUG: event called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.registerListener(this);
|
||||
// Check if it is enabled - it might be loaded, but not enabled.
|
||||
if (getPlugin() == null || !getPlugin().isEnabled()) {
|
||||
Bukkit.getLogger().severe("BentoBox is not available or disabled!");
|
||||
@ -79,6 +71,8 @@ public class ChallengesAddon extends Addon implements Listener {
|
||||
if (!getAddonByName("Level").isPresent()) {
|
||||
logWarning("Level add-on not found so level challenges will not work!");
|
||||
}
|
||||
// Register the reset listener
|
||||
this.registerListener(new ResetListener(this));
|
||||
// Done
|
||||
}
|
||||
|
||||
|
@ -511,5 +511,19 @@ public class ChallengesManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all the challenges for user in world
|
||||
* @param uuid - island owner's UUID
|
||||
* @param world - world
|
||||
*/
|
||||
public void resetAllChallenges(UUID uuid, World world) {
|
||||
User user = User.getInstance(uuid);
|
||||
addPlayer(user);
|
||||
playerData.get(user.getUniqueId()).reset(world);
|
||||
// Save
|
||||
savePlayer(user.getUniqueId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -178,4 +178,15 @@ public class ChallengesPlayerData implements DataObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all challenges and levels in world for this player
|
||||
* @param world
|
||||
*/
|
||||
public void reset(World world) {
|
||||
String worldName = Util.getWorld(world).getName();
|
||||
challengeStatus.keySet().removeIf(n -> n.startsWith(worldName));
|
||||
challengesTimestamp.keySet().removeIf(n -> n.startsWith(worldName));
|
||||
levelsDone.removeIf(n -> n.startsWith(worldName));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package bentobox.addon.challenges.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import bentobox.addon.challenges.ChallengesAddon;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||
|
||||
/**
|
||||
* Resets challenges when the island is reset
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class ResetListener implements Listener {
|
||||
|
||||
private ChallengesAddon addon;
|
||||
|
||||
public ResetListener(ChallengesAddon addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onIslandReset(IslandEvent e) {
|
||||
if (e.getReason().equals(Reason.CREATED) || (addon.getConfig().getBoolean("resetchallenges") && e.getReason().equals(Reason.RESETTED))) {
|
||||
addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld());
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
# Reset Challenges - if this is true, player's challenges will reset when they
|
||||
# reset an island or if they are kicked or leave a team. Prevents exploiting the
|
||||
# challenges by doing them repeatedly.
|
||||
resetchallenges: false
|
||||
resetchallenges: true
|
||||
|
||||
# Broadcast 1st time challenge completion messages to all players.
|
||||
# Change to false if the spam becomes too much.
|
||||
|
@ -6,36 +6,59 @@
|
||||
### Credits ###
|
||||
# Tastybento: maintainer
|
||||
|
||||
challenges:
|
||||
completed-times: "Completed [donetimes] out of [maxtimes]"
|
||||
max-reached: "Max reached [donetimes] out of [maxtimes]"
|
||||
challenge:
|
||||
challenges:
|
||||
admin:
|
||||
challenge-created: "[challenge] created!"
|
||||
complete:
|
||||
description: "Mark challenge complete"
|
||||
parameters: "<player> <unique challenge name>"
|
||||
unknown-challenge: "&cUnknown challenge"
|
||||
create:
|
||||
description: "&6Collect:"
|
||||
description-item-color: "&B"
|
||||
inventory:
|
||||
description: "create an inventory challenge"
|
||||
parameters: "[challenge name]"
|
||||
surrounding:
|
||||
description: "create a surrounding challenge"
|
||||
hit-things: "Hit things to add them to the list of things required. Right click when done."
|
||||
parameters: "[challenge name]"
|
||||
description: "challenges admin"
|
||||
error:
|
||||
no-name: "You must include a challenge name"
|
||||
gui-title: "&aChallenges Admin"
|
||||
import:
|
||||
description: "import challenges from challenges.yml"
|
||||
imported: "Imported '[challenge]'"
|
||||
levels: "Importing levels: [levels]"
|
||||
no-file: "&cCould not find challenges.yml file to import!"
|
||||
no-levels: "Warning: No levels defined in challenges.yml"
|
||||
no-load: "&cError: Could not load challenges.yml. [message]"
|
||||
number: "Imported [number] challenges"
|
||||
overwriting: "Overwriting '[challenge]'"
|
||||
parameters: "[overwrite]"
|
||||
skipping: "'[challenge]' already exists - skipping"
|
||||
parameters: ""
|
||||
reload:
|
||||
description: "reload challenges from the database"
|
||||
parameters: ""
|
||||
reset:
|
||||
description: "Reset challenge to 0 times / incomplete"
|
||||
parameters: "<player> <unique challenge name>"
|
||||
seticon:
|
||||
description: "sets the challenge icon to inhand item"
|
||||
error:
|
||||
no-such-challenge: "&cNo such challenge name"
|
||||
parameters: "[challenge name]"
|
||||
you-added: "You added one [thing] to the challenge"
|
||||
challenge:
|
||||
format: "[description]"
|
||||
parameters: "[Level]"
|
||||
description: "Open the challenges menu"
|
||||
complete: "&BComplete"
|
||||
exp-reward: "&6Exp reward: [reward]"
|
||||
first-time-rewards: "&6First time reward(s)"
|
||||
gui-title: "&aChallenges"
|
||||
incomplete: "Incomplete"
|
||||
item-take-warning: "&cAll required items are|&ctaken when you complete|&cthis challenge!"
|
||||
items-closeby: "&cAll required items|&cmust be close to you|&con your island!"
|
||||
level: "&FLevel: [level]"
|
||||
max-reached: "Max reached [donetimes] out of [maxtimes]"
|
||||
money-reward: "&6Money reward: $[reward]"
|
||||
name: "Challenge Name"
|
||||
name-has-completed: "[name] has completed the [challenge] challenge!"
|
||||
navigation: "Click to see [level] challenges!"
|
||||
repeatable: "This challenge can be repeated [maxtimes] times"
|
||||
not-repeatable: "This challenge is not repeatable!"
|
||||
repeat-rewards: "&6Repeat reward(s)"
|
||||
rewards: "&FReward(s)"
|
||||
to-complete: "Complete [challengesToDo] more [thisLevel] challenges to unlock this level!"
|
||||
you-completed: "You completed the [challenge] challenge!"
|
||||
you-repeated: "You repeated the [challenge] challenge!"
|
||||
completechallenge:
|
||||
challange-completed: "Challenge: [challengename] has been completed for [name]"
|
||||
error:
|
||||
completed-times: "Completed [donetimes] out of [maxtimes]"
|
||||
description: "Open the challenges menu"
|
||||
error:
|
||||
could-not-save: "&cCould not save the challenge!"
|
||||
island-level: "&cYour island must be level [number] to complete this challenge!"
|
||||
items-not-there: "&cAll required items must be close to you on your island!"
|
||||
@ -45,58 +68,34 @@ challenges:
|
||||
not-on-island: "&cYou must be on your island to do that!"
|
||||
reward-problem: "&cThere was a problem giving your reward. Ask Admin to check log!"
|
||||
you-still-need: "&cYou still need [amount] x [item]"
|
||||
help:
|
||||
exp-reward: "&6Exp reward: [reward]"
|
||||
first-time-rewards: "&6First time reward(s)"
|
||||
gui-title: "&aChallenges"
|
||||
help:
|
||||
command: "/challenges: &fshow challenges"
|
||||
config-reloaded: "Configuration reloaded from file."
|
||||
reset-all-challenges: "resets all of the player's challenges"
|
||||
reset-challenge: "marks a challenge as incomplete"
|
||||
reset-challenge-for-all: "globally resets a challenge for every player with an optional repetition"
|
||||
incomplete: Incomplete
|
||||
item-take-warning: "&cAll required items are|&ctaken when you complete|&cthis challenge!"
|
||||
items-closeby: "&cAll required items|&cmust be close to you|&con your island!"
|
||||
level: "&FLevel: [level]"
|
||||
max-reached: "Max reached [donetimes] out of [maxtimes]"
|
||||
money-reward: "&6Money reward: $[reward]"
|
||||
name: "Challenge Name"
|
||||
name-has-completed: "[name] has completed the [challenge] challenge!"
|
||||
navigation: "Click to see [level] challenges!"
|
||||
not-repeatable: "This challenge is not repeatable!"
|
||||
parameters: "[Level]"
|
||||
repeat-rewards: "&6Repeat reward(s)"
|
||||
repeatable: "This challenge can be repeated [maxtimes] times"
|
||||
resetallchallenges:
|
||||
success: "[name] has had all challenges reset."
|
||||
resetchallenge:
|
||||
challenge-reset: "Challenge: [challengename] has been reset for [name]"
|
||||
error-challenge-does-not-exist: "Challenge doesn't exist or isn't yet completed"
|
||||
admin:
|
||||
parameters: ""
|
||||
description: "challenges admin"
|
||||
reload:
|
||||
parameters: ""
|
||||
description: "reload challenges from the database"
|
||||
import:
|
||||
parameters: "[overwrite]"
|
||||
description: "import challenges from challenges.yml"
|
||||
no-file: "&cCould not find challenges.yml file to import!"
|
||||
no-load: "&cError: Could not load challenges.yml. [message]"
|
||||
no-levels: "Warning: No levels defined in challenges.yml"
|
||||
levels: "Importing levels: [levels]"
|
||||
number: "Imported [number] challenges"
|
||||
skipping: "'[challenge]' already exists - skipping"
|
||||
overwriting: "Overwriting '[challenge]'"
|
||||
imported: "Imported '[challenge]'"
|
||||
complete:
|
||||
description: "Mark challenge complete"
|
||||
parameters: "<player> <unique challenge name>"
|
||||
unknown-challenge: "&cUnknown challenge"
|
||||
reset:
|
||||
description: "Reset challenge to 0 times / incomplete"
|
||||
parameters: "<player> <unique challenge name>"
|
||||
create:
|
||||
description: "&6Collect:"
|
||||
description-item-color: "&B"
|
||||
inventory:
|
||||
parameters: "[challenge name]"
|
||||
description: "create an inventory challenge"
|
||||
surrounding:
|
||||
parameters: "[challenge name]"
|
||||
description: "create a surrounding challenge"
|
||||
hit-things: "Hit things to add them to the list of things required. Right click when done."
|
||||
error:
|
||||
no-name: "You must include a challenge name"
|
||||
challenge-created: "[challenge] created!"
|
||||
you-added: "You added one [thing] to the challenge"
|
||||
seticon:
|
||||
error:
|
||||
no-such-challenge: "&cNo such challenge name"
|
||||
description: "sets the challenge icon to inhand item"
|
||||
parameters: "[challenge name]"
|
||||
gui-title: "&aChallenges Admin"
|
||||
rewards: "&FReward(s)"
|
||||
to-complete: "Complete [challengesToDo] more [thisLevel] challenges to unlock this level!"
|
||||
you-completed: "You completed the [challenge] challenge!"
|
||||
you-repeated: "You repeated the [challenge] challenge!"
|
Loading…
Reference in New Issue
Block a user