mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-03-02 11:11:58 +01:00
Add support for vanilla item names from api.
This commit is contained in:
parent
63300866f9
commit
f0e4e8c5ba
@ -4,8 +4,10 @@ import static com.earth2me.essentials.I18n._;
|
|||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import com.earth2me.essentials.utils.StringUtil;
|
import com.earth2me.essentials.utils.StringUtil;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -18,13 +20,13 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
|||||||
private final transient Map<ItemData, String> primaryName = new HashMap<ItemData, 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("((.*)[:+',;.](\\d+))");
|
||||||
|
|
||||||
public ItemDb(final IEssentials ess)
|
public ItemDb(final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
file = new ManagedFile("items.csv", ess);
|
file = new ManagedFile("items.csv", ess);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig()
|
public void reloadConfig()
|
||||||
@ -93,27 +95,31 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
|||||||
int itemid = 0;
|
int itemid = 0;
|
||||||
String itemname = null;
|
String itemname = null;
|
||||||
short metaData = 0;
|
short metaData = 0;
|
||||||
String[] parts = splitPattern.split(id);
|
Matcher parts = splitPattern.matcher(id);
|
||||||
if (id.matches("^\\d+[:+',;.]\\d+$"))
|
if (parts.matches())
|
||||||
{
|
{
|
||||||
itemid = Integer.parseInt(parts[0]);
|
itemname = parts.group(2);
|
||||||
metaData = Short.parseShort(parts[1]);
|
metaData = Short.parseShort(parts.group(3));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemname = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NumberUtil.isInt(itemname))
|
||||||
|
{
|
||||||
|
itemid = Integer.parseInt(itemname);
|
||||||
}
|
}
|
||||||
else if (NumberUtil.isInt(id))
|
else if (NumberUtil.isInt(id))
|
||||||
{
|
{
|
||||||
itemid = Integer.parseInt(id);
|
itemid = Integer.parseInt(id);
|
||||||
}
|
}
|
||||||
else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
|
|
||||||
{
|
|
||||||
itemname = parts[0].toLowerCase(Locale.ENGLISH);
|
|
||||||
metaData = Short.parseShort(parts[1]);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemname = id.toLowerCase(Locale.ENGLISH);
|
itemname = itemname.toLowerCase(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemname != null)
|
if (itemid < 1)
|
||||||
{
|
{
|
||||||
if (items.containsKey(itemname))
|
if (items.containsKey(itemname))
|
||||||
{
|
{
|
||||||
@ -125,15 +131,28 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
|||||||
}
|
}
|
||||||
else if (Material.getMaterial(itemname.toUpperCase(Locale.ENGLISH)) != null)
|
else if (Material.getMaterial(itemname.toUpperCase(Locale.ENGLISH)) != null)
|
||||||
{
|
{
|
||||||
itemid = Material.getMaterial(itemname.toUpperCase(Locale.ENGLISH)).getId();
|
Material bMaterial = Material.getMaterial(itemname.toUpperCase(Locale.ENGLISH));
|
||||||
metaData = 0;
|
itemid = bMaterial.getId();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception(_("unknownItemName", id));
|
try
|
||||||
|
{
|
||||||
|
Material bMaterial = Bukkit.getUnsafe().getMaterialFromInternalName(itemname.toLowerCase(Locale.ENGLISH));
|
||||||
|
itemid = bMaterial.getId();
|
||||||
|
}
|
||||||
|
catch (Throwable throwable)
|
||||||
|
{
|
||||||
|
throw new Exception(_("unknownItemName", itemname), throwable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (itemid < 1)
|
||||||
|
{
|
||||||
|
throw new Exception(_("unknownItemName", itemname));
|
||||||
|
}
|
||||||
|
|
||||||
final Material mat = Material.getMaterial(itemid);
|
final Material mat = Material.getMaterial(itemid);
|
||||||
if (mat == null)
|
if (mat == null)
|
||||||
{
|
{
|
||||||
@ -193,7 +212,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
|||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String names(ItemStack item)
|
public String names(ItemStack item)
|
||||||
{
|
{
|
||||||
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
|
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
|
||||||
@ -215,7 +234,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
|||||||
return StringUtil.joinList(", ", nameList);
|
return StringUtil.joinList(", ", nameList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String name(ItemStack item)
|
public String name(ItemStack item)
|
||||||
{
|
{
|
||||||
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
|
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
|
||||||
@ -232,6 +251,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class ItemData
|
static class ItemData
|
||||||
{
|
{
|
||||||
final private int itemNo;
|
final private int itemNo;
|
||||||
|
Loading…
Reference in New Issue
Block a user