summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-12-21 03:28:18 +0000
committerKHobbits <rob@khobbits.co.uk>2013-12-21 03:33:27 +0000
commitb6b2ee61a4031f21977f4b39ff46fcf673d2d99d (patch)
tree767f3a31cdb66eaef337c0af226c29ea01a5c448
parent6362dbd5b3b21d46877f2e62eafcef2880cbbfc6 (diff)
downloadEssentials-b6b2ee61a4031f21977f4b39ff46fcf673d2d99d.tar
Essentials-b6b2ee61a4031f21977f4b39ff46fcf673d2d99d.tar.gz
Essentials-b6b2ee61a4031f21977f4b39ff46fcf673d2d99d.tar.lz
Essentials-b6b2ee61a4031f21977f4b39ff46fcf673d2d99d.tar.xz
Essentials-b6b2ee61a4031f21977f4b39ff46fcf673d2d99d.zip
Don't check for default worth durability if more than one durability price is defined.
This also adds support for '*' durability matching 'other'.
-rw-r--r--Essentials/src/com/earth2me/essentials/Worth.java37
1 files changed, 31 insertions, 6 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Worth.java b/Essentials/src/com/earth2me/essentials/Worth.java
index fe197b1a4..9c50e2ae4 100644
--- a/Essentials/src/com/earth2me/essentials/Worth.java
+++ b/Essentials/src/com/earth2me/essentials/Worth.java
@@ -7,6 +7,7 @@ import java.math.BigDecimal;
import java.util.Locale;
import java.util.logging.Logger;
import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
@@ -26,27 +27,49 @@ public class Worth implements IConf
{
String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
BigDecimal result;
+
+ //First check for matches with item name
result = config.getBigDecimal("worth." + itemname + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
if (result.signum() < 0)
{
- result = config.getBigDecimal("worth." + itemname + ".0", BigDecimal.ONE.negate());
+ final ConfigurationSection itemNameMatch = config.getConfigurationSection("worth." + itemname);
+ if (itemNameMatch != null && itemNameMatch.getKeys(false).size() == 1)
+ {
+ result = config.getBigDecimal("worth." + itemname + ".0", BigDecimal.ONE.negate());
+ }
+ }
+ if (result.signum() < 0)
+ {
+ result = config.getBigDecimal("worth." + itemname + ".*", BigDecimal.ONE.negate());
}
if (result.signum() < 0)
{
result = config.getBigDecimal("worth." + itemname, BigDecimal.ONE.negate());
}
+
+ //Now we should check for item ID
if (result.signum() < 0)
{
result = config.getBigDecimal("worth." + itemStack.getTypeId() + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
- }
+ }
if (result.signum() < 0)
{
- result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".0", BigDecimal.ONE.negate());
+ final ConfigurationSection itemNumberMatch = config.getConfigurationSection("worth." + itemStack.getTypeId());
+ if (itemNumberMatch != null && itemNumberMatch.getKeys(false).size() == 1)
+ {
+ result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".0", BigDecimal.ONE.negate());
+ }
+ }
+ if (result.signum() < 0)
+ {
+ result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".*", BigDecimal.ONE.negate());
}
if (result.signum() < 0)
{
result = config.getBigDecimal("worth." + itemStack.getTypeId(), BigDecimal.ONE.negate());
- }
+ }
+
+ //This is to match the old worth syntax
if (result.signum() < 0)
{
result = config.getBigDecimal("worth-" + itemStack.getTypeId(), BigDecimal.ONE.negate());
@@ -69,10 +92,12 @@ public class Worth implements IConf
if (args.length > 1)
{
- try {
+ try
+ {
amount = Integer.parseInt(args[1].replaceAll("[^0-9]", ""));
}
- catch (NumberFormatException ex) {
+ catch (NumberFormatException ex)
+ {
throw new NotEnoughArgumentsException(ex);
}
if (args[1].startsWith("-"))