Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.inventory.InventoryView Class Referenceabstract

Classes

enum  Property
 

Public Member Functions

abstract Inventory getTopInventory ()
 
abstract Inventory getBottomInventory ()
 
abstract HumanEntity getPlayer ()
 
abstract InventoryType getType ()
 
void setItem (int slot, ItemStack item)
 
ItemStack getItem (int slot)
 
final void setCursor (ItemStack item)
 
final ItemStack getCursor ()
 
final int convertSlot (int rawSlot)
 
final void close ()
 
final int countSlots ()
 
final boolean setProperty (Property prop, int value)
 
final String getTitle ()
 

Static Public Attributes

static final int OUTSIDE = -999
 

Detailed Description

Represents a view linking two inventories and a single player (whose inventory may or may not be one of the two).

Note: If you implement this interface but fail to satisfy the expected contracts of certain methods, there's no guarantee that the game will work as it should.

Definition at line 15 of file InventoryView.java.

Member Function Documentation

final void org.bukkit.inventory.InventoryView.close ( )

Closes the inventory view.

Definition at line 193 of file InventoryView.java.

References org.bukkit.entity.HumanEntity.closeInventory(), and org.bukkit.inventory.InventoryView.getPlayer().

193  {
195  }
abstract HumanEntity getPlayer()
final int org.bukkit.inventory.InventoryView.convertSlot ( int  rawSlot)

Converts a raw slot ID into its local slot ID into whichever of the two inventories the slot points to.

If the raw slot refers to the upper inventory, it will be returned unchanged and thus be suitable for getTopInventory().getItem(); if it refers to the lower inventory, the output will differ from the input and be suitable for getBottomInventory().getItem().

Parameters
rawSlotThe raw slot ID.
Returns
The converted slot ID.

Definition at line 172 of file InventoryView.java.

References org.bukkit.event.inventory.InventoryType.CRAFTING, org.bukkit.GameMode.CREATIVE, org.bukkit.inventory.InventoryView.getPlayer(), org.bukkit.inventory.Inventory.getSize(), org.bukkit.inventory.InventoryView.getTopInventory(), org.bukkit.inventory.InventoryView.getType(), and org.bukkit.event.inventory.InventoryType.PLAYER.

Referenced by org.bukkit.inventory.InventoryView.getItem(), and org.bukkit.inventory.InventoryView.setItem().

172  {
173  int numInTop = getTopInventory().getSize();
174  if (rawSlot < numInTop) {
175  return rawSlot;
176  }
177  int slot = rawSlot - numInTop;
178  if (getPlayer().getGameMode() == GameMode.CREATIVE && getType() == InventoryType.PLAYER) {
179  return slot;
180  }
181  if (getType() == InventoryType.CRAFTING) {
182  if(slot < 4) return 39 - slot;
183  else slot -= 4;
184  }
185  if (slot >= 27) slot -= 27;
186  else slot += 9;
187  return slot;
188  }
abstract HumanEntity getPlayer()
abstract InventoryType getType()
abstract Inventory getTopInventory()
final int org.bukkit.inventory.InventoryView.countSlots ( )

Check the total number of slots in this view, combining the upper and lower inventories.

Note though that it's possible for this to be greater than the sum of the two inventories if for example some slots are not being used.

Returns
The total size

Definition at line 206 of file InventoryView.java.

References org.bukkit.inventory.InventoryView.getBottomInventory(), org.bukkit.inventory.Inventory.getSize(), and org.bukkit.inventory.InventoryView.getTopInventory().

206  {
208  }
abstract Inventory getTopInventory()
abstract Inventory getBottomInventory()
abstract Inventory org.bukkit.inventory.InventoryView.getBottomInventory ( )
abstract

Get the lower inventory involved in this transaction.

Returns
the inventory

Referenced by org.bukkit.inventory.InventoryView.countSlots(), org.bukkit.inventory.InventoryView.getItem(), and org.bukkit.inventory.InventoryView.setItem().

final ItemStack org.bukkit.inventory.InventoryView.getCursor ( )

Get the item on the cursor of one of the viewing players.

Returns
The item on the player's cursor, or null if they aren't holding one.

Definition at line 156 of file InventoryView.java.

References org.bukkit.entity.HumanEntity.getItemOnCursor(), and org.bukkit.inventory.InventoryView.getPlayer().

Referenced by org.bukkit.event.inventory.InventoryClickEvent.getCursor().

156  {
157  return getPlayer().getItemOnCursor();
158  }
abstract HumanEntity getPlayer()
ItemStack org.bukkit.inventory.InventoryView.getItem ( int  slot)

