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


Java EnchantmentStorageMeta类代码示例

本文整理汇总了Java中org.bukkit.inventory.meta.EnchantmentStorageMeta的典型用法代码示例。如果您正苦于以下问题:Java EnchantmentStorageMeta类的具体用法?Java EnchantmentStorageMeta怎么用?Java EnchantmentStorageMeta使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: addEnchantment

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
/**
 * Add an enchantment to an {@link ItemStack}.
 *
 * @param stack    The item stack.
 * @param enchant  The enchantment to add.
 * @param level    The enchantment level.
 */
public static void addEnchantment(ItemStack stack, Enchantment enchant, int level) {
    PreCon.notNull(stack);
    PreCon.notNull(enchant);
    PreCon.positiveNumber(level);

    ItemMeta meta = stack.getItemMeta();

    // check for enchantment storage items such as enchanted books
    if (meta instanceof EnchantmentStorageMeta) {
        EnchantmentStorageMeta storage = (EnchantmentStorageMeta)meta;
        storage.addStoredEnchant(enchant, level, true);
        stack.setItemMeta(storage);
    }
    else {
        stack.addUnsafeEnchantment(enchant, level);
    }
}
 
开发者ID:JCThePants,项目名称:NucleusFramework,代码行数:25,代码来源:EnchantUtils.java

示例2: onPlayerInteract

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
        // The player didn't click an enchantment table, Creative players will instantly destroy.
        Player player = event.getPlayer();
        if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {

            // The player didn't click with an enchanted book.
            ItemStack stack = event.getItem();
            if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
                ItemMeta meta = stack.getItemMeta();
                if (meta instanceof EnchantmentStorageMeta) {
                    EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
                    for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
                        enchantmentStorageMeta.removeStoredEnchant(enchantment);
                    }

                    event.setCancelled(true);
                    player.setItemInHand(EMPTY_BOOK);
                    player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
                }
            }
        }
    }
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:26,代码来源:BookDeenchantListener.java

示例3: getRandomEnchant

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
public static ItemStack getRandomEnchant(List<Enchantment>enchants, int amount){
	ItemStack result = new ItemStack(Material.ENCHANTED_BOOK);
	List<Enchantment>left = new ArrayList<Enchantment>(enchants);
	EnchantmentStorageMeta meta = (EnchantmentStorageMeta) result.getItemMeta();
	if(amount > left.size())
		amount = left.size();
	for(int i = 0 ; i < amount && !left.isEmpty() ; i++){
		Enchantment e = VanillaPlusCore.getRandom(left);
		left.remove(e);
		int level = VanillaPlusCore.getRandom().nextInt(100);
		level = level % (e.getMaxLevel()+1-e.getStartLevel())+e.getStartLevel();
		meta.addStoredEnchant(e, level, false);
	}
	result.setItemMeta(meta);
	return result;
}
 
开发者ID:dracnis,项目名称:VanillaPlus,代码行数:17,代码来源:MinecraftUtils.java

示例4: get

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
@Override
@Nullable
protected ItemStack[] get(Event event) {
	ItemStack input = book.getSingle(event);
	EnchantmentStorageMeta meta = (EnchantmentStorageMeta) input.getItemMeta();
	final EnchantmentType[] enchs = enchants.getArray(event);
	for (final EnchantmentType ench : enchs) {
		if (meta.hasStoredEnchant(ench.getType())) {
			meta.removeEnchant(ench.getType());
		}
		meta.addStoredEnchant(ench.getType(), ench.getLevel(), true);
	}
	ItemStack result = book.getSingle(event);
	result.setItemMeta(meta);
	return new ItemStack[]{result};
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:17,代码来源:ExprEnchBookWithEnch.java

示例5: parse

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
public static ItemMeta parse(Element xml, ItemMeta source) {
    if (source instanceof BannerMeta) {
        return parseBanner(xml, (BannerMeta) source);
    } else if (source instanceof BookMeta) {
        return parseBook(xml, (BookMeta) source);
    } else if (source instanceof EnchantmentStorageMeta) {
        return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source);
    } else if (source instanceof FireworkMeta) {
        return parseFirework(xml, (FireworkMeta) source);
    } else if (source instanceof FireworkEffectMeta) {
        return parseFireworkEffect(xml, (FireworkEffectMeta) source);
    } else if (source instanceof LeatherArmorMeta) {
        return parseLeatherArmor(xml, (LeatherArmorMeta) source);
    } else if (source instanceof MapMeta) {
        return parseMap(xml, (MapMeta) source);
    } else if (source instanceof PotionMeta) {
        return parsePotion(xml, (PotionMeta) source);
    } else if (source instanceof SkullMeta) {
        return parseSkull(xml, (SkullMeta) source);
    } else if (source instanceof SpawnEggMeta) {
        return parseSpawnEgg(xml, (SpawnEggMeta) source);
    }

    return source;
}
 
