public boolean matches(ItemStack anotherItem) {
ItemStack base = itemTemplate.clone();
ItemStack given = anotherItem.clone();
base.setAmount(1);
given.setAmount(1);
if (requireExact) return base.equals(given);
if (!base.getType().equals(given.getType())) return false;
if (repairCostMatch == MatchingMode.EXACT) {
if (base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable) {
int cost1 = ((Repairable) given.getItemMeta()).getRepairCost();
int cost2 = ((Repairable) base.getItemMeta()).getRepairCost();
if (cost1 != cost2) return false;
} else if (base.getItemMeta() instanceof Repairable || given.getItemMeta() instanceof Repairable) {
return false;
}
}
int baseDamage = base.getDurability();
int givenDamage = given.getDurability();
if (minDamageValue == -2 && givenDamage < baseDamage) return false;
if (minDamageValue >= 0 && givenDamage < minDamageValue) return false;
if (maxDamageValue == -2 && givenDamage > baseDamage) return false;
if (maxDamageValue >= 0 && givenDamage > maxDamageValue) return false;
String baseDisplay = getDisplayName(base);
String givenDisplay = getDisplayName(given);
if (nameMatch == MatchingMode.EXACT && !baseDisplay.equals(givenDisplay)) return false;
if (nameMatch == MatchingMode.EXACT_TEXT && !ChatColor.stripColor(baseDisplay).equals(ChatColor.stripColor(givenDisplay)))
return false;
if (nameMatch == MatchingMode.CONTAINS && !givenDisplay.contains(baseDisplay)) return false;
if (nameMatch == MatchingMode.CONTAINS_TEXT && !ChatColor.stripColor(givenDisplay).contains(ChatColor.stripColor(baseDisplay)))
return false;
Map<Enchantment, Integer> baseEnch = base.getEnchantments();
Map<Enchantment, Integer> givenEnch = given.getEnchantments();
if (enchantMatch == MatchingMode.EXACT || enchantMatch == MatchingMode.EXACT_TEXT) {
if (!baseEnch.equals(givenEnch)) return false;
} else if (enchantMatch == MatchingMode.CONTAINS || enchantMatch == MatchingMode.CONTAINS_TEXT) {
for (Map.Entry<Enchantment, Integer> e : baseEnch.entrySet()) {
if (!givenEnch.containsKey(e.getKey()) || givenEnch.get(e.getKey()) < e.getValue())
return false;
}
}
String[] baseLore = getLore(base);
String[] givenLore = getLore(given);
if (loreMatch == MatchingMode.EXACT && !Arrays.deepEquals(baseLore, givenLore)) return false;
if (loreMatch == MatchingMode.CONTAINS && !containStrArr(givenLore, baseLore, false)) return false;
if (loreMatch == MatchingMode.EXACT_TEXT) {
for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[0]);
for (int i = 0; i < baseLore.length; i++) baseLore[i] = ChatColor.stripColor(baseLore[0]);
if (!Arrays.deepEquals(baseLore, givenLore)) return false;
}
if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;
return true;
}
RequisitionSpecification.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:HamsterEcoHelper
作者:
评论列表
文章目录