Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerItemConsumeEvent.java
1 package org.bukkit.event.player;
2 
3 import org.bukkit.Material;
4 import org.bukkit.entity.Player;
8 
9 /**
10  * This event will fire when a player is finishing consuming an item (food,
11  * potion, milk bucket).
12  * <br>
13  * If the ItemStack is modified the server will use the effects of the new
14  * item and not remove the original one from the player's inventory.
15  * <br>
16  * If the event is cancelled the effect will not be applied and the item will
17  * not be removed from the player's inventory.
18  */
19 public class PlayerItemConsumeEvent extends PlayerEvent implements Cancellable {
20  private static final HandlerList handlers = new HandlerList();
21  private boolean isCancelled = false;
22  private ItemStack item;
23 
24  /**
25  * @param player the player consuming
26  * @param item the ItemStack being consumed
27  */
28  public PlayerItemConsumeEvent(final Player player, final ItemStack item) {
29  super(player);
30 
31  this.item = item;
32  }
33 
34  /**
35  * Gets the item that is being consumed. Modifying the returned item will
36  * have no effect, you must use {@link
37  * #setItem(org.bukkit.inventory.ItemStack)} instead.
38  *
39  * @return an ItemStack for the item being consumed
40  */
41  public ItemStack getItem() {
42  return item.clone();
43  }
44 
45  /**
46  * Set the item being consumed
47  *
48  * @param item the item being consumed
49  */
50  public void setItem(ItemStack item) {
51  if (item == null) {
52  this.item = new ItemStack(Material.AIR);
53  } else {
54  this.item = item;
55  }
56  }
57 
58  public boolean isCancelled() {
59  return this.isCancelled;
60  }
61 
62  public void setCancelled(boolean cancel) {
63  this.isCancelled = cancel;
64  }
65 
66  @Override
67  public HandlerList getHandlers() {
68  return handlers;
69  }
70 
71  public static HandlerList getHandlerList() {
72  return handlers;
73  }
74 }
PlayerItemConsumeEvent(final Player player, final ItemStack item)