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


Java ItemStack.getEnchantments方法代码示例

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


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

示例1: InventoryToString

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static String InventoryToString (Inventory invInventory)
{
    String serialization = invInventory.getSize() + ";";
    for (int i = 0; i < invInventory.getSize(); i++)
    {
        ItemStack is = invInventory.getItem(i);
        if (is != null)
        {
            String serializedItemStack = new String();
           
            String isType = String.valueOf(is.getType().getId());
            serializedItemStack += "[email protected]" + isType;
           
            if (is.getDurability() != 0)
            {
                String isDurability = String.valueOf(is.getDurability());
                serializedItemStack += ":[email protected]" + isDurability;
            }
           
            if (is.getAmount() != 1)
            {
                String isAmount = String.valueOf(is.getAmount());
                serializedItemStack += ":[email protected]" + isAmount;
            }
           
            Map<Enchantment,Integer> isEnch = is.getEnchantments();
            if (isEnch.size() > 0)
            {
                for (Entry<Enchantment,Integer> ench : isEnch.entrySet())
                {
                    serializedItemStack += ":[email protected]" + ench.getKey().getId() + "@" + ench.getValue();
                }
            }
           
            serialization += i + "#" + serializedItemStack + ";";
        }
    }
    return serialization;
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:41,代码来源:InventoryStringDeSerializer.java

示例2: ItemBuilder

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public ItemBuilder(ItemStack is) {
    super();
    material = is.getType();
    amount = is.getAmount();
    damage = is.getDurability();
    if (is.hasItemMeta()) {
        if (is.getItemMeta().hasLore()) lore = is.getItemMeta().getLore();
        if (is.getItemMeta().hasDisplayName()) name = is.getItemMeta().getDisplayName();
        if (is.getItemMeta().hasEnchants()) enchantments = is.getEnchantments();
        itemflags.addAll(is.getItemMeta().getItemFlags());
    }
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:13,代码来源:ItemBuilder.java

示例3: itemStackToString

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static String itemStackToString(ItemStack item) {
    StringBuilder builder = new StringBuilder();

    if (item != null) {
        String isType = String.valueOf(item.getType().getId());
        builder.append("[email protected]").append(isType);

        if (item.getDurability() != 0) {
            String isDurability = String.valueOf(item.getDurability());
            builder.append(":[email protected]").append(isDurability);
        }

        if (item.getAmount() != 1) {
            String isAmount = String.valueOf(item.getAmount());
            builder.append(":[email protected]").append(isAmount);
        }

        Map<Enchantment, Integer> isEnch = (Map<Enchantment, Integer>) item.getEnchantments();
        if (isEnch.size() > 0) {
            for (Map.Entry<Enchantment, Integer> ench : isEnch.entrySet()) {
                builder.append(":[email protected]").append(ench.getKey().getId()).append("@").append(ench.getValue());
            }
        }

        if (item.hasItemMeta()) {
            ItemMeta imeta = item.getItemMeta();
            if (imeta.hasDisplayName()) {
                builder.append(":[email protected]").append(imeta.getDisplayName());
            }
            if (imeta.hasLore()) {
                builder.append(":[email protected]").append(imeta.getLore());
            }
        }
    }

    return builder.toString();
}
 
开发者ID:ijoeleoli,项目名称:ZorahPractice,代码行数:39,代码来源:InventoryUtils.java

示例4: matches

import org.bukkit.inventory.ItemStack; //导入方法依赖的package包/类
public boolean matches(ItemStack anotherItem) {
    ItemStack base = itemTemplate.clone();
    ItemStack given = anotherItem.clone();
    base.setAmount(1);
    given.setAmount(1);
    if (requireExact) return base.equals(given);
    if (!base.getType().equals(given.getType())) return false;

    if (repairCostMatch == MatchingMode.EXACT &&
            base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable &&
            !(((Repairable) given.getItemMeta()).getRepairCost() == ((Repairable) base.getItemMeta()).getRepairCost())) {
        return false;
    }

    int baseDamage = base.getDurability();
    int givenDamage = given.getDurability();
    if (minDamageValue == -2 && givenDamage < baseDamage) return false;
    if (minDamageValue >= 0 && givenDamage < minDamageValue) return false;
    if (maxDamageValue == -2 && givenDamage > baseDamage) return false;
    if (maxDamageValue >= 0 && givenDamage > maxDamageValue) return false;

    String baseDisplay = getDisplayName(base);
    String givenDisplay = getDisplayName(given);
    if (nameMatch == MatchingMode.EXACT && !baseDisplay.equals(givenDisplay)) return false;
    if (nameMatch == MatchingMode.EXACT_TEXT && !ChatColor.stripColor(baseDisplay).equals(ChatColor.stripColor(givenDisplay)))
        return false;
    if (nameMatch == MatchingMode.CONTAINS && !givenDisplay.contains(baseDisplay)) return false;
    if (nameMatch == MatchingMode.CONTAINS_TEXT && !ChatColor.stripColor(givenDisplay).contains(ChatColor.stripColor(baseDisplay)))
        return false;

    Map<Enchantment, Integer> baseEnch = base.getEnchantments();
    Map<Enchantment, Integer> givenEnch = given.getEnchantments();
    if (enchantMatch == MatchingMode.EXACT || enchantMatch == MatchingMode.EXACT_TEXT) {
        if (!baseEnch.equals(givenEnch)) return false;
    } else if (enchantMatch == MatchingMode.CONTAINS || enchantMatch == MatchingMode.CONTAINS_TEXT) {
        for (Map.Entry<Enchantment, Integer> e : baseEnch.entrySet()) {
            if (!givenEnch.containsKey(e.getKey()) || givenEnch.get(e.getKey()) < e.getValue())
                return false;
        }
    }

    String[] baseLore = getLore(base);
    String[] givenLore = getLore(given);
    if (loreMatch == MatchingMode.EXACT && !Arrays.deepEquals(baseLore, givenLore)) return false;
    if (loreMatch == MatchingMode.CONTAINS && !containStrArr(givenLore, baseLore, false)) return false;
    if (loreMatch == MatchingMode.EXACT_TEXT) {
        for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[i]);
        for (int i = 0; i < givenLore.length; i++) givenLore[i] = ChatColor.stripColor(givenLore[i]);
        if (!Arrays.deepEquals(baseLore, givenLore)) return false;
    }
    if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;

    return true;
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:55,代码来源:BasicItemMatcher.java


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