Package net.glowstone.inventory
Class GlowInventory
java.lang.Object
net.glowstone.inventory.GlowInventory
- All Implemented Interfaces:
Iterable<org.bukkit.inventory.ItemStack>
,org.bukkit.inventory.Inventory
- Direct Known Subclasses:
GlowAnvilInventory
,GlowBeaconInventory
,GlowBrewerInventory
,GlowChestInventory
,GlowCraftingInventory
,GlowEnchantingInventory
,GlowFurnaceInventory
,GlowHorseInventory
,GlowLlamaInventory
,GlowMerchantInventory
,GlowPlayerInventory
,GlowSuperInventory
A class which represents an inventory.
-
Constructor Summary
ModifierConstructorDescriptionprotected
GlowInventory
(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type) GlowInventory
(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size) GlowInventory
(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size, String title) -
Method Summary
Modifier and TypeMethodDescriptionaddItem
(org.bukkit.inventory.ItemStack... items) org.bukkit.inventory.ItemStack
addItemStack
(org.bukkit.inventory.ItemStack item, boolean ignoreMeta) Adds the contents of the given ItemStack to the inventory.void
addViewer
(org.bukkit.entity.HumanEntity viewer) Add a viewer to the inventory.all
(@NotNull org.bukkit.Material material) all
(org.bukkit.inventory.ItemStack item) void
clear()
void
clear
(int index) int
close()
int
consumeItem
(int slot) Consumes an item in the given slot.int
consumeItem
(int slot, boolean wholeStack) Consumes an item or the full stack in the given slot.boolean
contains
(@NotNull org.bukkit.Material material) boolean
contains
(@NotNull org.bukkit.Material material, int amount) boolean
contains
(org.bukkit.inventory.ItemStack item) boolean
contains
(org.bukkit.inventory.ItemStack item, int amount) boolean
containsAtLeast
(org.bukkit.inventory.ItemStack item, int amount) int
first
(@NotNull org.bukkit.inventory.ItemStack item) int
first
(@NotNull org.bukkit.Material material) int
org.bukkit.inventory.ItemStack @NotNull []
org.bukkit.inventory.InventoryHolder
The owner of this inventory.@Nullable org.bukkit.inventory.InventoryHolder
getHolder
(boolean snapshotBlockEntity) @NotNull org.bukkit.inventory.ItemStack
getItem
(int index) org.bukkit.Location
int
The inventory's maximum stack size.int
Gets the number of slots in this inventory according to the protocol.int
getSize()
getSlot
(int slot) Returns a certain slot.getSlots()
Returns the whole slot list.org.bukkit.event.inventory.InventoryType.SlotType
getSlotType
(int slot) Get the type of the specified slot.org.bukkit.inventory.ItemStack[]
getTitle()
The inventory's name.org.bukkit.event.inventory.InventoryType
getType()
The type of this inventory.@NotNull List<org.bukkit.entity.HumanEntity>
Set<org.bukkit.entity.HumanEntity>
Returns the set which contains viewers.void
handleShiftClick
(GlowPlayer player, org.bukkit.inventory.InventoryView view, int clickedSlot, org.bukkit.inventory.ItemStack clickedItem) Handle a shift click in this inventory by the specified player.protected void
initialize
(List<GlowInventorySlot> slots, Set<org.bukkit.entity.HumanEntity> viewers, org.bukkit.inventory.InventoryHolder owner, org.bukkit.event.inventory.InventoryType type, String title) Initializes some key components of this inventory.boolean
isEmpty()
boolean
itemPlaceAllowed
(int slot, org.bukkit.inventory.ItemStack stack) Check whether it is allowed for a player to insert the given ItemStack at the slot, regardless of the slot's current contents.boolean
itemShiftClickAllowed
(int slot, org.bukkit.inventory.ItemStack stack) Check whether, in a shift-click operation, an item of the specified type may be placed in the given slot.@NotNull ListIterator<org.bukkit.inventory.ItemStack>
iterator()
@NotNull ListIterator<org.bukkit.inventory.ItemStack>
iterator
(int index) void
remove
(@NotNull org.bukkit.inventory.ItemStack item) void
remove
(@NotNull org.bukkit.Material material) removeItem
(org.bukkit.inventory.ItemStack... items) removeItemAnySlot
(@NotNull org.bukkit.inventory.ItemStack... items) org.bukkit.inventory.ItemStack
removeItemStack
(org.bukkit.inventory.ItemStack item, boolean ignoreMeta) Removes the given ItemStack from the inventory.void
removeViewer
(org.bukkit.entity.HumanEntity viewer) Remove a viewer from the inventory.void
setContents
(org.bukkit.inventory.ItemStack[] items) void
setItem
(int index, org.bukkit.inventory.ItemStack item) void
setMaxStackSize
(int maxStackSize) The inventory's maximum stack size.void
setStorageContents
(org.bukkit.inventory.ItemStack[] items) void
Set the custom title of this inventory or reset it to the default.toString()
org.bukkit.inventory.ItemStack
tryToFillSlots
(org.bukkit.inventory.ItemStack stack, int... slots) Tries to put the given items into the specified slots of this inventory from the start slot (inclusive) to the end slot (exclusive).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
GlowInventory
protected GlowInventory() -
GlowInventory
public GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type) -
GlowInventory
public GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size) -
GlowInventory
public GlowInventory(org.bukkit.inventory.InventoryHolder holder, org.bukkit.event.inventory.InventoryType type, int size, String title)
-
-
Method Details
-
removeItemAnySlot
@NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> removeItemAnySlot(@NotNull @NotNull org.bukkit.inventory.ItemStack... items) throws IllegalArgumentException - Specified by:
removeItemAnySlot
in interfaceorg.bukkit.inventory.Inventory
- Throws:
IllegalArgumentException
-
initialize
protected void initialize(List<GlowInventorySlot> slots, Set<org.bukkit.entity.HumanEntity> viewers, org.bukkit.inventory.InventoryHolder owner, org.bukkit.event.inventory.InventoryType type, String title) Initializes some key components of this inventory.This should be called in the constructor.
- Parameters:
slots
- List of slots this inventory has.viewers
- Set for storage of current inventory viewers.owner
- InventoryHolder which owns this Inventory.type
- The inventory type.title
- Inventory title, displayed in the client.
-
addViewer
public void addViewer(org.bukkit.entity.HumanEntity viewer) Add a viewer to the inventory.- Parameters:
viewer
- The HumanEntity to add.
-
removeViewer
public void removeViewer(org.bukkit.entity.HumanEntity viewer) Remove a viewer from the inventory.- Parameters:
viewer
- The HumanEntity to remove.
-
getViewersSet
Returns the set which contains viewers.- Returns:
- Viewers set.
-
getSlot
Returns a certain slot.- Parameters:
slot
- index.- Returns:
- The requested slot.
-
getSlotType
public org.bukkit.event.inventory.InventoryType.SlotType getSlotType(int slot) Get the type of the specified slot.- Parameters:
slot
- The slot number.- Returns:
- The SlotType of the slot.
-
itemPlaceAllowed
public boolean itemPlaceAllowed(int slot, org.bukkit.inventory.ItemStack stack) Check whether it is allowed for a player to insert the given ItemStack at the slot, regardless of the slot's current contents.Should return false for crafting output slots or armor slots which cannot accept the given item.
- Parameters:
slot
- The slot number.stack
- The stack to add.- Returns:
- Whether the stack can be added there.
-
itemShiftClickAllowed
public boolean itemShiftClickAllowed(int slot, org.bukkit.inventory.ItemStack stack) Check whether, in a shift-click operation, an item of the specified type may be placed in the given slot.- Parameters:
slot
- The slot number.stack
- The stack to add.- Returns:
- Whether the stack can be added there.
-
handleShiftClick
public void handleShiftClick(GlowPlayer player, org.bukkit.inventory.InventoryView view, int clickedSlot, org.bukkit.inventory.ItemStack clickedItem) Handle a shift click in this inventory by the specified player.The default implementation distributes items from the right to the left and from the bottom to the top.
- Parameters:
player
- The player who clickedview
- The inventory view in which was clickedclickedSlot
- The slot in the viewclickedItem
- The item at which was clicked
-
tryToFillSlots
public org.bukkit.inventory.ItemStack tryToFillSlots(org.bukkit.inventory.ItemStack stack, int... slots) Tries to put the given items into the specified slots of this inventory from the start slot (inclusive) to the end slot (exclusive).The slots are supplied in pairs, first the start then the end slots.
This will first try to fill up all partial slots and if items are still left after doing so, it places them into the first empty slot.
If no empty slot was found and there are still items left, they're returned from this method.
- Parameters:
stack
- The items to place downslots
- Pairs of start/end slots- Returns:
- The remaining items or
null
if non are remaining
-
getRawSlots
public int getRawSlots()Gets the number of slots in this inventory according to the protocol.Some inventories have 0 slots in the protocol, despite having slots.
- Returns:
- The numbers of slots
-
getSize
public int getSize()- Specified by:
getSize
in interfaceorg.bukkit.inventory.Inventory
-
getSlots
Returns the whole slot list.- Returns:
- Slot list.
-
setTitle
Set the custom title of this inventory or reset it to the default.- Parameters:
title
- The new title, or null to reset.
-
getViewers
- Specified by:
getViewers
in interfaceorg.bukkit.inventory.Inventory
-
getHolder
@Nullable public @Nullable org.bukkit.inventory.InventoryHolder getHolder(boolean snapshotBlockEntity) - Specified by:
getHolder
in interfaceorg.bukkit.inventory.Inventory
-
iterator
-
iterator
- Specified by:
iterator
in interfaceorg.bukkit.inventory.Inventory
-
getLocation
public org.bukkit.Location getLocation()- Specified by:
getLocation
in interfaceorg.bukkit.inventory.Inventory
-
getItem
@NotNull public @NotNull org.bukkit.inventory.ItemStack getItem(int index) - Specified by:
getItem
in interfaceorg.bukkit.inventory.Inventory
-
setItem
public void setItem(int index, org.bukkit.inventory.ItemStack item) - Specified by:
setItem
in interfaceorg.bukkit.inventory.Inventory
-
addItem
@NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> addItem(org.bukkit.inventory.ItemStack... items) - Specified by:
addItem
in interfaceorg.bukkit.inventory.Inventory
-
addItemStack
public org.bukkit.inventory.ItemStack addItemStack(org.bukkit.inventory.ItemStack item, boolean ignoreMeta) Adds the contents of the given ItemStack to the inventory.- Parameters:
item
- the ItemStack to addignoreMeta
- if true, can convert to items with different NBT data in order to stack with existing copies of those items, provided the material and damage value match- Returns:
- the items that couldn't be added, or an empty stack if all were added
-
removeItem
@NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> removeItem(org.bukkit.inventory.ItemStack... items) - Specified by:
removeItem
in interfaceorg.bukkit.inventory.Inventory
-
removeItemStack
public org.bukkit.inventory.ItemStack removeItemStack(org.bukkit.inventory.ItemStack item, boolean ignoreMeta) Removes the given ItemStack from the inventory.- Parameters:
item
- the ItemStack to removeignoreMeta
- if true, can choose an item with different NBT data, provided the material and damage value match- Returns:
- the items that couldn't be removed, or an empty stack if all were removed
-
getContents
public org.bukkit.inventory.ItemStack @NotNull [] getContents()- Specified by:
getContents
in interfaceorg.bukkit.inventory.Inventory
-
setContents
public void setContents(org.bukkit.inventory.ItemStack[] items) - Specified by:
setContents
in interfaceorg.bukkit.inventory.Inventory
-
getStorageContents
public org.bukkit.inventory.ItemStack[] getStorageContents()- Specified by:
getStorageContents
in interfaceorg.bukkit.inventory.Inventory
-
setStorageContents
public void setStorageContents(org.bukkit.inventory.ItemStack[] items) throws IllegalArgumentException - Specified by:
setStorageContents
in interfaceorg.bukkit.inventory.Inventory
- Throws:
IllegalArgumentException
-
toString
-
contains
public boolean contains(@NotNull @NotNull org.bukkit.Material material) - Specified by:
contains
in interfaceorg.bukkit.inventory.Inventory
-
contains
public boolean contains(org.bukkit.inventory.ItemStack item) - Specified by:
contains
in interfaceorg.bukkit.inventory.Inventory
-
contains
public boolean contains(@NotNull @NotNull org.bukkit.Material material, int amount) - Specified by:
contains
in interfaceorg.bukkit.inventory.Inventory
-
contains
public boolean contains(org.bukkit.inventory.ItemStack item, int amount) - Specified by:
contains
in interfaceorg.bukkit.inventory.Inventory
-
containsAtLeast
public boolean containsAtLeast(org.bukkit.inventory.ItemStack item, int amount) - Specified by:
containsAtLeast
in interfaceorg.bukkit.inventory.Inventory
-
all
@NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> all(@NotNull @NotNull org.bukkit.Material material) - Specified by:
all
in interfaceorg.bukkit.inventory.Inventory
-
all
@NotNull public @NotNull HashMap<Integer,org.bukkit.inventory.ItemStack> all(org.bukkit.inventory.ItemStack item) - Specified by:
all
in interfaceorg.bukkit.inventory.Inventory
-
first
public int first(@NotNull @NotNull org.bukkit.Material material) - Specified by:
first
in interfaceorg.bukkit.inventory.Inventory
-
first
public int first(@NotNull @NotNull org.bukkit.inventory.ItemStack item) - Specified by:
first
in interfaceorg.bukkit.inventory.Inventory
-
firstEmpty
public int firstEmpty()- Specified by:
firstEmpty
in interfaceorg.bukkit.inventory.Inventory
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceorg.bukkit.inventory.Inventory
-
remove
public void remove(@NotNull @NotNull org.bukkit.Material material) - Specified by:
remove
in interfaceorg.bukkit.inventory.Inventory
-
remove
public void remove(@NotNull @NotNull org.bukkit.inventory.ItemStack item) - Specified by:
remove
in interfaceorg.bukkit.inventory.Inventory
-
clear
public void clear(int index) - Specified by:
clear
in interfaceorg.bukkit.inventory.Inventory
-
clear
public void clear()- Specified by:
clear
in interfaceorg.bukkit.inventory.Inventory
-
close
public int close()- Specified by:
close
in interfaceorg.bukkit.inventory.Inventory
-
consumeItem
public int consumeItem(int slot, boolean wholeStack) Consumes an item or the full stack in the given slot.- Parameters:
slot
- The slot to consume.wholeStack
- True if we should remove the complete stack.- Returns:
- The number of item really consumed.
-
consumeItem
public int consumeItem(int slot) Consumes an item in the given slot.- Parameters:
slot
- The slot to consume.- Returns:
- The number of item really consumed.
-
getHolder
public org.bukkit.inventory.InventoryHolder getHolder()The owner of this inventory.- Specified by:
getHolder
in interfaceorg.bukkit.inventory.Inventory
-
getType
public org.bukkit.event.inventory.InventoryType getType()The type of this inventory.- Specified by:
getType
in interfaceorg.bukkit.inventory.Inventory
-
getTitle
The inventory's name. -
getMaxStackSize
public int getMaxStackSize()The inventory's maximum stack size.- Specified by:
getMaxStackSize
in interfaceorg.bukkit.inventory.Inventory
-
setMaxStackSize
public void setMaxStackSize(int maxStackSize) The inventory's maximum stack size.- Specified by:
setMaxStackSize
in interfaceorg.bukkit.inventory.Inventory
-