Updated inventories to a has-a relationship.

Added PlayerInventory interface with playeronly methods.
Add equals to ItemStack.

By: Erik Broes <erikbroes@grum.nl>
This commit is contained in:
Bukkit/Spigot
2011-01-09 18:21:31 +01:00
parent f81c44fbba
commit f95c139dd6
6 changed files with 237 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
package org.bukkit;
import java.util.Collection;
import java.util.HashMap;
/**
* Interface to the various inventories
@@ -20,21 +20,6 @@ public interface Inventory {
*/
public String getName();
/**
* TODO Set the name of the inventory
*
* @param name The new name of the inventory
public void setName(String name);
*/
/** TODO: Appears minecraft has different ideas for slots!
* Get the slot at a specific index of an inventory
*
* @param index The index of the slot to get
* @return The Slot found at the index
public Slot getSlot(int index);
*/
/**
* Get the ItemStack found in the slot at the given index
*
@@ -43,23 +28,108 @@ public interface Inventory {
*/
public ItemStack getItem(int index);
/**
* Stores the ItemStack at the given index
*
* @param index The index where to put the ItemStack
* @param item The ItemStack to set
*/
public void setItem(int index, ItemStack item);
/**
* Stores the given ItemStacks in the inventory
*
* @param items The ItemStacks to add
* @return
*/
public HashMap<Integer, ItemStack> addItem(ItemStack... items);
/**
* Get all ItemStacks from the inventory
*
* @return All the ItemStacks from all slots
*/
public Collection<ItemStack> getContents();
public ItemStack[] getContents();
/*
* TODO public boolean contains(int materialId); public boolean
* contains(Material material); public boolean contains(ItemStack item);
/**
* Check if the inventory contains any ItemStacks with the given materialId
*
* public Collection<Slot> all(int materialId); public Collection<Slot>
* all(Material material); public Collection<Slot> all(ItemStack item);
*
* public Slot first(int materialId); public Slot first(Material material);
* public Slot first(ItemStack item);
*
* public int firstEmptyIndex();
* @param materialId The materialId to check for
* @return If any ItemStacks were found
*/
public boolean contains(int materialId);
/**
* Check if the inventory contains any ItemStacks with the given material
*
* @param material The material to check for
* @return If any ItemStacks were found
*/
public boolean contains(Material material);
/**
* Check if the inventory contains any ItemStacks matching the given ItemStack
* This will only match if both the type and the amount of the stack match
*
* @param item The ItemStack to match against
* @return If any matching ItemStacks were found
*/
public boolean contains(ItemStack item);
/**
* Find all slots in the inventory containing any ItemStacks with the given materialId
*
* @param materialId The materialId to look for
* @return The Slots found.
*/
public HashMap<Integer,ItemStack> all(int materialId);
/**
* Find all slots in the inventory containing any ItemStacks with the given material
*
* @param materialId The material to look for
* @return The Slots found.
*/
public HashMap<Integer,ItemStack> all(Material material);
/**
* Find all slots in the inventory containing any ItemStacks with the given ItemStack
* This will only match slots if both the type and the amount of the stack match
*
* @param item The ItemStack to match against
* @return The Slots found.
*/
public HashMap<Integer,ItemStack> all(ItemStack item);
/**
* Find the first slot in the inventory containing an ItemStack with the given materialId
*
* @param materialId The materialId to look for
* @return The Slot found.
*/
public int first(int materialId);
/**
* Find the first slot in the inventory containing an ItemStack with the given material
*
* @param materialId The material to look for
* @return The Slot found.
*/
public int first(Material material);
/**
* Find the first slot in the inventory containing an ItemStack with the given stack
* This will only match a slot if both the type and the amount of the stack match
*
* @param item The ItemStack to match against
* @return The Slot found.
*/
public int first(ItemStack item);
/**
* Find the first empty Slot.
*
* @return The first empty Slot found.
*/
public int firstEmpty();
}