Skip to content

Commit

Permalink
Enable early regex detection, so that split would not break them.
Browse files Browse the repository at this point in the history
  • Loading branch information
aagrishankov committed Nov 2, 2020
1 parent 1ae643f commit bafbb7f
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/main/scala/extracells/part/PartOreDictExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public void setFilter(String filter) {
* Call when the filter string has changed to parse and recompile the filter.
*/
private void updateFilter() {
if (!this.filter.trim().isEmpty()) {
//ArrayList<String> matchingNames = new ArrayList<>();
Predicate<ItemStack> matcher = null;

Predicate<ItemStack> matcher = null;
if (filter.contains("\\") || filter.contains("^") || filter.contains("$") || filter.contains("+") || filter.contains("(") || filter.contains(")") || filter.contains("[") || filter.contains("]")) {
final Predicate<String> test = Pattern.compile(filter).asPredicate();
matcher = (is) -> is != null && IntStream.of(OreDictionary.getOreIDs(is)).mapToObj(OreDictionary::getOreName).anyMatch(test);
} else if (!this.filter.trim().isEmpty()) {
String[] filters = this.filter.split("[&|]");
String lastFilter = null;

Expand Down Expand Up @@ -108,31 +109,21 @@ private void updateFilter() {
}
}
}
}

if (matcher == null) {
//filterPredicate = null;
oreDictFilteredItems = new ItemStack[0];
return;
}

//Mod name and path evaluation can only be done during tick, can't precompile whitelist for this.
if (!this.filter.contains("@") && !this.filter.contains("~")) {
//Precompiled whitelist of oredict itemstacks.
ArrayList<ItemStack> filtered = new ArrayList<>();
for (String name : OreDictionary.getOreNames())
for (ItemStack s : OreDictionary.getOres(name))
if (matcher.test(s)) {
filtered.add(s);
}
oreDictFilteredItems = filtered.toArray(oreDictFilteredItems);
// Mod name and path evaluation are disabled in this version
if (matcher != null && !this.filter.contains("@") && !this.filter.contains("~")) {
//Precompiled whitelist of oredict itemstacks.
ArrayList<ItemStack> filtered = new ArrayList<>();
for (String name : OreDictionary.getOreNames())
for (ItemStack s : OreDictionary.getOres(name))
if (matcher.test(s)) {
filtered.add(s);
}
oreDictFilteredItems = filtered.toArray(oreDictFilteredItems);

} else {
// mod filtering disabled
//filterPredicate = matcher;
this.oreDictFilteredItems = new ItemStack[0];
}
} else {
//this.filterPredicate = null;
// mod filtering disabled
this.oreDictFilteredItems = new ItemStack[0];
}
}
Expand Down

0 comments on commit bafbb7f

Please sign in to comment.