public class InventoryDragEvent extends InventoryInteractEvent
getType()
.
Canceling this event will result in none of the changes described in
getNewItems()
being applied to the Inventory.
Because InventoryDragEvent occurs within a modification of the Inventory, not all Inventory related methods are safe to use.
The following should never be invoked by an EventHandler for InventoryDragEvent using the HumanEntity or InventoryView associated with this event.
HumanEntity.closeInventory()
HumanEntity.openInventory(Inventory)
HumanEntity.openWorkbench(Location, boolean)
HumanEntity.openEnchanting(Location, boolean)
InventoryView.close()
BukkitScheduler.runTask(Plugin, Runnable)
, which will run the task
on the next tick. Also be aware that this is not an exhaustive list, and
other methods could potentially create issues as well.
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()
.
Any modifications to slots that are modified by the results of this
InventoryDragEvent will be overwritten. To change these slots, this event
should be cancelled and the changes 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
Constructor and Description |
---|
InventoryDragEvent(@NotNull InventoryView what,
@Nullable ItemStack newCursor,
@NotNull ItemStack oldCursor,
boolean right,
@NotNull Map<Integer,ItemStack> slots) |
Modifier and Type | Method and Description |
---|---|
@Nullable ItemStack |
getCursor()
Gets the result cursor after the drag is done.
|
static @NotNull HandlerList |
getHandlerList() |
@NotNull HandlerList |
getHandlers() |
@NotNull Set<Integer> |
getInventorySlots()
Gets the slots to be changed in this drag.
|
@NotNull Map<Integer,ItemStack> |
getNewItems()
Gets all items to be added to the inventory in this drag.
|
@NotNull ItemStack |
getOldCursor()
Gets an ItemStack representing the cursor prior to any modifications
as a result of this drag.
|
@NotNull Set<Integer> |
getRawSlots()
Gets the raw slot ids to be changed in this drag.
|
@NotNull DragType |
getType()
Gets the DragType that describes the behavior of ItemStacks placed
after this InventoryDragEvent.
|
void |
setCursor(@Nullable ItemStack newCursor)
Sets the result cursor after the drag is done.
|
getResult, getWhoClicked, isCancelled, setCancelled, setResult
getInventory, getView, getViewers
callEvent, getEventName, isAsynchronous
@NotNull public @NotNull Map<Integer,ItemStack> getNewItems()
@NotNull public @NotNull Set<Integer> getRawSlots()
@NotNull public @NotNull Set<Integer> getInventorySlots()
Inventory.getItem(int)
.@Nullable public @Nullable ItemStack getCursor()
public void setCursor(@Nullable @Nullable ItemStack newCursor)
Changing this item stack changes the cursor item. Note that changing the affected "dragged" slots does not change this ItemStack, nor does changing this ItemStack affect the "dragged" slots.
newCursor
- the new cursor ItemStack@NotNull public @NotNull ItemStack getOldCursor()
@NotNull public @NotNull DragType getType()
The ItemStacks and the raw slots that they're being applied to can be
found using getNewItems()
.
@NotNull public @NotNull HandlerList getHandlers()
getHandlers
in class InventoryEvent
@NotNull public static @NotNull HandlerList getHandlerList()
Copyright © 2021. All rights reserved.