當前位置: 首頁>>代碼示例>>Java>>正文


Java Material.ENCHANTED_BOOK屬性代碼示例

本文整理匯總了Java中org.bukkit.Material.ENCHANTED_BOOK屬性的典型用法代碼示例。如果您正苦於以下問題:Java Material.ENCHANTED_BOOK屬性的具體用法?Java Material.ENCHANTED_BOOK怎麽用?Java Material.ENCHANTED_BOOK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.bukkit.Material的用法示例。


在下文中一共展示了Material.ENCHANTED_BOOK屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onPlayerInteract

@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,代碼行數:25,代碼來源:BookDeenchantListener.java

示例2: getRandomEnchant

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,代碼行數:16,代碼來源:MinecraftUtils.java

示例3: getItem

public static ItemStack getItem(BookDesign design) {
	switch (design) {
	case BOOK: {
		return new CustomItem(new MaterialData(Material.ENCHANTED_BOOK), "&a粘液科技指南 &7(書與筆版式)", "", "&e右鍵 &8\u21E8 &7瀏覽粘液科技物品", "&eShift + 右鍵 &8\u21E8 &7打開設置 / 製作人員頁麵");
	}
	case CHEAT_SHEET: {
		return new CustomItem(new MaterialData(Material.ENCHANTED_BOOK), "&a粘液科技指南 &7(作弊版式)", "", "&4&l僅限管理員使用!", "", "&e右鍵 &8\u21E8 &7瀏覽粘液科技物品", "&eShift + 右鍵 &8\u21E8 &7打開設置 / 製作人員頁麵");
	}
	case CHEST: {
		return new CustomItem(new MaterialData(Material.ENCHANTED_BOOK), "&a粘液科技指南 &7(箱子版式)", "", "&e右鍵 &8\u21E8 &7瀏覽粘液科技物品", "&eShift + 右鍵 &8\u21E8 &7打開設置 / 製作人員頁麵");
	}
	default:
		return null;
	}
}
 
開發者ID:StarWishsama,項目名稱:Slimefun4-Chinese-Version,代碼行數:15,代碼來源:SlimefunGuide.java

示例4: addEnchantments

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,代碼行數:34,代碼來源:ShopItem.java

示例5: fill

public static void fill(Random random, List<WeightedRandomItem> list, Inventory inventory, int amount) {
	for (int j = 0; j < amount; ++j) {
		WeightedRandomItem loot = (WeightedRandomItem) WeightedRandom.getChoice(random, list);
		int k = loot.min + random.nextInt(loot.max - loot.min + 1);
		for (int l = 0; l < k; l += loot.loot.getMaxStackSize()) {
			ItemStack item = loot.loot.clone();
			if(item.getType() == Material.ENCHANTED_BOOK && ! item.hasItemMeta())
				item = MinecraftUtils.getDongeonBook();
			item.setAmount(loot.loot.getMaxStackSize() > k ? k : loot.loot.getMaxStackSize());
			inventory.setItem(random.nextInt(inventory.getSize()), item);
		}
    }

}
 
開發者ID:dracnis,項目名稱:VanillaPlus,代碼行數:14,代碼來源:WeightedRandomItem.java

示例6: EnchantedBookMaker

public EnchantedBookMaker() {
    itemStack = new ItemStack(Material.ENCHANTED_BOOK);
}
 
開發者ID:cadox8,項目名稱:WC,代碼行數:3,代碼來源:ItemMaker.java


注:本文中的org.bukkit.Material.ENCHANTED_BOOK屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。