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;
}
Aggregations