当前位置: 首页>>代码示例>>Java>>正文


Java PlayerItemHeldEvent.isCancelled方法代码示例

本文整理汇总了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;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:27,代码来源:PlayerInventory.java

示例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);
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:19,代码来源:PlayerInventory.java


注:本文中的cn.nukkit.event.player.PlayerItemHeldEvent.isCancelled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。