Removed unnecessary Container interface

Added a class which implements Inventory instead
This commit is contained in:
Acrobot 2012-08-10 18:58:45 +02:00
parent d1dd4b7f5d
commit b8d8cdb398
4 changed files with 159 additions and 125 deletions

View File

@ -1,30 +0,0 @@
package com.Acrobot.ChestShop.Containers;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public class AdminChest implements Container {
public boolean isEmpty() {
return false;
}
public void addItem(ItemStack item) {
}
public void removeItem(ItemStack item) {
}
public int amount(ItemStack item) {
return Integer.MAX_VALUE;
}
public boolean hasEnough(ItemStack item) {
return true;
}
public boolean fits(ItemStack item) {
return true;
}
}

View File

@ -0,0 +1,159 @@
package com.Acrobot.ChestShop.Containers;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
/**
* @author Acrobot
*/
public class AdminInventory implements Inventory {
public int getSize() {
return Integer.MAX_VALUE;
}
public int getMaxStackSize() {
return Integer.MAX_VALUE;
}
public void setMaxStackSize(int i) {
}
public String getName() {
return "Admin inventory";
}
public ItemStack getItem(int i) {
return null;
}
public void setItem(int i, ItemStack itemStack) {
}
public HashMap<Integer, ItemStack> addItem(ItemStack... itemStacks) {
return new HashMap<Integer, ItemStack>();
}
public HashMap<Integer, ItemStack> removeItem(ItemStack... itemStacks) {
return new HashMap<Integer, ItemStack>();
}
public ItemStack[] getContents() {
return new ItemStack[] {
new ItemStack(Material.CHEST, 1),
new ItemStack(Material.AIR, Integer.MAX_VALUE)
};
}
public void setContents(ItemStack[] itemStacks) {
}
public boolean contains(int i) {
return true;
}
public boolean contains(Material material) {
return true;
}
public boolean contains(ItemStack itemStack) {
return true;
}
public boolean contains(int i, int i1) {
return true;
}
public boolean contains(Material material, int i) {
return true;
}
public boolean contains(ItemStack itemStack, int i) {
return true;
}
public HashMap<Integer, ? extends ItemStack> all(int i) {
HashMap<Integer, ItemStack> items = new HashMap<Integer, ItemStack>();
items.put(1, new ItemStack(i, Integer.MAX_VALUE));
return items;
}
public HashMap<Integer, ? extends ItemStack> all(Material material) {
return all(material.getId());
}
public HashMap<Integer, ? extends ItemStack> all(ItemStack itemStack) {
HashMap<Integer, ItemStack> items = new HashMap<Integer, ItemStack>();
ItemStack clone = itemStack.clone();
clone.setAmount(Integer.MAX_VALUE);
items.put(1, clone);
return items;
}
public int first(int i) {
return 0;
}
public int first(Material material) {
return 0;
}
public int first(ItemStack itemStack) {
return 0;
}
public int firstEmpty() {
return 0;
}
public void remove(int i) {
}
public void remove(Material material) {
}
public void remove(ItemStack itemStack) {
}
public void clear(int i) {
}
public void clear() {
}
public List<HumanEntity> getViewers() {
return new ArrayList<HumanEntity>();
}
public String getTitle() {
return "Admin inventory";
}
public InventoryType getType() {
return null;
}
public InventoryHolder getHolder() {
return null;
}
public ListIterator<ItemStack> iterator() {
return null;
}
public ListIterator<ItemStack> iterator(int i) {
return null;
}
}

View File

@ -1,20 +0,0 @@
package com.Acrobot.ChestShop.Containers;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public interface Container {
boolean isEmpty();
void addItem(ItemStack item);
void removeItem(ItemStack item);
int amount(ItemStack item);
boolean hasEnough(ItemStack item);
boolean fits(ItemStack item);
}

View File

@ -1,75 +0,0 @@
package com.Acrobot.ChestShop.Containers;
import com.Acrobot.Breeze.Utils.InventoryUtil;
import com.Acrobot.ChestShop.Utils.uBlock;
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 ShopChest implements Container {
private final Chest chest;
private static final BlockFace[] NEIGHBOR_FACES = new BlockFace[]{BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH};
public ShopChest(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) {
InventoryUtil.add(item, chest.getInventory());
}
public void removeItem(ItemStack item) {
InventoryUtil.remove(item, chest.getInventory());
}
public int amount(ItemStack item) {
return InventoryUtil.getAmount(item, chest.getInventory());
}
public boolean hasEnough(ItemStack item) {
return amount(item) >= item.getAmount();
}
public boolean fits(ItemStack item) {
return InventoryUtil.fits(item, chest.getInventory());
}
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 : NEIGHBOR_FACES) {
Block relative = chestBlock.getRelative(chestFace);
if (relative.getState() instanceof Chest) {
return (Chest) relative.getState();
}
}
return null;
}
}