Initial removal of item IDs.

We do not rely on Bukkit's item ids anymore, though we still support them in commands via a mapping built off of the items.csv.
This commit is contained in:
Trent Hensler 2017-12-12 22:06:25 -08:00
parent dcbc106e62
commit 1a820ad9b7
24 changed files with 225 additions and 141 deletions

View File

@ -596,7 +596,7 @@ public class EssentialsPlayerListener implements Listener {
case LEFT_CLICK_BLOCK:
if (event.getItem() != null && event.getItem().getType() != Material.AIR) {
final User user = ess.getUser(event.getPlayer());
if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getTypeId())) {
if (user.hasPowerTools() && user.arePowerToolsEnabled() && usePowertools(user, event.getItem().getType())) {
event.setCancelled(true);
}
}
@ -630,8 +630,8 @@ public class EssentialsPlayerListener implements Listener {
}
}
private boolean usePowertools(final User user, final int id) {
final List<String> commandList = user.getPowertool(id);
private boolean usePowertools(final User user, final Material material) {
final List<String> commandList = user.getPowertool(material);
if (commandList == null || commandList.isEmpty()) {
return false;
}

View File

@ -5,6 +5,7 @@ import com.earth2me.essentials.signs.EssentialsSign;
import com.earth2me.essentials.textreader.IText;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventPriority;
@ -80,7 +81,7 @@ public interface ISettings extends IConf {
int getProtectCreeperMaxHeight();
List<Integer> getProtectList(final String configName);
List<Material> getProtectList(final String configName);
boolean getProtectPreventSpawn(final String creatureName);
@ -120,7 +121,7 @@ public interface ISettings extends IConf {
boolean isTradeInStacks(int id);
List<Integer> itemSpawnBlacklist();
List<Material> itemSpawnBlacklist();
List<EssentialsSign> enabledSigns();

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.commands.IEssentialsCommand;
import net.ess3.api.ITeleport;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.math.BigDecimal;
@ -35,7 +36,7 @@ public interface IUser {
boolean canAfford(BigDecimal value);
Boolean canSpawnItem(final int itemId);
Boolean canSpawnItem(final Material material);
void setLastLocation();

View File

@ -20,6 +20,7 @@ import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionEffect;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -27,10 +28,12 @@ import static com.earth2me.essentials.I18n.tl;
public class ItemDb implements IConf, net.ess3.api.IItemDb {
protected static final Logger LOGGER = Logger.getLogger("Essentials");
private final transient IEssentials ess;
private final transient Map<String, Integer> items = new HashMap<>();
private final transient Map<ItemData, List<String>> names = new HashMap<>();
private final transient Map<ItemData, String> primaryName = new HashMap<>();
private final transient Map<Integer, ItemData> legacyIds = new HashMap<>();
private final transient Map<String, Short> durabilities = new HashMap<>();
private final transient Map<String, String> nbtData = new HashMap<>();
private final transient ManagedFile file;
@ -95,13 +98,19 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
if (itemName == null || numeric < 0) {
continue;
}
Material material = Material.matchMaterial(itemName);
if (material == null) {
LOGGER.warning(String.format("Failed to find material for %s", itemName));
continue;
}
durabilities.put(itemName, data);
items.put(itemName, numeric);
if (nbt != null) {
nbtData.put(itemName, nbt);
}
ItemData itemData = new ItemData(numeric, data);
ItemData itemData = new ItemData(material, numeric, data);
if (names.containsKey(itemData)) {
List<String> nameList = names.get(itemData);
nameList.add(itemName);
@ -111,6 +120,8 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
names.put(itemData, nameList);
primaryName.put(itemData, itemName);
}
legacyIds.put(numeric, itemData);
}
for (List<String> nameList : names.values()) {
@ -152,16 +163,6 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
if (durabilities.containsKey(itemname) && metaData == 0) {
metaData = durabilities.get(itemname);
}
} else if (Material.getMaterial(itemname.toUpperCase(Locale.ENGLISH)) != null) {
Material bMaterial = Material.getMaterial(itemname.toUpperCase(Locale.ENGLISH));
itemid = bMaterial.getId();
} else {
try {
Material bMaterial = Bukkit.getUnsafe().getMaterialFromInternalName(itemname.toLowerCase(Locale.ENGLISH));
itemid = bMaterial.getId();
} catch (Throwable throwable) {
throw new Exception(tl("unknownItemName", itemname), throwable);
}
}
}
@ -169,10 +170,12 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
throw new Exception(tl("unknownItemName", itemname));
}
final Material mat = Material.getMaterial(itemid);
if (mat == null) {
ItemData data = legacyIds.get(itemid);
if (data == null) {
throw new Exception(tl("unknownItemId", itemid));
}
Material mat = data.getMaterial();
ItemStack retval = new ItemStack(mat);
if (nbtData.containsKey(itemname)) {
String nbt = nbtData.get(itemname);
@ -241,10 +244,10 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
@Override
public String names(ItemStack item) {
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
ItemData itemData = new ItemData(item.getType(), item.getDurability());
List<String> nameList = names.get(itemData);
if (nameList == null) {
itemData = new ItemData(item.getTypeId(), (short) 0);
itemData = new ItemData(item.getType(), (short) 0);
nameList = names.get(itemData);
if (nameList == null) {
return null;
@ -259,10 +262,10 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
@Override
public String name(ItemStack item) {
ItemData itemData = new ItemData(item.getTypeId(), item.getDurability());
ItemData itemData = new ItemData(item.getType(), item.getDurability());
String name = primaryName.get(itemData);
if (name == null) {
itemData = new ItemData(item.getTypeId(), (short) 0);
itemData = new ItemData(item.getType(), (short) 0);
name = primaryName.get(itemData);
if (name == null) {
return null;
@ -415,22 +418,56 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
return sb.toString().trim().replaceAll("§", "&");
}
@Override
public Material getFromLegacyId(int id) {
ItemData data = this.legacyIds.get(id);
if(data == null) {
return null;
}
return data.getMaterial();
}
@Override
public int getLegacyId(Material material) throws Exception {
for(Map.Entry<String, Integer> entry : items.entrySet()) {
if(material.name().toLowerCase(Locale.ENGLISH).equalsIgnoreCase(entry.getKey())) {
return entry.getValue();
}
}
throw new Exception("Itemid not found for material: " + material.name());
}
@Override
public Collection<String> listNames() {
return primaryName.values();
}
static class ItemData {
final private int itemNo;
final private Material material;
private int legacyId;
final private short itemData;
ItemData(final int itemNo, final short itemData) {
this.itemNo = itemNo;
ItemData(Material material, short itemData) {
this.material = material;
this.itemData = itemData;
}
@Deprecated
ItemData(Material material, final int legacyId, final short itemData) {
this.material = material;
this.legacyId = legacyId;
this.itemData = itemData;
}
public Material getMaterial() {
return material;
}
@Deprecated
public int getItemNo() {
return itemNo;
return legacyId;
}
public short getItemData() {
@ -439,7 +476,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
@Override
public int hashCode() {
return (31 * itemNo) ^ itemData;
return (31 * material.hashCode()) ^ itemData;
}
@Override
@ -451,7 +488,7 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
return false;
}
ItemData pairo = (ItemData) o;
return this.itemNo == pairo.getItemNo() && this.itemData == pairo.getItemData();
return this.material == pairo.getMaterial() && this.itemData == pairo.getItemData();
}
}

View File

@ -10,6 +10,7 @@ import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.IEssentials;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.event.EventPriority;
@ -555,15 +556,15 @@ public class Settings implements net.ess3.api.ISettings {
unprotectedSigns = _getUnprotectedSign();
}
private List<Integer> itemSpawnBl = new ArrayList<Integer>();
private List<Material> itemSpawnBl = new ArrayList<Material>();
@Override
public List<Integer> itemSpawnBlacklist() {
public List<Material> itemSpawnBlacklist() {
return itemSpawnBl;
}
private List<Integer> _getItemSpawnBlacklist() {
final List<Integer> epItemSpwn = new ArrayList<Integer>();
private List<Material> _getItemSpawnBlacklist() {
final List<Material> epItemSpwn = new ArrayList<>();
if (ess.getItemDb() == null) {
logger.log(Level.FINE, "Aborting ItemSpawnBL read, itemDB not yet loaded.");
return epItemSpwn;
@ -575,7 +576,7 @@ public class Settings implements net.ess3.api.ISettings {
}
try {
final ItemStack iStack = ess.getItemDb().get(itemName);
epItemSpwn.add(iStack.getTypeId());
epItemSpwn.add(iStack.getType());
} catch (Exception ex) {
logger.log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"));
}
@ -685,8 +686,8 @@ public class Settings implements net.ess3.api.ISettings {
}
@Override
public List<Integer> getProtectList(final String configName) {
final List<Integer> list = new ArrayList<Integer>();
public List<Material> getProtectList(final String configName) {
final List<Material> list = new ArrayList<>();
for (String itemName : config.getString(configName, "").split(",")) {
itemName = itemName.trim();
if (itemName.isEmpty()) {
@ -695,7 +696,7 @@ public class Settings implements net.ess3.api.ISettings {
ItemStack itemStack;
try {
itemStack = ess.getItemDb().get(itemName);
list.add(itemStack.getTypeId());
list.add(itemStack.getType());
} catch (Exception ex) {
logger.log(Level.SEVERE, tl("unknownItemInList", itemName, configName));
}

View File

@ -18,6 +18,7 @@ import net.ess3.nms.refl.ReflUtil;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
@ -222,8 +223,8 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
}
@Override
public Boolean canSpawnItem(final int itemId) {
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
public Boolean canSpawnItem(final Material material) {
return !ess.getSettings().itemSpawnBlacklist().contains(material);
}
@Override

View File

@ -7,6 +7,7 @@ import net.ess3.api.IEssentials;
import net.ess3.api.InvalidWorldException;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -231,26 +232,35 @@ public abstract class UserData extends PlayerExtension implements IConf {
config.save();
}
private List<Integer> unlimited;
private List<Material> unlimited;
private List<Integer> _getUnlimited() {
return config.getIntegerList("unlimited");
private List<Material> _getUnlimited() {
List<Material> retlist = new ArrayList<>();
List<String> configList = config.getStringList("unlimited");
for(String s : configList) {
Material mat = Material.matchMaterial(s);
if(mat != null) {
retlist.add(mat);
}
}
public List<Integer> getUnlimited() {
return retlist;
}
public List<Material> getUnlimited() {
return unlimited;
}
public boolean hasUnlimited(ItemStack stack) {
return unlimited.contains(stack.getTypeId());
return unlimited.contains(stack.getType());
}
public void setUnlimited(ItemStack stack, boolean state) {
if (unlimited.contains(stack.getTypeId())) {
unlimited.remove(Integer.valueOf(stack.getTypeId()));
if (unlimited.contains(stack.getType())) {
unlimited.remove(stack.getType());
}
if (state) {
unlimited.add(stack.getTypeId());
unlimited.add(stack.getType());
}
config.setProperty("unlimited", unlimited);
config.save();
@ -262,7 +272,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
if (config.isConfigurationSection("powertools")) {
return config.getConfigurationSection("powertools").getValues(false);
}
return new HashMap<String, Object>();
return new HashMap<>();
}
public void clearAllPowertools() {
@ -273,19 +283,19 @@ public abstract class UserData extends PlayerExtension implements IConf {
@SuppressWarnings("unchecked")
public List<String> getPowertool(ItemStack stack) {
return (List<String>) powertools.get("" + stack.getTypeId());
return (List<String>) powertools.get(stack.getType().name().toLowerCase(Locale.ENGLISH));
}
@SuppressWarnings("unchecked")
public List<String> getPowertool(int id) {
return (List<String>) powertools.get("" + id);
public List<String> getPowertool(Material material) {
return (List<String>) powertools.get(material.name().toLowerCase(Locale.ENGLISH));
}
public void setPowertool(ItemStack stack, List<String> commandList) {
if (commandList == null || commandList.isEmpty()) {
powertools.remove("" + stack.getTypeId());
powertools.remove(stack.getType().name().toLowerCase(Locale.ENGLISH));
} else {
powertools.put("" + stack.getTypeId(), commandList);
powertools.put(stack.getType().name().toLowerCase(Locale.ENGLISH), commandList);
}
config.setProperty("powertools", powertools);
config.save();

View File

@ -21,9 +21,17 @@ public class Worth implements IConf {
config.load();
}
public BigDecimal getPrice(ItemStack itemStack) {
String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
public BigDecimal getPrice(IEssentials essentials, ItemStack itemStack) {
BigDecimal result;
int itemId;
try {
itemId = essentials.getItemDb().getLegacyId(itemStack.getType());
} catch (Exception e) {
return null;
}
String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
//First check for matches with item name
result = config.getBigDecimal("worth." + itemname + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
@ -42,24 +50,24 @@ public class Worth implements IConf {
//Now we should check for item ID
if (result.signum() < 0) {
result = config.getBigDecimal("worth." + itemStack.getTypeId() + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
result = config.getBigDecimal("worth." + itemId + "." + itemStack.getDurability(), BigDecimal.ONE.negate());
}
if (result.signum() < 0) {
final ConfigurationSection itemNumberMatch = config.getConfigurationSection("worth." + itemStack.getTypeId());
final ConfigurationSection itemNumberMatch = config.getConfigurationSection("worth." + itemId);
if (itemNumberMatch != null && itemNumberMatch.getKeys(false).size() == 1) {
result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".0", BigDecimal.ONE.negate());
result = config.getBigDecimal("worth." + itemId + ".0", BigDecimal.ONE.negate());
}
}
if (result.signum() < 0) {
result = config.getBigDecimal("worth." + itemStack.getTypeId() + ".*", BigDecimal.ONE.negate());
result = config.getBigDecimal("worth." + itemId + ".*", BigDecimal.ONE.negate());
}
if (result.signum() < 0) {
result = config.getBigDecimal("worth." + itemStack.getTypeId(), BigDecimal.ONE.negate());
result = config.getBigDecimal("worth." + itemId, BigDecimal.ONE.negate());
}
//This is to match the old worth syntax
if (result.signum() < 0) {
result = config.getBigDecimal("worth-" + itemStack.getTypeId(), BigDecimal.ONE.negate());
result = config.getBigDecimal("worth-" + itemId, BigDecimal.ONE.negate());
}
if (result.signum() < 0) {
return null;
@ -71,7 +79,15 @@ public class Worth implements IConf {
if (is == null || is.getType() == Material.AIR) {
throw new Exception(tl("itemSellAir"));
}
int id = is.getTypeId();
int id;
try {
id = ess.getItemDb().getLegacyId(is.getType());
} catch (Exception e) {
return 0;
}
int amount = 0;
if (args.length > 1) {
@ -123,14 +139,22 @@ public class Worth implements IConf {
return amount;
}
public void setPrice(ItemStack itemStack, double price) {
public void setPrice(IEssentials ess, ItemStack itemStack, double price) {
if (itemStack.getType().getData() == null) {
config.setProperty("worth." + itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""), price);
} else {
// Bukkit-bug: getDurability still contains the correct value, while getData().getData() is 0.
config.setProperty("worth." + itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "") + "." + itemStack.getDurability(), price);
}
config.removeProperty("worth-" + itemStack.getTypeId());
int itemId;
try {
itemId = ess.getItemDb().getLegacyId(itemStack.getType());
} catch (Exception e) {
return;
}
config.removeProperty("worth-" + itemId);
config.save();
}

View File

@ -1,6 +1,7 @@
package com.earth2me.essentials.api;
import com.earth2me.essentials.User;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
@ -21,4 +22,8 @@ public interface IItemDb {
String serialize(ItemStack is);
Collection<String> listNames();
Material getFromLegacyId(int id);
int getLegacyId(Material material) throws Exception;
}

View File

@ -31,9 +31,10 @@ public class Commandgive extends EssentialsCommand {
}
ItemStack stack = ess.getItemDb().get(args[1]);
int itemId = ess.getItemDb().getLegacyId(stack.getType());
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (sender.isPlayer() && (ess.getSettings().permissionBasedItemSpawn() ? (!ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-all") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-" + itemname) && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) : (!ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.exempt") && !ess.getUser(sender.getPlayer()).canSpawnItem(stack.getTypeId())))) {
if (sender.isPlayer() && (ess.getSettings().permissionBasedItemSpawn() ? (!ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-all") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-" + itemname) && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.item-" + itemId)) : (!ess.getUser(sender.getPlayer()).isAuthorized("essentials.itemspawn.exempt") && !ess.getUser(sender.getPlayer()).canSpawnItem(stack.getType())))) {
throw new Exception(tl("cantSpawnItem", itemname));
}

View File

@ -25,10 +25,13 @@ public class Commanditem extends EssentialsCommand {
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
ItemStack stack = ess.getItemDb().get(args[0]);
int itemId = ess.getItemDb().getLegacyId(stack.getType());
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (ess.getSettings().permissionBasedItemSpawn() ? (!user.isAuthorized("essentials.itemspawn.item-all") && !user.isAuthorized("essentials.itemspawn.item-" + itemname) && !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) : (!user.isAuthorized("essentials.itemspawn.exempt") && !user.canSpawnItem(stack.getTypeId()))) {
if (ess.getSettings().permissionBasedItemSpawn() ? (!user.isAuthorized("essentials.itemspawn.item-all") && !user.isAuthorized("essentials.itemspawn.item-" + itemname) && !user.isAuthorized("essentials.itemspawn.item-" + itemId)) : (!user.isAuthorized("essentials.itemspawn.exempt") && !user.canSpawnItem(stack.getType()))) {
throw new Exception(tl("cantSpawnItem", itemname));
}
try {

View File

@ -21,9 +21,9 @@ public class Commanditemdb extends EssentialsCommand {
ItemStack itemStack = null;
boolean itemHeld = false;
if (args.length < 1) {
if (sender.isPlayer()) {
if (sender.isPlayer() && sender.getPlayer() != null) {
itemHeld = true;
itemStack = sender.getPlayer().getItemInHand();
itemStack = sender.getPlayer().getInventory().getItemInMainHand();
}
if (itemStack == null) {
throw new NotEnoughArgumentsException();
@ -31,7 +31,9 @@ public class Commanditemdb extends EssentialsCommand {
} else {
itemStack = ess.getItemDb().get(args[0]);
}
sender.sendMessage(tl("itemType", itemStack.getType().toString(), itemStack.getTypeId() + ":" + Integer.toString(itemStack.getDurability())));
int itemId = ess.getItemDb().getLegacyId(itemStack.getType());
sender.sendMessage(tl("itemType", itemStack.getType().toString(), itemId + ":" + Integer.toString(itemStack.getDurability())));
if (itemHeld && itemStack.getType() != Material.AIR) {
int maxuses = itemStack.getType().getMaxDurability();

View File

@ -16,15 +16,18 @@ public class Commandmore extends EssentialsCommand {
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final ItemStack stack = user.getBase().getItemInHand();
final ItemStack stack = user.getBase().getInventory().getItemInMainHand();
if (stack == null) {
throw new Exception(tl("cantSpawnItem", "Air"));
}
int itemId = ess.getItemDb().getLegacyId(stack.getType());
if (stack.getAmount() >= ((user.isAuthorized("essentials.oversizedstacks")) ? ess.getSettings().getOversizedStackSize() : stack.getMaxStackSize())) {
throw new Exception(tl("fullStack"));
}
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (ess.getSettings().permissionBasedItemSpawn() ? (!user.isAuthorized("essentials.itemspawn.item-all") && !user.isAuthorized("essentials.itemspawn.item-" + itemname) && !user.isAuthorized("essentials.itemspawn.item-" + stack.getTypeId())) : (!user.isAuthorized("essentials.itemspawn.exempt") && !user.canSpawnItem(stack.getTypeId()))) {
if (ess.getSettings().permissionBasedItemSpawn() ? (!user.isAuthorized("essentials.itemspawn.item-all") && !user.isAuthorized("essentials.itemspawn.item-" + itemname) && !user.isAuthorized("essentials.itemspawn.item-" + itemId)) : (!user.isAuthorized("essentials.itemspawn.exempt") && !user.canSpawnItem(stack.getType()))) {
throw new Exception(tl("cantSpawnItem", itemname));
}
if (user.isAuthorized("essentials.oversizedstacks")) {

View File

@ -38,7 +38,7 @@ public class Commandrepair extends EssentialsCommand {
}
public void repairHand(User user) throws Exception {
final ItemStack item = user.getBase().getItemInHand();
final ItemStack item = user.getBase().getInventory().getItemInMainHand();
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
throw new Exception(tl("repairInvalidType"));
}
@ -47,8 +47,10 @@ public class Commandrepair extends EssentialsCommand {
throw new Exception(tl("repairEnchanted"));
}
int itemId = ess.getItemDb().getLegacyId(item.getType());
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + itemId, new Trade("repair-item", ess), ess), ess);
charge.isAffordableFor(user);
@ -76,7 +78,7 @@ public class Commandrepair extends EssentialsCommand {
}
private void repairItem(final ItemStack item) throws Exception {
final Material material = Material.getMaterial(item.getTypeId());
final Material material = item.getType();
if (material.isBlock() || material.getMaxDurability() < 1) {
throw new Exception(tl("repairInvalidType"));
}
@ -88,13 +90,16 @@ public class Commandrepair extends EssentialsCommand {
item.setDurability((short) 0);
}
private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired) {
private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired) throws Exception {
for (ItemStack item : items) {
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
continue;
}
int itemId = ess.getItemDb().getLegacyId(item.getType());
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + itemId, new Trade("repair-item", ess), ess), ess);
try {
charge.isAffordableFor(user);
} catch (ChargeException ex) {

View File

@ -69,7 +69,7 @@ public class Commandsell extends EssentialsCommand {
private BigDecimal sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception {
int amount = ess.getWorth().getAmount(ess, user, is, args, isBulkSell);
BigDecimal worth = ess.getWorth().getPrice(is);
BigDecimal worth = ess.getWorth().getPrice(ess, is);
if (worth == null) {
throw new Exception(tl("itemCannotBeSold"));

View File

@ -31,7 +31,7 @@ public class Commandsetworth extends EssentialsCommand {
price = args[1];
}
ess.getWorth().setPrice(stack, FloatUtil.parseDouble(price));
ess.getWorth().setPrice(ess, stack, FloatUtil.parseDouble(price));
user.sendMessage(tl("worthSet"));
}
@ -42,7 +42,7 @@ public class Commandsetworth extends EssentialsCommand {
}
ItemStack stack = ess.getItemDb().get(args[0]);
ess.getWorth().setPrice(stack, FloatUtil.parseDouble(args[1]));
ess.getWorth().setPrice(ess, stack, FloatUtil.parseDouble(args[1]));
sender.sendMessage(tl("worthSet"));
}
}

View File

@ -32,12 +32,12 @@ public class Commandunlimited extends EssentialsCommand {
final String list = getList(target);
user.sendMessage(list);
} else if (args[0].equalsIgnoreCase("clear")) {
final List<Integer> itemList = target.getUnlimited();
final List<Material> itemList = target.getUnlimited();
int index = 0;
while (itemList.size() > index) {
final Integer item = itemList.get(index);
if (toggleUnlimited(user, target, item.toString()) == false) {
final Material item = itemList.get(index);
if (!toggleUnlimited(user, target, item.toString())) {
index++;
}
}
@ -50,16 +50,16 @@ public class Commandunlimited extends EssentialsCommand {
final StringBuilder output = new StringBuilder();
output.append(tl("unlimitedItems")).append(" ");
boolean first = true;
final List<Integer> items = target.getUnlimited();
final List<Material> items = target.getUnlimited();
if (items.isEmpty()) {
output.append(tl("none"));
}
for (Integer integer : items) {
for (Material material : items) {
if (!first) {
output.append(", ");
}
first = false;
final String matname = Material.getMaterial(integer).toString().toLowerCase(Locale.ENGLISH).replace("_", "");
final String matname = material.toString().toLowerCase(Locale.ENGLISH).replace("_", "");
output.append(matname);
}

View File

@ -84,7 +84,7 @@ public class Commandworth extends EssentialsCommand {
amount = ess.getWorth().getAmount(ess, user, is, args, true);
}
BigDecimal worth = ess.getWorth().getPrice(is);
BigDecimal worth = ess.getWorth().getPrice(ess, is);
if (worth == null) {
throw new Exception(tl("itemCannotBeSold"));

View File

@ -36,15 +36,9 @@ public class BukkitConstructor extends CustomClassLoaderConstructor {
public Object construct(final Node node) {
if (node.getType().equals(Material.class)) {
final String val = (String) constructScalar((ScalarNode) node);
Material mat;
if (NumberUtil.isInt(val)) {
final int typeId = Integer.parseInt(val);
mat = Material.getMaterial(typeId);
} else {
mat = Material.matchMaterial(val);
}
return mat;
return Material.matchMaterial(val);
}
if (node.getType().equals(MaterialData.class)) {
final String val = (String) constructScalar((ScalarNode) node);
if (val.isEmpty()) {
@ -54,13 +48,9 @@ public class BukkitConstructor extends CustomClassLoaderConstructor {
if (split.length == 0) {
return null;
}
Material mat;
if (NumberUtil.isInt(split[0])) {
final int typeId = Integer.parseInt(split[0]);
mat = Material.getMaterial(typeId);
} else {
mat = Material.matchMaterial(split[0]);
}
Material mat = Material.matchMaterial(split[0]);
if (mat == null) {
return null;
}
@ -83,13 +73,9 @@ public class BukkitConstructor extends CustomClassLoaderConstructor {
if (split2.length == 0) {
return null;
}
Material mat;
if (NumberUtil.isInt(split2[0])) {
final int typeId = Integer.parseInt(split2[0]);
mat = Material.getMaterial(typeId);
} else {
mat = Material.matchMaterial(split2[0]);
}
Material mat = Material.matchMaterial(split2[0]);
if (mat == null) {
return null;
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.antibuild;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@ -10,8 +11,8 @@ import java.util.Map;
public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
private final transient Map<AntiBuildConfig, Boolean> settingsBoolean = new EnumMap<AntiBuildConfig, Boolean>(AntiBuildConfig.class);
private final transient Map<AntiBuildConfig, List<Integer>> settingsList = new EnumMap<AntiBuildConfig, List<Integer>>(AntiBuildConfig.class);
private final transient Map<AntiBuildConfig, Boolean> settingsBoolean = new EnumMap<>(AntiBuildConfig.class);
private final transient Map<AntiBuildConfig, List<Material>> settingsList = new EnumMap<>(AntiBuildConfig.class);
private transient EssentialsConnect ess = null;
@Override
@ -28,9 +29,9 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
}
@Override
public boolean checkProtectionItems(final AntiBuildConfig list, final int id) {
final List<Integer> itemList = settingsList.get(list);
return itemList != null && !itemList.isEmpty() && itemList.contains(id);
public boolean checkProtectionItems(final AntiBuildConfig list, final Material mat) {
final List<Material> itemList = settingsList.get(list);
return itemList != null && !itemList.isEmpty() && itemList.contains(mat);
}
@Override
@ -44,7 +45,7 @@ public class EssentialsAntiBuild extends JavaPlugin implements IAntiBuild {
}
@Override
public Map<AntiBuildConfig, List<Integer>> getSettingsList() {
public Map<AntiBuildConfig, List<Material>> getSettingsList() {
return settingsList;
}

View File

@ -40,16 +40,16 @@ public class EssentialsAntiBuildListener implements Listener {
}
return false;
}
return metaPermCheck(user, action, block.getTypeId(), block.getData());
return metaPermCheck(user, action, block.getType(), block.getData());
}
private boolean metaPermCheck(final User user, final String action, final int blockId) {
final String blockPerm = "essentials.build." + action + "." + blockId;
private boolean metaPermCheck(final User user, final String action, final Material material) {
final String blockPerm = "essentials.build." + action + "." + material;
return user.isAuthorized(blockPerm);
}
private boolean metaPermCheck(final User user, final String action, final int blockId, final short data) {
final String blockPerm = "essentials.build." + action + "." + blockId;
private boolean metaPermCheck(final User user, final String action, final Material material, final short data) {
final String blockPerm = "essentials.build." + action + "." + material;
final String dataPerm = blockPerm + ":" + data;
if (user.getBase().isPermissionSet(dataPerm)) {
@ -78,7 +78,7 @@ public class EssentialsAntiBuildListener implements Listener {
return;
}
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, typeId) && !user.isAuthorized("essentials.protect.exemptplacement")) {
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_placement, type) && !user.isAuthorized("essentials.protect.exemptplacement")) {
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildPlace", type.toString()));
}
@ -86,7 +86,7 @@ public class EssentialsAntiBuildListener implements Listener {
return;
}
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, typeId) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_placement, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertPlaced"));
}
}
@ -106,7 +106,7 @@ public class EssentialsAntiBuildListener implements Listener {
return;
}
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, typeId) && !user.isAuthorized("essentials.protect.exemptbreak")) {
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_break, type) && !user.isAuthorized("essentials.protect.exemptbreak")) {
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildBreak", type.toString()));
}
@ -114,7 +114,7 @@ public class EssentialsAntiBuildListener implements Listener {
return;
}
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, typeId) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
if (prot.checkProtectionItems(AntiBuildConfig.alert_on_break, type) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
prot.getEssentialsConnect().alert(user, type.toString(), tl("alertBroke"));
}
}
@ -127,12 +127,12 @@ public class EssentialsAntiBuildListener implements Listener {
final EntityType type = event.getEntity().getType();
final boolean warn = ess.getSettings().warnOnBuildDisallow();
if (prot.getSettingBool(AntiBuildConfig.disable_build) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING.getId())) {
if (type == EntityType.PAINTING && !metaPermCheck(user, "break", Material.PAINTING)) {
if (warn) {
user.sendMessage(tl("antiBuildBreak", Material.PAINTING.toString()));
}
event.setCancelled(true);
} else if (type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME.getId())) {
} else if (type == EntityType.ITEM_FRAME && !metaPermCheck(user, "break", Material.ITEM_FRAME)) {
if (warn) {
user.sendMessage(tl("antiBuildBreak", Material.ITEM_FRAME.toString()));
}
@ -145,7 +145,7 @@ public class EssentialsAntiBuildListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
for (Block block : event.getBlocks()) {
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) {
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getType())) {
event.setCancelled(true);
return;
}
@ -158,7 +158,7 @@ public class EssentialsAntiBuildListener implements Listener {
return;
}
final Block block = event.getBlock();
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getTypeId())) {
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_piston, block.getType())) {
event.setCancelled(true);
}
}
@ -169,7 +169,7 @@ public class EssentialsAntiBuildListener implements Listener {
final User user = ess.getUser(event.getPlayer());
final ItemStack item = event.getItem();
if (item != null && prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getTypeId()) && !user.isAuthorized("essentials.protect.exemptusage")) {
if (item != null && prot.checkProtectionItems(AntiBuildConfig.blacklist_usage, item.getType()) && !user.isAuthorized("essentials.protect.exemptusage")) {
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
}
@ -177,12 +177,12 @@ public class EssentialsAntiBuildListener implements Listener {
return;
}
if (item != null && prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getTypeId()) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
if (item != null && prot.checkProtectionItems(AntiBuildConfig.alert_on_use, item.getType()) && !user.isAuthorized("essentials.protect.alerts.notrigger")) {
prot.getEssentialsConnect().alert(user, item.getType().toString(), tl("alertUsed"));
}
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (event.hasItem() && !metaPermCheck(user, "interact", item.getTypeId(), item.getDurability())) {
if (event.hasItem() && !metaPermCheck(user, "interact", item.getType(), item.getDurability())) {
event.setCancelled(true);
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildUse", item.getType().toString()));
@ -207,7 +207,7 @@ public class EssentialsAntiBuildListener implements Listener {
final ItemStack item = event.getRecipe().getResult();
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability())) {
if (!metaPermCheck(user, "craft", item.getType(), item.getDurability())) {
event.setCancelled(true);
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildCraft", item.getType().toString()));
@ -224,7 +224,7 @@ public class EssentialsAntiBuildListener implements Listener {
final ItemStack item = event.getItem().getItemStack();
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getDurability())) {
if (!metaPermCheck(user, "pickup", item.getType(), item.getDurability())) {
event.setCancelled(true);
event.getItem().setPickupDelay(50);
}
@ -238,7 +238,7 @@ public class EssentialsAntiBuildListener implements Listener {
final ItemStack item = event.getItemDrop().getItemStack();
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (!metaPermCheck(user, "drop", item.getTypeId(), item.getDurability())) {
if (!metaPermCheck(user, "drop", item.getType(), item.getDurability())) {
event.setCancelled(true);
user.getBase().updateInventory();
if (ess.getSettings().warnOnBuildDisallow()) {
@ -251,7 +251,7 @@ public class EssentialsAntiBuildListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDispense(final BlockDispenseEvent event) {
final ItemStack item = event.getItem();
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_dispenser, item.getTypeId())) {
if (prot.checkProtectionItems(AntiBuildConfig.blacklist_dispenser, item.getType())) {
event.setCancelled(true);
}
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.antibuild;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
import java.util.List;
@ -7,7 +8,7 @@ import java.util.Map;
public interface IAntiBuild extends Plugin {
boolean checkProtectionItems(final AntiBuildConfig list, final int id);
boolean checkProtectionItems(final AntiBuildConfig list, final Material mat);
boolean getSettingBool(final AntiBuildConfig protectConfig);
@ -15,5 +16,5 @@ public interface IAntiBuild extends Plugin {
Map<AntiBuildConfig, Boolean> getSettingsBoolean();
Map<AntiBuildConfig, List<Integer>> getSettingsList();
Map<AntiBuildConfig, List<Material>> getSettingsList();
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.protect;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@ -14,9 +15,9 @@ import java.util.logging.Logger;
public class EssentialsProtect extends JavaPlugin implements IProtect {
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private final Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<ProtectConfig, Boolean>(ProtectConfig.class);
private final Map<ProtectConfig, String> settingsString = new EnumMap<ProtectConfig, String>(ProtectConfig.class);
private final Map<ProtectConfig, List<Integer>> settingsList = new EnumMap<ProtectConfig, List<Integer>>(ProtectConfig.class);
private final Map<ProtectConfig, Boolean> settingsBoolean = new EnumMap<>(ProtectConfig.class);
private final Map<ProtectConfig, String> settingsString = new EnumMap<>(ProtectConfig.class);
private final Map<ProtectConfig, List<Material>> settingsList = new EnumMap<>(ProtectConfig.class);
private EssentialsConnect ess = null;
@Override
@ -65,7 +66,7 @@ public class EssentialsProtect extends JavaPlugin implements IProtect {
}
@Override
public Map<ProtectConfig, List<Integer>> getSettingsList() {
public Map<ProtectConfig, List<Material>> getSettingsList() {
return settingsList;
}

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.protect;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
import java.util.List;
@ -17,5 +18,5 @@ public interface IProtect extends Plugin {
Map<ProtectConfig, String> getSettingsString();
Map<ProtectConfig, List<Integer>> getSettingsList();
Map<ProtectConfig, List<Material>> getSettingsList();
}