aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAscynx <78341107+Ascynx@users.noreply.github.com>2022-10-21 10:28:33 +0200
committerGitHub <noreply@github.com>2022-10-21 10:28:33 +0200
commit9d62422902e2cb9a90b7a58089e892b61faf9f74 (patch)
treedbc87ec9b1512cac8159b0e43234a6410a4fcae7 /src/main/java
parent5f2cfe2d07e0ddfc4f600d6ea31bad11d896e72f (diff)
downloadNotEnoughUpdates-9d62422902e2cb9a90b7a58089e892b61faf9f74.tar.gz
NotEnoughUpdates-9d62422902e2cb9a90b7a58089e892b61faf9f74.tar.bz2
NotEnoughUpdates-9d62422902e2cb9a90b7a58089e892b61faf9f74.zip
AND | OR support for container search. (#311)
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index 598ecc2e..710bdd6c 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -429,6 +429,33 @@ public class NEUManager {
}
/**
+ * SearchString but with AND | OR support
+ */
+
+ public boolean multiSearchString(String match, String query) {
+ boolean totalMatches = false;
+
+ StringBuilder query2 = new StringBuilder();
+ char lastOp = '|';
+ for (char c : query.toCharArray()) {
+ if (c == '|' || c == '&') {
+ boolean matches = searchString(match, query2.toString());
+ totalMatches = lastOp == '|' ? totalMatches || matches : totalMatches && matches;
+
+ query2 = new StringBuilder();
+ lastOp = c;
+ } else {
+ query2.append(c);
+ }
+ }
+
+ boolean matches = searchString(match, query2.toString());
+ totalMatches = lastOp == '|' ? totalMatches || matches : totalMatches && matches;
+
+ return totalMatches;
+ }
+
+ /**
* Searches a string for a query. This method is used to mimic the behaviour of the more complex map-based search
* function. This method is used for the chest-item-search feature.
*/
@@ -490,7 +517,7 @@ public class NEUManager {
public boolean doesStackMatchSearch(ItemStack stack, String query) {
if (query.startsWith("title:")) {
query = query.substring(6);
- return searchString(stack.getDisplayName(), query);
+ return multiSearchString(stack.getDisplayName(), query);
} else if (query.startsWith("desc:")) {
query = query.substring(5);
String lore = "";
@@ -504,7 +531,7 @@ public class NEUManager {
}
}
}
- return searchString(lore, query);
+ return multiSearchString(lore, query);
} else if (query.startsWith("id:")) {
query = query.substring(3);
String internalName = getInternalNameForItem(stack);
@@ -516,9 +543,11 @@ public class NEUManager {
for (char c : query.toCharArray()) {
sb.append(c).append(" ");
}
- result = result || searchString(stack.getDisplayName(), sb.toString());
+ result = result || multiSearchString(stack.getDisplayName(), sb.toString());
}
- result = result || searchString(stack.getDisplayName(), query);
+
+
+ result = result || multiSearchString(stack.getDisplayName(), query);
String lore = "";
NBTTagCompound tag = stack.getTagCompound();
@@ -532,7 +561,7 @@ public class NEUManager {
}
}
- result = result || searchString(lore, query);
+ result = result || multiSearchString(lore, query);
return result;
}