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


Java ItemMeta.getEnchants方法代碼示例

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


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

示例1: matches

import org.bukkit.inventory.meta.ItemMeta; //導入方法依賴的package包/類
public boolean matches(ItemStack tool) {
	ItemStack compare = this.getTemplate();
	if (compare == null) {
		return true; // this is catchall! matches everything.
	}
	if (compare.getType() != tool.getType()) return false;
	if (!ignoreDurability() && 
			compare.getDurability() != tool.getDurability()) return false;
	if (!ignoreAmount() && compare.getAmount() != tool.getAmount()) return false;

	// Short circuit of metachecks.
	if (ignoreMeta()) return true;

	// Metachecks.
	ItemMeta compmeta = compare.getItemMeta();
	ItemMeta toolmeta = tool.getItemMeta();
	if (toolmeta == null && toolmeta == compmeta) return true; // equal but no further compare
	
	if (compmeta == null) return false; // toolmeta != null but compmeta == null
	
	// both non-null.
	if (!ignoreName() && !(toolmeta.hasDisplayName() ? 
			toolmeta.getDisplayName().equals(compmeta.getDisplayName()) : !compmeta.hasDisplayName() ) ) return false;
	if (!ignoreLore() &&
			!(toolmeta.hasLore() ? toolmeta.getLore().equals(compmeta.getLore()) : !compmeta.hasLore())) return false;
	
	// Expensive enchantment checks.
	if (!ignoreEnchants()) {
		Map<Enchantment, Integer> compench = compmeta.getEnchants();
		Map<Enchantment, Integer> toolench = toolmeta.getEnchants();

		// check that set of enchants is same (both null or both not null and same) else bail
		if (!ignoreOtherEnchants() && !((compench == null && toolench == null) || 
				(compench != null && toolench != null && compench.keySet().equals(toolench.keySet()) ) ) ) return false; 

		// check that tool has at least the enchantments specified; ignore the rest.
		if (ignoreOtherEnchants() && !(compench == null || 
				(toolench != null && toolench.keySet().containsAll(compench.keySet()) ) ) ) return false; 

		// also check _level_ of enchants
		if (!ignoreEnchantsLvl() && compench != null) { 
			boolean fail = false;
			for(Enchantment ech : compench.keySet()) {
				if (!compench.get(ech).equals(toolench.get(ech))) {
					fail = true;
					break;
				}
			}
			if (fail) return false;
		}
	}
	return true;
}
 
開發者ID:DevotedMC,項目名稱:CropControl,代碼行數:54,代碼來源:ToolConfig.java


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