diff --git a/pom.xml b/pom.xml
index 8003889..fce8045 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
us.tastybento
Challenges
- 0.0.1-SNAPSHOT
+ 0.0.3-SNAPSHOT
Challenges
Challenges is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like ASkyBlock or AcidIsland.
@@ -86,7 +86,7 @@
src/main/resources
- false
+ true
src/main/resources/locales
diff --git a/src/main/java/bentobox/addon/challenges/FreshSqueezedChallenges.java b/src/main/java/bentobox/addon/challenges/FreshSqueezedChallenges.java
index 374b205..9c2fa1f 100644
--- a/src/main/java/bentobox/addon/challenges/FreshSqueezedChallenges.java
+++ b/src/main/java/bentobox/addon/challenges/FreshSqueezedChallenges.java
@@ -65,7 +65,7 @@ public class FreshSqueezedChallenges {
}
makeLevels(user);
makeChallenges(user, world, overwrite);
- addon.getChallengesManager().save(true);
+ addon.getChallengesManager().save(false);
return true;
}
diff --git a/src/main/java/bentobox/addon/challenges/ParseItem.java b/src/main/java/bentobox/addon/challenges/ParseItem.java
index 9160624..7e6b93a 100644
--- a/src/main/java/bentobox/addon/challenges/ParseItem.java
+++ b/src/main/java/bentobox/addon/challenges/ParseItem.java
@@ -29,13 +29,14 @@ public class ParseItem {
*/
private ItemStack parseItem(String s) {
String[] part = s.split(":");
+ if (part.length > 0 && (part[0].equalsIgnoreCase("POTION") || part[0].equalsIgnoreCase("TIPPED_ARROW"))) {
+ return potion(s, part);
+ }
// Material:Qty
if (part.length == 2) {
return two(s, part);
} else if (part.length == 3) {
return three(s, part);
- } else if (part.length == 6 && (part[0].contains("POTION") || part[0].equalsIgnoreCase("TIPPED_ARROW"))) {
- return potion(s, part);
}
showError(s);
return null;
@@ -43,13 +44,6 @@ public class ParseItem {
}
private ItemStack potion(String s, String[] part) {
- int reqAmount = 0;
- try {
- reqAmount = Integer.parseInt(part[5]);
- } catch (Exception e) {
- addon.getLogger().severe(() -> "Could not parse the quantity of the potion or tipped arrow " + s);
- return null;
- }
/*
* # Format POTION:NAME::::QTY
# LEVEL, EXTENDED, SPLASH, LINGER are optional.
@@ -61,24 +55,67 @@ public class ParseItem {
# POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1
# POTION:WEAKNESS::::1 - any weakness potion
*/
+
ItemStack result = new ItemStack(Material.POTION);
- if (part[4].equalsIgnoreCase("SPLASH")) {
- result = new ItemStack(Material.SPLASH_POTION);
- } else if (part[4].equalsIgnoreCase("LINGER")) {
- result = new ItemStack(Material.LINGERING_POTION);
- }
if (part[0].equalsIgnoreCase("TIPPED_ARROW")) {
result = new ItemStack(Material.TIPPED_ARROW);
+ } else if (part[0].equalsIgnoreCase("SPLASH_POTION")) {
+ result = new ItemStack(Material.SPLASH_POTION);
+ } else if (part[0].equalsIgnoreCase("LINGERING_POTION")) {
+ result = new ItemStack(Material.LINGERING_POTION);
+ }
+ int reqAmount = 0;
+ String amount = "1";
+ String level = "1";
+ String ext = "";
+ String splashLinger = "";
+ switch (part.length) {
+ case 3:
+ amount = part[2];
+ break;
+ case 4:
+ level = part[2];
+ amount = part[3];
+ break;
+ case 5:
+ level = part[2];
+ ext = part[3];
+ amount = part[4];
+ break;
+ case 6:
+ level = part[2];
+ ext = part[3];
+ splashLinger = part[4];
+ amount = part[5];
+ break;
+
+ default:
+ // Because I don't know!
+ return null;
+ }
+ // Parse the quantity
+ try {
+ reqAmount = Integer.parseInt(amount);
+ } catch (Exception e) {
+ addon.getLogger().severe(() -> "Could not parse the quantity of the potion or tipped arrow " + s);
+ return null;
}
result.setAmount(reqAmount);
+
+ // Parse the legacy splash / linger
+ if (splashLinger.equalsIgnoreCase("SPLASH")) {
+ result = new ItemStack(Material.SPLASH_POTION);
+ } else if (splashLinger.equalsIgnoreCase("LINGER")) {
+ result = new ItemStack(Material.LINGERING_POTION);
+ }
+ // Parse the type of potion
PotionMeta potionMeta = (PotionMeta)(result.getItemMeta());
PotionType type = PotionType.valueOf(part[1].toUpperCase());
- boolean isUpgraded = (part[2].isEmpty() || part[2].equalsIgnoreCase("1")) ? false: true;
- boolean isExtended = part[3].equalsIgnoreCase("EXTENDED") ? true : false;
+ boolean isUpgraded = (level.isEmpty() || level.equalsIgnoreCase("1")) ? false: true;
+ boolean isExtended = ext.equalsIgnoreCase("EXTENDED") ? true : false;
PotionData data = new PotionData(type, isExtended, isUpgraded);
potionMeta.setBasePotionData(data);
-
- result.setAmount(reqAmount);
+ result.setItemMeta(potionMeta);
return result;
}
diff --git a/src/main/java/bentobox/addon/challenges/commands/admin/Challenges.java b/src/main/java/bentobox/addon/challenges/commands/admin/Challenges.java
index 237cc7b..e16d2aa 100644
--- a/src/main/java/bentobox/addon/challenges/commands/admin/Challenges.java
+++ b/src/main/java/bentobox/addon/challenges/commands/admin/Challenges.java
@@ -25,6 +25,7 @@ public class Challenges extends CompositeCommand {
// Register sub commands
new ImportCommand(getAddon(), this);
//new ShowChallenges(getAddon(), this);
+ //new CreateChallenge(getAddon(), this);
}
diff --git a/src/main/java/bentobox/addon/challenges/commands/admin/CreateChallenge.java b/src/main/java/bentobox/addon/challenges/commands/admin/CreateChallenge.java
index 3aa0edf..467af46 100644
--- a/src/main/java/bentobox/addon/challenges/commands/admin/CreateChallenge.java
+++ b/src/main/java/bentobox/addon/challenges/commands/admin/CreateChallenge.java
@@ -4,24 +4,20 @@ import java.util.List;
import bentobox.addon.challenges.ChallengesAddon;
import bentobox.addon.challenges.panel.CreateChallengeListener;
+import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.user.User;
public class CreateChallenge extends CompositeCommand {
-
- private ChallengesAddon addon;
-
/**
* Admin command to make challenges
* @param parent
*/
- public CreateChallenge(ChallengesAddon addon, CompositeCommand parent) {
- super(parent, "create");
- this.addon = addon;
+ public CreateChallenge(Addon addon, CompositeCommand parent) {
+ super(addon, parent, "create");
new CreateSurrounding(addon, this);
-
}
@Override
@@ -42,7 +38,7 @@ public class CreateChallenge extends CompositeCommand {
new PanelBuilder()
.name(args.get(0))
.size(49)
- .listener(new CreateChallengeListener(addon, user))
+ .listener(new CreateChallengeListener((ChallengesAddon) getAddon(), user))
.user(user)
.build();
return true;
diff --git a/src/main/java/bentobox/addon/challenges/commands/admin/CreateSurrounding.java b/src/main/java/bentobox/addon/challenges/commands/admin/CreateSurrounding.java
index 97aaeab..bbbf5f9 100644
--- a/src/main/java/bentobox/addon/challenges/commands/admin/CreateSurrounding.java
+++ b/src/main/java/bentobox/addon/challenges/commands/admin/CreateSurrounding.java
@@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import bentobox.addon.challenges.ChallengesAddon;
+import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
@@ -28,17 +29,14 @@ import world.bentobox.bentobox.util.Util;
*/
public class CreateSurrounding extends CompositeCommand implements Listener {
-
- private ChallengesAddon addon;
HashMap inProgress = new HashMap<>();
/**
* Admin command to make surrounding challenges
* @param parent
*/
- public CreateSurrounding(ChallengesAddon addon, CompositeCommand parent) {
- super(parent, "surrounding");
- this.addon = addon;
+ public CreateSurrounding(Addon addon, CompositeCommand parent) {
+ super(addon, parent, "surrounding");
addon.getServer().getPluginManager().registerEvents(this, addon.getPlugin());
}
@@ -58,7 +56,7 @@ public class CreateSurrounding extends CompositeCommand implements Listener {
}
// Tell user to hit objects to add to the surrounding object requirements
user.sendMessage("challenges.admin.create.surrounding.hit-things");
- inProgress.put(user.getUniqueId(), new SurroundChallengeBuilder(addon).owner(user).name(args.get(0)));
+ inProgress.put(user.getUniqueId(), new SurroundChallengeBuilder((ChallengesAddon) getAddon()).owner(user).name(args.get(0)));
return true;
}
diff --git a/src/main/java/bentobox/addon/challenges/commands/admin/ImportCommand.java b/src/main/java/bentobox/addon/challenges/commands/admin/ImportCommand.java
index 6096b3c..f35e037 100644
--- a/src/main/java/bentobox/addon/challenges/commands/admin/ImportCommand.java
+++ b/src/main/java/bentobox/addon/challenges/commands/admin/ImportCommand.java
@@ -18,7 +18,7 @@ public class ImportCommand extends CompositeCommand {
* @param cmd
*/
public ImportCommand(Addon addon, CompositeCommand cmd) {
- super(addon, cmd, "cimport");
+ super(addon, cmd, "import");
}
@Override
diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml
index 7614a21..a8e421f 100755
--- a/src/main/resources/addon.yml
+++ b/src/main/resources/addon.yml
@@ -1,6 +1,6 @@
name: BentoBox-Challenges
main: bentobox.addon.challenges.ChallengesAddon
-version: 0.1
+version: ${version}
authors: tastybento
diff --git a/src/test/java/bentobox/addon/challenges/ParseItemTest.java b/src/test/java/bentobox/addon/challenges/ParseItemTest.java
index cb0e155..ee6cc21 100644
--- a/src/test/java/bentobox/addon/challenges/ParseItemTest.java
+++ b/src/test/java/bentobox/addon/challenges/ParseItemTest.java
@@ -69,10 +69,12 @@ public class ParseItemTest {
// Material
for (Material mat : Material.values()) {
ItemStack test = new ParseItem(addon, mat.name() + ":5").getItem();
- if (test.getType().toString().endsWith("_ITEM") && !mat.toString().endsWith("_ITEM")) {
- assertEquals(mat.toString() + "_ITEM", test.getType().toString());
- } else {
- assertEquals(mat, test.getType());
+ if (test != null) {
+ if (test.getType().toString().endsWith("_ITEM") && !mat.toString().endsWith("_ITEM")) {
+ assertEquals(mat.toString() + "_ITEM", test.getType().toString());
+ } else {
+ assertEquals(mat, test.getType());
+ }
}
}
@@ -106,6 +108,8 @@ public class ParseItemTest {
test = new ParseItem(addon, "POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1").getItem();
assertEquals(Material.POTION, test.getType());
+ test = new ParseItem(addon, "POTION:JUMP:2").getItem();
+ assertEquals(Material.POTION, test.getType());
test = new ParseItem(addon, "POTION:STRENGTH:1:EXTENDED:SPLASH:1").getItem();
assertEquals(Material.SPLASH_POTION, test.getType());
test = new ParseItem(addon, "POTION:INSTANT_DAMAGE:2::LINGER:2").getItem();