[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:
@@ -7,14 +7,15 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.InventoryEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Called when an ItemStack is successfully enchanted (currently at enchantment table)
|
||||
*/
|
||||
public class EnchantItemEvent extends Event implements Cancellable {
|
||||
public class EnchantItemEvent extends InventoryEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Block table;
|
||||
private final ItemStack item;
|
||||
@@ -22,14 +23,17 @@ public class EnchantItemEvent extends Event implements Cancellable {
|
||||
private boolean cancelled;
|
||||
private final Map<Enchantment,Integer> enchants;
|
||||
private final Player enchanter;
|
||||
private int button;
|
||||
|
||||
public EnchantItemEvent(final Player enchanter, final Block table, final ItemStack item, final int level, final Map<Enchantment, Integer> enchants) {
|
||||
public EnchantItemEvent(final Player enchanter, final InventoryView view, final Block table, final ItemStack item, final int level, final Map<Enchantment, Integer> enchants, final int i) {
|
||||
super(view);
|
||||
this.enchanter = enchanter;
|
||||
this.table = table;
|
||||
this.item = item;
|
||||
this.level = level;
|
||||
this.enchants = new HashMap<Enchantment, Integer>(enchants);
|
||||
this.cancelled = false;
|
||||
this.button = i;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +89,14 @@ public class EnchantItemEvent extends Event implements Cancellable {
|
||||
return enchants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which button was pressed to initiate the enchanting.
|
||||
* @return The button index (0, 1, or 2).
|
||||
*/
|
||||
public int whichButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package org.bukkit.event.enchantment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.InventoryEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Called when an ItemStack is inserted in an enchantment table - can be called multiple times
|
||||
*/
|
||||
public class PrepareItemEnchantEvent extends Event implements Cancellable {
|
||||
public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Block table;
|
||||
private final ItemStack item;
|
||||
@@ -19,7 +20,8 @@ public class PrepareItemEnchantEvent extends Event implements Cancellable {
|
||||
private boolean cancelled;
|
||||
private final Player enchanter;
|
||||
|
||||
public PrepareItemEnchantEvent(final Player enchanter, final Block table, final ItemStack item, final int[] levelsOffered, final int bonus) {
|
||||
public PrepareItemEnchantEvent(final Player enchanter, InventoryView view, final Block table, final ItemStack item, final int[] levelsOffered, final int bonus) {
|
||||
super(view);
|
||||
this.enchanter = enchanter;
|
||||
this.table = table;
|
||||
this.item = item;
|
||||
|
||||
Reference in New Issue
Block a user