本文整理汇总了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;
}