mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-04 06:21:35 +01:00
Use essentials itemdb for charge messages.
This commit is contained in:
parent
ffae86dd42
commit
2928e8a99f
@ -21,6 +21,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||
}
|
||||
private final transient Map<String, Integer> items = new HashMap<String, Integer>();
|
||||
private final transient Map<ItemData, List<String>> names = new HashMap<ItemData, List<String>>();
|
||||
private final transient Map<ItemData, String> primaryName = new HashMap<ItemData, String>();
|
||||
private final transient Map<String, Short> durabilities = new HashMap<String, Short>();
|
||||
private final transient ManagedFile file;
|
||||
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||
@ -38,6 +39,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||
durabilities.clear();
|
||||
items.clear();
|
||||
names.clear();
|
||||
primaryName.clear();
|
||||
|
||||
for (String line : lines)
|
||||
{
|
||||
@ -72,6 +74,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||
List<String> nameList = new ArrayList<String>();
|
||||
nameList.add(itemName);
|
||||
names.put(itemData, nameList);
|
||||
primaryName.put(itemData, itemName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,6 +215,22 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||
return StringUtil.joinList(", ", nameList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name(ItemStack item)
|
||||
{
|
||||
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
|
||||
String name = primaryName.get(itemData);
|
||||
if (name == null)
|
||||
{
|
||||
itemData = new ItemData(item.getTypeId(), (short)0);
|
||||
name = primaryName.get(itemData);
|
||||
if (name == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
static class ItemData
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ public class Trade
|
||||
if (getItemStack() != null
|
||||
&& !user.getBase().getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
||||
{
|
||||
throw new ChargeException(_("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
||||
throw new ChargeException(_("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack())));
|
||||
}
|
||||
|
||||
BigDecimal money;
|
||||
|
@ -14,5 +14,7 @@ public interface IItemDb
|
||||
|
||||
public String names(ItemStack item);
|
||||
|
||||
public String name(ItemStack item);
|
||||
|
||||
List<ItemStack> getMatching(User user, String[] args) throws Exception;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user