BasicItemMatcher.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:NyaaCore 作者:
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 &&
            base.getItemMeta() instanceof Repairable && given.getItemMeta() instanceof Repairable &&
            !(((Repairable) given.getItemMeta()).getRepairCost() == ((Repairable) base.getItemMeta()).getRepairCost())) {
        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[i]);
        for (int i = 0; i < givenLore.length; i++) givenLore[i] = ChatColor.stripColor(givenLore[i]);
        if (!Arrays.deepEquals(baseLore, givenLore)) return false;
    }
    if (loreMatch == MatchingMode.CONTAINS_TEXT && !containStrArr(givenLore, baseLore, true)) return false;

    return true;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号