开发者ID:ShootGame,项目名称:Arcade2,代码行数:26,代码来源:XMLItemMeta.java

示例6: parseEnchantmentStorage

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
public static EnchantmentStorageMeta parseEnchantmentStorage(Element xml, EnchantmentStorageMeta source) {
    Element book = xml.getChild("enchanted-book");
    if (book != null) {
        for (Element enchantment : book.getChildren("enchantment")) {
            Enchantment type = Enchantment.getByName(XMLParser.parseEnumValue(enchantment.getTextNormalize()));
            int level = 1;

            try {
                Attribute levelAttribute = enchantment.getAttribute("level");
                if (levelAttribute != null) {
                    level = levelAttribute.getIntValue();
                }
            } catch (DataConversionException ignored) {
            }

            source.addStoredEnchant(type, level, false);
        }
    }

    return source;
}
 
开发者ID:ShootGame,项目名称:Arcade2,代码行数:22,代码来源:XMLItemMeta.java

示例7: addMcEnchant

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
private void addMcEnchant(final EnchantmentStorageMeta meta, final by enchNbt) {
    try {
        // Here we are not using (dh.e(String)) because it does not fail correctly:
        // it returns 0 instead of throwing an exception.
        // Instead, we use (dw.e()). This way either the cast will fail or a NPE will be thrown.
        final short enchId = ((cj) enchNbt.a("r1_6_4/net/minecraft/server/id")).a;
        final short enchLvl = ((cj) enchNbt.a("lvl")).a;
        @SuppressWarnings("deprecation")
        final Enchantment ench = Enchantment.getById(enchId);
        if (ench == null) {
            Log.warn("Unknown Enchantment ID (" + enchId + "), ignored.");
        } else {
            meta.addStoredEnchant(ench, enchLvl, false);
        }
    } catch (final RuntimeException e) {
        if (e instanceof ClassCastException || e instanceof NullPointerException) {
            Log.error("Failed to add Enchantment to Enchanted Book, ignored.\nThe NBT was: " + enchNbt, e);
        } else {
            throw e;
        }
    }
}
 
开发者ID:Ribesg,项目名称:Pure,代码行数:23,代码来源:NmsProxyTileChest.java

示例8: getSpecialMetaString

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
/**
 * Gets a String representing all special meta of this ItemStack, if any.
 *
 * @param is         the ItemStack
 * @param separators the separators
 *
 * @return a String representing this ItemStack's special meta or an empty String
 *
 * @throws InventoryUtilException if something goes wrong
 */
public static String getSpecialMetaString(final ItemStack is, final String[] separators) throws InventoryUtilException {
    final ItemMeta meta = is.getItemMeta();

    if (meta instanceof BookMeta) {
        return getBookMetaString((BookMeta)meta);
    } else if (meta instanceof EnchantmentStorageMeta) {
        return getEnchantmentStorageMetaString((EnchantmentStorageMeta)meta, separators);
    } else if (meta instanceof FireworkEffectMeta) {
        return getFireworkEffectMetaString((FireworkEffectMeta)meta);
    } else if (meta instanceof FireworkMeta) {
        return getFireworkMetaString((FireworkMeta)meta, separators);
    } else if (meta instanceof LeatherArmorMeta) {
        return getLeatherArmorMetaString((LeatherArmorMeta)meta);
    } else if (meta instanceof MapMeta) {
        return getMapMetaString((MapMeta)meta);
    } else if (meta instanceof PotionMeta) {
        return getPotionMetaString((PotionMeta)meta, separators);
    } else if (meta instanceof SkullMeta) {
        return getSkullMetaString((SkullMeta)meta);
    } else {
        throw new InventoryUtilException("Unknown Meta type '" + meta.getClass().getName() + "', please report this to the author (Ribesg)!");
    }
}
 
开发者ID:Ribesg,项目名称:NPlugins,代码行数:34,代码来源:ItemMetaUtil.java

示例9: getEnchantmentStorageMetaString

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
private static String getEnchantmentStorageMetaString(final EnchantmentStorageMeta meta, final String[] separators) {
    if (meta.getStoredEnchants().isEmpty()) {
        return "";
    } else {
        final StringBuilder enchantmentsStringBuilder = new StringBuilder();
        final Map<Enchantment, Integer> sortedEnchantmentMap = new TreeMap<>(EnchantmentUtil.ENCHANTMENT_COMPARATOR);
        sortedEnchantmentMap.putAll(meta.getStoredEnchants());
        for (final Map.Entry<Enchantment, Integer> e : sortedEnchantmentMap.entrySet()) {
            enchantmentsStringBuilder.append(e.getKey().getName());
            enchantmentsStringBuilder.append(separators[2]);
            enchantmentsStringBuilder.append(e.getValue());
            enchantmentsStringBuilder.append(separators[1]);
        }
        return enchantmentsStringBuilder.substring(0, enchantmentsStringBuilder.length() - separators[1].length());
    }
}
 
