Class ItemPreUpdateEvent

java.lang.Object
xyz.xenondevs.invui.inventory.event.ItemPreUpdateEvent

public class ItemPreUpdateEvent extends Object
An event that is called whenever a slot inside a Inventory gets updated.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.bukkit.inventory.ItemStack
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ItemPreUpdateEvent(@NotNull Inventory inventory, int slot, @Nullable UpdateReason updateReason, @Nullable org.bukkit.inventory.ItemStack previousItem, @Nullable org.bukkit.inventory.ItemStack newItem)
    Creates a new ItemPreUpdateEvent.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the amount of items that have been added.
    @NotNull Inventory
    Gets the Inventory where this action takes place.
    @Nullable org.bukkit.inventory.ItemStack
    Gets clone of the new ItemStack that will be there if the event isn't cancelled.
    @Nullable org.bukkit.inventory.ItemStack
    Gets a clone of the ItemStack that was there previously.
    int
    Gets the amount of items that have been removed.
    int
    Gets the slot that is affected.
    @Nullable UpdateReason
    Gets the UpdateReason for the calling of this event.
    boolean
    Gets if the action resulted in items being added to the Inventory.
    boolean
    Gets the cancellation state of this event.
    boolean
    Gets if the action resulted in items being removed from the Inventory.
    boolean
    Gets if the type of the ItemStack has changed.
    void
    setCancelled(boolean cancel)
    Sets the cancellation state of this event.
    void
    setNewItem(@Nullable org.bukkit.inventory.ItemStack newItem)
    Change the ItemStack that will appear in the Inventory to a different one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 new ItemPreUpdateEvent.
      Parameters:
      inventory - The Inventory where this action takes place.
      slot - The slot that is affected
      updateReason - The UpdateReason for the calling of this event. This will probably be a PlayerUpdateReason in most cases but can be a custom one if you called the methods in the Inventory yourself. if it wasn't a Player
      previousItem - The ItemStack that was there previously
      newItem - The ItemStack that will be there if the event isn't cancelled
  • Method Details

    • setNewItem

      public void setNewItem(@Nullable @Nullable org.bukkit.inventory.ItemStack newItem)
      Change the ItemStack that will appear in the Inventory to a different one.
      Parameters:
      newItem - The ItemStack to appear in the Inventory if the ItemPreUpdateEvent is 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

      @NotNull public @NotNull Inventory getInventory()
      Gets the Inventory where this action takes place.
      Returns:
      The Inventory
    • getUpdateReason

      @Nullable public @Nullable UpdateReason getUpdateReason()
      Gets the UpdateReason for the calling of this event.
      Returns:
      The reason why this event was called. Probably a PlayerUpdateReason in most cases.
    • getPreviousItem

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getPreviousItem()
      Gets a clone of the ItemStack that was there previously.
      Returns:
      The ItemStack
    • getNewItem

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getNewItem()
      Gets clone of the new ItemStack that 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 the Inventory.
      Returns:
      If items were added to the Inventory
    • isRemove

      public boolean isRemove()
      Gets if the action resulted in items being removed from the Inventory.
      Returns:
      If items were removed from the Inventory
    • isSwap

      public boolean isSwap()
      Gets if the type of the ItemStack has changed. This does not account for an ItemStack turning null or being null previously, isRemove() and isAdd() should be used for that.
      Returns:
      If the type of the ItemStack has 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 - when isRemove() 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 - when isAdd() is false