Skip to content

Commit

Permalink
feat: KeyFilterImpl support regex
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Dec 25, 2023
1 parent 0c8a1af commit f172794
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;

/**
* @author Blank038
Expand Down Expand Up @@ -45,17 +46,23 @@ public boolean check(ItemStack itemStack) {
if (itemStack == null) {
return false;
}
BiFunction<String, String, Boolean> func = (text, require) -> {
if (require.startsWith("regex:")) {
return text.matches(require.substring(6));
}
return text.toLowerCase().contains(require.toLowerCase());
};
return this.keys.stream().anyMatch((s) -> {
if (itemStack.getType().name().toLowerCase().contains(s.toLowerCase())) {
return true;
}
if (!itemStack.hasItemMeta()) {
return false;
}
if (itemStack.getItemMeta().hasDisplayName() && itemStack.getItemMeta().getDisplayName().toLowerCase().contains(s.toLowerCase())) {
if (itemStack.getItemMeta().hasDisplayName() && func.apply(itemStack.getItemMeta().getDisplayName(), s)) {
return true;
}
return itemStack.getItemMeta().hasLore() && itemStack.getItemMeta().getLore().stream().anyMatch((i) -> i.toLowerCase().contains(s.toLowerCase()));
return itemStack.getItemMeta().hasLore() && itemStack.getItemMeta().getLore().stream().anyMatch((i) -> func.apply(i, s));
});
}
}

0 comments on commit f172794

Please sign in to comment.