Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
InventoryClickEvent.java
Go to the documentation of this file.
1 package org.bukkit.event.inventory;
2 
3 import org.bukkit.inventory.Inventory;
4 import org.bukkit.inventory.InventoryView;
5 import org.bukkit.entity.HumanEntity;
6 import org.bukkit.event.Cancellable;
7 import org.bukkit.event.HandlerList;
8 import org.bukkit.event.inventory.InventoryType.SlotType;
9 import org.bukkit.inventory.ItemStack;
10 
11 public class InventoryClickEvent extends InventoryEvent implements Cancellable {
12  private static final HandlerList handlers = new HandlerList();
13  private SlotType slot_type;
14  private boolean rightClick, shiftClick;
15  private Result result;
16  private int whichSlot;
17  private int rawSlot;
18  private ItemStack current = null;
19 
20  public InventoryClickEvent(InventoryView what, SlotType type, int slot, boolean right, boolean shift) {
21  super(what);
22  this.slot_type = type;
23  this.rightClick = right;
24  this.shiftClick = shift;
25  this.result = Result.DEFAULT;
26  this.rawSlot = slot;
27  this.whichSlot = what.convertSlot(slot);
28  }
29 
34  public SlotType getSlotType() {
35  return slot_type;
36  }
37 
42  public ItemStack getCursor() {
43  return getView().getCursor();
44  }
45 
51  if(slot_type == SlotType.OUTSIDE) return current;
52  return getView().getItem(rawSlot);
53  }
54 
58  public boolean isRightClick() {
59  return rightClick;
60  }
61 
65  public boolean isLeftClick() {
66  return !rightClick;
67  }
68 
73  public boolean isShiftClick() {
74  return shiftClick;
75  }
76 
77  public void setResult(Result newResult) {
78  result = newResult;
79  }
80 
81  public Result getResult() {
82  return result;
83  }
84 
90  return getView().getPlayer();
91  }
92 
97  public void setCursor(ItemStack what) {
98  getView().setCursor(what);
99  }
100 
105  public void setCurrentItem(ItemStack what) {
106  if(slot_type == SlotType.OUTSIDE) current = what;
107  else getView().setItem(rawSlot, what);
108  }
109 
110  public boolean isCancelled() {
111  return result == Result.DENY;
112  }
113 
114  public void setCancelled(boolean toCancel) {
115  result = toCancel ? Result.DENY : Result.ALLOW;
116  }
117 
123  public int getSlot() {
124  return whichSlot;
125  }
126 
131  public int getRawSlot() {
132  return rawSlot;
133  }
134 
135  @Override
137  return handlers;
138  }
139 
140  public static HandlerList getHandlerList() {
141  return handlers;
142  }
143 }