- Compatibility with PailStone

- Renamed a lot of things
- Added chest masking option
This commit is contained in:
Acrobot 2011-07-05 19:08:55 +02:00
parent 0bde74f3ad
commit e27cdfb70c
20 changed files with 150 additions and 87 deletions

View File

@ -11,6 +11,7 @@ import com.Acrobot.ChestShop.DB.Transaction;
import com.Acrobot.ChestShop.Listeners.*; import com.Acrobot.ChestShop.Listeners.*;
import com.Acrobot.ChestShop.Logging.FileWriterQueue; import com.Acrobot.ChestShop.Logging.FileWriterQueue;
import com.Acrobot.ChestShop.Logging.Logging; import com.Acrobot.ChestShop.Logging.Logging;
import com.Acrobot.ChestShop.Protection.MaskChest;
import com.avaje.ebean.EbeanServer; import com.avaje.ebean.EbeanServer;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -43,8 +44,6 @@ public class ChestShop extends JavaPlugin {
private static PluginDescriptionFile desc; private static PluginDescriptionFile desc;
private static Server server; private static Server server;
public static String mainWorldName;
public void onEnable() { public void onEnable() {
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
@ -58,7 +57,6 @@ public class ChestShop extends JavaPlugin {
desc = this.getDescription(); //Description of the plugin desc = this.getDescription(); //Description of the plugin
server = getServer(); //Setting out server variable 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! //Yep, set up our folder!
folder = getDataFolder(); folder = getDataFolder();
@ -69,7 +67,7 @@ public class ChestShop extends JavaPlugin {
//Now set up our database for storing transactions! //Now set up our database for storing transactions!
setupDBfile(); setupDBfile();
if (Config.getBoolean(Property.USE_DATABASE)) { if (Config.getBoolean(Property.LOG_TO_DATABASE)) {
setupDB(); setupDB();
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Queue(), 200L, 200L); 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); 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! //Register our commands!
getCommand("iteminfo").setExecutor(new ItemInfo()); getCommand("iteminfo").setExecutor(new ItemInfo());
getCommand("chestOptions").setExecutor(new Options()); getCommand("chestOptions").setExecutor(new Options());
getCommand("csVersion").setExecutor(new Version()); getCommand("csVersion").setExecutor(new Version());
System.out.println('[' + desc.getName() + "] version " + desc.getVersion() + " initialized!"); System.out.println('[' + getPluginName() + "] version " + getVersion() + " initialized!");
} }
public void onDisable() { public void onDisable() {
System.out.println('[' + desc.getName() + "] version " + desc.getVersion() + " shutting down!"); System.out.println('[' + getPluginName() + "] version " + getVersion() + " shutting down!");
} }
///////////////////// DATABASE STUFF //////////////////////////////// ///////////////////// DATABASE STUFF ////////////////////////////////

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop.Chests; package com.Acrobot.ChestShop.Chests;
import com.Acrobot.ChestShop.Utils.BlockSearch; import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.InventoryUtil; import com.Acrobot.ChestShop.Utils.uInventory;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -80,25 +80,25 @@ public class MinecraftChest implements ChestObject {
} }
private Chest getNeighbor() { private Chest getNeighbor() {
return BlockSearch.findNeighbor(main); return uBlock.findNeighbor(main);
} }
private static int amount(ItemStack item, short durability, Chest chest) { 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) { private static int fits(ItemStack item, int amount, short durability, Chest chest) {
Inventory inv = chest.getInventory(); 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) { private static int addItem(ItemStack item, int amount, Chest chest) {
Inventory inv = chest.getInventory(); 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) { private static int removeItem(ItemStack item, short durability, int amount, Chest chest) {
Inventory inv = chest.getInventory(); Inventory inv = chest.getInventory();
return InventoryUtil.remove(inv, item, amount, durability); return uInventory.remove(inv, item, amount, durability);
} }
} }

View File

@ -6,16 +6,17 @@ package com.Acrobot.ChestShop.Config;
public enum Property { public enum Property {
REVERSE_BUTTONS(false, "If true, people will buy with left-click and sell with right-click."), 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"), 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_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?"), 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"), LOG_TO_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"),
GENERATE_STATISTICS_PAGE(false, "If true, plugin will generate shop statistics webpage."), 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?"), 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?"), 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?"), 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_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; private Object value;

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Items; package com.Acrobot.ChestShop.Items;
import com.Acrobot.ChestShop.Utils.Numerical; import com.Acrobot.ChestShop.Utils.uNumber;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack;
public class Items { public class Items {
public static Material getMat(String itemName) { public static Material getMat(String itemName) {
if (Numerical.isInteger(itemName)) { if (uNumber.isInteger(itemName)) {
return Material.getMaterial(Integer.parseInt(itemName)); return Material.getMaterial(Integer.parseInt(itemName));
} }
int length = 256; int length = 256;
@ -36,7 +36,7 @@ public class Items {
} }
String[] split = itemName.split(":"); String[] split = itemName.split(":");
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 && uNumber.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0);
Material mat; Material mat;

View File

@ -2,8 +2,8 @@ package com.Acrobot.ChestShop.Listeners;
import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Restrictions.RestrictedSign; import com.Acrobot.ChestShop.Restrictions.RestrictedSign;
import com.Acrobot.ChestShop.Utils.BlockSearch; import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.SignUtil; import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -24,7 +24,7 @@ public class blockBreak extends BlockListener {
return; return;
} }
if (SignUtil.isSign(block)) { if (uSign.isSign(block)) {
Sign currentSign = (Sign) block.getState(); Sign currentSign = (Sign) block.getState();
if (RestrictedSign.isRestricted(currentSign)) { if (RestrictedSign.isRestricted(currentSign)) {
event.setCancelled(true); event.setCancelled(true);
@ -32,7 +32,7 @@ public class blockBreak extends BlockListener {
currentSign.update(true); currentSign.update(true);
} }
Sign sign = BlockSearch.findSign(block); Sign sign = uBlock.findSign(block);
if (sign != null) { if (sign != null) {
if (!player.getName().equals(sign.getLine(0))) { if (!player.getName().equals(sign.getLine(0))) {

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Listeners; 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.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockListener;
@ -12,7 +12,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
public class blockPlace extends BlockListener { public class blockPlace extends BlockListener {
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlockAgainst(); 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); event.setCancelled(true);
} }
} }

View File

@ -7,8 +7,8 @@ import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Protection.Default; import com.Acrobot.ChestShop.Protection.Default;
import com.Acrobot.ChestShop.Restrictions.RestrictedSign; import com.Acrobot.ChestShop.Restrictions.RestrictedSign;
import com.Acrobot.ChestShop.Shop.ShopManagement; import com.Acrobot.ChestShop.Shop.ShopManagement;
import com.Acrobot.ChestShop.Utils.BlockSearch; import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.SignUtil; import com.Acrobot.ChestShop.Utils.uSign;
import net.minecraft.server.IInventory; import net.minecraft.server.IInventory;
import net.minecraft.server.InventoryLargeChest; import net.minecraft.server.InventoryLargeChest;
import org.bukkit.Material; import org.bukkit.Material;
@ -52,15 +52,12 @@ public class playerInteract extends PlayerListener {
} }
} }
if (!SignUtil.isSign(block)) { if (!uSign.isSign(block)) {
return;
}
Sign sign = (Sign) block.getState();
if (!SignUtil.isValid(sign)) {
return; 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; return;
} }
@ -71,7 +68,7 @@ public class playerInteract extends PlayerListener {
} }
if (player.getName().equals(sign.getLine(0))) { if (player.getName().equals(sign.getLine(0))) {
Chest chest1 = BlockSearch.findChest(sign); Chest chest1 = uBlock.findChest(sign);
if (chest1 == null) { if (chest1 == null) {
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED)); player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
return; return;
@ -80,7 +77,7 @@ public class playerInteract extends PlayerListener {
Inventory inv1 = chest1.getInventory(); Inventory inv1 = chest1.getInventory();
IInventory iInv1 = ((CraftInventory) inv1).getInventory(); IInventory iInv1 = ((CraftInventory) inv1).getInventory();
Chest chest2 = BlockSearch.findNeighbor(chest1); Chest chest2 = uBlock.findNeighbor(chest1);
if (chest2 != null) { if (chest2 != null) {
Inventory inv2 = chest2.getInventory(); Inventory inv2 = chest2.getInventory();

View File

@ -8,9 +8,9 @@ import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Protection.Default; import com.Acrobot.ChestShop.Protection.Default;
import com.Acrobot.ChestShop.Protection.Security; import com.Acrobot.ChestShop.Protection.Security;
import com.Acrobot.ChestShop.Restrictions.RestrictedSign; import com.Acrobot.ChestShop.Restrictions.RestrictedSign;
import com.Acrobot.ChestShop.Utils.BlockSearch; import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.Numerical; import com.Acrobot.ChestShop.Utils.uNumber;
import com.Acrobot.ChestShop.Utils.SignUtil; import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -30,7 +30,7 @@ public class signChange extends BlockListener {
Block signBlock = event.getBlock(); Block signBlock = event.getBlock();
String[] line = event.getLines(); String[] line = event.getLines();
Boolean isAlmostReady = SignUtil.isValidPreparedSign(event.getLines()); Boolean isAlmostReady = uSign.isValidPreparedSign(event.getLines());
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -70,14 +70,14 @@ public class signChange extends BlockListener {
return; return;
} }
Block secondSign = signBlock.getFace(BlockFace.DOWN); 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); dropSign(event);
} }
} }
return; 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))) { if (line[0].isEmpty() || (!line[0].startsWith(player.getName()) && !Permission.has(player, Permission.ADMIN))) {
event.setLine(0, player.getName()); event.setLine(0, player.getName());
@ -85,7 +85,7 @@ public class signChange extends BlockListener {
line = event.getLines(); line = event.getLines();
boolean isAdminShop = SignUtil.isAdminShop(line[0]); boolean isAdminShop = uSign.isAdminShop(line[0]);
if (!isReady) { if (!isReady) {
int prices = line[2].split(":").length; int prices = line[2].split(":").length;
@ -98,7 +98,7 @@ public class signChange extends BlockListener {
} }
String[] split = line[3].split(":"); String[] split = line[3].split(":");
if (Numerical.isInteger(split[0])) { if (uNumber.isInteger(split[0])) {
String matName = mat.name(); String matName = mat.name();
if (split.length == 2) { if (split.length == 2) {
int length = matName.length(); 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 (!isAdminShop) {
if (chest == null) { if (chest == null) {

View File

@ -32,7 +32,7 @@ public class Logging {
public static void logTransaction(boolean isBuying, Shop shop, Player player) { 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); 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; return;
} }
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop.Protection; package com.Acrobot.ChestShop.Protection;
import com.Acrobot.ChestShop.Utils.BlockSearch; import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.SignUtil; import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -12,17 +12,17 @@ import org.bukkit.entity.Player;
*/ */
public class Default implements Protection { public class Default implements Protection {
public boolean isProtected(Block block) { 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; return true;
} else { } else {
if (!(block.getState() instanceof Chest)) { if (!(block.getState() instanceof Chest)) {
return false; return false;
} }
if (BlockSearch.findSign(block) != null) { if (uBlock.findSign(block) != null) {
return true; return true;
} }
Chest neighbor = BlockSearch.findNeighbor(block); Chest neighbor = uBlock.findNeighbor(block);
if (neighbor != null && BlockSearch.findSign(neighbor.getBlock()) != null) { if (neighbor != null && uBlock.findSign(neighbor.getBlock()) != null) {
return true; return true;
} }
} }
@ -31,10 +31,10 @@ public class Default implements Protection {
} }
public boolean canAccess(Player player, Block block) { public boolean canAccess(Player player, Block block) {
Sign sign = BlockSearch.findSign(block); Sign sign = uBlock.findSign(block);
Chest nChest = BlockSearch.findNeighbor(block); Chest nChest = uBlock.findNeighbor(block);
Sign nSign = (nChest != null ? BlockSearch.findSign(nChest.getBlock()) : null); Sign nSign = (nChest != null ? uBlock.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()))) 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())); || (nSign != null && nSign.getLine(0).equals(player.getName()));
} }

View File

@ -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;
}
}

View File

@ -1,6 +1,6 @@
package com.Acrobot.ChestShop.Protection; 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.Block;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -25,9 +25,9 @@ public class Security {
} }
public static boolean canPlaceSign(Player p, Block block) { public static boolean canPlaceSign(Player p, Block block) {
Chest chest = BlockSearch.findChest(block); Chest chest = uBlock.findChest(block);
Sign sign1 = BlockSearch.findSign(chest.getBlock()); Sign sign1 = uBlock.findSign(chest.getBlock());
Sign sign2 = BlockSearch.findSign(block); Sign sign2 = uBlock.findSign(block);
return (sign1 == null || sign1.getLine(0).startsWith(p.getName())) && (sign2 == null || sign2.getLine(0).startsWith(p.getName())); return (sign1 == null || sign1.getLine(0).startsWith(p.getName())) && (sign2 == null || sign2.getLine(0).startsWith(p.getName()));
} }

View File

@ -1,7 +1,7 @@
package com.Acrobot.ChestShop.Restrictions; package com.Acrobot.ChestShop.Restrictions;
import com.Acrobot.ChestShop.Permission; 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.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
public class RestrictedSign { public class RestrictedSign {
public static boolean isRestricted(Sign sign) { public static boolean isRestricted(Sign sign) {
Block blockUp = sign.getBlock().getFace(BlockFace.UP); 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) { public static boolean isRestricted(String[] lines) {
@ -22,7 +22,7 @@ public class RestrictedSign {
public static boolean canAccess(Sign sign, Player player) { public static boolean canAccess(Sign sign, Player player) {
Block blockUp = sign.getBlock().getFace(BlockFace.UP); 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; return true;
} }
String world = blockUp.getWorld().getName(); String world = blockUp.getWorld().getName();

View File

@ -8,8 +8,8 @@ import com.Acrobot.ChestShop.Config.Property;
import com.Acrobot.ChestShop.Economy; import com.Acrobot.ChestShop.Economy;
import com.Acrobot.ChestShop.Logging.Logging; import com.Acrobot.ChestShop.Logging.Logging;
import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.Utils.InventoryUtil; import com.Acrobot.ChestShop.Utils.uInventory;
import com.Acrobot.ChestShop.Utils.SignUtil; import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -30,10 +30,10 @@ public class Shop {
this.stock = itemStacks[0]; this.stock = itemStacks[0];
this.durability = stock.getDurability(); this.durability = stock.getDurability();
this.chest = chest; this.chest = chest;
this.buyPrice = SignUtil.buyPrice(sign.getLine(2)); this.buyPrice = uSign.buyPrice(sign.getLine(2));
this.sellPrice = SignUtil.sellPrice(sign.getLine(2)); this.sellPrice = uSign.sellPrice(sign.getLine(2));
this.owner = sign.getLine(0); this.owner = sign.getLine(0);
this.stockAmount = SignUtil.itemAmount(sign.getLine(1)); this.stockAmount = uSign.itemAmount(sign.getLine(1));
} }
public boolean buy(Player player) { public boolean buy(Player player) {
@ -83,7 +83,7 @@ public class Shop {
.replace("%owner", owner) .replace("%owner", owner)
.replace("%price", formatedPrice)); .replace("%price", formatedPrice));
InventoryUtil.add(player.getInventory(), stock, stockAmount); uInventory.add(player.getInventory(), stock, stockAmount);
Logging.logTransaction(true, this, player); Logging.logTransaction(true, this, player);
player.updateInventory(); player.updateInventory();
@ -122,7 +122,7 @@ public class Shop {
return false; 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)); player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL));
return false; return false;
} }
@ -147,7 +147,7 @@ public class Shop {
.replace("%buyer", owner) .replace("%buyer", owner)
.replace("%price", formatedBalance)); .replace("%price", formatedBalance));
InventoryUtil.remove(player.getInventory(), stock, stockAmount, durability); uInventory.remove(player.getInventory(), stock, stockAmount, durability);
Logging.logTransaction(false, this, player); Logging.logTransaction(false, this, player);
player.updateInventory(); player.updateInventory();
@ -162,7 +162,7 @@ public class Shop {
} }
private String getOwnerAccount() { private String getOwnerAccount() {
if (SignUtil.isAdminShop(owner)) { if (uSign.isAdminShop(owner)) {
return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); return Config.getString(Property.SERVER_ECONOMY_ACCOUNT);
} else { } else {
return owner; return owner;
@ -170,7 +170,7 @@ public class Shop {
} }
private boolean isAdminShop() { private boolean isAdminShop() {
return SignUtil.isAdminShop(owner); return uSign.isAdminShop(owner);
} }
private boolean hasEnoughStock() { private boolean hasEnoughStock() {
@ -178,7 +178,7 @@ public class Shop {
} }
private boolean stockFitsPlayer(Player player) { 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) { private boolean stockFitsChest(ChestObject chest) {

View File

@ -2,7 +2,7 @@ package com.Acrobot.ChestShop.Shop;
import com.Acrobot.ChestShop.Chests.MinecraftChest; import com.Acrobot.ChestShop.Chests.MinecraftChest;
import com.Acrobot.ChestShop.Items.Items; 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.ChatColor;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
*/ */
public class ShopManagement { public class ShopManagement {
public static boolean buy(Sign sign, Player player) { 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)); ItemStack item = Items.getItemStack(sign.getLine(3));
if (item == null) { if (item == null) {
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!"); 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) { 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)); ItemStack item = Items.getItemStack(sign.getLine(3));
if (item == null) { if (item == null) {
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!"); player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");

View File

@ -9,7 +9,7 @@ import org.bukkit.block.Sign;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class BlockSearch { public class uBlock {
static BlockFace[] chestFaces = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH}; 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}; 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) { public static Sign findSign(Block block) {
for (BlockFace bf : shopFaces) { for (BlockFace bf : shopFaces) {
Block faceBlock = block.getFace(bf); Block faceBlock = block.getFace(bf);
if (SignUtil.isSign(faceBlock)) { if (uSign.isSign(faceBlock)) {
Sign sign = (Sign) faceBlock.getState(); Sign sign = (Sign) faceBlock.getState();
if (SignUtil.isValid(sign)) { if (uSign.isValid(sign)) {
return sign; return sign;
} }
} }

View File

@ -10,7 +10,7 @@ import java.util.HashMap;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class InventoryUtil { public class uInventory {
public static int remove(Inventory inv, ItemStack item, int amount, short durability) { public static int remove(Inventory inv, ItemStack item, int amount, short durability) {
amount = (amount > 0 ? amount : 1); amount = (amount > 0 ? amount : 1);

View File

@ -5,7 +5,7 @@ package com.Acrobot.ChestShop.Utils;
* *
* @author Acrobot * @author Acrobot
*/ */
public class Numerical { public class uNumber {
public static boolean isInteger(String string) { public static boolean isInteger(String string) {
try { try {
Integer.parseInt(string); Integer.parseInt(string);

View File

@ -9,7 +9,7 @@ import org.bukkit.block.Sign;
/** /**
* @author Acrobot * @author Acrobot
*/ */
public class SignUtil { public class uSign {
public static boolean isSign(Block block) { public static boolean isSign(Block block) {
return (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN); return (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN);
@ -33,7 +33,7 @@ public class SignUtil {
public static boolean isValidPreparedSign(String[] line) { public static boolean isValidPreparedSign(String[] line) {
try { 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) { } catch (Exception e) {
return false; return false;
} }
@ -48,7 +48,7 @@ public class SignUtil {
} }
text = text.replace("b", "").replace("s", ""); text = text.replace("b", "").replace("s", "");
String[] split = text.split(":"); String[] split = text.split(":");
if (Numerical.isFloat(split[0])) { if (uNumber.isFloat(split[0])) {
float buyPrice = Float.parseFloat(split[0]); float buyPrice = Float.parseFloat(split[0]);
return (buyPrice != 0 ? buyPrice : -1); return (buyPrice != 0 ? buyPrice : -1);
} else if (split[0].equals("free")) { } else if (split[0].equals("free")) {
@ -69,7 +69,7 @@ public class SignUtil {
return -1; return -1;
} }
if (Numerical.isFloat(split[sellPart])) { if (uNumber.isFloat(split[sellPart])) {
Float sellPrice = Float.parseFloat(split[sellPart]); Float sellPrice = Float.parseFloat(split[sellPart]);
return (sellPrice != 0 ? sellPrice : -1); return (sellPrice != 0 ? sellPrice : -1);
} else if (split[sellPart].equals("free")) { } else if (split[sellPart].equals("free")) {
@ -79,7 +79,7 @@ public class SignUtil {
} }
public static int itemAmount(String text) { public static int itemAmount(String text) {
if (Numerical.isInteger(text)) { if (uNumber.isInteger(text)) {
int amount = Integer.parseInt(text); int amount = Integer.parseInt(text);
return (amount >= 1 ? amount : 1); return (amount >= 1 ? amount : 1);
} else { } else {

View File

@ -3,7 +3,7 @@ name: ChestShop
main: com.Acrobot.ChestShop.ChestShop main: com.Acrobot.ChestShop.ChestShop
database: true database: true
version: 3.00 BETA 7 version: 3.00 BETA 8
author: Acrobot author: Acrobot