Gets one item in this inventory view by its raw slot ID.

Parameters
slotThe ID as returned by InventoryClickEvent.getRawSlot()
Returns
The item currently in the slot.

Definition at line 129 of file InventoryView.java.

References org.bukkit.inventory.InventoryView.convertSlot(), org.bukkit.inventory.InventoryView.getBottomInventory(), org.bukkit.inventory.Inventory.getItem(), and org.bukkit.inventory.InventoryView.getTopInventory().

Referenced by org.bukkit.event.inventory.InventoryClickEvent.getCurrentItem().

129  {
130  if (slot == OUTSIDE) {
131  return null;
132  }
133  if (slot < getTopInventory().getSize()) {
134  return getTopInventory().getItem(convertSlot(slot));
135  } else {
136  return getBottomInventory().getItem(convertSlot(slot));
137  }
138  }
final int convertSlot(int rawSlot)
ItemStack getItem(int index)
abstract Inventory getTopInventory()
abstract Inventory getBottomInventory()
final String org.bukkit.inventory.InventoryView.getTitle ( )

Get the title of this inventory window.

Returns
The title.

Definition at line 228 of file InventoryView.java.

References org.bukkit.inventory.Inventory.getTitle(), and org.bukkit.inventory.InventoryView.getTopInventory().

228  {
229  return getTopInventory().getTitle();
230  }
abstract Inventory getTopInventory()
abstract InventoryType org.bukkit.inventory.InventoryView.getType ( )
abstract

Determine the type of inventory involved in the transaction. This indicates the window style being shown. It will never return PLAYER, since that is common to all windows.

Returns
the inventory type

Referenced by org.bukkit.inventory.InventoryView.convertSlot().

final void org.bukkit.inventory.InventoryView.setCursor ( ItemStack  item)

Sets the item on the cursor of one of the viewing players.

Parameters
itemThe item to put on the cursor, or null to remove the item on their cursor.

Definition at line 146 of file InventoryView.java.

References org.bukkit.inventory.InventoryView.getPlayer(), and org.bukkit.entity.HumanEntity.setItemOnCursor().

Referenced by org.bukkit.event.inventory.InventoryClickEvent.setCursor().

146  {
147  getPlayer().setItemOnCursor(item);
148  }
abstract HumanEntity getPlayer()
void setItemOnCursor(ItemStack item)
void org.bukkit.inventory.InventoryView.setItem ( int  slot,
ItemStack  item 
)

Sets one item in this inventory view by its raw slot ID.

Note: If slot ID -999 is chosen, it may be expected that the item is dropped on the ground. This is not required behaviour, however.

Parameters
slotThe ID as returned by InventoryClickEvent.getRawSlot()
itemThe new item to put in the slot, or null to clear it.

Definition at line 111 of file InventoryView.java.

References org.bukkit.inventory.InventoryView.convertSlot(), org.bukkit.World.dropItemNaturally(), org.bukkit.inventory.InventoryView.getBottomInventory(), org.bukkit.inventory.InventoryView.getPlayer(), org.bukkit.inventory.InventoryView.getTopInventory(), org.bukkit.entity.Entity.getWorld(), and org.bukkit.inventory.Inventory.setItem().

Referenced by org.bukkit.event.inventory.InventoryClickEvent.setCurrentItem().

111  {
112  if (slot != OUTSIDE) {
113  if (slot < getTopInventory().getSize()) {
114  getTopInventory().setItem(convertSlot(slot),item);
115  } else {
116  getBottomInventory().setItem(convertSlot(slot),item);
117  }
118  } else {
119  getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), item);
120  }
121  }
abstract HumanEntity getPlayer()
final int convertSlot(int rawSlot)
Item dropItemNaturally(Location location, ItemStack item)
abstract Inventory getTopInventory()
void setItem(int index, ItemStack item)
abstract Inventory getBottomInventory()
final boolean org.bukkit.inventory.InventoryView.setProperty ( Property  prop,
int  value 
)

Sets an extra property of this inventory if supported by that inventory, for example the state of a progress bar.

Parameters
propthe window property to update
valuethe new value for the window property
Returns
true if the property was updated successfully, false if the property is not supported by that inventory

Definition at line 219 of file InventoryView.java.

References org.bukkit.inventory.InventoryView.getPlayer(), and org.bukkit.entity.HumanEntity.setWindowProperty().

219  {
220  return getPlayer().setWindowProperty(prop, value);
221  }
abstract HumanEntity getPlayer()
boolean setWindowProperty(InventoryView.Property prop, int value)

The documentation for this class was generated from the following file: