ChestShop-3/com/Acrobot/ChestShop/Containers/MinecraftChest.java
Acrobot f1ee558e3a - Reformatted code
- Switched from YamlConfiguration to BreezeConfiguration (from ChestShop 4)
- Fixed getDouble()
- Instead of checking for Admin Shops, we just pass in a new AdminShop Container
- Created events for shop creation, protection checks and protection creation
- Expanded string data value parsing, for example - you can use "Ocelot Monster" on the sign
- Collected all external plugin wrappers in a single folder
- Instead of using statics, now we use objects
- Fixed enchantments for armour
- Made config more readable
- Added a setting for removing empty shops
- Switched from System.out to logger
- Also, switched from ugly file logging to Java's native one (FileHandler)
- Added an option to tax transactions even when SERVER_ECONOMY_ACCOUNT is empty
- Changed the Container interface
2012-05-10 16:32:25 +02:00

76 lines
2.1 KiB
Java

package com.Acrobot.ChestShop.Containers;
import com.Acrobot.ChestShop.Utils.uBlock;
import com.Acrobot.ChestShop.Utils.uInventory;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public class MinecraftChest implements Container {
private final Chest chest;
private final BlockFace[] neighborFaces = new BlockFace[]{BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
public MinecraftChest(Chest chest) {
this.chest = chest;
}
public boolean isEmpty() {
for (ItemStack item : chest.getInventory()) {
if (item != null) {
return false;
}
}
return true;
}
public void addItem(ItemStack item, int amount) {
uInventory.add(chest.getInventory(), item, amount);
}
public void removeItem(ItemStack item, short durability, int amount) {
uInventory.remove(chest.getInventory(), item, amount, durability);
}
public int amount(ItemStack item, short durability) {
return uInventory.amount(chest.getInventory(), item, durability);
}
public boolean hasEnough(ItemStack item, int amount, short durability) {
return amount(item, durability) >= amount;
}
public boolean fits(ItemStack item, int amount, short durability) {
return uInventory.fits(chest.getInventory(), item, amount, durability) <= 0;
}
public Sign findShopSign() {
Sign sign = uBlock.findAnyNearbyShopSign(chest.getBlock());
if (sign == null && getNeighbor() != null) {
sign = uBlock.findAnyNearbyShopSign(getNeighbor().getBlock());
}
return sign;
}
private Chest getNeighbor() {
Block chestBlock = chest.getBlock();
for (BlockFace chestFace : neighborFaces) {
Block relative = chestBlock.getRelative(chestFace);
if (relative.getState() instanceof Chest) {
return (Chest) relative.getState();
}
}
return null;
}
}