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


Java EnchantmentStorageMeta.addStoredEnchant方法代码示例

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


在下文中一共展示了EnchantmentStorageMeta.addStoredEnchant方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: change

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
public void change(Event event, Object[] delta, Changer.ChangeMode mode){
	EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getSingle(event).getItemMeta();
	Enchantment ench = enchant.getSingle(event).getType();
	Integer level = meta.getStoredEnchantLevel(ench);
	Logging.info("Initial level: " + level);
	if (meta.hasStoredEnchant(ench)) meta.removeStoredEnchant(ench);
	if (mode == ChangeMode.SET) level = ((Number) delta[0]).intValue();
	if (mode == ChangeMode.ADD) level += ((Number) delta[0]).intValue();
	if (mode == ChangeMode.REMOVE) level -= ((Number) delta[0]).intValue();
	Logging.info("New level: " + level);
	if (level > 0) meta.addStoredEnchant(ench, level, true);
	book.getSingle(event).setItemMeta(meta);
}
 
开发者ID:MundoSK,项目名称:MundoSK,代码行数:14,代码来源:ExprEnchantLevelInEnchBook.java

示例10: testConflictingStoredEnchantment

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
@Test
public void testConflictingStoredEnchantment() {
    EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);
    assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.DURABILITY), is(false));

    itemMeta.addStoredEnchant(Enchantment.SILK_TOUCH, 1, false);
    assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.DURABILITY), is(false));
    assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
    assertThat(itemMeta.hasConflictingStoredEnchant(null), is(false));
}
 
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:11,代码来源:ItemMetaTest.java

示例11: testConflictingStoredEnchantments

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
@Test
public void testConflictingStoredEnchantments() {
    EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);
    itemMeta.addStoredEnchant(Enchantment.DURABILITY, 6, true);
    itemMeta.addStoredEnchant(Enchantment.DIG_SPEED, 6, true);
    assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(false));

    itemMeta.addStoredEnchant(Enchantment.SILK_TOUCH, 1, false);
    assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
    assertThat(itemMeta.hasConflictingStoredEnchant(null), is(false));
}
 
开发者ID:OvercastNetwork,项目名称:CraftBukkit,代码行数:12,代码来源:ItemMetaTest.java

示例12: unbox

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public ItemMeta unbox() {

	ItemFactory factory = Bukkit.getServer().getItemFactory();
	EnchantmentStorageMeta meta = (EnchantmentStorageMeta) factory.getItemMeta(Material.getMaterial(this.id));

	for (CardboardEnchantment e : this.enchantments.keySet()) {
		meta.addStoredEnchant(e.unbox(), this.enchantments.get(e), true);
	}
	return meta;
}
 
开发者ID:StarQuestMinecraft,项目名称:StarQuestCode,代码行数:12,代码来源:CardboardMetaEnchantment.java

示例13: unbox

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
public ItemMeta unbox() {

		ItemFactory factory = Bukkit.getServer().getItemFactory();
		EnchantmentStorageMeta meta = (EnchantmentStorageMeta) factory.getItemMeta(Material.getMaterial(this.id));

		for (CardboardEnchantment e : this.enchantments.keySet()) {
			meta.addStoredEnchant(e.unbox(), this.enchantments.get(e), true);
		}
		return meta;
	}
 
开发者ID:StarQuestMinecraft,项目名称:StarQuestCode,代码行数:11,代码来源:CardboardMetaEnchantment.java

示例14: addToItem

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
@Override
public ItemStack addToItem(final ItemStack item, final int level) {
    if (item.getType() == Material.BOOK) {
        item.setType(Material.ENCHANTED_BOOK);
    }
    if (item.getType() == Material.ENCHANTED_BOOK) {
        final EnchantmentStorageMeta meta = (EnchantmentStorageMeta)item.getItemMeta();
        meta.addStoredEnchant(enchantment, level, true);
        item.setItemMeta(meta);
        return item;
    }
    item.addUnsafeEnchantment(enchantment, level);
    return item;
}
 
开发者ID:Eniripsa96,项目名称:EnchantmentAPI,代码行数:15,代码来源:VanillaEnchantment.java

示例15: addEnchants

import org.bukkit.inventory.meta.EnchantmentStorageMeta; //导入方法依赖的package包/类
private void addEnchants(ItemStack stack, SaleSign saleSign)
{
    Map<Enchantment, Integer> enchants = saleSign.getEnchantments();
    if (saleSign.hasStoredEnchantments()) {
        EnchantmentStorageMeta enchantMeta = getStorageMeta(stack);
        for (Map.Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
            enchantMeta.addStoredEnchant(enchant.getKey(),
                                         enchant.getValue(),
                                         false);
        }
        stack.setItemMeta(enchantMeta);
    } else {
        stack.addEnchantments(saleSign.getEnchantments());
    }
}
 
开发者ID:sabersamus,项目名称:Bytecraft,代码行数:16,代码来源:SaleSignListener.java


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