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
commit7e69cd2270ef6c80d43c0622ddcee8650a9c5a77 (patch)
tree64ec4428c434e35737595d55b5a49745e4be708b
parentd8386f33fd039fc4b3bcae2aec88dab9923915ca (diff)
downloadEssentials-7e69cd2270ef6c80d43c0622ddcee8650a9c5a77.tar
Essentials-7e69cd2270ef6c80d43c0622ddcee8650a9c5a77.tar.gz
Essentials-7e69cd2270ef6c80d43c0622ddcee8650a9c5a77.tar.lz
Essentials-7e69cd2270ef6c80d43c0622ddcee8650a9c5a77.tar.xz
Essentials-7e69cd2270ef6c80d43c0622ddcee8650a9c5a77.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("-"))