diff options
author | Erik Broes <erikbroes@grum.nl> | 2011-01-09 18:21:31 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@grum.nl> | 2011-01-09 18:29:48 +0100 |
commit | 5a1310148e9475e41a3c0a1ea51dc87d9a196593 (patch) | |
tree | c94dec0c433f495d196b46587ce45b8a6c0c361c /src/main/java/org | |
parent | 7c93a16862c7d41c0765efb11e900621525c3c8a (diff) | |
download | bukkit-5a1310148e9475e41a3c0a1ea51dc87d9a196593.tar bukkit-5a1310148e9475e41a3c0a1ea51dc87d9a196593.tar.gz bukkit-5a1310148e9475e41a3c0a1ea51dc87d9a196593.tar.lz bukkit-5a1310148e9475e41a3c0a1ea51dc87d9a196593.tar.xz bukkit-5a1310148e9475e41a3c0a1ea51dc87d9a196593.zip |
Updated inventories to a has-a relationship.
Added PlayerInventory interface with playeronly methods.
Add equals to ItemStack.
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/HumanEntity.java | 32 | ||||
-rw-r--r-- | src/main/java/org/bukkit/Inventory.java | 114 | ||||
-rw-r--r-- | src/main/java/org/bukkit/ItemStack.java | 19 | ||||
-rw-r--r-- | src/main/java/org/bukkit/PlayerInventory.java | 82 | ||||
-rw-r--r-- | src/main/java/org/bukkit/Slot.java | 22 | ||||
-rw-r--r-- | src/main/java/org/bukkit/StorageMinecart.java | 8 |
6 files changed, 232 insertions, 45 deletions
diff --git a/src/main/java/org/bukkit/HumanEntity.java b/src/main/java/org/bukkit/HumanEntity.java index 0cc7c1f5..04b391a8 100644 --- a/src/main/java/org/bukkit/HumanEntity.java +++ b/src/main/java/org/bukkit/HumanEntity.java @@ -13,10 +13,34 @@ public interface HumanEntity extends LivingEntity { public String getName(); /** - * Gets the item this entity has currently selected, which will be shown in - * their hand + * Get the player's inventory. * - * @return ItemStack containing details on the item this entity has selected + * @return The inventory of the player, this also contains the armor slots. */ - public ItemStack getSelectedItem(); + public PlayerInventory getInventory(); + + /** + * Returns the ItemStack currently in your hand, can be empty. + * + * @return The ItemStack of the item you are currently holding. + */ + public ItemStack getItemInHand(); + + + /** TODO: This probably won't work ;( + * Sets the item to the given ItemStack, this will replace whatever the + * user was holding. + * + * @param item The ItemStack which will end up in the hand + * @return + * + public void setItemInHand( ItemStack item ); + + ** + * Changes the item in hand to another of your 'action slots'. + * + * @param index The new index to use, only valid ones are 0-8. + * + public void selectItemInHand( int index ); + */ } diff --git a/src/main/java/org/bukkit/Inventory.java b/src/main/java/org/bukkit/Inventory.java index 7378903e..a3233694 100644 --- a/src/main/java/org/bukkit/Inventory.java +++ b/src/main/java/org/bukkit/Inventory.java @@ -1,6 +1,6 @@ package org.bukkit; -import java.util.Collection; +import java.util.HashMap; /** * Interface to the various inventories @@ -21,45 +21,115 @@ public interface Inventory { public String getName(); /** - * TODO Set the name of the inventory + * Get the ItemStack found in the slot at the given index * - * @param name The new name of the inventory - public void setName(String name); + * @param index The index of the Slot's ItemStack to return + * @return The ItemStack in the slot */ + public ItemStack getItem(int index); - /** TODO: Appears minecraft has different ideas for slots! - * Get the slot at a specific index of an inventory + /** + * Stores the ItemStack at the given index * - * @param index The index of the slot to get - * @return The Slot found at the index - public Slot getSlot(int index); + * @param index The index where to put the ItemStack + * @param item The ItemStack to set */ + public void setItem(int index, ItemStack item); /** - * Get the ItemStack found in the slot at the given index + * Stores the given ItemStacks in the inventory * - * @param index The index of the Slot's ItemStack to return - * @return The ItemStack in the slot + * @param items The ItemStacks to add + * @return */ - public ItemStack getItem(int index); + 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(); + + /** + * Check if the inventory contains any ItemStacks with the given materialId + * + * @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); - /* - * TODO public boolean contains(int materialId); public boolean - * contains(Material material); public boolean contains(ItemStack item); + /** + * Find all slots in the inventory containing any ItemStacks with the given material * - * public Collection<Slot> all(int materialId); public Collection<Slot> - * all(Material material); public Collection<Slot> all(ItemStack item); + * @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 * - * public Slot first(int materialId); public Slot first(Material material); - * public Slot first(ItemStack item); + * @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. * - * public int firstEmptyIndex(); + * @return The first empty Slot found. */ + public int firstEmpty(); }
\ No newline at end of file diff --git a/src/main/java/org/bukkit/ItemStack.java b/src/main/java/org/bukkit/ItemStack.java index f2350621..e90a5fe5 100644 --- a/src/main/java/org/bukkit/ItemStack.java +++ b/src/main/java/org/bukkit/ItemStack.java @@ -115,4 +115,23 @@ public class ItemStack { public byte getDamage() {
return damage;
}
+
+ /**
+ * Get the maximum stacksize for the material hold in this ItemStack
+ * Returns -1 if it has no idea.
+ *
+ * @return The maximum you can stack this material to.
+ */
+ public int getMaxStackSize() {
+ return -1;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ return false;
+ }
+
+ public boolean equals(ItemStack item) {
+ return item.getAmount() == getAmount() && item.getTypeID() == getTypeID();
+ }
}
diff --git a/src/main/java/org/bukkit/PlayerInventory.java b/src/main/java/org/bukkit/PlayerInventory.java new file mode 100644 index 00000000..419eb07b --- /dev/null +++ b/src/main/java/org/bukkit/PlayerInventory.java @@ -0,0 +1,82 @@ +package org.bukkit;
+
+import java.util.ArrayList;
+
+/**
+ * Includes interface to the 4 armor slots
+ */
+public interface PlayerInventory extends Inventory {
+ /**
+ * Get all ItemStacks from the armor slots
+ *
+ * @return All the ItemStacks from the armor slots
+ */
+ public ArrayList<ItemStack> getArmorContents();
+
+ /**
+ * Return the ItemStack from the helmet slot
+ *
+ * @return The ItemStack in the helmet slot
+ */
+ public ItemStack getHelmet();
+
+ /**
+ * Return the ItemStack from the chestplate slot
+ *
+ * @return The ItemStack in the chestplate slot
+ */
+ public ItemStack getChestplate();
+
+ /**
+ * Return the ItemStack from the leg slot
+ *
+ * @return The ItemStack in the leg slot
+ */
+ public ItemStack getLeggings();
+
+ /**
+ * Return the ItemStack from the boots slot
+ *
+ * @return The ItemStack in the boots slot
+ */
+ public ItemStack getBoots();
+
+ /**
+ * Put the given ItemStack into the helmet slot
+ * This does not check if the ItemStack is a helmet
+ *
+ * @param helmet The ItemStack to use as helmet
+ */
+ public void setHelmet(ItemStack helmet);
+
+ /**
+ * Put the given ItemStack into the chestplate slot
+ * This does not check if the ItemStack is a chestplate
+ *
+ * @param chestplate The ItemStack to use as chestplate
+ */
+ public void setChestplate(ItemStack chestplate);
+
+ /**
+ * Put the given ItemStack into the leg slot
+ * This does not check if the ItemStack is a pair of leggings
+ *
+ * @param leggings The ItemStack to use as leggings
+ */
+ public void setLeggings(ItemStack leggings);
+
+ /**
+ * Put the given ItemStack into the boots slot
+ * This does not check if the ItemStack is a boots
+ *
+ * @param boots The ItemStack to use as boots
+ */
+ public void setBoots(ItemStack boots);
+
+ /**
+ * Returns the ItemStack currently hold
+ *
+ * @return The currently holded ItemStack
+ */
+ public ItemStack getItemInHand();
+}
\ No newline at end of file diff --git a/src/main/java/org/bukkit/Slot.java b/src/main/java/org/bukkit/Slot.java index 3ead0399..008c464f 100644 --- a/src/main/java/org/bukkit/Slot.java +++ b/src/main/java/org/bukkit/Slot.java @@ -3,39 +3,25 @@ package org.bukkit; /** * Represents a slot in an inventory */ -public class Slot { - private Inventory inventory; - private int index; - - public Slot(Inventory inventory, int index) { - this.inventory = inventory; - this.index = index; - } - +public interface Slot { /** * Gets the inventory this slot belongs to * * @return The inventory */ - public Inventory getInventory() { - return inventory; - } + public Inventory getInventory(); /** * Get the index this slot belongs to * * @return Index of the slot */ - public int getIndex() { - return index; - } + public int getIndex(); /** * Get the item from the slot. * * @return ItemStack in the slot. */ - public ItemStack getItem() { - return inventory.getItem(index); - } + public ItemStack getItem(); } diff --git a/src/main/java/org/bukkit/StorageMinecart.java b/src/main/java/org/bukkit/StorageMinecart.java index bd7b1b02..7ec1b5ac 100644 --- a/src/main/java/org/bukkit/StorageMinecart.java +++ b/src/main/java/org/bukkit/StorageMinecart.java @@ -5,5 +5,11 @@ package org.bukkit; *
* @author sk89q
*/
-public interface StorageMinecart extends Minecart, Inventory {
+public interface StorageMinecart extends Minecart {
+ /**
+ * Return the inventory object for this StorageMinecart.
+ *
+ * @return The inventory for this Minecart
+ */
+ public Inventory getInventory();
}
|