Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
EnchantItemEvent.java
1 package org.bukkit.event.enchantment;
2 
3 import java.util.HashMap;
4 import java.util.Map;
5 
6 import org.bukkit.block.Block;
8 import org.bukkit.entity.Player;
14 
15 /**
16  * Called when an ItemStack is successfully enchanted (currently at
17  * enchantment table)
18  */
19 public class EnchantItemEvent extends InventoryEvent implements Cancellable {
20  private static final HandlerList handlers = new HandlerList();
21  private final Block table;
22  private final ItemStack item;
23  private int level;
24  private boolean cancelled;
25  private final Map<Enchantment,Integer> enchants;
26  private final Player enchanter;
27  private int button;
28 
29  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) {
30  super(view);
31  this.enchanter = enchanter;
32  this.table = table;
33  this.item = item;
34  this.level = level;
35  this.enchants = new HashMap<Enchantment, Integer>(enchants);
36  this.cancelled = false;
37  this.button = i;
38  }
39 
40  /**
41  * Gets the player enchanting the item
42  *
43  * @return enchanting player
44  */
45  public Player getEnchanter() {
46  return enchanter;
47  }
48 
49  /**
50  * Gets the block being used to enchant the item
51  *
52  * @return the block used for enchanting
53  */
55  return table;
56  }
57 
58  /**
59  * Gets the item to be enchanted (can be modified)
60  *
61  * @return ItemStack of item
62  */
63  public ItemStack getItem() {
64  return item;
65  }
66 
67  /**
68  * Get cost in exp levels of the enchantment
69  *
70  * @return experience level cost
71  */
72  public int getExpLevelCost() {
73  return level;
74  }
75 
76  /**
77  * Set cost in exp levels of the enchantment
78  *
79  * @param level - cost in levels
80  */
81  public void setExpLevelCost(int level) {
82  this.level = level;
83  }
84 
85  /**
86  * Get map of enchantment (levels, keyed by type) to be added to item
87  * (modify map returned to change values). Note: Any enchantments not
88  * allowed for the item will be ignored
89  *
90  * @return map of enchantment levels, keyed by enchantment
91  */
92  public Map<Enchantment, Integer> getEnchantsToAdd() {
93  return enchants;
94  }
95 
96  /**
97  * Which button was pressed to initiate the enchanting.
98  *
99  * @return The button index (0, 1, or 2).
100  */
101  public int whichButton() {
102  return button;
103  }
104 
105  public boolean isCancelled() {
106  return cancelled;
107  }
108 
109  public void setCancelled(boolean cancel) {
110  this.cancelled = cancel;
111  }
112 
113  @Override
114  public HandlerList getHandlers() {
115  return handlers;
116  }
117 
118  public static HandlerList getHandlerList() {
119  return handlers;
120  }
121 }
Map< Enchantment, Integer > getEnchantsToAdd()