diff --git a/Essentials/src/com/earth2me/essentials/ItemDb.java b/Essentials/src/com/earth2me/essentials/ItemDb.java index 58733ed54..18df08347 100644 --- a/Essentials/src/com/earth2me/essentials/ItemDb.java +++ b/Essentials/src/com/earth2me/essentials/ItemDb.java @@ -2,10 +2,7 @@ package com.earth2me.essentials; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IItemDb; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -20,6 +17,7 @@ public class ItemDb implements IConf, IItemDb file = new ManagedFile("items.csv", ess); } private final transient Map items = new HashMap(); + private final transient Map> names = new HashMap>(); private final transient Map durabilities = new HashMap(); private final transient ManagedFile file; @@ -35,6 +33,7 @@ public class ItemDb implements IConf, IItemDb durabilities.clear(); items.clear(); + names.clear(); for (String line : lines) { @@ -51,9 +50,25 @@ public class ItemDb implements IConf, IItemDb } final int numeric = Integer.parseInt(parts[1]); + final short data = parts.length > 2 && !parts[2].equals("0") ? Short.parseShort(parts[2]) : 0; + String itemName = parts[0].toLowerCase(Locale.ENGLISH); - 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); + durabilities.put(itemName, data); + items.put(itemName, numeric); + + ItemData itemData = new ItemData(numeric, data); + if (names.containsKey(itemData)) + { + List nameList = names.get(itemData); + nameList.add(itemName); + Collections.sort(nameList, new LengthCompare()); + } + else + { + List nameList = new ArrayList(); + nameList.add(itemName); + names.put(itemData, nameList); + } } } @@ -119,4 +134,73 @@ public class ItemDb implements IConf, IItemDb retval.setDurability(metaData); return retval; } + + public String names(ItemStack item) + { + ItemData itemData = new ItemData(item.getTypeId(), item.getDurability()); + List nameList = names.get(itemData); + if (nameList.size() > 15) + { + nameList = nameList.subList(0, 14); + } + return Util.joinList(", ", nameList); + } + + class ItemData + { + final private int itemNo; + final private short itemData; + + ItemData(final int itemNo, final short itemData) + { + this.itemNo = itemNo; + this.itemData = itemData; + } + + public int getItemNo() + { + return itemNo; + } + + public short getItemData() + { + return itemData; + } + + @Override + public int hashCode() + { + return (31 * itemNo) ^ itemData; + } + + @Override + public boolean equals(Object o) + { + if (o == null) + { + return false; + } + if (!(o instanceof ItemData)) + { + return false; + } + ItemData pairo = (ItemData)o; + return this.itemNo == pairo.getItemNo() + && this.itemData == pairo.getItemData(); + } + } + + class LengthCompare implements java.util.Comparator + { + public LengthCompare() + { + super(); + } + + @Override + public int compare(String s1, String s2) + { + return s1.length() - s2.length(); + } + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java index 71b428287..260c76693 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java @@ -36,7 +36,7 @@ public class Commanditemdb extends EssentialsCommand { itemStack = ess.getItemDb().get(args[0]); } - sender.sendMessage(itemStack.getType().toString() + "- " + itemStack.getTypeId() + ":" + Integer.toString(itemStack.getDurability())); + sender.sendMessage(_("itemType", itemStack.getType().toString(), itemStack.getTypeId() + ":" + Integer.toString(itemStack.getDurability()))); if (itemHeld && itemStack.getType() != Material.AIR) { @@ -46,6 +46,7 @@ public class Commanditemdb extends EssentialsCommand { sender.sendMessage(_("durability", Integer.toString(durability))); } - } + } + sender.sendMessage(_("itemNames", ess.getItemDb().names(itemStack))); } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index a00ea1e7f..5b81f9e3e 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 4b0879747..9149b9d90 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -452,3 +452,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index 7a23abb8a..9a463c628 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 8048bb599..f59eaca48 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index a00ea1e7f..5b81f9e3e 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index b4e8bd73a..0e8404c30 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 16173d6f2..c26976306 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index 46053ad6c..812dcbfb5 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index c3634eaad..67a8112b5 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index a56888081..cc3eaff93 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 9dc4d541f..267337191 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index 43dfa69cf..407036916 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1} diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties index 2b339f037..7b27704fa 100644 --- a/Essentials/src/messages_se.properties +++ b/Essentials/src/messages_se.properties @@ -449,3 +449,5 @@ antiBuildPlace=\u00a74You are not permitted to place {0} here. antiBuildBreak=\u00a74You are not permitted to break {0} blocks here. antiBuildUse=\u00a74You are not permitted to use {0}. antiBuildInteract=\u00a74You are not permitted to interact with {0}. +itemNames=Item short names: {0} +itemType=Item: {0} - {1}