Skip to content

Commit

Permalink
Fix null ItemFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
slprime committed Dec 11, 2024
1 parent bf789fc commit aebb989
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/main/java/codechicken/nei/SearchTokenParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,24 @@ && getRedefinedPrefix(provider.getPrefix()) == ch)
.findFirst().orElse(null);
}

public ItemFilter getFilter(String filterText) {
public synchronized ItemFilter getFilter(String filterText) {
filterText = EnumChatFormatting.getTextWithoutFormattingCodes(filterText).toLowerCase();

if (!this.filtersCache.containsKey(filterText)) {
final String[] parts = filterText.split("\\|");
return this.filtersCache.computeIfAbsent(filterText, text -> {
final String[] parts = text.split("\\|");
final List<ItemFilter> searchTokens = Arrays.stream(parts).map(this::parseSearchText).filter(s -> s != null)
.collect(Collectors.toCollection(ArrayList::new));

if (searchTokens.isEmpty()) {
this.filtersCache.put(filterText, new EverythingItemFilter());
return new EverythingItemFilter();
} else if (searchTokens.size() == 1) {
this.filtersCache.put(filterText, new IsRegisteredItemFilter(new ItemFilterCache(searchTokens.get(0))));
return new IsRegisteredItemFilter(new ItemFilterCache(searchTokens.get(0)));
} else {
this.filtersCache.put(
filterText,
new IsRegisteredItemFilter(new ItemFilterCache(new AnyMultiItemFilter(searchTokens))));
return new IsRegisteredItemFilter(new ItemFilterCache(new AnyMultiItemFilter(searchTokens)));
}

}
});

return this.filtersCache.get(filterText);
}

public Pattern getSplitPattern() {
Expand Down

0 comments on commit aebb989

Please sign in to comment.