mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 12:02:53 +00:00
Use essentials itemdb for charge messages.
This commit is contained in:
parent
ffae86dd42
commit
2928e8a99f
3 changed files with 25 additions and 4 deletions
|
@ -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<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, 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 Map<String, Short> durabilities = new HashMap<String, Short>();
|
||||||
private final transient ManagedFile file;
|
private final transient ManagedFile file;
|
||||||
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
private final transient Pattern splitPattern = Pattern.compile("[:+',;.]");
|
||||||
|
@ -38,6 +39,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||||
durabilities.clear();
|
durabilities.clear();
|
||||||
items.clear();
|
items.clear();
|
||||||
names.clear();
|
names.clear();
|
||||||
|
primaryName.clear();
|
||||||
|
|
||||||
for (String line : lines)
|
for (String line : lines)
|
||||||
{
|
{
|
||||||
|
@ -68,10 +70,11 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||||
Collections.sort(nameList, new LengthCompare());
|
Collections.sort(nameList, new LengthCompare());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<String> nameList = new ArrayList<String>();
|
List<String> nameList = new ArrayList<String>();
|
||||||
nameList.add(itemName);
|
nameList.add(itemName);
|
||||||
names.put(itemData, nameList);
|
names.put(itemData, nameList);
|
||||||
|
primaryName.put(itemData, itemName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,8 +214,24 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
||||||
}
|
}
|
||||||
return StringUtil.joinList(", ", nameList);
|
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
|
static class ItemData
|
||||||
{
|
{
|
||||||
final private int itemNo;
|
final private int itemNo;
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class Trade
|
||||||
if (getItemStack() != null
|
if (getItemStack() != null
|
||||||
&& !user.getBase().getInventory().containsAtLeast(itemStack, itemStack.getAmount()))
|
&& !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;
|
BigDecimal money;
|
||||||
|
|
|
@ -14,5 +14,7 @@ public interface IItemDb
|
||||||
|
|
||||||
public String names(ItemStack item);
|
public String names(ItemStack item);
|
||||||
|
|
||||||
|
public String name(ItemStack item);
|
||||||
|
|
||||||
List<ItemStack> getMatching(User user, String[] args) throws Exception;
|
List<ItemStack> getMatching(User user, String[] args) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue