diff --git a/com/Acrobot/ChestShop/Chests/MinecraftChest.java b/com/Acrobot/ChestShop/Chests/MinecraftChest.java index ee27260..b969957 100644 --- a/com/Acrobot/ChestShop/Chests/MinecraftChest.java +++ b/com/Acrobot/ChestShop/Chests/MinecraftChest.java @@ -1,7 +1,7 @@ package com.Acrobot.ChestShop.Chests; -import com.Acrobot.ChestShop.Utils.InventoryUtil; import com.Acrobot.ChestShop.Utils.BlockSearch; +import com.Acrobot.ChestShop.Utils.InventoryUtil; import org.bukkit.block.Chest; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index 2d3908b..5297fa1 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -23,8 +23,8 @@ public class Config { public static void setUp() { config.load(); - for (Property def : com.Acrobot.ChestShop.Config.Property.values()){ - if(config.getProperty(def.name()) == null){ + for (Property def : com.Acrobot.ChestShop.Config.Property.values()) { + if (config.getProperty(def.name()) == null) { writeToFile(def.name() + ": " + def.getValue() + " #" + def.getComment(), configFile); } } @@ -49,19 +49,19 @@ public class Config { } } - public static boolean getBoolean(Property value){ + public static boolean getBoolean(Property value) { return (Boolean) getValue(value.name()); } - public static String getString(Property value){ + public static String getString(Property value) { return (String) getValue(value.name()); } - public static int getInteger(Property value){ + public static int getInteger(Property value) { return Integer.parseInt(getValue(value.name()).toString()); } - public static double getDouble(Property value){ + public static double getDouble(Property value) { return config.getDouble(value.name(), -1); } diff --git a/com/Acrobot/ChestShop/Config/Language.java b/com/Acrobot/ChestShop/Config/Language.java index 54b0457..6a6c337 100644 --- a/com/Acrobot/ChestShop/Config/Language.java +++ b/com/Acrobot/ChestShop/Config/Language.java @@ -41,7 +41,7 @@ public enum Language { SHOP_CREATED("Shop successfully created!"), NO_PERMISSION("You don't have permissions to do that!"), - NAME_TOO_LONG ("Unfortunately, your name is too long :( Please wait for newer shop version!"), + NAME_TOO_LONG("Unfortunately, your name is too long :( Please wait for newer shop version!"), INCORRECT_ITEM_ID("You have specified invalid item id!"); diff --git a/com/Acrobot/ChestShop/Config/Property.java b/com/Acrobot/ChestShop/Config/Property.java index 7a4ec0f..7632350 100644 --- a/com/Acrobot/ChestShop/Config/Property.java +++ b/com/Acrobot/ChestShop/Config/Property.java @@ -4,8 +4,8 @@ package com.Acrobot.ChestShop.Config; * @author Acrobot */ public enum Property { - REVERSE_BUTTONS (false, "If true, people will buy with left-click and sell with right-click."), - SERVER_ECONOMY_ACCOUNT ("", "Economy account's name you want Admin Shops to be assigned to"), + REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."), + SERVER_ECONOMY_ACCOUNT("", "Economy account's name you want Admin Shops to be assigned to"), LOG_TO_FILE(false, "If true, plugin will log transactions in its own file"), LOG_TO_CONSOLE(true, "Do you want ChestShop's messages to show up in console?"), USE_DATABASE(false, "If true, plugin will log transactions in EBean database"), @@ -13,11 +13,11 @@ public enum Property { GENERATE_STATISTICS_PAGE(false, "If true, plugin will generate shop statistics webpage."), STATISTICS_PAGE_PATH("plugins/ChestShop/website.html", "Where should your generated website be saved?"), RECORD_TIME_TO_LIVE(600, "How long should transaction information be stored?"), - USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection?"), + USE_BUILT_IN_PROTECTION(true, "Do you want to use built-in protection against chest destruction?"), PROTECT_CHEST_WITH_LWC(false, "Do you want to protect shop chests with LWC?"), PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?"); - + private Object value; private String comment; diff --git a/com/Acrobot/ChestShop/Items/DataValue.java b/com/Acrobot/ChestShop/Items/DataValue.java index 07638e4..c2f4602 100644 --- a/com/Acrobot/ChestShop/Items/DataValue.java +++ b/com/Acrobot/ChestShop/Items/DataValue.java @@ -10,17 +10,17 @@ import org.bukkit.material.*; * @author Acrobot */ public class DataValue { - public static byte get(String arg, Material material){ - if(material == null){ + public static byte get(String arg, Material material) { + if (material == null) { return 0; } - + arg = arg.toUpperCase().replace(" ", "_"); MaterialData materialData = null; - switch (material){ + switch (material) { case SAPLING: case LOG: materialData = new Tree(TreeSpecies.valueOf(arg)); diff --git a/com/Acrobot/ChestShop/Items/Items.java b/com/Acrobot/ChestShop/Items/Items.java index bb2ea3a..33c28fd 100644 --- a/com/Acrobot/ChestShop/Items/Items.java +++ b/com/Acrobot/ChestShop/Items/Items.java @@ -41,14 +41,14 @@ public class Items { Material mat; String[] data = itemName.split(" "); - if(data.length >= 2){ + if (data.length >= 2) { mat = getMat(itemName.substring(itemName.indexOf(' '))); byte argData = DataValue.get(data[0], mat); - if(argData != 0){ + if (argData != 0) { dataValue = argData; } - } else{ + } else { mat = getMat(itemName); } diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index dba7768..f14671f 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -24,14 +24,14 @@ public class blockBreak extends BlockListener { return; } - if(SignUtil.isSign(block)){ + if (SignUtil.isSign(block)) { Sign currentSign = (Sign) block.getState(); - if(RestrictedSign.isRestricted(currentSign)){ + if (RestrictedSign.isRestricted(currentSign)) { event.setCancelled(true); } currentSign.update(true); } - + Sign sign = BlockSearch.findSign(block); if (sign != null) { diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index 0230255..d361b3e 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -44,8 +44,8 @@ public class playerInteract extends PlayerListener { Block block = event.getClickedBlock(); if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) { - Default defProtection = new Default(); - if (!Permission.has(player, Permission.ADMIN) && !Permission.has(player, Permission.MOD) && (defProtection.isProtected(block) && !defProtection.canAccess(player, block))) { + Default protection = new Default(); + if (!Permission.has(player, Permission.ADMIN) && !Permission.has(player, Permission.MOD) && (protection.isProtected(block) && !protection.canAccess(player, block))) { player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); event.setCancelled(true); return; @@ -93,8 +93,8 @@ public class playerInteract extends PlayerListener { return; } - if(RestrictedSign.isRestricted(sign)){ - if(!RestrictedSign.canAccess(sign, player)){ + if (RestrictedSign.isRestricted(sign)) { + if (!RestrictedSign.canAccess(sign, player)) { player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); return; } diff --git a/com/Acrobot/ChestShop/Listeners/pluginDisable.java b/com/Acrobot/ChestShop/Listeners/pluginDisable.java index be63710..026a50c 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginDisable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginDisable.java @@ -7,12 +7,12 @@ import org.bukkit.event.server.ServerListener; /** * @author Acrobot */ -public class pluginDisable extends ServerListener{ - public void onPluginDisable(PluginDisableEvent event){ - if(Economy.economy != null && pluginEnable.methods.hasMethod()){ +public class pluginDisable extends ServerListener { + public void onPluginDisable(PluginDisableEvent event) { + if (Economy.economy != null && pluginEnable.methods.hasMethod()) { boolean check = pluginEnable.methods.checkDisabled(event.getPlugin()); - if(check){ + if (check) { Economy.economy = null; System.out.println("[ChestShop] Economy plugin disabled!"); } diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index 472117e..ec95de3 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -54,7 +54,7 @@ public class pluginEnable extends ServerListener { PluginDescriptionFile pDesc = lwcPlugin.getDescription(); LWCplugin.lwc = ((LWCPlugin) lwcPlugin).getLWC(); Security.protection = new LWCplugin(); - + System.out.println("[ChestShop] " + pDesc.getName() + " version " + pDesc.getVersion() + " loaded."); } } diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 9875940..7969727 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -43,7 +43,7 @@ public class signChange extends BlockListener { if (isAlmostReady) { - if(player.getName().length() > 15){ + if (player.getName().length() > 15) { player.sendMessage(Config.getLocal(Language.NAME_TOO_LONG)); dropSign(event); return; @@ -54,24 +54,23 @@ public class signChange extends BlockListener { return; } if (!(playerIsAdmin || - Permission.has(player, Permission.SHOP_CREATION) || + Permission.has(player, Permission.SHOP_CREATION) || (Permission.has(player, Permission.SHOP_CREATION + "." + mat.getId()) && - !Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId())))) - { + !Permission.has(player, Permission.EXCLUDE_ITEM + "." + mat.getId())))) { player.sendMessage(Config.getLocal(Language.YOU_CANNOT_CREATE_SHOP)); dropSign(event); return; } } else { - if(RestrictedSign.isRestricted(event.getLines())){ - if(!playerIsAdmin){ + if (RestrictedSign.isRestricted(event.getLines())) { + if (!playerIsAdmin) { player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); dropSign(event); return; } Block secondSign = signBlock.getFace(BlockFace.DOWN); - if(!SignUtil.isSign(secondSign) || !SignUtil.isValid((Sign) secondSign.getState())){ + if (!SignUtil.isSign(secondSign) || !SignUtil.isValid((Sign) secondSign.getState())) { dropSign(event); } } @@ -121,29 +120,36 @@ public class signChange extends BlockListener { dropSign(event); return; } else if (!playerIsAdmin) { - boolean canPlaceSign = Security.canPlaceSign(player, signBlock); - - if (!canPlaceSign) { + if (!Security.canPlaceSign(player, signBlock)) { player.sendMessage(Config.getLocal(Language.ANOTHER_SHOP_DETECTED)); dropSign(event); return; } - Default protection = new Default(); + boolean canAccess = true; Block chestBlock = chest.getBlock(); - if(Security.isProtected(chestBlock) || protection.isProtected(chestBlock)){ - if(!Security.canAccess(player, chestBlock) || !protection.canAccess(player, chestBlock)){ - player.sendMessage(Config.getLocal(Language.CANNOT_ACCESS_THE_CHEST)); - dropSign(event); - return; + if (Security.isProtected(chestBlock) && !Security.canAccess(player, chestBlock)) { + canAccess = false; + } + + if (!(Security.protection instanceof Default)) { + Default protection = new Default(); + if (protection.isProtected(chestBlock) && !protection.canAccess(player, chestBlock)) { + canAccess = false; } } + + if (!canAccess) { + player.sendMessage(Config.getLocal(Language.CANNOT_ACCESS_THE_CHEST)); + dropSign(event); + return; + } } } if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) { - if(Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)){ + if (Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)) { Security.protect(player.getName(), signBlock); } player.sendMessage(Config.getLocal(Language.PROTECTED_SHOP)); diff --git a/com/Acrobot/ChestShop/Protection/Default.java b/com/Acrobot/ChestShop/Protection/Default.java index ecde708..a9b6bac 100644 --- a/com/Acrobot/ChestShop/Protection/Default.java +++ b/com/Acrobot/ChestShop/Protection/Default.java @@ -12,17 +12,17 @@ import org.bukkit.entity.Player; */ public class Default implements Protection { public boolean isProtected(Block block) { - if((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) || BlockSearch.findSign(block) != null){ + if ((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) || BlockSearch.findSign(block) != null) { return true; } else { - if(!(block.getState() instanceof Chest)){ + if (!(block.getState() instanceof Chest)) { return false; } - if(BlockSearch.findSign(block) != null){ + if (BlockSearch.findSign(block) != null) { return true; } Chest neighbor = BlockSearch.findNeighbor(block); - if(neighbor != null && BlockSearch.findSign(neighbor.getBlock()) != null){ + if (neighbor != null && BlockSearch.findSign(neighbor.getBlock()) != null) { return true; } } diff --git a/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java b/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java index d63c9aa..01e7644 100644 --- a/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java +++ b/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java @@ -11,18 +11,18 @@ import org.bukkit.entity.Player; * @author Acrobot */ public class RestrictedSign { - public static boolean isRestricted(Sign sign){ + public static boolean isRestricted(Sign sign) { Block blockUp = sign.getBlock().getFace(BlockFace.UP); return SignUtil.isSign(blockUp) && isRestricted(((Sign) blockUp.getState()).getLines()); } - public static boolean isRestricted(String[] lines){ + public static boolean isRestricted(String[] lines) { return lines[0].equalsIgnoreCase("[restricted]"); } - public static boolean canAccess(Sign sign, Player player){ + public static boolean canAccess(Sign sign, Player player) { Block blockUp = sign.getBlock().getFace(BlockFace.UP); - if(Permission.permissions == null || !SignUtil.isSign(blockUp) || Permission.has(player, Permission.ADMIN)){ + if (Permission.permissions == null || !SignUtil.isSign(blockUp) || Permission.has(player, Permission.ADMIN)) { return true; } String world = blockUp.getWorld().getName(); @@ -31,7 +31,7 @@ public class RestrictedSign { sign = (Sign) blockUp.getState(); boolean result = false; - for(int i = 1; i <= 3; i++){ + for (int i = 1; i <= 3; i++) { result = result || Permission.permissions.inGroup(world, playerName, sign.getLine(i)); } return result; diff --git a/com/Acrobot/ChestShop/Shop/Shop.java b/com/Acrobot/ChestShop/Shop/Shop.java index 0d672ea..7a69ca7 100644 --- a/com/Acrobot/ChestShop/Shop/Shop.java +++ b/com/Acrobot/ChestShop/Shop/Shop.java @@ -45,7 +45,7 @@ public class Shop { player.sendMessage(Config.getLocal(Language.NO_BUYING_HERE)); return false; } - if(!Permission.has(player, Permission.BUY)){ + if (!Permission.has(player, Permission.BUY)) { player.sendMessage(Config.getLocal(Language.NO_PERMISSION)); return false; } @@ -104,7 +104,7 @@ public class Shop { player.sendMessage(Config.getLocal(Language.NO_SELLING_HERE)); return false; } - if(!Permission.has(player, Permission.SELL)){ + if (!Permission.has(player, Permission.SELL)) { player.sendMessage(Config.getLocal(Language.NO_PERMISSION)); return false; } diff --git a/com/Acrobot/ChestShop/Shop/ShopManagement.java b/com/Acrobot/ChestShop/Shop/ShopManagement.java index 053ed1b..d353206 100644 --- a/com/Acrobot/ChestShop/Shop/ShopManagement.java +++ b/com/Acrobot/ChestShop/Shop/ShopManagement.java @@ -16,7 +16,7 @@ public class ShopManagement { public static boolean buy(Sign sign, Player player) { Chest chestMc = BlockSearch.findChest(sign); ItemStack item = Items.getItemStack(sign.getLine(3)); - if(item == null){ + if (item == null) { player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!"); return false; } @@ -28,7 +28,7 @@ public class ShopManagement { public static boolean sell(Sign sign, Player player) { Chest chestMc = BlockSearch.findChest(sign); ItemStack item = Items.getItemStack(sign.getLine(3)); - if(item == null){ + if (item == null) { player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!"); return false; } diff --git a/com/Acrobot/ChestShop/Utils/BlockSearch.java b/com/Acrobot/ChestShop/Utils/BlockSearch.java index 292ec07..7d77aba 100644 --- a/com/Acrobot/ChestShop/Utils/BlockSearch.java +++ b/com/Acrobot/ChestShop/Utils/BlockSearch.java @@ -52,7 +52,7 @@ public class BlockSearch { return null; //Shame, we didn't find double chest :/ } - public static Chest findNeighbor(Chest chest){ + public static Chest findNeighbor(Chest chest) { return findNeighbor(chest.getBlock()); } } diff --git a/com/Acrobot/ChestShop/Utils/InventoryUtil.java b/com/Acrobot/ChestShop/Utils/InventoryUtil.java index e8db093..d575817 100644 --- a/com/Acrobot/ChestShop/Utils/InventoryUtil.java +++ b/com/Acrobot/ChestShop/Utils/InventoryUtil.java @@ -17,7 +17,7 @@ public class InventoryUtil { Material itemMaterial = item.getType(); int first = inv.first(itemMaterial); - if(first == -1){ + if (first == -1) { return amount; } @@ -52,7 +52,7 @@ public class InventoryUtil { public static int add(Inventory inv, ItemStack item, int amount) { amount = (amount > 0 ? amount : 1); - + Material itemMaterial = item.getType(); int maxStackSize = itemMaterial.getMaxStackSize(); @@ -84,10 +84,9 @@ public class InventoryUtil { public static int amount(Inventory inv, ItemStack item, short durability) { int amount = 0; - if(!inv.contains(item.getType())){ + if (!inv.contains(item.getType())) { return amount; } - ItemStack[] contents = inv.getContents(); for (ItemStack i : contents) { if (i != null) { diff --git a/plugin.yml b/plugin.yml index 9666890..d996300 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop database: true -version: 3.00 BETA 6 +version: 3.00 BETA 7 author: Acrobot