[Bleeding] Inventory framework and events. Addresses BUKKIT-856
New events: - InventoryOpenEvent - InventoryClickEvent - detects any clicks on a slot or outside the window - In the creative inventory view, only clicks on the quickbar are detected - InventoryCloseEvent - BrewEvent - when a potion finishes brewing - CraftItemEvent (a subevent of InventoryClickEvent) - fired when taking the crafted item - PrepareItemCraftEvent - fired just before updating the result slot Changes to existing events: - EnchantItemEvent extends InventoryEvent and also has a new whichButton() method - PrepareItemEnchantEvent also extends InventoryEvent - FurnaceBurnEvent and FurnaceSmeltEvent now extend BlockEvent (as does BrewEvent) - PlayerInventoryEvent is deprecated (though it never did anything anyway) New subclasses of Inventory: - BrewerInventory - CraftingInventory - DoubleChestInventory - EnchantingInventory - FurnaceInventory New methods in Inventory: - getViewers() - getTitle() - getType() - getHolder() - iterator() - Yes, inventories are now iterable! - The iterator is a ListIterator that does not support add or remove New methods in Player: - getOpenInventory() - openInventory() - openWorkbench() - openEnchanting() - closeInventory() - setWindowProperty() - getItemOnCursor() - setItemOnCursor() Other changes: - createInventory() methods in Server to make inventories not linked to an object - ContainerBlock is deprecated in favour of InventoryHolder - New InventoryView class gives direct access to an inventory window! - Removed the Slot class which did nothing and was used nowhere Some small credit goes to Afforess (initial conception of openInventory() methods) and Drakia (initial conception of InventoryOpenEvent and InventoryCloseEvent). By: Celtic Minstrel <celtic.minstrel.ca@some.place>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
@@ -8,7 +12,7 @@ import org.bukkit.permissions.Permissible;
|
||||
/**
|
||||
* Represents a human entity, such as an NPC or a player
|
||||
*/
|
||||
public interface HumanEntity extends LivingEntity, AnimalTamer, Permissible {
|
||||
public interface HumanEntity extends LivingEntity, AnimalTamer, Permissible, InventoryHolder {
|
||||
|
||||
/**
|
||||
* Returns the name of this player
|
||||
@@ -24,6 +28,59 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, Permissible {
|
||||
*/
|
||||
public PlayerInventory getInventory();
|
||||
|
||||
/**
|
||||
* If the player currently has an inventory window open, this method will set a
|
||||
* property of that window, such as the state of a progress bar.
|
||||
* @param prop The property.
|
||||
* @param value The value to set the property to.
|
||||
* @return True if the property was successfully set.
|
||||
*/
|
||||
public boolean setWindowProperty(InventoryView.Property prop, int value);
|
||||
|
||||
/**
|
||||
* Gets the inventory view the player is currently viewing. If they do not have
|
||||
* an inventory window open, it returns their internal crafting view.
|
||||
* @return The inventory view.
|
||||
*/
|
||||
public InventoryView getOpenInventory();
|
||||
|
||||
/**
|
||||
* Opens an inventory window with the specified inventory on the top and the player's inventory
|
||||
* on the bottom.
|
||||
* @param inventory The inventory to open
|
||||
* @return The newly opened inventory view
|
||||
*/
|
||||
public InventoryView openInventory(Inventory inventory);
|
||||
|
||||
/**
|
||||
* Opens an empty workbench inventory window with the player's inventory on the bottom.
|
||||
* @param location The location to attach it to. If null, the player's location is used.
|
||||
* @param force If false, and there is no workbench block at the location, no inventory will be
|
||||
* opened and null will be returned.
|
||||
* @return The newly opened inventory view, or null if it could not be opened.
|
||||
*/
|
||||
public InventoryView openWorkbench(Location location, boolean force);
|
||||
|
||||
/**
|
||||
* Opens an empty enchanting inventory window with the player's inventory on the bottom.
|
||||
* @param location The location to attach it to. If null, the player's location is used.
|
||||
* @param force If false, and there is no enchanting table at the location, no inventory will be
|
||||
* opened and null will be returned.
|
||||
* @return The newly opened inventory view, or null if it could not be opened.
|
||||
*/
|
||||
public InventoryView openEnchanting(Location location, boolean force);
|
||||
|
||||
/**
|
||||
* Opens an inventory window to the specified inventory view
|
||||
* @param inventory The view to open
|
||||
*/
|
||||
public void openInventory(InventoryView inventory);
|
||||
|
||||
/**
|
||||
* Force-closes the currently open inventory view for this player, if any.
|
||||
*/
|
||||
public void closeInventory();
|
||||
|
||||
/**
|
||||
* Returns the ItemStack currently in your hand, can be empty.
|
||||
*
|
||||
@@ -39,6 +96,22 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, Permissible {
|
||||
*/
|
||||
public void setItemInHand(ItemStack item);
|
||||
|
||||
/**
|
||||
* Returns the ItemStack currently on your cursor, can be empty.
|
||||
* Will always be empty if the player currently has no open window.
|
||||
*
|
||||
* @return The ItemStack of the item you are currently moving around.
|
||||
*/
|
||||
public ItemStack getItemOnCursor();
|
||||
|
||||
/**
|
||||
* Sets the item to the given ItemStack, this will replace whatever the
|
||||
* user was moving. Will always be empty if the player currently has no open window.
|
||||
*
|
||||
* @param item The ItemStack which will end up in the hand
|
||||
*/
|
||||
public void setItemOnCursor(ItemStack item);
|
||||
|
||||
/**
|
||||
* Returns whether this player is slumbering.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user