- Corrected a mistake with default protection
- Made it possible to write item names such as "Red Wool" - Slightly speeded up configuration reading
This commit is contained in:
parent
fbc87e8977
commit
247b65c9e1
|
@ -53,7 +53,7 @@ public class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString(Property value){
|
public static String getString(Property value){
|
||||||
return getColored((String) getValue(value.name()));
|
return (String) getValue(value.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInteger(Property value){
|
public static int getInteger(Property value){
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,15 +10,10 @@ import org.bukkit.inventory.ItemStack;
|
||||||
*/
|
*/
|
||||||
public class Items {
|
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) {
|
public static Material getMat(String itemName) {
|
||||||
|
if (Numerical.isInteger(itemName)) {
|
||||||
|
return Material.getMaterial(Integer.parseInt(itemName));
|
||||||
|
}
|
||||||
int length = 256;
|
int length = 256;
|
||||||
Material finalMat = null;
|
Material finalMat = null;
|
||||||
itemName = itemName.toLowerCase().replace("_", "").replace(" ", "");
|
itemName = itemName.toLowerCase().replace("_", "").replace(" ", "");
|
||||||
|
@ -32,10 +27,6 @@ public class Items {
|
||||||
return finalMat;
|
return finalMat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getItemID(String itemName) {
|
|
||||||
return getMat(itemName).getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getItemStack(String itemName) {
|
public static ItemStack getItemStack(String itemName) {
|
||||||
if (Odd.isInitialized()) {
|
if (Odd.isInitialized()) {
|
||||||
ItemStack odd = Odd.returnItemStack(itemName.replace(":", ";"));
|
ItemStack odd = Odd.returnItemStack(itemName.replace(":", ";"));
|
||||||
|
@ -47,18 +38,20 @@ public class Items {
|
||||||
itemName = split[0];
|
itemName = split[0];
|
||||||
short dataValue = (short) (split.length > 1 && Numerical.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0);
|
short dataValue = (short) (split.length > 1 && Numerical.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0);
|
||||||
|
|
||||||
if (Numerical.isInteger(itemName)) {
|
Material mat;
|
||||||
Material mat = Material.getMaterial(Integer.parseInt(itemName));
|
|
||||||
return mat == null ? null : new ItemStack(mat, 1, dataValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.Acrobot.ChestShop.Config.Config;
|
||||||
import com.Acrobot.ChestShop.Config.Language;
|
import com.Acrobot.ChestShop.Config.Language;
|
||||||
import com.Acrobot.ChestShop.Config.Property;
|
import com.Acrobot.ChestShop.Config.Property;
|
||||||
import com.Acrobot.ChestShop.Permission;
|
import com.Acrobot.ChestShop.Permission;
|
||||||
|
import com.Acrobot.ChestShop.Protection.Default;
|
||||||
import com.Acrobot.ChestShop.Protection.Security;
|
import com.Acrobot.ChestShop.Protection.Security;
|
||||||
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
||||||
import com.Acrobot.ChestShop.Utils.SearchForBlock;
|
import com.Acrobot.ChestShop.Utils.SearchForBlock;
|
||||||
|
@ -43,7 +44,8 @@ public class playerInteract extends PlayerListener {
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
|
|
||||||
if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
|
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));
|
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -3,7 +3,7 @@ name: ChestShop
|
||||||
main: com.Acrobot.ChestShop.ChestShop
|
main: com.Acrobot.ChestShop.ChestShop
|
||||||
|
|
||||||
database: true
|
database: true
|
||||||
version: 3.00
|
version: 3.00 BETA 2
|
||||||
|
|
||||||
|
|
||||||
author: Acrobot
|
author: Acrobot
|
||||||
|
|
Loading…
Reference in New Issue