本文整理汇总了Java中cn.nukkit.event.player.PlayerItemHeldEvent.isCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerItemHeldEvent.isCancelled方法的具体用法?Java PlayerItemHeldEvent.isCancelled怎么用?Java PlayerItemHeldEvent.isCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.event.player.PlayerItemHeldEvent
的用法示例。
在下文中一共展示了PlayerItemHeldEvent.isCancelled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equipItem
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入方法依赖的package包/类
/**
* 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;
}
示例2: setHeldItemSlot
import cn.nukkit.event.player.PlayerItemHeldEvent; //导入方法依赖的package包/类
public void setHeldItemSlot(int slot) {
if (slot >= -1 && slot < this.getSize()) {
Item item = this.getItem(slot);
int itemIndex = this.getHeldItemIndex();
if (this.getHolder() instanceof Player) {
PlayerItemHeldEvent ev = new PlayerItemHeldEvent((Player) this.getHolder(), item, slot, itemIndex);
Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
this.sendContents((Player) this.getHolder());
return;
}
}
this.setHotbarSlotIndex(itemIndex, slot);
}
}