Class PlayerProcessItemEvent

All Implemented Interfaces:
Cancellable

public final class PlayerProcessItemEvent extends PlayerEvent implements Cancellable
Called when the player "processes" an item in his inventory. For example, this is called when the player cuts a watermelon, slices bread, fills a canteen or bucket etc. This usually (but not always) results in the item being removed (e.g the water melon) and one or more new items being added to the inventory (e.g water melon slices). In other situations (e.g when filling a canteen), the item instance is kept and just the item status/value is changed.
Example: Trigger non-lethal explosion if player cuts a watermelon
1@EventMethod
2public void onPlayerProcessItem(PlayerProcessItemEvent e) {
3 //Check if item is a water melon
4 if (e.getItem().getName().equals("watermelon")) {
5 //We don't want any new items being added, so provide 0 or -1 as new type ID
6 e.setNewTypeID(0);
7
8 //Spawn explosion at player position
9 World.triggerExplosion(e.getPlayer().getViewPosition(), Quaternion.IDENTITY, Vector3f.ONE, 0f);
10 }
11}
  • Method Details

    • getItem

      public Item getItem()
      Gets the item the player wants to process.
      Returns:
      the item that's about to be processed.
    • getNewTypeID

      public short getNewTypeID()
      Gets the new target item type ID. This means this item will transform to this item (e.g if getItem() returns a water melon, getNewTypeID() would usually return the type ID of a water melon slice etc).
      Returns:
      the new type ID.
    • setNewTypeID

      public void setNewTypeID(short newTypeID)
      Sets a new target item type ID (i.e the type ID of the new item).
      Parameters:
      newTypeID - the new type ID. Set to 0 or negative value to prevent the game from adding a new item to inventory.
    • getNewStack

      public int getNewStack()
      Gets the new stack size of the item.
      Returns:
      the new stack size (amount of items).
    • setNewStack

      public void setNewStack(int newStack)
      Sets a new stack (amount of items).
      Parameters:
      newStack - the new stack size (amount of items).
    • getNewStatus

      public int getNewStatus()
      Gets the optional new status for the item.
      Returns:
      the new item status.
    • setNewStatus

      public void setNewStatus(int newStatus)
      Sets a new optional status for the item.
      Parameters:
      newStatus - the new item status.
    • getNewValue

      public float getNewValue()
      Gets the optional new value for the item.
      Returns:
      the new item value.
    • setNewValue

      public void setNewValue(float newValue)
      Sets a new optional value for the item.
      Parameters:
      newValue - the new item value.
    • getItemInfoType

      public Items.ItemInfoType getItemInfoType()
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: Cancellable
      Determines if the event is cancelled. If an event is cancelled, it will no longer be executed, but other plugins will still receive the event.

      Please note: If the event is threaded, cancellation has no effect, i.e the event will still be executed.
      Specified by:
      isCancelled in interface Cancellable
      Returns:
      true if the event is cancelled, or false if not.
    • setCancelled

      public void setCancelled(boolean cancel)
      Description copied from interface: Cancellable
      Cancels this event. This means it will no longer be executed, but other plugins will still receive the event.

      Specified by:
      setCancelled in interface Cancellable
      Parameters:
      cancel - set to true if you want to cancel this event.
      Example: Cancel "PlayerEnterAreaEvent", i.e prevent player from entering an area
      1//Listener class
      2public class PlayerListener implements Listener{
      3 @EventMethod
      4 public void onEnterArea(PlayerEnterAreaEvent evt){
      5 //Now the player will not be able to enter the area, i.e.
      6 //he will be teleported back to his old position (outside the area)
      7 evt.setCancelled(true);
      8 }
      9}