开发者ID:Ribesg,项目名称:NPlugins,代码行数:17,代码来源:ItemMetaUtil.java

示例10: processMeta

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
@Override
public void processMeta(Player player, ItemMeta m) {
    super.processMeta(player, m);
    EnchantmentStorageMeta meta = (EnchantmentStorageMeta) m;
    for(Map.Entry<Enchantment, PlaceholderValue<Integer>> ench : storedEnchantments.entrySet())
        meta.addStoredEnchant(ench.getKey(), ench.getValue().resolve(player), true);
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:8,代码来源:EnchantedBookCustomItem.java

示例11: setLores

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
public EnchantedBookMaker setLores(String... lores) {
    EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta)this.itemStack.getItemMeta();
    List<String> loresList = new ArrayList<>();
    for (String lore : lores) {
        loresList.add(lore);
    }
    itemMeta.setLore(loresList);
    this.itemStack.setItemMeta(itemMeta);
    return this;
}
 
开发者ID:cadox8,项目名称:WC,代码行数:11,代码来源:ItemMaker.java

示例12: addEnchantments

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
private void addEnchantments(String enchantments, String level, ItemStack is) {
	try {
	if (enchantments == null || level == null)
		return;

	ArrayList<String> enchants = new ArrayList<String>(Arrays.asList(enchantments.split("!")));
	ArrayList<String> levels = new ArrayList<String>(Arrays.asList(level.split("!")));

	if (enchantments.isEmpty())
		return;

	for (int i = 0; i < enchants.size(); i++) {
		if (!enchants.get(i).equalsIgnoreCase(" ") && !enchants.get(i).equalsIgnoreCase("")) {
			if (is.getType() == Material.ENCHANTED_BOOK) {
				EnchantmentStorageMeta meta = (EnchantmentStorageMeta) is.getItemMeta();
				meta.addStoredEnchant(Enchantment.getByName(enchants.get(i)), Integer.parseInt(levels.get(i)), true);
			    
				is.setItemMeta(meta);
			} else
				is.addEnchantment(Enchantment.getByName(enchants.get(i)), Integer.parseInt(levels.get(i)));
		}
	}

	enchants.clear();
	levels.clear();
	} catch(Exception e) {
		if(e instanceof java.lang.IllegalArgumentException) {
		Logger.ERROR.log("couldn't add enchantment " + enchantments + " level " + level + " to " + is.getType().toString());
	    Logger.ERROR.log("Cause: java.lang.IllegalArgumentException");
		} else {
		e.printStackTrace();
		}
	}
}
 
开发者ID:ThEWiZ76,项目名称:KingdomFactions,代码行数:35,代码来源:ShopItem.java

示例13: setTo

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
@Override
public void setTo(ItemMeta meta) {
    if(meta instanceof EnchantmentStorageMeta){
        EnchantmentStorageMeta enc = (EnchantmentStorageMeta) meta;
        for(Enchants a : array)
        {
            Enchantment ment = Enchantment.getById(a.id);
            if(ment != null)
                enc.addStoredEnchant(ment,a.level,true);
        }
    }
}
 
开发者ID:DevCrafters,项目名称:SaveableSerializing,代码行数:13,代码来源:SaveableEnchantBook.java

示例14: setFrom

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
@Override
public SubMeta setFrom(ItemMeta meta) {
    if(meta instanceof EnchantmentStorageMeta){
        EnchantmentStorageMeta enc = (EnchantmentStorageMeta) meta;
        for(Enchantment a : enc.getStoredEnchants().keySet())
            array.add(new Enchants(a,enc.getStoredEnchants().get(a)));
    }
    return this;
}
 
开发者ID:DevCrafters,项目名称:SaveableSerializing,代码行数:10,代码来源:SaveableEnchantBook.java

示例15: get

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入依赖的package包/类
@Override
@Nullable
protected Integer[] get(Event event) {
	ItemStack input = book.getSingle(event);
	EnchantmentStorageMeta meta = (EnchantmentStorageMeta) input.getItemMeta();
	return new Integer[]{meta.getStoredEnchantLevel(enchant.getSingle(event).getType())};
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:8,代码来源:ExprEnchantLevelInEnchBook.java


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