diff --git a/com/Acrobot/ChestShop/ChestShop.java b/com/Acrobot/ChestShop/ChestShop.java index 9a58773..8618c6a 100644 --- a/com/Acrobot/ChestShop/ChestShop.java +++ b/com/Acrobot/ChestShop/ChestShop.java @@ -30,7 +30,7 @@ import java.util.List; */ public class ChestShop extends JavaPlugin { - public static File folder = new File("plugins/ChestShop"); + public static final File folder = new File("plugins/ChestShop"); private static EbeanServer DB; private static PluginDescriptionFile description; @@ -45,6 +45,9 @@ public class ChestShop extends JavaPlugin { //Register our events blockBreak blockBreak = new blockBreak(); + description = this.getDescription(); //Description of the plugin + server = getServer(); //Setting out server variable + pm.registerEvent(Event.Type.BLOCK_BREAK, blockBreak, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACE, new blockPlace(), Event.Priority.Normal, this); pm.registerEvent(Event.Type.SIGN_CHANGE, new signChange(), Event.Priority.Normal, this); @@ -58,9 +61,6 @@ public class ChestShop extends JavaPlugin { pm.registerEvent(Event.Type.ENTITY_EXPLODE, new entityExplode(), Event.Priority.Normal, this); } - description = this.getDescription(); //Description of the plugin - server = getServer(); //Setting out server variable - if (Config.getBoolean(Property.LOG_TO_DATABASE) || Config.getBoolean(Property.GENERATE_STATISTICS_PAGE)) { //Now set up our database for storing transactions! setupDB(); getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); diff --git a/com/Acrobot/ChestShop/Config/Config.java b/com/Acrobot/ChestShop/Config/Config.java index 397842d..0292953 100644 --- a/com/Acrobot/ChestShop/Config/Config.java +++ b/com/Acrobot/ChestShop/Config/Config.java @@ -11,10 +11,10 @@ import java.io.FileWriter; * @author Acrobot */ public class Config { - private static File configFile = new File(ChestShop.folder, "config.yml"); - private static File langFile = new File(ChestShop.folder, "local.yml"); - private static Configuration config = new Configuration(configFile); - private static Configuration language = new Configuration(langFile); + private static final File configFile = new File(ChestShop.folder, "config.yml"); + private static final File langFile = new File(ChestShop.folder, "local.yml"); + private static final Configuration config = new Configuration(configFile); + private static final Configuration language = new Configuration(langFile); public static void setUp() { if(!ChestShop.folder.exists()) ChestShop.folder.mkdir(); diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index 1dc5a99..a48ca05 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -22,16 +22,24 @@ public class blockBreak extends BlockListener { if (uSign.isSign(block)) block.getState().update(); Sign sign = uBlock.findRestrictedSign(block); - if (sign != null) return true; + if (sign != null && getAttachedFace(sign) == block) return true; sign = uBlock.findSign(block); - return sign != null && (player == null || (!uLongName.stripName(player.getName()).equals(sign.getLine(0)))); + return sign != null && getAttachedFace(sign) == block && playerIsNotOwner(player, sign); } public void onBlockBreak(BlockBreakEvent event) { if (cancellingBlockBreak(event.getBlock(), event.getPlayer())) event.setCancelled(true); } + private static Block getAttachedFace(Sign sign){ + return sign.getBlock().getRelative(((org.bukkit.material.Sign) sign.getData()).getAttachedFace()); + } + + private static boolean playerIsNotOwner(Player player, Sign sign){ + return player == null || !uLongName.stripName(player.getName()).equals(sign.getLine(0)); + } + public void onBlockPistonExtend(BlockPistonExtendEvent event) { for (Block b : event.getBlocks()) { if (cancellingBlockBreak(b, null)) { @@ -42,6 +50,6 @@ public class blockBreak extends BlockListener { } public void onBlockPistonRetract(BlockPistonRetractEvent event) { - if (cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true); + if (!uSign.isSign(event.getRetractLocation().getBlock()) && cancellingBlockBreak(event.getRetractLocation().getBlock(), null)) event.setCancelled(true); } } diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index ee00b7e..21bd9fd 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -68,7 +68,7 @@ public class playerInteract extends PlayerListener { player.sendMessage(Config.getLocal(Language.ACCESS_DENIED)); return; } - + Action buy = (Config.getBoolean(Property.REVERSE_BUTTONS) ? Action.LEFT_CLICK_BLOCK : Action.RIGHT_CLICK_BLOCK); if (action == buy) { diff --git a/com/Acrobot/ChestShop/Listeners/pluginEnable.java b/com/Acrobot/ChestShop/Listeners/pluginEnable.java index 0234062..1a6675c 100644 --- a/com/Acrobot/ChestShop/Listeners/pluginEnable.java +++ b/com/Acrobot/ChestShop/Listeners/pluginEnable.java @@ -30,7 +30,7 @@ public class pluginEnable extends ServerListener { public static final Methods methods = new Methods(Config.getPreferred()); private static final String lineStart = "[ChestShop] "; - private static List pluginsToLoad = new LinkedList(Arrays.asList( + private static final List pluginsToLoad = new LinkedList(Arrays.asList( "Permissions", "LWC", "Lockette", diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 71f7203..79c53f9 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -74,22 +74,11 @@ public class signChange extends BlockListener { return; } event.setLine(2, thirdLine); - - String[] split = line[3].split(":"); - if (uNumber.isInteger(split[0])) { - String materialLine = mat.name(); - if (split.length == 2) { - int maxLength = (15 - split[1].length() - 1); - if (materialLine.length() > maxLength) materialLine = materialLine.substring(0, maxLength); - materialLine = materialLine + ':' + split[1]; - } - event.setLine(3, materialLine); - } + event.setLine(3, formatFourthLine(line[3], mat)); Chest chest = uBlock.findChest(signBlock); - line = event.getLines(); - boolean isAdminShop = uSign.isAdminShop(line[0]); + boolean isAdminShop = uSign.isAdminShop(event.getLine(0)); if (!isAdminShop) { if (chest == null) { player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); @@ -160,6 +149,20 @@ public class signChange extends BlockListener { return (thirdLine.length() > 15 ? null : thirdLine); } + private static String formatFourthLine(String fourthLine, Material material){ + String[] split = fourthLine.split(":"); + if (uNumber.isInteger(split[0])) { + String materialLine = material.name(); + if (split.length == 2) { + int maxLength = (14 - split[1].length()); //15 - length - 1 + if (materialLine.length() > maxLength) materialLine = materialLine.substring(0, maxLength); + materialLine = materialLine + ':' + split[1]; + } + return materialLine; + } + return fourthLine; + } + private static boolean formatFirstLine(String line1, Player player) { return line1.isEmpty() || (!line1.equals(uLongName.stripName(player.getName())) && !Permission.has(player, Permission.ADMIN)); diff --git a/com/Acrobot/ChestShop/Utils/uInventory.java b/com/Acrobot/ChestShop/Utils/uInventory.java index e2358b7..823f3f9 100644 --- a/com/Acrobot/ChestShop/Utils/uInventory.java +++ b/com/Acrobot/ChestShop/Utils/uInventory.java @@ -4,7 +4,6 @@ import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; import java.util.HashMap; /** @@ -47,28 +46,13 @@ public class uInventory { public static int add(Inventory inv, ItemStack item, int amount) { amount = (amount > 0 ? amount : 1); - int maxStackSize = item.getType().getMaxStackSize(); - - if (amount <= maxStackSize) { - item.setAmount(amount); - HashMap left = inv.addItem(item); - return (left.isEmpty() ? 0 : left.get(0).getAmount()); - } - - ArrayList items = new ArrayList(); - for (int i = 0; i < Math.ceil(amount / maxStackSize); i++) { - if (amount <= maxStackSize) { - item.setAmount(amount); - return 0; - } else { - item.setAmount(maxStackSize); - items.add(item); - } - } - + ItemStack itemToAdd = new ItemStack(item.getType(), amount, item.getDurability()); + HashMap items = inv.addItem(itemToAdd); + amount = 0; - for (ItemStack itemToAdd : items) amount += (!inv.addItem(itemToAdd).isEmpty() ? itemToAdd.getAmount() : 0); - + for(ItemStack toAdd : items.values()){ + amount += toAdd.getAmount(); + } return amount; } diff --git a/com/Acrobot/ChestShop/Utils/uLongName.java b/com/Acrobot/ChestShop/Utils/uLongName.java index 350a050..b6840c8 100644 --- a/com/Acrobot/ChestShop/Utils/uLongName.java +++ b/com/Acrobot/ChestShop/Utils/uLongName.java @@ -9,7 +9,7 @@ import java.io.File; * @author Acrobot */ public class uLongName { - public static Configuration config = new Configuration(new File(ChestShop.folder, "longName.storage")); + public static final Configuration config = new Configuration(new File(ChestShop.folder, "longName.storage")); public static String getName(final String shortName) { return config.getString(shortName, shortName); diff --git a/com/Acrobot/ChestShop/Utils/uSign.java b/com/Acrobot/ChestShop/Utils/uSign.java index b041054..179697d 100644 --- a/com/Acrobot/ChestShop/Utils/uSign.java +++ b/com/Acrobot/ChestShop/Utils/uSign.java @@ -68,7 +68,7 @@ public class uSign { if (uNumber.isFloat(split[part])) { Float price = Float.parseFloat(split[part]); - return (price != 0 ? price : -1); + return (price > 0 ? price : -1); } else if (split[part].equals("free")) return 0; return -1; } diff --git a/com/lennardf1989/bukkitex/Database.java b/com/lennardf1989/bukkitex/Database.java index 69b9073..37a1cda 100644 --- a/com/lennardf1989/bukkitex/Database.java +++ b/com/lennardf1989/bukkitex/Database.java @@ -247,7 +247,7 @@ public abstract class Database { //Found a table, so get its name and remember the line it has been encountered on currentTable = currentLine.split(" ", 4)[2]; foundTables.put(currentLine.split(" ", 3)[2], scriptLines.size() - 1); - } else if (currentLine.startsWith(";") && currentTable != null && !currentTable.isEmpty()) { + } else if (currentLine.length() > 0 && currentLine.charAt(0) == ';' && currentTable != null && !currentTable.isEmpty()) { //Found the end of a table definition, so update the entry int index = scriptLines.size() - 1; foundTables.put(currentTable, index); diff --git a/com/nijikokun/register/payment/forChestShop/methods/iCo4.java b/com/nijikokun/register/payment/forChestShop/methods/iCo4.java index ceb3ee0..11a5f2c 100644 --- a/com/nijikokun/register/payment/forChestShop/methods/iCo4.java +++ b/com/nijikokun/register/payment/forChestShop/methods/iCo4.java @@ -58,7 +58,7 @@ public class iCo4 implements Method { } public boolean isCompatible(Plugin plugin) { - return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().startsWith("4") && plugin instanceof iConomy; + return plugin.getDescription().getName().equalsIgnoreCase("iconomy") && !plugin.getClass().getName().equals("com.iConomy.iConomy") && plugin.getDescription().getVersion().length() > 0 && plugin.getDescription().getVersion().charAt(0) == '4' && plugin instanceof iConomy; } public void setPlugin(Plugin plugin) { diff --git a/plugin.yml b/plugin.yml index 5f03454..9d34da5 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.01 +version: 3.02 author: Acrobot