diff --git a/com/Acrobot/ChestShop/ChestShop.java b/com/Acrobot/ChestShop/ChestShop.java index 7c0704c..6826d70 100644 --- a/com/Acrobot/ChestShop/ChestShop.java +++ b/com/Acrobot/ChestShop/ChestShop.java @@ -11,6 +11,7 @@ import com.Acrobot.ChestShop.DB.Transaction; import com.Acrobot.ChestShop.Listeners.*; import com.Acrobot.ChestShop.Logging.FileWriterQueue; import com.Acrobot.ChestShop.Logging.Logging; +import com.Acrobot.ChestShop.Protection.MaskChest; import com.avaje.ebean.EbeanServer; import org.bukkit.Server; import org.bukkit.event.Event; @@ -43,8 +44,6 @@ public class ChestShop extends JavaPlugin { private static PluginDescriptionFile desc; private static Server server; - public static String mainWorldName; - public void onEnable() { PluginManager pm = getServer().getPluginManager(); @@ -58,7 +57,6 @@ public class ChestShop extends JavaPlugin { desc = this.getDescription(); //Description of the plugin server = getServer(); //Setting out server variable - mainWorldName = server.getWorlds().get(0).getName(); //Set up our main world's name - currently not used //Yep, set up our folder! folder = getDataFolder(); @@ -69,7 +67,7 @@ public class ChestShop extends JavaPlugin { //Now set up our database for storing transactions! setupDBfile(); - if (Config.getBoolean(Property.USE_DATABASE)) { + if (Config.getBoolean(Property.LOG_TO_DATABASE)) { setupDB(); getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); @@ -84,17 +82,22 @@ public class ChestShop extends JavaPlugin { getServer().getScheduler().scheduleAsyncRepeatingTask(this, new FileWriterQueue(), 201L, 201L); } + //And now for the chest masking + if (Config.getBoolean(Property.MASK_CHESTS_AS_OTHER_BLOCKS)) { + getServer().getScheduler().scheduleAsyncRepeatingTask(this, new MaskChest(), 40L, 40L); + } + //Register our commands! getCommand("iteminfo").setExecutor(new ItemInfo()); getCommand("chestOptions").setExecutor(new Options()); getCommand("csVersion").setExecutor(new Version()); - System.out.println('[' + desc.getName() + "] version " + desc.getVersion() + " initialized!"); + System.out.println('[' + getPluginName() + "] version " + getVersion() + " initialized!"); } public void onDisable() { - System.out.println('[' + desc.getName() + "] version " + desc.getVersion() + " shutting down!"); + System.out.println('[' + getPluginName() + "] version " + getVersion() + " shutting down!"); } ///////////////////// DATABASE STUFF //////////////////////////////// diff --git a/com/Acrobot/ChestShop/Chests/MinecraftChest.java b/com/Acrobot/ChestShop/Chests/MinecraftChest.java index b969957..32f707b 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.BlockSearch; -import com.Acrobot.ChestShop.Utils.InventoryUtil; +import com.Acrobot.ChestShop.Utils.uBlock; +import com.Acrobot.ChestShop.Utils.uInventory; import org.bukkit.block.Chest; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; @@ -80,25 +80,25 @@ public class MinecraftChest implements ChestObject { } private Chest getNeighbor() { - return BlockSearch.findNeighbor(main); + return uBlock.findNeighbor(main); } private static int amount(ItemStack item, short durability, Chest chest) { - return InventoryUtil.amount(chest.getInventory(), item, durability); + return uInventory.amount(chest.getInventory(), item, durability); } private static int fits(ItemStack item, int amount, short durability, Chest chest) { Inventory inv = chest.getInventory(); - return InventoryUtil.fits(inv, item, amount, durability); + return uInventory.fits(inv, item, amount, durability); } private static int addItem(ItemStack item, int amount, Chest chest) { Inventory inv = chest.getInventory(); - return InventoryUtil.add(inv, item, amount); + return uInventory.add(inv, item, amount); } private static int removeItem(ItemStack item, short durability, int amount, Chest chest) { Inventory inv = chest.getInventory(); - return InventoryUtil.remove(inv, item, amount, durability); + return uInventory.remove(inv, item, amount, durability); } } diff --git a/com/Acrobot/ChestShop/Config/Property.java b/com/Acrobot/ChestShop/Config/Property.java index 7632350..5944308 100644 --- a/com/Acrobot/ChestShop/Config/Property.java +++ b/com/Acrobot/ChestShop/Config/Property.java @@ -6,16 +6,17 @@ package com.Acrobot.ChestShop.Config; 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"), + ADMIN_SHOP_NAME("Admin Shop", "First line of your admin shop should look like this"), 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"), - ADMIN_SHOP_NAME("Admin Shop", "First line of your admin shop should look like this"), + LOG_TO_DATABASE(false, "If true, plugin will log transactions in EBean database"), 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 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?"); + PROTECT_SIGN_WITH_LWC(false, "Do you want to protect shop signs with LWC?"), + MASK_CHESTS_AS_OTHER_BLOCKS(false, "Do you want to mask shop chests as other blocks? HIGHLY EXPERIMENTAL, CAN LAG!"); private Object value; diff --git a/com/Acrobot/ChestShop/Items/Items.java b/com/Acrobot/ChestShop/Items/Items.java index 33c28fd..8c5d043 100644 --- a/com/Acrobot/ChestShop/Items/Items.java +++ b/com/Acrobot/ChestShop/Items/Items.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Items; -import com.Acrobot.ChestShop.Utils.Numerical; +import com.Acrobot.ChestShop.Utils.uNumber; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack; public class Items { public static Material getMat(String itemName) { - if (Numerical.isInteger(itemName)) { + if (uNumber.isInteger(itemName)) { return Material.getMaterial(Integer.parseInt(itemName)); } int length = 256; @@ -36,7 +36,7 @@ public class Items { } String[] split = itemName.split(":"); itemName = split[0]; - short dataValue = (short) (split.length > 1 && Numerical.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0); + short dataValue = (short) (split.length > 1 && uNumber.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0); Material mat; diff --git a/com/Acrobot/ChestShop/Listeners/blockBreak.java b/com/Acrobot/ChestShop/Listeners/blockBreak.java index f14671f..a30e562 100644 --- a/com/Acrobot/ChestShop/Listeners/blockBreak.java +++ b/com/Acrobot/ChestShop/Listeners/blockBreak.java @@ -2,8 +2,8 @@ package com.Acrobot.ChestShop.Listeners; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Restrictions.RestrictedSign; -import com.Acrobot.ChestShop.Utils.BlockSearch; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uBlock; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; @@ -24,7 +24,7 @@ public class blockBreak extends BlockListener { return; } - if (SignUtil.isSign(block)) { + if (uSign.isSign(block)) { Sign currentSign = (Sign) block.getState(); if (RestrictedSign.isRestricted(currentSign)) { event.setCancelled(true); @@ -32,7 +32,7 @@ public class blockBreak extends BlockListener { currentSign.update(true); } - Sign sign = BlockSearch.findSign(block); + Sign sign = uBlock.findSign(block); if (sign != null) { if (!player.getName().equals(sign.getLine(0))) { diff --git a/com/Acrobot/ChestShop/Listeners/blockPlace.java b/com/Acrobot/ChestShop/Listeners/blockPlace.java index fc87afe..5fe4d4f 100644 --- a/com/Acrobot/ChestShop/Listeners/blockPlace.java +++ b/com/Acrobot/ChestShop/Listeners/blockPlace.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Listeners; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.event.block.BlockListener; @@ -12,7 +12,7 @@ import org.bukkit.event.block.BlockPlaceEvent; public class blockPlace extends BlockListener { public void onBlockPlace(BlockPlaceEvent event) { Block block = event.getBlockAgainst(); - if (SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) { + if (uSign.isSign(block) && uSign.isValid((Sign) block.getState())) { event.setCancelled(true); } } diff --git a/com/Acrobot/ChestShop/Listeners/playerInteract.java b/com/Acrobot/ChestShop/Listeners/playerInteract.java index d361b3e..39f6696 100644 --- a/com/Acrobot/ChestShop/Listeners/playerInteract.java +++ b/com/Acrobot/ChestShop/Listeners/playerInteract.java @@ -7,8 +7,8 @@ import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Protection.Default; import com.Acrobot.ChestShop.Restrictions.RestrictedSign; import com.Acrobot.ChestShop.Shop.ShopManagement; -import com.Acrobot.ChestShop.Utils.BlockSearch; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uBlock; +import com.Acrobot.ChestShop.Utils.uSign; import net.minecraft.server.IInventory; import net.minecraft.server.InventoryLargeChest; import org.bukkit.Material; @@ -52,15 +52,12 @@ public class playerInteract extends PlayerListener { } } - if (!SignUtil.isSign(block)) { - return; - } - Sign sign = (Sign) block.getState(); - if (!SignUtil.isValid(sign)) { + if (!uSign.isSign(block)) { return; } - if (time.containsKey(player) && (System.currentTimeMillis() - time.get(player)) < interval) { + Sign sign = (Sign) block.getState(); + if (!uSign.isValid(sign) || time.containsKey(player) && (System.currentTimeMillis() - time.get(player)) < interval) { return; } @@ -71,7 +68,7 @@ public class playerInteract extends PlayerListener { } if (player.getName().equals(sign.getLine(0))) { - Chest chest1 = BlockSearch.findChest(sign); + Chest chest1 = uBlock.findChest(sign); if (chest1 == null) { player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); return; @@ -80,7 +77,7 @@ public class playerInteract extends PlayerListener { Inventory inv1 = chest1.getInventory(); IInventory iInv1 = ((CraftInventory) inv1).getInventory(); - Chest chest2 = BlockSearch.findNeighbor(chest1); + Chest chest2 = uBlock.findNeighbor(chest1); if (chest2 != null) { Inventory inv2 = chest2.getInventory(); diff --git a/com/Acrobot/ChestShop/Listeners/signChange.java b/com/Acrobot/ChestShop/Listeners/signChange.java index 7969727..d7f2b0a 100644 --- a/com/Acrobot/ChestShop/Listeners/signChange.java +++ b/com/Acrobot/ChestShop/Listeners/signChange.java @@ -8,9 +8,9 @@ import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Protection.Default; import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Restrictions.RestrictedSign; -import com.Acrobot.ChestShop.Utils.BlockSearch; -import com.Acrobot.ChestShop.Utils.Numerical; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uBlock; +import com.Acrobot.ChestShop.Utils.uNumber; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -30,7 +30,7 @@ public class signChange extends BlockListener { Block signBlock = event.getBlock(); String[] line = event.getLines(); - Boolean isAlmostReady = SignUtil.isValidPreparedSign(event.getLines()); + Boolean isAlmostReady = uSign.isValidPreparedSign(event.getLines()); Player player = event.getPlayer(); @@ -70,14 +70,14 @@ public class signChange extends BlockListener { return; } Block secondSign = signBlock.getFace(BlockFace.DOWN); - if (!SignUtil.isSign(secondSign) || !SignUtil.isValid((Sign) secondSign.getState())) { + if (!uSign.isSign(secondSign) || !uSign.isValid((Sign) secondSign.getState())) { dropSign(event); } } return; } - Boolean isReady = SignUtil.isValid(line); + Boolean isReady = uSign.isValid(line); if (line[0].isEmpty() || (!line[0].startsWith(player.getName()) && !Permission.has(player, Permission.ADMIN))) { event.setLine(0, player.getName()); @@ -85,7 +85,7 @@ public class signChange extends BlockListener { line = event.getLines(); - boolean isAdminShop = SignUtil.isAdminShop(line[0]); + boolean isAdminShop = uSign.isAdminShop(line[0]); if (!isReady) { int prices = line[2].split(":").length; @@ -98,7 +98,7 @@ public class signChange extends BlockListener { } String[] split = line[3].split(":"); - if (Numerical.isInteger(split[0])) { + if (uNumber.isInteger(split[0])) { String matName = mat.name(); if (split.length == 2) { int length = matName.length(); @@ -112,7 +112,7 @@ public class signChange extends BlockListener { } } - Chest chest = BlockSearch.findChest(signBlock); + Chest chest = uBlock.findChest(signBlock); if (!isAdminShop) { if (chest == null) { diff --git a/com/Acrobot/ChestShop/Logging/Logging.java b/com/Acrobot/ChestShop/Logging/Logging.java index daa1d9e..ebb6cd0 100644 --- a/com/Acrobot/ChestShop/Logging/Logging.java +++ b/com/Acrobot/ChestShop/Logging/Logging.java @@ -32,7 +32,7 @@ public class Logging { public static void logTransaction(boolean isBuying, Shop shop, Player player) { log(player.getName() + (isBuying ? " bought " : " sold ") + shop.stockAmount + ' ' + shop.stock.getType() + " for " + (isBuying ? shop.buyPrice + " from " : shop.sellPrice + " to ") + shop.owner); - if (!Config.getBoolean(Property.USE_DATABASE)) { + if (!Config.getBoolean(Property.LOG_TO_DATABASE)) { return; } Transaction transaction = new Transaction(); diff --git a/com/Acrobot/ChestShop/Protection/Default.java b/com/Acrobot/ChestShop/Protection/Default.java index a9b6bac..923235f 100644 --- a/com/Acrobot/ChestShop/Protection/Default.java +++ b/com/Acrobot/ChestShop/Protection/Default.java @@ -1,7 +1,7 @@ package com.Acrobot.ChestShop.Protection; -import com.Acrobot.ChestShop.Utils.BlockSearch; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uBlock; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.Sign; @@ -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 ((uSign.isSign(block) && uSign.isValid((Sign) block.getState())) || uBlock.findSign(block) != null) { return true; } else { if (!(block.getState() instanceof Chest)) { return false; } - if (BlockSearch.findSign(block) != null) { + if (uBlock.findSign(block) != null) { return true; } - Chest neighbor = BlockSearch.findNeighbor(block); - if (neighbor != null && BlockSearch.findSign(neighbor.getBlock()) != null) { + Chest neighbor = uBlock.findNeighbor(block); + if (neighbor != null && uBlock.findSign(neighbor.getBlock()) != null) { return true; } } @@ -31,10 +31,10 @@ public class Default implements Protection { } public boolean canAccess(Player player, Block block) { - Sign sign = BlockSearch.findSign(block); - Chest nChest = BlockSearch.findNeighbor(block); - Sign nSign = (nChest != null ? BlockSearch.findSign(nChest.getBlock()) : null); - return ((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState()) && ((Sign) block.getState()).getLine(0).equals(player.getName())) || (sign != null && sign.getLine(0).equals(player.getName()))) + Sign sign = uBlock.findSign(block); + Chest nChest = uBlock.findNeighbor(block); + Sign nSign = (nChest != null ? uBlock.findSign(nChest.getBlock()) : null); + return ((uSign.isSign(block) && uSign.isValid((Sign) block.getState()) && ((Sign) block.getState()).getLine(0).equals(player.getName())) || (sign != null && sign.getLine(0).equals(player.getName()))) || (nSign != null && nSign.getLine(0).equals(player.getName())); } diff --git a/com/Acrobot/ChestShop/Protection/MaskChest.java b/com/Acrobot/ChestShop/Protection/MaskChest.java new file mode 100644 index 0000000..eb76572 --- /dev/null +++ b/com/Acrobot/ChestShop/Protection/MaskChest.java @@ -0,0 +1,62 @@ +package com.Acrobot.ChestShop.Protection; + +import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Utils.uBlock; +import com.Acrobot.ChestShop.Utils.uSign; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Chest; +import org.bukkit.entity.Player; + +/** + * @author Acrobot + */ +public class MaskChest implements Runnable { + BlockFace[] bf = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN}; + + public void run() { + Player[] players = ChestShop.getBukkitServer().getOnlinePlayers(); + + for (Player player : players) { + Location location = player.getLocation(); + + int pX = location.getBlockX(); + int pY = location.getBlockY(); + int pZ = location.getBlockZ(); + + int radius = 25; + + for (int x = -radius; x < radius; x++) { + for (int y = -radius; y < radius; y++) { + for (int z = -radius; z < radius; z++) { + Block block = player.getWorld().getBlockAt(x + pX, y + pY, z + pZ); + + if (block.getType() == Material.CHEST) { + if (uBlock.findSign(block) != null) { + Chest neighbor = uBlock.findNeighbor(block); + Material nMat = returnNearestMat(block); + if (neighbor != null) { + player.sendBlockChange(neighbor.getBlock().getLocation(), nMat, (byte) 0); + } + player.sendBlockChange(block.getLocation(), nMat, (byte) 0); + } + } + } + } + } + } + } + + Material returnNearestMat(Block block) { + for (BlockFace face : bf) { + Block faceBlock = block.getFace(face); + Material type = faceBlock.getType(); + if (type != Material.AIR && !uSign.isSign(faceBlock) && type != Material.CHEST) { + return type; + } + } + return Material.CHEST; + } +} diff --git a/com/Acrobot/ChestShop/Protection/Security.java b/com/Acrobot/ChestShop/Protection/Security.java index 5ab0549..49166a9 100644 --- a/com/Acrobot/ChestShop/Protection/Security.java +++ b/com/Acrobot/ChestShop/Protection/Security.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Protection; -import com.Acrobot.ChestShop.Utils.BlockSearch; +import com.Acrobot.ChestShop.Utils.uBlock; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.Sign; @@ -25,9 +25,9 @@ public class Security { } public static boolean canPlaceSign(Player p, Block block) { - Chest chest = BlockSearch.findChest(block); - Sign sign1 = BlockSearch.findSign(chest.getBlock()); - Sign sign2 = BlockSearch.findSign(block); + Chest chest = uBlock.findChest(block); + Sign sign1 = uBlock.findSign(chest.getBlock()); + Sign sign2 = uBlock.findSign(block); return (sign1 == null || sign1.getLine(0).startsWith(p.getName())) && (sign2 == null || sign2.getLine(0).startsWith(p.getName())); } diff --git a/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java b/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java index 01e7644..86e76d2 100644 --- a/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java +++ b/com/Acrobot/ChestShop/Restrictions/RestrictedSign.java @@ -1,7 +1,7 @@ package com.Acrobot.ChestShop.Restrictions; import com.Acrobot.ChestShop.Permission; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; @@ -13,7 +13,7 @@ import org.bukkit.entity.Player; public class RestrictedSign { public static boolean isRestricted(Sign sign) { Block blockUp = sign.getBlock().getFace(BlockFace.UP); - return SignUtil.isSign(blockUp) && isRestricted(((Sign) blockUp.getState()).getLines()); + return uSign.isSign(blockUp) && isRestricted(((Sign) blockUp.getState()).getLines()); } public static boolean isRestricted(String[] lines) { @@ -22,7 +22,7 @@ public class RestrictedSign { 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 || !uSign.isSign(blockUp) || Permission.has(player, Permission.ADMIN)) { return true; } String world = blockUp.getWorld().getName(); diff --git a/com/Acrobot/ChestShop/Shop/Shop.java b/com/Acrobot/ChestShop/Shop/Shop.java index 7a69ca7..bad0e71 100644 --- a/com/Acrobot/ChestShop/Shop/Shop.java +++ b/com/Acrobot/ChestShop/Shop/Shop.java @@ -8,8 +8,8 @@ import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Logging.Logging; import com.Acrobot.ChestShop.Permission; -import com.Acrobot.ChestShop.Utils.InventoryUtil; -import com.Acrobot.ChestShop.Utils.SignUtil; +import com.Acrobot.ChestShop.Utils.uInventory; +import com.Acrobot.ChestShop.Utils.uSign; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -30,10 +30,10 @@ public class Shop { this.stock = itemStacks[0]; this.durability = stock.getDurability(); this.chest = chest; - this.buyPrice = SignUtil.buyPrice(sign.getLine(2)); - this.sellPrice = SignUtil.sellPrice(sign.getLine(2)); + this.buyPrice = uSign.buyPrice(sign.getLine(2)); + this.sellPrice = uSign.sellPrice(sign.getLine(2)); this.owner = sign.getLine(0); - this.stockAmount = SignUtil.itemAmount(sign.getLine(1)); + this.stockAmount = uSign.itemAmount(sign.getLine(1)); } public boolean buy(Player player) { @@ -83,7 +83,7 @@ public class Shop { .replace("%owner", owner) .replace("%price", formatedPrice)); - InventoryUtil.add(player.getInventory(), stock, stockAmount); + uInventory.add(player.getInventory(), stock, stockAmount); Logging.logTransaction(true, this, player); player.updateInventory(); @@ -122,7 +122,7 @@ public class Shop { return false; } - if (InventoryUtil.amount(player.getInventory(), stock, durability) < stockAmount) { + if (uInventory.amount(player.getInventory(), stock, durability) < stockAmount) { player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL)); return false; } @@ -147,7 +147,7 @@ public class Shop { .replace("%buyer", owner) .replace("%price", formatedBalance)); - InventoryUtil.remove(player.getInventory(), stock, stockAmount, durability); + uInventory.remove(player.getInventory(), stock, stockAmount, durability); Logging.logTransaction(false, this, player); player.updateInventory(); @@ -162,7 +162,7 @@ public class Shop { } private String getOwnerAccount() { - if (SignUtil.isAdminShop(owner)) { + if (uSign.isAdminShop(owner)) { return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); } else { return owner; @@ -170,7 +170,7 @@ public class Shop { } private boolean isAdminShop() { - return SignUtil.isAdminShop(owner); + return uSign.isAdminShop(owner); } private boolean hasEnoughStock() { @@ -178,7 +178,7 @@ public class Shop { } private boolean stockFitsPlayer(Player player) { - return InventoryUtil.fits(player.getInventory(), stock, stockAmount, durability) <= 0; + return uInventory.fits(player.getInventory(), stock, stockAmount, durability) <= 0; } private boolean stockFitsChest(ChestObject chest) { diff --git a/com/Acrobot/ChestShop/Shop/ShopManagement.java b/com/Acrobot/ChestShop/Shop/ShopManagement.java index d353206..bec3dd4 100644 --- a/com/Acrobot/ChestShop/Shop/ShopManagement.java +++ b/com/Acrobot/ChestShop/Shop/ShopManagement.java @@ -2,7 +2,7 @@ package com.Acrobot.ChestShop.Shop; import com.Acrobot.ChestShop.Chests.MinecraftChest; import com.Acrobot.ChestShop.Items.Items; -import com.Acrobot.ChestShop.Utils.BlockSearch; +import com.Acrobot.ChestShop.Utils.uBlock; import org.bukkit.ChatColor; import org.bukkit.block.Chest; import org.bukkit.block.Sign; @@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack; */ public class ShopManagement { public static boolean buy(Sign sign, Player player) { - Chest chestMc = BlockSearch.findChest(sign); + Chest chestMc = uBlock.findChest(sign); ItemStack item = Items.getItemStack(sign.getLine(3)); if (item == null) { player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!"); @@ -26,7 +26,7 @@ public class ShopManagement { } public static boolean sell(Sign sign, Player player) { - Chest chestMc = BlockSearch.findChest(sign); + Chest chestMc = uBlock.findChest(sign); ItemStack item = Items.getItemStack(sign.getLine(3)); if (item == null) { player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!"); diff --git a/com/Acrobot/ChestShop/Utils/BlockSearch.java b/com/Acrobot/ChestShop/Utils/uBlock.java similarity index 93% rename from com/Acrobot/ChestShop/Utils/BlockSearch.java rename to com/Acrobot/ChestShop/Utils/uBlock.java index 7d77aba..176ab38 100644 --- a/com/Acrobot/ChestShop/Utils/BlockSearch.java +++ b/com/Acrobot/ChestShop/Utils/uBlock.java @@ -9,7 +9,7 @@ import org.bukkit.block.Sign; /** * @author Acrobot */ -public class BlockSearch { +public class uBlock { static BlockFace[] chestFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH}; static BlockFace[] shopFaces = {BlockFace.DOWN, BlockFace.UP, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH, BlockFace.SELF}; @@ -32,9 +32,9 @@ public class BlockSearch { public static Sign findSign(Block block) { for (BlockFace bf : shopFaces) { Block faceBlock = block.getFace(bf); - if (SignUtil.isSign(faceBlock)) { + if (uSign.isSign(faceBlock)) { Sign sign = (Sign) faceBlock.getState(); - if (SignUtil.isValid(sign)) { + if (uSign.isValid(sign)) { return sign; } } diff --git a/com/Acrobot/ChestShop/Utils/InventoryUtil.java b/com/Acrobot/ChestShop/Utils/uInventory.java similarity index 99% rename from com/Acrobot/ChestShop/Utils/InventoryUtil.java rename to com/Acrobot/ChestShop/Utils/uInventory.java index d575817..da06ad8 100644 --- a/com/Acrobot/ChestShop/Utils/InventoryUtil.java +++ b/com/Acrobot/ChestShop/Utils/uInventory.java @@ -10,7 +10,7 @@ import java.util.HashMap; /** * @author Acrobot */ -public class InventoryUtil { +public class uInventory { public static int remove(Inventory inv, ItemStack item, int amount, short durability) { amount = (amount > 0 ? amount : 1); diff --git a/com/Acrobot/ChestShop/Utils/Numerical.java b/com/Acrobot/ChestShop/Utils/uNumber.java similarity index 96% rename from com/Acrobot/ChestShop/Utils/Numerical.java rename to com/Acrobot/ChestShop/Utils/uNumber.java index 9e011e4..7d0f840 100644 --- a/com/Acrobot/ChestShop/Utils/Numerical.java +++ b/com/Acrobot/ChestShop/Utils/uNumber.java @@ -5,7 +5,7 @@ package com.Acrobot.ChestShop.Utils; * * @author Acrobot */ -public class Numerical { +public class uNumber { public static boolean isInteger(String string) { try { Integer.parseInt(string); diff --git a/com/Acrobot/ChestShop/Utils/SignUtil.java b/com/Acrobot/ChestShop/Utils/uSign.java similarity index 87% rename from com/Acrobot/ChestShop/Utils/SignUtil.java rename to com/Acrobot/ChestShop/Utils/uSign.java index b17ce1e..232c8a7 100644 --- a/com/Acrobot/ChestShop/Utils/SignUtil.java +++ b/com/Acrobot/ChestShop/Utils/uSign.java @@ -9,7 +9,7 @@ import org.bukkit.block.Sign; /** * @author Acrobot */ -public class SignUtil { +public class uSign { public static boolean isSign(Block block) { return (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN); @@ -33,7 +33,7 @@ public class SignUtil { public static boolean isValidPreparedSign(String[] line) { try { - return !line[0].contains("[") && !line[0].contains("]") && !line[3].isEmpty() && !line[3].split(":")[0].isEmpty() && Numerical.isInteger(line[1]) && line[2].split(":").length <= 2; + return !line[0].startsWith("[") && !line[0].endsWith("]") && !line[0].startsWith(":") && !line[3].split(":")[0].isEmpty() && uNumber.isInteger(line[1]) && line[2].split(":").length <= 2; } catch (Exception e) { return false; } @@ -48,7 +48,7 @@ public class SignUtil { } text = text.replace("b", "").replace("s", ""); String[] split = text.split(":"); - if (Numerical.isFloat(split[0])) { + if (uNumber.isFloat(split[0])) { float buyPrice = Float.parseFloat(split[0]); return (buyPrice != 0 ? buyPrice : -1); } else if (split[0].equals("free")) { @@ -69,7 +69,7 @@ public class SignUtil { return -1; } - if (Numerical.isFloat(split[sellPart])) { + if (uNumber.isFloat(split[sellPart])) { Float sellPrice = Float.parseFloat(split[sellPart]); return (sellPrice != 0 ? sellPrice : -1); } else if (split[sellPart].equals("free")) { @@ -79,7 +79,7 @@ public class SignUtil { } public static int itemAmount(String text) { - if (Numerical.isInteger(text)) { + if (uNumber.isInteger(text)) { int amount = Integer.parseInt(text); return (amount >= 1 ? amount : 1); } else { diff --git a/plugin.yml b/plugin.yml index d996300..0cabb10 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop database: true -version: 3.00 BETA 7 +version: 3.00 BETA 8 author: Acrobot