diff --git a/pom.xml b/pom.xml
index f721293..01df943 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,13 +36,13 @@
2.0.2
1.15.2-R0.1-SNAPSHOT
- 1.13.1
+ 1.14.0-SNAPSHOT
1.6.0
1.7
${build.version}-SNAPSHOT
- 0.9.0
+ 0.10.0
-LOCAL
diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java
index e3e72db..c98d823 100644
--- a/src/main/java/world/bentobox/challenges/ChallengesManager.java
+++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java
@@ -402,27 +402,6 @@ public class ChallengesManager
return true;
}
-
- /**
- * This method stores PlayerData into local cache.
- *
- * @param playerData ChallengesPlayerData that must be loaded.
- *
- * TODO: Remove this unused method?
- */
- private void loadPlayerData(@NonNull ChallengesPlayerData playerData)
- {
- try
- {
- this.playerCacheData.put(playerData.getUniqueId(), playerData);
- }
- catch (Exception e)
- {
- this.addon.getLogger().severe("UUID for player in challenge data file is invalid!");
- }
- }
-
-
/**
* This method removes given player from cache data.
*
@@ -503,7 +482,7 @@ public class ChallengesManager
if (!this.challengeCacheData.containsKey(uniqueID))
{
if (!this.challengeDatabase.objectExists(uniqueID) ||
- !this.loadChallenge(this.challengeDatabase.loadObject(uniqueID), false, null, true))
+ !this.loadChallenge(this.challengeDatabase.loadObject(uniqueID), false, null, true))
{
this.addon.logError("Cannot find " + uniqueID + " challenge for " + level.getUniqueId());
return false;
@@ -549,7 +528,7 @@ public class ChallengesManager
{
// Create the player data
ChallengesPlayerData pd = new ChallengesPlayerData(uniqueID);
- this.playersDatabase.saveObject(pd);
+ this.playersDatabase.saveObjectAsync(pd);
// Add to cache
this.playerCacheData.put(uniqueID, pd);
}
@@ -696,7 +675,7 @@ public class ChallengesManager
challengesID.forEach(challenge ->
level.getChallenges().add(addonName + challenge.substring(world.getName().length())));
- this.levelDatabase.saveObject(level);
+ this.levelDatabase.saveObjectAsync(level);
this.levelCacheData.put(level.getUniqueId(), level);
updated = true;
@@ -740,7 +719,7 @@ public class ChallengesManager
updated = true;
- this.challengeDatabase.saveObject(challenge);
+ this.challengeDatabase.saveObjectAsync(challenge);
this.challengeCacheData.put(challenge.getUniqueId(), challenge);
}
@@ -783,7 +762,7 @@ public class ChallengesManager
// This save should not involve any upgrades in other parts.
- this.challengeDatabase.saveObject(challenge);
+ this.challengeDatabase.saveObjectAsync(challenge);
this.challengeCacheData.put(challenge.getUniqueId(), challenge);
}
}
@@ -834,7 +813,7 @@ public class ChallengesManager
}
});
- this.playersDatabase.saveObject(playerData);
+ this.playersDatabase.saveObjectAsync(playerData);
});
}
@@ -1535,7 +1514,7 @@ public class ChallengesManager
public List getAllChallengeLevelStatus(User user, World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
- this.getAllChallengeLevelStatus(
+ this.getAllChallengeLevelStatus(
this.getDataUniqueID(user, Util.getWorld(world)),
gameMode.getDescription().getName())).
orElse(Collections.emptyList());
@@ -1554,7 +1533,7 @@ public class ChallengesManager
LevelStatus lastStatus = null;
for (Iterator statusIterator = this.getAllChallengeLevelStatus(user, world).iterator();
- statusIterator.hasNext() && (lastStatus == null || lastStatus.isUnlocked());)
+ statusIterator.hasNext() && (lastStatus == null || lastStatus.isUnlocked());)
{
lastStatus = statusIterator.next();
}
@@ -1577,12 +1556,12 @@ public class ChallengesManager
public List getAllChallengesNames(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
- this.challengeCacheData.values().stream().
- filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
- sorted(this.challengeComparator).
- map(Challenge::getUniqueId).
- collect(Collectors.toList())).
- orElse(Collections.emptyList());
+ this.challengeCacheData.values().stream().
+ filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
+ sorted(this.challengeComparator).
+ map(Challenge::getUniqueId).
+ collect(Collectors.toList())).
+ orElse(Collections.emptyList());
}
@@ -1595,11 +1574,11 @@ public class ChallengesManager
public List getAllChallenges(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
- this.challengeCacheData.values().stream().
- filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
- sorted(this.challengeComparator).
- collect(Collectors.toList())).
- orElse(Collections.emptyList());
+ this.challengeCacheData.values().stream().
+ filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())).
+ sorted(this.challengeComparator).
+ collect(Collectors.toList())).
+ orElse(Collections.emptyList());
}
@@ -1761,8 +1740,8 @@ public class ChallengesManager
public long getCompletedChallengeCount(User user, World world)
{
return this.getAllChallenges(world).stream().
- filter(challenge -> this.getChallengeTimes(user, world, challenge) > 0).
- count();
+ filter(challenge -> this.getChallengeTimes(user, world, challenge) > 0).
+ count();
}
@@ -1775,8 +1754,8 @@ public class ChallengesManager
public long getTotalChallengeCompletionCount(User user, World world)
{
return this.getAllChallenges(world).stream().
- mapToLong(challenge -> this.getChallengeTimes(user, world, challenge)).
- sum();
+ mapToLong(challenge -> this.getChallengeTimes(user, world, challenge)).
+ sum();
}
@@ -1793,8 +1772,8 @@ public class ChallengesManager
public List getLevels(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
- this.getLevels(gameMode.getDescription().getName())).
- orElse(Collections.emptyList());
+ this.getLevels(gameMode.getDescription().getName())).
+ orElse(Collections.emptyList());
}
@@ -1807,9 +1786,9 @@ public class ChallengesManager
{
// TODO: Probably need to check also database.
return this.levelCacheData.values().stream().
- sorted(ChallengeLevel::compareTo).
- filter(level -> level.matchGameMode(gameMode)).
- collect(Collectors.toList());
+ sorted(ChallengeLevel::compareTo).
+ filter(level -> level.matchGameMode(gameMode)).
+ collect(Collectors.toList());
}
@@ -1821,12 +1800,12 @@ public class ChallengesManager
public List getLevelNames(@NonNull World world)
{
return this.islandWorldManager.getAddon(world).map(gameMode ->
- this.levelCacheData.values().stream().
- sorted(ChallengeLevel::compareTo).
- filter(level -> level.matchGameMode(gameMode.getDescription().getName())).
- map(ChallengeLevel::getUniqueId).
- collect(Collectors.toList())).
- orElse(Collections.emptyList());
+ this.levelCacheData.values().stream().
+ sorted(ChallengeLevel::compareTo).
+ filter(level -> level.matchGameMode(gameMode.getDescription().getName())).
+ map(ChallengeLevel::getUniqueId).
+ collect(Collectors.toList())).
+ orElse(Collections.emptyList());
}
@@ -2072,8 +2051,8 @@ public class ChallengesManager
public long getCompletedLevelCount(User user, World world)
{
return this.getAllChallengeLevelStatus(user, world).stream().
- filter(LevelStatus::isComplete).
- count();
+ filter(LevelStatus::isComplete).
+ count();
}
@@ -2086,7 +2065,7 @@ public class ChallengesManager
public long getUnlockedLevelCount(User user, World world)
{
return this.getAllChallengeLevelStatus(user, world).stream().
- filter(LevelStatus::isUnlocked).
- count();
+ filter(LevelStatus::isUnlocked).
+ count();
}
}
\ No newline at end of file
diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenge.java b/src/main/java/world/bentobox/challenges/database/object/Challenge.java
index cff291f..41b9018 100644
--- a/src/main/java/world/bentobox/challenges/database/object/Challenge.java
+++ b/src/main/java/world/bentobox/challenges/database/object/Challenge.java
@@ -19,6 +19,7 @@ import com.google.gson.annotations.Expose;
import com.google.gson.annotations.JsonAdapter;
import world.bentobox.bentobox.database.objects.DataObject;
+import world.bentobox.bentobox.database.objects.Table;
import world.bentobox.challenges.database.object.adapters.RequirementsAdapter;
import world.bentobox.challenges.database.object.requirements.Requirements;
@@ -28,6 +29,7 @@ import world.bentobox.challenges.database.object.requirements.Requirements;
* @author tastybento
*
*/
+@Table(name = "Challenge")
public class Challenge implements DataObject
{
/**
diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java
index 7fb26bf..5eec573 100644
--- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java
+++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java
@@ -14,6 +14,7 @@ import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.database.objects.DataObject;
+import world.bentobox.bentobox.database.objects.Table;
import world.bentobox.challenges.ChallengesManager;
/**
@@ -21,6 +22,7 @@ import world.bentobox.challenges.ChallengesManager;
* @author tastybento
*
*/
+@Table(name = "ChallengeLevel")
public class ChallengeLevel implements DataObject, Comparable
{
/**
@@ -31,9 +33,9 @@ public class ChallengeLevel implements DataObject, Comparable
}
-// ---------------------------------------------------------------------
-// Section: Variables
-// ---------------------------------------------------------------------
+ // ---------------------------------------------------------------------
+ // Section: Variables
+ // ---------------------------------------------------------------------
@ConfigComment("")
@ConfigComment("Level name")
@@ -114,9 +116,9 @@ public class ChallengeLevel implements DataObject, Comparable
private Set challenges = new HashSet<>();
-// ---------------------------------------------------------------------
-// Section: Getters
-// ---------------------------------------------------------------------
+ // ---------------------------------------------------------------------
+ // Section: Getters
+ // ---------------------------------------------------------------------
/**
@@ -261,9 +263,9 @@ public class ChallengeLevel implements DataObject, Comparable
}
-// ---------------------------------------------------------------------
-// Section: Setters
-// ---------------------------------------------------------------------
+ // ---------------------------------------------------------------------
+ // Section: Setters
+ // ---------------------------------------------------------------------
/**
@@ -422,9 +424,9 @@ public class ChallengeLevel implements DataObject, Comparable
}
-// ---------------------------------------------------------------------
-// Section: Other methods
-// ---------------------------------------------------------------------
+ // ---------------------------------------------------------------------
+ // Section: Other methods
+ // ---------------------------------------------------------------------
/**
@@ -440,7 +442,7 @@ public class ChallengeLevel implements DataObject, Comparable
public boolean matchGameMode(String gameMode)
{
return gameMode != null &&
- this.uniqueId.regionMatches(true, 0, gameMode, 0, gameMode.length());
+ this.uniqueId.regionMatches(true, 0, gameMode, 0, gameMode.length());
}
diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java b/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java
index db306a9..c1de447 100644
--- a/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java
+++ b/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java
@@ -14,6 +14,7 @@ import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.database.objects.DataObject;
+import world.bentobox.bentobox.database.objects.Table;
import world.bentobox.bentobox.database.objects.adapters.Adapter;
import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
@@ -23,6 +24,7 @@ import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
* @author tastybento
*
*/
+@Table(name = "ChallengesPlayerData")
public class ChallengesPlayerData implements DataObject
{
/**
diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java
index b50b360..9d5dfb1 100644
--- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java
+++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java
@@ -263,7 +263,6 @@ public abstract class CommonGUI
* @param button Button that must be returned.
* @return PanelItem with requested functionality.
*/
- @SuppressWarnings("deprecation")
protected PanelItem getButton(CommonButtons button)
{
ItemStack icon;
diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java
index 216d6f1..7a65aee 100644
--- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java
+++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java
@@ -1,13 +1,16 @@
package world.bentobox.challenges.panel.admin;
-import java.util.Locale;
import java.util.function.Consumer;
import java.util.function.Function;
import org.bukkit.Material;
import org.bukkit.World;
-import org.bukkit.conversations.*;
+import org.bukkit.conversations.Conversation;
+import org.bukkit.conversations.ConversationContext;
+import org.bukkit.conversations.ConversationFactory;
+import org.bukkit.conversations.Prompt;
+import org.bukkit.conversations.ValidatingPrompt;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull;
@@ -44,10 +47,10 @@ public class AdminGUI extends CommonGUI
*/
private boolean resetAllMode;
- /**
- * This indicate if wipe button should clear all data, or only challenges.
- */
- private boolean wipeAll;
+ /**
+ * This indicate if wipe button should clear all data, or only challenges.
+ */
+ private boolean wipeAll;
// ---------------------------------------------------------------------
@@ -158,14 +161,14 @@ public class AdminGUI extends CommonGUI
// Button that deletes everything from challenges addon
- if (this.wipeAll)
- {
- panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE));
- }
- else
- {
- panelBuilder.item(34, this.createButton(Button.CHALLENGE_WIPE));
- }
+ if (this.wipeAll)
+ {
+ panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE));
+ }
+ else
+ {
+ panelBuilder.item(34, this.createButton(Button.CHALLENGE_WIPE));
+ }
panelBuilder.item(44, this.returnButton);
@@ -249,33 +252,33 @@ public class AdminGUI extends CommonGUI
clickHandler = (panel, user, clickType, slot) -> {
this.getNewUniqueID(challenge ->
+ {
+ if (challenge == null)
{
- if (challenge == null)
- {
- // Build Admin Gui if input is null.
- this.build();
- }
- else
- {
- String uniqueId = Utils.getGameMode(this.world) + "_" + challenge;
+ // Build Admin Gui if input is null.
+ this.build();
+ }
+ else
+ {
+ String uniqueId = Utils.getGameMode(this.world) + "_" + challenge;
- ChallengeTypeGUI.open(user,
+ ChallengeTypeGUI.open(user,
this.addon.getChallengesSettings().getLoreLineLength(),
(type, requirements) -> new EditChallengeGUI(this.addon,
- this.world,
- this.user,
- this.addon.getChallengesManager().createChallenge(uniqueId, type, requirements),
- this.topLabel,
- this.permissionPrefix,
- this).build());
- }
- },
- input -> {
- String uniqueId = Utils.getGameMode(this.world) + "_" + input;
- return !this.addon.getChallengesManager().containsChallenge(uniqueId);
- },
- this.user.getTranslation("challenges.gui.questions.admin.unique-id")
- );
+ this.world,
+ this.user,
+ this.addon.getChallengesManager().createChallenge(uniqueId, type, requirements),
+ this.topLabel,
+ this.permissionPrefix,
+ this).build());
+ }
+ },
+ input -> {
+ String uniqueId = Utils.getGameMode(this.world) + "_" + input;
+ return !this.addon.getChallengesManager().containsChallenge(uniqueId);
+ },
+ this.user.getTranslation("challenges.gui.questions.admin.unique-id")
+ );
return true;
};
@@ -291,31 +294,31 @@ public class AdminGUI extends CommonGUI
clickHandler = (panel, user, clickType, slot) -> {
this.getNewUniqueID(level ->
+ {
+ if (level == null)
{
- if (level == null)
- {
- // Build Admin Gui if input is null.
- this.build();
- }
- else
- {
- String newName = Utils.getGameMode(this.world) + "_" + level;
+ // Build Admin Gui if input is null.
+ this.build();
+ }
+ else
+ {
+ String newName = Utils.getGameMode(this.world) + "_" + level;
- new EditLevelGUI(this.addon,
+ new EditLevelGUI(this.addon,
this.world,
this.user,
this.addon.getChallengesManager().createLevel(newName, this.world),
this.topLabel,
this.permissionPrefix,
this).build();
- }
- },
- input -> {
- String newName = Utils.getGameMode(this.world) + "_" + input;
- return !this.addon.getChallengesManager().containsLevel(newName);
- },
- this.user.getTranslation("challenges.gui.questions.admin.unique-id")
- );
+ }
+ },
+ input -> {
+ String newName = Utils.getGameMode(this.world) + "_" + input;
+ return !this.addon.getChallengesManager().containsLevel(newName);
+ },
+ this.user.getTranslation("challenges.gui.questions.admin.unique-id")
+ );
return true;
};
@@ -482,9 +485,9 @@ public class AdminGUI extends CommonGUI
if (clickType.isRightClick())
{
- this.wipeAll = false;
- this.build();
- }
+ this.wipeAll = false;
+ this.build();
+ }
else
{
new ConfirmationGUI(this.user, value -> {
@@ -515,7 +518,7 @@ public class AdminGUI extends CommonGUI
if (clickType.isRightClick())
{
- this.wipeAll = true;
+ this.wipeAll = true;
this.build();
}
else
@@ -616,11 +619,11 @@ public class AdminGUI extends CommonGUI
clickHandler(clickHandler).
build();
}
-
-// ---------------------------------------------------------------------
-// Section: Conversation
-// ---------------------------------------------------------------------
+
+ // ---------------------------------------------------------------------
+ // Section: Conversation
+ // ---------------------------------------------------------------------
/**
@@ -630,93 +633,93 @@ public class AdminGUI extends CommonGUI
* @param question Message that will be displayed in chat when player triggers conversion.
*/
private void getNewUniqueID(Consumer consumer,
- Function stringValidation,
- @NonNull String question)
+ Function stringValidation,
+ @NonNull String question)
{
final User user = this.user;
Conversation conversation =
- new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
- new ValidatingPrompt()
- {
+ new ConversationFactory(BentoBox.getInstance()).withFirstPrompt(
+ new ValidatingPrompt()
+ {
- /**
- * Gets the text to display to the user when
- * this prompt is first presented.
- *
- * @param context Context information about the
- * conversation.
- * @return The text to display.
- */
- @Override
- public String getPromptText(ConversationContext context)
- {
- // Close input GUI.
- user.closeInventory();
+ /**
+ * Gets the text to display to the user when
+ * this prompt is first presented.
+ *
+ * @param context Context information about the
+ * conversation.
+ * @return The text to display.
+ */
+ @Override
+ public String getPromptText(ConversationContext context)
+ {
+ // Close input GUI.
+ user.closeInventory();
- // There are no editable message. Just return question.
- return question;
- }
+ // There are no editable message. Just return question.
+ return question;
+ }
- /**
- * Override this method to check the validity of
- * the player's input.
- *
- * @param context Context information about the
- * conversation.
- * @param input The player's raw console input.
- * @return True or false depending on the
- * validity of the input.
- */
- @Override
- protected boolean isInputValid(ConversationContext context, String input)
- {
- return stringValidation.apply(GuiUtils.sanitizeInput(input));
- }
+ /**
+ * Override this method to check the validity of
+ * the player's input.
+ *
+ * @param context Context information about the
+ * conversation.
+ * @param input The player's raw console input.
+ * @return True or false depending on the
+ * validity of the input.
+ */
+ @Override
+ protected boolean isInputValid(ConversationContext context, String input)
+ {
+ return stringValidation.apply(GuiUtils.sanitizeInput(input));
+ }
- /**
- * Optionally override this method to
- * display an additional message if the
- * user enters an invalid input.
- *
- * @param context Context information
- * about the conversation.
- * @param invalidInput The invalid input
- * provided by the user.
- * @return A message explaining how to
- * correct the input.
- */
- @Override
- protected String getFailedValidationText(ConversationContext context,
- String invalidInput)
- {
- return user.getTranslation("challenges.errors.unique-id", "[id]", GuiUtils.sanitizeInput(invalidInput));
- }
+ /**
+ * Optionally override this method to
+ * display an additional message if the
+ * user enters an invalid input.
+ *
+ * @param context Context information
+ * about the conversation.
+ * @param invalidInput The invalid input
+ * provided by the user.
+ * @return A message explaining how to
+ * correct the input.
+ */
+ @Override
+ protected String getFailedValidationText(ConversationContext context,
+ String invalidInput)
+ {
+ return user.getTranslation("challenges.errors.unique-id", "[id]", GuiUtils.sanitizeInput(invalidInput));
+ }
- /**
- * Override this method to accept and processes
- * the validated input from the user. Using the
- * input, the next Prompt in the prompt graph
- * should be returned.
- *
- * @param context Context information about the
- * conversation.
- * @param input The validated input text from
- * the user.
- * @return The next Prompt in the prompt graph.
- */
- @Override
- protected Prompt acceptValidatedInput(ConversationContext context, String input)
- {
- // Add answer to consumer.
- consumer.accept(GuiUtils.sanitizeInput(input));
- // End conversation
- return Prompt.END_OF_CONVERSATION;
- }
- }).
+ /**
+ * Override this method to accept and processes
+ * the validated input from the user. Using the
+ * input, the next Prompt in the prompt graph
+ * should be returned.
+ *
+ * @param context Context information about the
+ * conversation.
+ * @param input The validated input text from
+ * the user.
+ * @return The next Prompt in the prompt graph.
+ */
+ @Override
+ protected Prompt acceptValidatedInput(ConversationContext context, String input)
+ {
+ // Add answer to consumer.
+ consumer.accept(GuiUtils.sanitizeInput(input));
+ // End conversation
+ return Prompt.END_OF_CONVERSATION;
+ }
+ }).
// On cancel conversation will be closed.
withEscapeSequence("cancel").
// Use null value in consumer to detect if user has abandoned conversation.
diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml
index 2a96852..642aa64 100755
--- a/src/main/resources/addon.yml
+++ b/src/main/resources/addon.yml
@@ -1,7 +1,7 @@
name: Challenges
main: world.bentobox.challenges.ChallengesAddon
version: ${version}${build.number}
-api-version: 1.13.1
+api-version: 1.14
repository: 'BentoBoxWorld/Challenges'
metrics: true