public class InventoryClickEvent extends InventoryInteractEvent
由于InventoryClickEvent
是通过修改物品栏
的实现类来触发的,所以并非所有与物品栏
相关的方法都是安全的。
下面这些属于HumanEntity
和 InventoryView
的方法不应该被处理
InventoryClickEvent
事件的 事件处理器
调用
HumanEntity.closeInventory()
HumanEntity.openInventory(Inventory)
HumanEntity.openWorkbench(Location, boolean)
HumanEntity.openEnchanting(Location, boolean)
InventoryView.close()
BukkitScheduler.runTask(Plugin, Runnable)
来执行
,这个方法将在下一个tick执行你的任务。
Assuming the EntityHuman associated with this event is an instance of a
Player, manipulating the MaxStackSize or contents of an Inventory will
require an Invocation of Player.updateInventory()
.
Modifications to slots that are modified by the results of this
InventoryClickEvent can be overwritten. To change these slots, this event
should be cancelled and all desired changes to the inventory applied.
Alternatively, scheduling a task using
BukkitScheduler.runTask( Plugin, Runnable)
, which would execute the
task on the next tick, would work as well.
Event.Result
transaction
构造器和说明 |
---|
InventoryClickEvent(InventoryView view,
InventoryType.SlotType type,
int slot,
ClickType click,
InventoryAction action) |
InventoryClickEvent(InventoryView view,
InventoryType.SlotType type,
int slot,
ClickType click,
InventoryAction action,
int key) |
限定符和类型 | 方法和说明 |
---|---|
InventoryAction |
getAction()
Gets the InventoryAction that triggered this event.
|
ClickType |
getClick()
获取本事件的ClickType.
|
ItemStack |
getCurrentItem()
获取被点击的格子的物品
原文:Gets the ItemStack currently in the clicked slot.
|
ItemStack |
getCursor()
获取当前光标所指的物品
原文:Gets the current ItemStack on the cursor.
|
static HandlerList |
getHandlerList() |
HandlerList |
getHandlers() |
int |
getHotbarButton()
如果ClickType是NUMVER_KEY(按下数字切换物品),这个方法将返回按下的键的索引(0-8)
原文:If the ClickType is NUMBER_KEY, this method will return the index of the
pressed key (0-8).
|
int |
getRawSlot()
返回点击的原始格子序号,可传递给
#getItem(int) 。 |
int |
getSlot()
返回点击的格子序号,可传递给
Inventory.getItem(int) 。 |
InventoryType.SlotType |
getSlotType()
获取被点击的格子的类型.
|
boolean |
isLeftClick()
获取是否左击背包
原文:Gets whether or not the ClickType for this event represents a left click.
|
boolean |
isRightClick()
获取是否右击背包
原文:
Gets whether or not the ClickType for this event represents a right
click.
|
boolean |
isShiftClick()
获取是否按住shift点击背包
原文:Gets whether the ClickType for this event indicates that the key was
pressed down when the click was made.
|
void |
setCurrentItem(ItemStack stack)
Sets the ItemStack currently in the clicked slot.
|
void |
setCursor(ItemStack stack)
已过时。
This changes the ItemStack in their hand before any
calculations are applied to the Inventory, which has a
tendency to create inconsistencies between the Player and the
server, and to make unexpected changes in the behavior of the
clicked Inventory.
|
getResult, getWhoClicked, isCancelled, setCancelled, setResult
getInventory, getView, getViewers
getEventName, isAsynchronous
public InventoryClickEvent(InventoryView view, InventoryType.SlotType type, int slot, ClickType click, InventoryAction action)
public InventoryClickEvent(InventoryView view, InventoryType.SlotType type, int slot, ClickType click, InventoryAction action, int key)
public InventoryType.SlotType getSlotType()
原文:Gets the type of slot that was clicked.
public ItemStack getCursor()
原文:Gets the current ItemStack on the cursor.
public ItemStack getCurrentItem()
原文:Gets the ItemStack currently in the clicked slot.
public boolean isRightClick()
原文: Gets whether or not the ClickType for this event represents a right click.
ClickType.isRightClick()
public boolean isLeftClick()
原文:Gets whether or not the ClickType for this event represents a left click.
ClickType.isLeftClick()
public boolean isShiftClick()
原文:Gets whether the ClickType for this event indicates that the key was pressed down when the click was made.
ClickType.isShiftClick()
@Deprecated public void setCursor(ItemStack stack)
stack
- the new cursor itempublic void setCurrentItem(ItemStack stack)
stack
- the item to be placed in the current slotpublic int getSlot()
Inventory.getItem(int)
。注意由于连接两个不同背包的视图,可能两个格子都是同一个格子序号
原文:The slot number that was clicked, ready for passing to
Inventory.getItem(int)
. Note that there may be two slots with the
same slot number, since a view links two different inventories.
public int getRawSlot()
#getItem(int)
。这个序号对每个视图是唯一的。
原文:The raw slot number clicked, ready for passing to
#getItem(int)
This slot number is unique for the
view.
public int getHotbarButton()
原文:If the ClickType is NUMBER_KEY, this method will return the index of the pressed key (0-8).
public InventoryAction getAction()
This action cannot be changed, and represents what the normal outcome of the event will be. To change the behavior of this InventoryClickEvent, changes must be manually applied.
public ClickType getClick()
???????????????
原文:Gets the ClickType for this event.
This is insulated against changes to the inventory by other plugins.
public HandlerList getHandlers()
getHandlers
在类中 InventoryEvent
public static HandlerList getHandlerList()