Class ItemPreUpdateEvent
java.lang.Object
xyz.xenondevs.invui.inventory.event.ItemPreUpdateEvent
An event that is called whenever a slot inside a
Inventory gets updated.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionItemPreUpdateEvent(@NotNull Inventory inventory, int slot, @Nullable UpdateReason updateReason, @Nullable org.bukkit.inventory.ItemStack previousItem, @Nullable org.bukkit.inventory.ItemStack newItem) Creates a newItemPreUpdateEvent. -
Method Summary
Modifier and TypeMethodDescriptionintGets the amount of items that have been added.@NotNull InventoryGets theInventorywhere this action takes place.@Nullable org.bukkit.inventory.ItemStackGets clone of the newItemStackthat will be there if the event isn't cancelled.@Nullable org.bukkit.inventory.ItemStackGets a clone of theItemStackthat was there previously.intGets the amount of items that have been removed.intgetSlot()Gets the slot that is affected.@Nullable UpdateReasonGets theUpdateReasonfor the calling of this event.booleanisAdd()Gets if the action resulted in items being added to theInventory.booleanGets the cancellation state of this event.booleanisRemove()Gets if the action resulted in items being removed from theInventory.booleanisSwap()Gets if the type of theItemStackhas changed.voidsetCancelled(boolean cancel) Sets the cancellation state of this event.voidsetNewItem(@Nullable org.bukkit.inventory.ItemStack newItem) Change theItemStackthat will appear in theInventoryto a different one.
-
Field Details
-
newItemStack
protected org.bukkit.inventory.ItemStack newItemStack
-
-
Constructor Details
-
ItemPreUpdateEvent
public ItemPreUpdateEvent(@NotNull @NotNull Inventory inventory, int slot, @Nullable @Nullable UpdateReason updateReason, @Nullable @Nullable org.bukkit.inventory.ItemStack previousItem, @Nullable @Nullable org.bukkit.inventory.ItemStack newItem) Creates a newItemPreUpdateEvent.- Parameters:
inventory- TheInventorywhere this action takes place.slot- The slot that is affectedupdateReason- TheUpdateReasonfor the calling of this event. This will probably be aPlayerUpdateReasonin most cases but can be a custom one if you called the methods in theInventoryyourself. if it wasn't aPlayerpreviousItem- TheItemStackthat was there previouslynewItem- TheItemStackthat will be there if the event isn't cancelled
-
-
Method Details
-
setNewItem
public void setNewItem(@Nullable @Nullable org.bukkit.inventory.ItemStack newItem) Change theItemStackthat will appear in theInventoryto a different one.- Parameters:
newItem- TheItemStackto appear in theInventoryif theItemPreUpdateEventis not cancelled.
-
isCancelled
public boolean isCancelled()Gets the cancellation state of this event.- Returns:
- The cancellation state of this event.
-
setCancelled
public void setCancelled(boolean cancel) Sets the cancellation state of this event.- Parameters:
cancel- If this event should be cancelled.
-
getInventory
Gets theInventorywhere this action takes place.- Returns:
- The
Inventory
-
getUpdateReason
Gets theUpdateReasonfor the calling of this event.- Returns:
- The reason why this event was called. Probably a
PlayerUpdateReasonin most cases.
-
getPreviousItem
@Nullable public @Nullable org.bukkit.inventory.ItemStack getPreviousItem()Gets a clone of theItemStackthat was there previously.- Returns:
- The
ItemStack
-
getNewItem
@Nullable public @Nullable org.bukkit.inventory.ItemStack getNewItem()Gets clone of the newItemStackthat will be there if the event isn't cancelled.- Returns:
- The new
ItemStack
-
getSlot
public int getSlot()Gets the slot that is affected.- Returns:
- The slot
-
isAdd
public boolean isAdd()Gets if the action resulted in items being added to theInventory.- Returns:
- If items were added to the
Inventory
-
isRemove
public boolean isRemove()Gets if the action resulted in items being removed from theInventory.- Returns:
- If items were removed from the
Inventory
-
isSwap
public boolean isSwap()Gets if the type of theItemStackhas changed. This does not account for anItemStackturning null or being null previously,isRemove()andisAdd()should be used for that.- Returns:
- If the type of the
ItemStackhas changed
-
getRemovedAmount
public int getRemovedAmount()Gets the amount of items that have been removed.- Returns:
- The amount of items that have been removed
- Throws:
IllegalStateException- whenisRemove()is false
-
getAddedAmount
public int getAddedAmount()Gets the amount of items that have been added.- Returns:
- The amount of items that have been added
- Throws:
IllegalStateException- whenisAdd()is false
-