Search in sources :

Example 1 with PlayerItemHeldEvent

use of cn.nukkit.event.player.PlayerItemHeldEvent in project Nukkit by Nukkit.

the class PlayerInventory method equipItem.

/**
 * Called when a client equips a hotbar inventorySlot. This method should not be used by plugins.
 * This method will call PlayerItemHeldEvent.
 *
 * @param slot hotbar slot Number of the hotbar slot to equip.
 * @return boolean if the equipment change was successful, false if not.
 */
public boolean equipItem(int slot) {
    if (!isHotbarSlot(slot)) {
        this.sendContents((Player) this.getHolder());
        return false;
    }
    if (this.getHolder() instanceof Player) {
        PlayerItemHeldEvent ev = new PlayerItemHeldEvent((Player) this.getHolder(), this.getItem(slot), slot);
        this.getHolder().getLevel().getServer().getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            this.sendContents(this.getViewers());
            return false;
        }
    }
    this.setHeldItemIndex(slot, false);
    return true;
}
Also used : Player(cn.nukkit.Player) PlayerItemHeldEvent(cn.nukkit.event.player.PlayerItemHeldEvent)

Aggregations

Player (cn.nukkit.Player)1 PlayerItemHeldEvent (cn.nukkit.event.player.PlayerItemHeldEvent)1