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


Java Item.addEnchantment方法代码示例

本文整理汇总了Java中cn.nukkit.item.Item.addEnchantment方法的典型用法代码示例。如果您正苦于以下问题:Java Item.addEnchantment方法的具体用法?Java Item.addEnchantment怎么用?Java Item.addEnchantment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cn.nukkit.item.Item的用法示例。


在下文中一共展示了Item.addEnchantment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onEnchant

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void onEnchant(Player who, Item before, Item after) {
    Item result = (before.getId() == Item.BOOK) ? new ItemBookEnchanted() : before;
    if (!before.hasEnchantments() && after.hasEnchantments() && after.getId() == result.getId() && this.levels != null && this.entries != null) {
        Enchantment[] enchantments = after.getEnchantments();
        for (int i = 0; i < 3; i++) {
            if (Arrays.equals(enchantments, this.entries[i].getEnchantments())) {
                Item lapis = this.getItem(1);
                int level = who.getExperienceLevel();
                int exp = who.getExperience();
                int cost = this.entries[i].getCost();
                if (lapis.getId() == Item.DYE && lapis.getDamage() == DyeColor.BLUE.getDyeData() && lapis.getCount() > i && level >= cost) {
                    result.addEnchantment(enchantments);
                    this.setItem(0, result);
                    lapis.setCount(lapis.getCount() - i - 1);
                    this.setItem(1, lapis);
                    who.setExperience(exp, level - cost);
                    break;
                }
            }
        }
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:23,代码来源:EnchantInventory.java

示例2: execute

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }
    if (args.length < 2) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Player player = sender.getServer().getPlayer(args[0]);
    if (player == null) {
        sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound"));
        return true;
    }
    int enchantId;
    int enchantLevel;
    try {
        enchantId = getIdByName(args[1]);
        enchantLevel = args.length == 3 ? Integer.parseInt(args[2]) : 1;
    } catch (NumberFormatException e) {
        sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
        return true;
    }
    Enchantment enchantment = Enchantment.getEnchantment(enchantId);
    if (enchantment == null) {
        sender.sendMessage(new TranslationContainer("commands.enchant.notFound", String.valueOf(enchantId)));
        return true;
    }
    enchantment.setLevel(enchantLevel);
    Item item = player.getInventory().getItemInHand();
    if (item.getId() <= 0) {
        sender.sendMessage(new TranslationContainer("commands.enchant.noItem"));
        return true;
    }
    item.addEnchantment(enchantment);
    player.getInventory().setItemInHand(item);
    Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.enchant.success"));
    return true;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:40,代码来源:EnchantCommand.java


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