Klasse PlayerProcessItemEvent

Alle implementierten Schnittstellen:
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}
  • Methodendetails

    • getItem

      public Item getItem()
      Gets the item the player wants to process.
      Gibt zurück:
      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).
      Gibt zurück:
      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).
      Parameter:
      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.
      Gibt zurück:
      the new stack size (amount of items).
    • setNewStack

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

      public int getNewStatus()
      Gets the optional new status for the item.
      Gibt zurück:
      the new item status.
    • setNewStatus

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

      public float getNewValue()
      Gets the optional new value for the item.
      Gibt zurück:
      the new item value.
    • setNewValue

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

      public Items.ItemInfoType getItemInfoType()
    • isCancelled

      public boolean isCancelled()
      Beschreibung aus Schnittstelle kopiert: 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.
      Angegeben von:
      isCancelled in Schnittstelle Cancellable
      Gibt zurück:
      true if the event is cancelled, or false if not.
    • setCancelled

      public void setCancelled(boolean cancel)
      Beschreibung aus Schnittstelle kopiert: Cancellable
      Cancels this event. This means it will no longer be executed, but other plugins will still receive the event.

      Angegeben von:
      setCancelled in Schnittstelle Cancellable
      Parameter:
      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}