mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 13:36:06 +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>
|
<groupId>us.tastybento</groupId>
|
||||||
<artifactId>Challenges</artifactId>
|
<artifactId>Challenges</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.3-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>Challenges</name>
|
<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>
|
<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>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources</directory>
|
<directory>src/main/resources</directory>
|
||||||
<filtering>false</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>src/main/resources/locales</directory>
|
<directory>src/main/resources/locales</directory>
|
||||||
|
@ -65,7 +65,7 @@ public class FreshSqueezedChallenges {
|
|||||||
}
|
}
|
||||||
makeLevels(user);
|
makeLevels(user);
|
||||||
makeChallenges(user, world, overwrite);
|
makeChallenges(user, world, overwrite);
|
||||||
addon.getChallengesManager().save(true);
|
addon.getChallengesManager().save(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,13 +29,14 @@ public class ParseItem {
|
|||||||
*/
|
*/
|
||||||
private ItemStack parseItem(String s) {
|
private ItemStack parseItem(String s) {
|
||||||
String[] part = s.split(":");
|
String[] part = s.split(":");
|
||||||
|
if (part.length > 0 && (part[0].equalsIgnoreCase("POTION") || part[0].equalsIgnoreCase("TIPPED_ARROW"))) {
|
||||||
|
return potion(s, part);
|
||||||
|
}
|
||||||
// Material:Qty
|
// Material:Qty
|
||||||
if (part.length == 2) {
|
if (part.length == 2) {
|
||||||
return two(s, part);
|
return two(s, part);
|
||||||
} else if (part.length == 3) {
|
} else if (part.length == 3) {
|
||||||
return three(s, part);
|
return three(s, part);
|
||||||
} else if (part.length == 6 && (part[0].contains("POTION") || part[0].equalsIgnoreCase("TIPPED_ARROW"))) {
|
|
||||||
return potion(s, part);
|
|
||||||
}
|
}
|
||||||
showError(s);
|
showError(s);
|
||||||
return null;
|
return null;
|
||||||
@ -43,13 +44,6 @@ public class ParseItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack potion(String s, String[] part) {
|
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
|
* # Format POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY
|
||||||
# LEVEL, EXTENDED, SPLASH, LINGER are optional.
|
# LEVEL, EXTENDED, SPLASH, LINGER are optional.
|
||||||
@ -61,24 +55,67 @@ public class ParseItem {
|
|||||||
# POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1
|
# POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1
|
||||||
# POTION:WEAKNESS::::1 - any weakness potion
|
# POTION:WEAKNESS::::1 - any weakness potion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ItemStack result = new ItemStack(Material.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")) {
|
if (part[0].equalsIgnoreCase("TIPPED_ARROW")) {
|
||||||
result = new ItemStack(Material.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);
|
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());
|
PotionMeta potionMeta = (PotionMeta)(result.getItemMeta());
|
||||||
PotionType type = PotionType.valueOf(part[1].toUpperCase());
|
PotionType type = PotionType.valueOf(part[1].toUpperCase());
|
||||||
boolean isUpgraded = (part[2].isEmpty() || part[2].equalsIgnoreCase("1")) ? false: true;
|
boolean isUpgraded = (level.isEmpty() || level.equalsIgnoreCase("1")) ? false: true;
|
||||||
boolean isExtended = part[3].equalsIgnoreCase("EXTENDED") ? true : false;
|
boolean isExtended = ext.equalsIgnoreCase("EXTENDED") ? true : false;
|
||||||
PotionData data = new PotionData(type, isExtended, isUpgraded);
|
PotionData data = new PotionData(type, isExtended, isUpgraded);
|
||||||
potionMeta.setBasePotionData(data);
|
potionMeta.setBasePotionData(data);
|
||||||
|
result.setItemMeta(potionMeta);
|
||||||
result.setAmount(reqAmount);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ public class Challenges extends CompositeCommand {
|
|||||||
// Register sub commands
|
// Register sub commands
|
||||||
new ImportCommand(getAddon(), this);
|
new ImportCommand(getAddon(), this);
|
||||||
//new ShowChallenges(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.ChallengesAddon;
|
||||||
import bentobox.addon.challenges.panel.CreateChallengeListener;
|
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.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
|
||||||
public class CreateChallenge extends CompositeCommand {
|
public class CreateChallenge extends CompositeCommand {
|
||||||
|
|
||||||
|
|
||||||
private ChallengesAddon addon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin command to make challenges
|
* Admin command to make challenges
|
||||||
* @param parent
|
* @param parent
|
||||||
*/
|
*/
|
||||||
public CreateChallenge(ChallengesAddon addon, CompositeCommand parent) {
|
public CreateChallenge(Addon addon, CompositeCommand parent) {
|
||||||
super(parent, "create");
|
super(addon, parent, "create");
|
||||||
this.addon = addon;
|
|
||||||
new CreateSurrounding(addon, this);
|
new CreateSurrounding(addon, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,7 +38,7 @@ public class CreateChallenge extends CompositeCommand {
|
|||||||
new PanelBuilder()
|
new PanelBuilder()
|
||||||
.name(args.get(0))
|
.name(args.get(0))
|
||||||
.size(49)
|
.size(49)
|
||||||
.listener(new CreateChallengeListener(addon, user))
|
.listener(new CreateChallengeListener((ChallengesAddon) getAddon(), user))
|
||||||
.user(user)
|
.user(user)
|
||||||
.build();
|
.build();
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import bentobox.addon.challenges.ChallengesAddon;
|
import bentobox.addon.challenges.ChallengesAddon;
|
||||||
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
@ -28,17 +29,14 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
public class CreateSurrounding extends CompositeCommand implements Listener {
|
public class CreateSurrounding extends CompositeCommand implements Listener {
|
||||||
|
|
||||||
|
|
||||||
private ChallengesAddon addon;
|
|
||||||
HashMap<UUID,SurroundChallengeBuilder> inProgress = new HashMap<>();
|
HashMap<UUID,SurroundChallengeBuilder> inProgress = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Admin command to make surrounding challenges
|
* Admin command to make surrounding challenges
|
||||||
* @param parent
|
* @param parent
|
||||||
*/
|
*/
|
||||||
public CreateSurrounding(ChallengesAddon addon, CompositeCommand parent) {
|
public CreateSurrounding(Addon addon, CompositeCommand parent) {
|
||||||
super(parent, "surrounding");
|
super(addon, parent, "surrounding");
|
||||||
this.addon = addon;
|
|
||||||
addon.getServer().getPluginManager().registerEvents(this, addon.getPlugin());
|
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
|
// Tell user to hit objects to add to the surrounding object requirements
|
||||||
user.sendMessage("challenges.admin.create.surrounding.hit-things");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public class ImportCommand extends CompositeCommand {
|
|||||||
* @param cmd
|
* @param cmd
|
||||||
*/
|
*/
|
||||||
public ImportCommand(Addon addon, CompositeCommand cmd) {
|
public ImportCommand(Addon addon, CompositeCommand cmd) {
|
||||||
super(addon, cmd, "cimport");
|
super(addon, cmd, "import");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: BentoBox-Challenges
|
name: BentoBox-Challenges
|
||||||
main: bentobox.addon.challenges.ChallengesAddon
|
main: bentobox.addon.challenges.ChallengesAddon
|
||||||
version: 0.1
|
version: ${version}
|
||||||
|
|
||||||
authors: tastybento
|
authors: tastybento
|
||||||
|
|
||||||
|
@ -69,10 +69,12 @@ public class ParseItemTest {
|
|||||||
// Material
|
// Material
|
||||||
for (Material mat : Material.values()) {
|
for (Material mat : Material.values()) {
|
||||||
ItemStack test = new ParseItem(addon, mat.name() + ":5").getItem();
|
ItemStack test = new ParseItem(addon, mat.name() + ":5").getItem();
|
||||||
if (test.getType().toString().endsWith("_ITEM") && !mat.toString().endsWith("_ITEM")) {
|
if (test != null) {
|
||||||
assertEquals(mat.toString() + "_ITEM", test.getType().toString());
|
if (test.getType().toString().endsWith("_ITEM") && !mat.toString().endsWith("_ITEM")) {
|
||||||
} else {
|
assertEquals(mat.toString() + "_ITEM", test.getType().toString());
|
||||||
assertEquals(mat, test.getType());
|
} else {
|
||||||
|
assertEquals(mat, test.getType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +108,8 @@ public class ParseItemTest {
|
|||||||
|
|
||||||
test = new ParseItem(addon, "POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1").getItem();
|
test = new ParseItem(addon, "POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1").getItem();
|
||||||
assertEquals(Material.POTION, test.getType());
|
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();
|
test = new ParseItem(addon, "POTION:STRENGTH:1:EXTENDED:SPLASH:1").getItem();
|
||||||
assertEquals(Material.SPLASH_POTION, test.getType());
|
assertEquals(Material.SPLASH_POTION, test.getType());
|
||||||
test = new ParseItem(addon, "POTION:INSTANT_DAMAGE:2::LINGER:2").getItem();
|
test = new ParseItem(addon, "POTION:INSTANT_DAMAGE:2::LINGER:2").getItem();
|
||||||
|
Loading…
Reference in New Issue
Block a user