当前位置: 首页>>代码示例>>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;未经允许,请勿转载。