mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-30 12:57:52 +01:00
Fixes parsing bug for potions.
https://github.com/BentoBoxWorld/bentobox/issues/265 Adds version from POM to addon.yml
This commit is contained in:
parent
5d2f4f3316
commit
482c95d9ce
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>us.tastybento</groupId>
|
||||
<artifactId>Challenges</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
|
||||
<name>Challenges</name>
|
||||
<description>Challenges is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like ASkyBlock or AcidIsland.</description>
|
||||
@ -86,7 +86,7 @@
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources/locales</directory>
|
||||
|
@ -65,7 +65,7 @@ public class FreshSqueezedChallenges {
|
||||
}
|
||||
makeLevels(user);
|
||||
makeChallenges(user, world, overwrite);
|
||||
addon.getChallengesManager().save(true);
|
||||
addon.getChallengesManager().save(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -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:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>: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;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ public class Challenges extends CompositeCommand {
|
||||
// Register sub commands
|
||||
new ImportCommand(getAddon(), this);
|
||||
//new ShowChallenges(getAddon(), this);
|
||||
//new CreateChallenge(getAddon(), this);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<UUID,SurroundChallengeBuilder> 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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: BentoBox-Challenges
|
||||
main: bentobox.addon.challenges.ChallengesAddon
|
||||
version: 0.1
|
||||
version: ${version}
|
||||
|
||||
authors: tastybento
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user