- Fix for infinite items
- Tried to fix the NPE during transaction - Fixed NPE during Admin Shop setup - Speeded up protection system - Made configuration system more flexible
This commit is contained in:
parent
d919818bb6
commit
51296f6ac9
|
@ -43,6 +43,8 @@ public class ChestShop extends JavaPlugin {
|
|||
private static PluginDescriptionFile desc;
|
||||
private static Server server;
|
||||
|
||||
public static String mainWorldName;
|
||||
|
||||
public void onEnable() {
|
||||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
|
@ -56,12 +58,14 @@ public class ChestShop extends JavaPlugin {
|
|||
|
||||
desc = this.getDescription();
|
||||
server = getServer();
|
||||
mainWorldName = server.getWorlds().get(0).getName();
|
||||
|
||||
//Yep, set up our folder!
|
||||
folder = getDataFolder();
|
||||
|
||||
//Set up our config file!
|
||||
Config.setUp();
|
||||
|
||||
//Yep, set up our folder!
|
||||
folder = getDataFolder();
|
||||
|
||||
//Now set up our database for storing transactions!
|
||||
setupDBfile();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.Acrobot.ChestShop.Config;
|
||||
|
||||
import com.Acrobot.ChestShop.ChestShop;
|
||||
import com.Acrobot.ChestShop.Logging.Logging;
|
||||
import org.bukkit.util.config.Configuration;
|
||||
|
||||
|
@ -11,8 +12,8 @@ import java.util.HashMap;
|
|||
* @author Acrobot
|
||||
*/
|
||||
public class Config {
|
||||
private static File configFile = new File("plugins/ChestShop/config.yml");
|
||||
private static File langFile = new File("plugins/ChestShop/local.yml");
|
||||
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);
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.Acrobot.ChestShop.Config.Language;
|
|||
import com.Acrobot.ChestShop.Config.Property;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Protection.Default;
|
||||
import com.Acrobot.ChestShop.Protection.Security;
|
||||
import com.Acrobot.ChestShop.Shop.ShopManagement;
|
||||
import com.Acrobot.ChestShop.Utils.SearchForBlock;
|
||||
import com.Acrobot.ChestShop.Utils.SignUtil;
|
||||
|
@ -45,7 +44,7 @@ public class playerInteract extends PlayerListener {
|
|||
|
||||
if (Config.getBoolean(Property.USE_BUILT_IN_PROTECTION) && block.getType() == Material.CHEST) {
|
||||
Default defProtection = new Default();
|
||||
if (!Permission.has(player, Permission.ADMIN) && (defProtection.isProtected(block) && !defProtection.canAccess(player, block)) || (Security.isProtected(block) && !Security.canAccess(player, block))) {
|
||||
if (!Permission.has(player, Permission.ADMIN) && (defProtection.isProtected(block) && !defProtection.canAccess(player, block))) {
|
||||
player.sendMessage(Config.getLocal(Language.ACCESS_DENIED));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
@ -72,7 +71,6 @@ public class playerInteract extends PlayerListener {
|
|||
|
||||
if (player.getName().equals(sign.getLine(0))) {
|
||||
Chest chest1 = SearchForBlock.findChest(sign);
|
||||
|
||||
if (chest1 == null) {
|
||||
player.sendMessage(Config.getLocal(Language.NO_CHEST_DETECTED));
|
||||
return;
|
||||
|
|
|
@ -121,7 +121,7 @@ public class signChange extends BlockListener {
|
|||
}
|
||||
}
|
||||
|
||||
if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && Security.protect(player.getName(), chest.getBlock())) {
|
||||
if (Config.getBoolean(Property.PROTECT_CHEST_WITH_LWC) && chest != null && Security.protect(player.getName(), chest.getBlock())) {
|
||||
if(Config.getBoolean(Property.PROTECT_SIGN_WITH_LWC)){
|
||||
Security.protect(player.getName(), signBlock);
|
||||
}
|
||||
|
|
|
@ -8,15 +8,17 @@ import java.util.Map;
|
|||
* @author Acrobot
|
||||
*/
|
||||
public enum Option {
|
||||
BALANCE(true),
|
||||
OUT_OF_STOCK(true),
|
||||
SOMEONE_BOUGHT(true);
|
||||
BALANCE("balance", true),
|
||||
OUT_OF_STOCK("outOfStock", true),
|
||||
SOMEONE_BOUGHT("someoneBought", true);
|
||||
|
||||
private boolean enabled;
|
||||
private String name;
|
||||
private static final Map<String, Option> names = new HashMap<String, Option>();
|
||||
|
||||
private Option(boolean enabled) {
|
||||
private Option(String name, boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.Acrobot.ChestShop.Protection;
|
|||
import com.Acrobot.ChestShop.Utils.SearchForBlock;
|
||||
import com.Acrobot.ChestShop.Utils.SignUtil;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -12,12 +13,15 @@ import org.bukkit.entity.Player;
|
|||
public class Default implements Protection {
|
||||
public boolean isProtected(Block block) {
|
||||
Sign sign = SearchForBlock.findSign(block);
|
||||
return (block != null) && ((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) || sign != null);
|
||||
Chest nChest = SearchForBlock.findChest(block);
|
||||
return ((SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState())) || sign != null) || (nChest != null && SearchForBlock.findSign(nChest.getBlock()) != null);
|
||||
}
|
||||
|
||||
public boolean canAccess(Player player, Block block) {
|
||||
Sign sign = SearchForBlock.findSign(block);
|
||||
return (block != null) && (SignUtil.isSign(block) && SignUtil.isValid((Sign) block.getState()) && ((Sign) block.getState()).getLine(0).equals(player.getName())) || (sign != null && sign.getLine(0).equals(player.getName()));
|
||||
Chest nChest = SearchForBlock.findNeighbor(block);
|
||||
Sign nSign = (nChest != null ? SearchForBlock.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()))) || (nSign != null && nSign.getLine(0).equals(player.getName()));
|
||||
}
|
||||
|
||||
public boolean protect(String name, Block block) {
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
*/
|
||||
public class Shop {
|
||||
public ItemStack stock;
|
||||
public short durability;
|
||||
public int stockAmount;
|
||||
public ChestObject chest;
|
||||
public float buyPrice;
|
||||
|
@ -26,6 +27,7 @@ public class Shop {
|
|||
|
||||
public Shop(ChestObject chest, Sign sign, ItemStack... itemStacks) {
|
||||
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));
|
||||
|
@ -67,7 +69,7 @@ public class Shop {
|
|||
Economy.substract(playerName, buyPrice);
|
||||
|
||||
if (!isAdminShop()) {
|
||||
chest.removeItem(stock, stock.getDurability(), stockAmount);
|
||||
chest.removeItem(stock, durability, stockAmount);
|
||||
}
|
||||
String formatedPrice = Economy.formatBalance(buyPrice);
|
||||
player.sendMessage(Config.getLocal(Language.YOU_BOUGHT_FROM_SHOP)
|
||||
|
@ -111,7 +113,7 @@ public class Shop {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (InventoryUtil.amount(player.getInventory(), stock, stock.getDurability()) < stockAmount) {
|
||||
if (InventoryUtil.amount(player.getInventory(), stock, durability) < stockAmount) {
|
||||
player.sendMessage(Config.getLocal(Language.NOT_ENOUGH_ITEMS_TO_SELL));
|
||||
return false;
|
||||
}
|
||||
|
@ -136,7 +138,7 @@ public class Shop {
|
|||
.replace("%buyer", owner)
|
||||
.replace("%price", formatedBalance));
|
||||
|
||||
InventoryUtil.remove(player.getInventory(), stock, stockAmount, stock.getDurability());
|
||||
InventoryUtil.remove(player.getInventory(), stock, stockAmount, durability);
|
||||
Logging.logTransaction(false, this, player);
|
||||
player.updateInventory();
|
||||
|
||||
|
@ -163,15 +165,15 @@ public class Shop {
|
|||
}
|
||||
|
||||
private boolean hasEnoughStock() {
|
||||
return chest.hasEnough(stock, stockAmount, stock.getDurability());
|
||||
return chest.hasEnough(stock, stockAmount, durability);
|
||||
}
|
||||
|
||||
private boolean stockFitsPlayer(Player player) {
|
||||
return InventoryUtil.fits(player.getInventory(), stock, stockAmount, stock.getDurability()) <= 0;
|
||||
return InventoryUtil.fits(player.getInventory(), stock, stockAmount, durability) <= 0;
|
||||
}
|
||||
|
||||
private boolean stockFitsChest(ChestObject chest) {
|
||||
return chest.fits(stock, stockAmount, stock.getDurability());
|
||||
return chest.fits(stock, stockAmount, durability);
|
||||
}
|
||||
|
||||
private void sendMessageToOwner(String msg) {
|
||||
|
|
|
@ -3,9 +3,11 @@ package com.Acrobot.ChestShop.Shop;
|
|||
import com.Acrobot.ChestShop.Chests.MinecraftChest;
|
||||
import com.Acrobot.ChestShop.Items.Items;
|
||||
import com.Acrobot.ChestShop.Utils.SearchForBlock;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
|
@ -13,14 +15,24 @@ import org.bukkit.entity.Player;
|
|||
public class ShopManagement {
|
||||
public static boolean buy(Sign sign, Player player) {
|
||||
Chest chestMc = SearchForBlock.findChest(sign);
|
||||
Shop shop = new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, sign, Items.getItemStack(sign.getLine(3)));
|
||||
ItemStack item = Items.getItemStack(sign.getLine(3));
|
||||
if(item == null){
|
||||
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
|
||||
return false;
|
||||
}
|
||||
Shop shop = new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, sign, item);
|
||||
|
||||
return shop.buy(player);
|
||||
}
|
||||
|
||||
public static boolean sell(Sign sign, Player player) {
|
||||
Chest chestMc = SearchForBlock.findChest(sign);
|
||||
Shop shop = new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, sign, Items.getItemStack(sign.getLine(3)));
|
||||
ItemStack item = Items.getItemStack(sign.getLine(3));
|
||||
if(item == null){
|
||||
player.sendMessage(ChatColor.RED + "[Shop] The item is not recognised!");
|
||||
return false;
|
||||
}
|
||||
Shop shop = new Shop(chestMc != null ? new MinecraftChest(chestMc) : null, sign, item);
|
||||
|
||||
return shop.sell(player);
|
||||
}
|
||||
|
|
|
@ -39,15 +39,18 @@ public class SearchForBlock {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static Chest findNeighbor(Chest chest) {
|
||||
public static Chest findNeighbor(Block block) {
|
||||
BlockFace[] bf = {BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
|
||||
Block chestBlock = chest.getBlock();
|
||||
for (BlockFace blockFace : bf) {
|
||||
Block neighborBlock = chestBlock.getFace(blockFace);
|
||||
Block neighborBlock = block.getFace(blockFace);
|
||||
if (neighborBlock.getType() == Material.CHEST) {
|
||||
return (Chest) neighborBlock.getState();
|
||||
}
|
||||
}
|
||||
return null; //Shame, we didn't find double chest :/
|
||||
}
|
||||
|
||||
public static Chest findNeighbor(Chest chest){
|
||||
return findNeighbor(chest.getBlock());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,9 +80,10 @@ public class SignUtil {
|
|||
|
||||
public static int itemAmount(String text) {
|
||||
if (Numerical.isInteger(text)) {
|
||||
return Integer.parseInt(text);
|
||||
int amount = Integer.parseInt(text);
|
||||
return (amount >= 1 ? amount : 1);
|
||||
} else {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ name: ChestShop
|
|||
main: com.Acrobot.ChestShop.ChestShop
|
||||
|
||||
database: true
|
||||
version: 3.00 BETA 3
|
||||
version: 3.00 BETA 4
|
||||
|
||||
|
||||
author: Acrobot
|
||||
|
|
Loading…
Reference in New Issue