From 247b65c9e12d39651d9bddeb0499897695f6db7a Mon Sep 17 00:00:00 2001 From: Acrobot Date: Mon, 13 Jun 2011 00:59:10 +0200 Subject: [PATCH] - Corrected a mistake with default protection - Made it possible to write item names such as "Red Wool" - Slightly speeded up configuration reading --- com/Acrobot/ChestShop/Config/Config.java | 2 +- com/Acrobot/ChestShop/Items/DataValue.java | 39 +++++++++++++++++++ com/Acrobot/ChestShop/Items/Items.java | 37 +++++++----------- .../ChestShop/Listeners/playerInteract.java | 4 +- plugin.yml | 2 +- 5 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 com/Acrobot/ChestShop/Items/DataValue.java diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index 9321b49..d025eb8 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -53,7 +53,7 @@ public class Config { } public static String getString(Property value){ - return getColored((String) getValue(value.name())); + return (String) getValue(value.name()); } public static int getInteger(Property value){ diff --git a/com/Acrobot/ChestShop/Items/DataValue.java b/com/Acrobot/ChestShop/Items/DataValue.java new file mode 100644 index 0000000..7cd8bc7 --- /dev/null +++ b/com/Acrobot/ChestShop/Items/DataValue.java @@ -0,0 +1,39 @@ +package com.Acrobot.ChestShop.Items; + +import org.bukkit.CoalType; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.TreeSpecies; +import org.bukkit.material.*; + +/** + * @author Acrobot + */ +public class DataValue { + public static byte get(String arg, Material material){ + arg = arg.toUpperCase().replace(" ", "_"); + + + MaterialData materialData = null; + + switch (material){ + case SAPLING: + case LOG: + materialData = new Tree(TreeSpecies.valueOf(arg)); + break; + case STEP: + case DOUBLE_STEP: + materialData = new Step(Items.getMat(arg)); + break; + case WOOL: + case INK_SACK: + materialData = new Wool(DyeColor.valueOf(arg)); + break; + case COAL: + materialData = new Coal(CoalType.valueOf(arg)); + break; + } + + return (materialData == null ? 0 : materialData.getData()); + } +} diff --git a/com/Acrobot/ChestShop/Items/Items.java b/com/Acrobot/ChestShop/Items/Items.java index 78bf229..bb2ea3a 100644 --- a/com/Acrobot/ChestShop/Items/Items.java +++ b/com/Acrobot/ChestShop/Items/Items.java @@ -10,15 +10,10 @@ import org.bukkit.inventory.ItemStack; */ public class Items { - public static String getItemName(ItemStack itemStack) { - return getItemName(itemStack.getType().name()); - } - - public static String getItemName(String itemName) { - return getMat(itemName).name(); - } - public static Material getMat(String itemName) { + if (Numerical.isInteger(itemName)) { + return Material.getMaterial(Integer.parseInt(itemName)); + } int length = 256; Material finalMat = null; itemName = itemName.toLowerCase().replace("_", "").replace(" ", ""); @@ -32,10 +27,6 @@ public class Items { return finalMat; } - public static int getItemID(String itemName) { - return getMat(itemName).getId(); - } - public static ItemStack getItemStack(String itemName) { if (Odd.isInitialized()) { ItemStack odd = Odd.returnItemStack(itemName.replace(":", ";")); @@ -47,18 +38,20 @@ public class Items { itemName = split[0]; short dataValue = (short) (split.length > 1 && Numerical.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0); - if (Numerical.isInteger(itemName)) { - Material mat = Material.getMaterial(Integer.parseInt(itemName)); - return mat == null ? null : new ItemStack(mat, 1, dataValue); - } + Material mat; - Material mat = getMat(itemName); + String[] data = itemName.split(" "); + if(data.length >= 2){ + mat = getMat(itemName.substring(itemName.indexOf(' '))); + byte argData = DataValue.get(data[0], mat); + + if(argData != 0){ + dataValue = argData; + } + } else{ + mat = getMat(itemName); + } return (mat != null ? new ItemStack(mat, 1, dataValue) : null); } - - public static Material getMaterial(String name) { - ItemStack is = getItemStack(name); - return is != null ? is.getType() : null; - } } diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index f0d0b68..08539ec 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Language; import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Permission; +import com.Acrobot.ChestShop.Protection.Default; import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Shop.ShopManagement; import com.Acrobot.ChestShop.Utils.SearchForBlock; @@ -43,7 +44,8 @@ public class playerInteract extends PlayerListener { Block block = event.getClickedBlock(); if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) { - if (!Permission.has(player, Permission.ADMIN) && Security.isProtected(block) && !Security.canAccess(player, block)) { + Default defProtection = new Default(); + if (!Permission.has(player, Permission.ADMIN) && (defProtection.isProtected(block) && !defProtection.canAccess(player, block)) || (Security.isProtected(block) && !Security.canAccess(player, block))) { player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); event.setCancelled(true); return; diff --git a/plugin.yml b/plugin.yml index cb628bd..c5f157c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop database: true -version: 3.00 +version: 3.00 BETA 2 author: Acrobot