Class InventoryAction

java.lang.Object
cn.nukkit.inventory.transaction.action.InventoryAction
Direct Known Subclasses:
CraftingTakeResultAction, CraftingTransferMaterialAction, CreativeInventoryAction, DamageAnvilAction, DropItemAction, GrindstoneItemAction, NoOpIventoryAction, SlotChangeAction, SmithingItemAction, TakeLevelAction, TradeAction

public abstract class InventoryAction extends Object
Author:
CreeperFace
  • Field Details

    • sourceItem

      protected Item sourceItem
    • targetItem

      protected Item targetItem
  • Constructor Details

    • InventoryAction

      public InventoryAction(Item sourceItem, Item targetItem)
  • Method Details

    • getCreationTime

      public long getCreationTime()
    • getSourceItem

      public Item getSourceItem()
      Returns the item that was present before the action took place.
      Returns:
      source item
    • getTargetItem

      public Item getTargetItem()
      Returns the item that the action attempted to replace the source item with.
      Returns:
      target item
    • onPreExecute

      public boolean onPreExecute(Player source)
      Called by inventory transactions before any actions are processed. If this returns false, the transaction will be cancelled.
      Parameters:
      source - player
      Returns:
      cancelled
    • isValid

      public abstract boolean isValid(Player source)
      Returns whether this action is currently valid. This should perform any necessary sanity checks.
      Parameters:
      source - player
      Returns:
      valid
    • onAddToTransaction

      public void onAddToTransaction(InventoryTransaction transaction)
      Called when the action is added to the specified InventoryTransaction.
      Parameters:
      transaction - to add
    • execute

      public abstract boolean execute(Player source)
      Performs actions needed to complete the inventory-action server-side. Returns if it was successful. Will return false if plugins cancelled events. This will only be called if the transaction which it is part of is considered valid.
      Parameters:
      source - player
      Returns:
      successfully executed
    • onExecuteSuccess

      public abstract void onExecuteSuccess(Player source)
      Performs additional actions when this inventory-action completed successfully.
      Parameters:
      source - player
    • onExecuteFail

      public abstract void onExecuteFail(Player source)
      Performs additional actions when this inventory-action did not complete successfully.
      Parameters:
      source - player
    • toString

      public String toString()
      Overrides:
      toString in class Object