diff --git a/pom.xml b/pom.xml
index 9629a35..54dbda6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,7 +66,7 @@
world.bentobox
bentobox
- 0.12.0-SNAPSHOT
+ 0.15.0-SNAPSHOT
provided
diff --git a/src/main/java/bentobox/addon/challenges/ChallengesAddon.java b/src/main/java/bentobox/addon/challenges/ChallengesAddon.java
index ee5e59f..e006dfb 100644
--- a/src/main/java/bentobox/addon/challenges/ChallengesAddon.java
+++ b/src/main/java/bentobox/addon/challenges/ChallengesAddon.java
@@ -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
}
diff --git a/src/main/java/bentobox/addon/challenges/ChallengesManager.java b/src/main/java/bentobox/addon/challenges/ChallengesManager.java
index 0e50e7c..e38aed2 100644
--- a/src/main/java/bentobox/addon/challenges/ChallengesManager.java
+++ b/src/main/java/bentobox/addon/challenges/ChallengesManager.java
@@ -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());
+
+ }
+
}
diff --git a/src/main/java/bentobox/addon/challenges/database/object/ChallengesPlayerData.java b/src/main/java/bentobox/addon/challenges/database/object/ChallengesPlayerData.java
index dd23802..74f0716 100644
--- a/src/main/java/bentobox/addon/challenges/database/object/ChallengesPlayerData.java
+++ b/src/main/java/bentobox/addon/challenges/database/object/ChallengesPlayerData.java
@@ -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));
+ }
+
}
diff --git a/src/main/java/bentobox/addon/challenges/listeners/ResetListener.java b/src/main/java/bentobox/addon/challenges/listeners/ResetListener.java
new file mode 100644
index 0000000..d69a5f2
--- /dev/null
+++ b/src/main/java/bentobox/addon/challenges/listeners/ResetListener.java
@@ -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());
+ }
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index d7a7d65..9760fcd 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -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.
diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml
index ca97f86..c4138f4 100755
--- a/src/main/resources/locales/en-US.yml
+++ b/src/main/resources/locales/en-US.yml
@@ -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: " "
+ 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: " "
+ 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: " "
- unknown-challenge: "&cUnknown challenge"
- reset:
- description: "Reset challenge to 0 times / incomplete"
- parameters: " "
- 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"
\ No newline at end of file
+ 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!"
\ No newline at end of file