當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。