001 package org.bukkit.event.enchantment; 002 003 import org.bukkit.block.Block; 004 import org.bukkit.entity.Player; 005 import org.bukkit.event.Cancellable; 006 import org.bukkit.event.HandlerList; 007 import org.bukkit.event.inventory.InventoryEvent; 008 import org.bukkit.inventory.InventoryView; 009 import org.bukkit.inventory.ItemStack; 010 011 /** 012 * Called when an ItemStack is inserted in an enchantment table - can be 013 * called multiple times 014 */ 015 public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellable { 016 private static final HandlerList handlers = new HandlerList(); 017 private final Block table; 018 private final ItemStack item; 019 private final int[] levelsOffered; 020 private final int bonus; 021 private boolean cancelled; 022 private final Player enchanter; 023 024 public PrepareItemEnchantEvent(final Player enchanter, InventoryView view, final Block table, final ItemStack item, final int[] levelsOffered, final int bonus) { 025 super(view); 026 this.enchanter = enchanter; 027 this.table = table; 028 this.item = item; 029 this.levelsOffered = levelsOffered; 030 this.bonus = bonus; 031 this.cancelled = false; 032 } 033 034 /** 035 * Gets the player enchanting the item 036 * 037 * @return enchanting player 038 */ 039 public Player getEnchanter() { 040 return enchanter; 041 } 042 043 /** 044 * Gets the block being used to enchant the item 045 * 046 * @return the block used for enchanting 047 */ 048 public Block getEnchantBlock() { 049 return table; 050 } 051 052 /** 053 * Gets the item to be enchanted (can be modified) 054 * 055 * @return ItemStack of item 056 */ 057 public ItemStack getItem() { 058 return item; 059 } 060 061 /** 062 * Get list of offered exp level costs of the enchantment (modify values 063 * to change offer) 064 * 065 * @return experience level costs offered 066 */ 067 public int[] getExpLevelCostsOffered() { 068 return levelsOffered; 069 } 070 071 /** 072 * Get enchantment bonus in effect - corresponds to number of bookshelves 073 * 074 * @return enchantment bonus 075 */ 076 public int getEnchantmentBonus() { 077 return bonus; 078 } 079 080 public boolean isCancelled() { 081 return cancelled; 082 } 083 084 public void setCancelled(boolean cancel) { 085 this.cancelled = cancel; 086 } 087 088 @Override 089 public HandlerList getHandlers() { 090 return handlers; 091 } 092 093 public static HandlerList getHandlerList() { 094 return handlers; 095 } 096 }