Skip to content

PlayerItemHeldEvent ​

class · pocketmine\event\player\PlayerItemHeldEvent · source

Extends PlayerEvent
Implements Cancellable

Called when a player's held item changes. This could be because they selected a different hotbar slot, or because the item in the selected hotbar slot was changed.

Methods ​

__construct() ​

php
public function __construct(\pocketmine\player\Player $player, \pocketmine\item\Item $item, int $hotbarSlot)

getItem() ​

php
public function getItem() : \pocketmine\item\Item

Returns the item in the slot that the player is trying to equip.

getSlot() ​

php
public function getSlot() : int

Returns the hotbar slot the player is attempting to hold.

NOTE: This event is called BEFORE the slot is equipped server-side. Setting the player's held item during this event will result in the old slot being changed, not this one.

To change the item in the slot that the player is attempting to hold, set the slot that this function reports.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.