diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index 3ac4326f7..775c0df4e 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.regex.Pattern; import lombok.Cleanup; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -22,9 +23,9 @@ public class ItemDb implements IItemDb this.ess = ess; file = new ManagedFile("items.csv", ess); } - private final transient Map items = new HashMap(); - private final transient Map durabilities = new HashMap(); + private final transient Map items = new HashMap(); private final transient ManagedFile file; + private static final Pattern SPLIT = Pattern.compile("[^a-zA-Z0-9]"); @Override public void onReload() @@ -36,55 +37,54 @@ public class ItemDb implements IItemDb return; } - durabilities.clear(); items.clear(); for (String line : lines) { - line = line.trim().toLowerCase(Locale.ENGLISH); + line = line.trim(); if (line.length() > 0 && line.charAt(0) == '#') { continue; } - final String[] parts = line.split("[^a-z0-9]"); + final String[] parts = SPLIT.split(line); if (parts.length < 2) { continue; } - final int numeric = Integer.parseInt(parts[1]); + final long numeric = Integer.parseInt(parts[1]); - durabilities.put(parts[0].toLowerCase(Locale.ENGLISH), parts.length > 2 && !parts[2].equals("0") ? Short.parseShort(parts[2]) : 0); - items.put(parts[0].toLowerCase(Locale.ENGLISH), numeric); + final long durability = parts.length > 2 && !(parts[2].length() == 1 && parts[2].charAt(0) == '0') ? Short.parseShort(parts[2]) : 0; + items.put(parts[0].toLowerCase(Locale.ENGLISH), numeric | (durability << 32)); } } public ItemStack get(final String id, final IUser user) throws Exception { final ItemStack stack = get(id.toLowerCase(Locale.ENGLISH)); - - int defaultStackSize = 0; - int oversizedStackSize = 0; + @Cleanup com.earth2me.essentials.api.ISettings settings = ess.getSettings(); settings.acquireReadLock(); - - defaultStackSize = settings.getData().getGeneral().getDefaultStacksize(); - oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize(); - + + final int defaultStackSize = settings.getData().getGeneral().getDefaultStacksize(); + if (defaultStackSize > 0) { stack.setAmount(defaultStackSize); } - else if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks")) + else { - stack.setAmount(oversizedStackSize); + final int oversizedStackSize = settings.getData().getGeneral().getOversizedStacksize(); + if (oversizedStackSize > 0 && user.isAuthorized("essentials.oversizedstacks")) + { + stack.setAmount(oversizedStackSize); + } } - return stack; } - + public ItemStack get(final String id, final int quantity) throws Exception { final ItemStack retval = get(id.toLowerCase(Locale.ENGLISH)); @@ -120,10 +120,11 @@ public class ItemDb implements IItemDb { if (items.containsKey(itemname)) { - itemid = items.get(itemname); - if (durabilities.containsKey(itemname) && metaData == 0) + long item = items.get(itemname); + itemid = (int)(item & 0xffffffffL); + if (metaData == 0) { - metaData = durabilities.get(itemname); + metaData = (short)((item >> 32) & 0xffffL); } } else if (Material.getMaterial(itemname) != null)