aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-17 19:30:57 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-17 19:30:57 +0200
commitf9f22a5f61d129a17073a795537dcb222907964f (patch)
tree6c58201259d8be10617b6dcff63735de062fdd56 /src/main/java/at/hannibal2/skyhanni/utils
parentce43d92584b785650b35d5a6ebdbfddd7d31661c (diff)
downloadskyhanni-f9f22a5f61d129a17073a795537dcb222907964f.tar.gz
skyhanni-f9f22a5f61d129a17073a795537dcb222907964f.tar.bz2
skyhanni-f9f22a5f61d129a17073a795537dcb222907964f.zip
added player chat filter
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MultiFilter.kt40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MultiFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MultiFilter.kt
index 5786cb9e7..947019aa6 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MultiFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MultiFilter.kt
@@ -4,21 +4,24 @@ import com.google.gson.JsonObject
class MultiFilter {
- val equals = mutableListOf<String>()
- val startsWith = mutableListOf<String>()
- val endsWith = mutableListOf<String>()
- val contains = mutableListOf<String>()
+ private val equals = mutableListOf<String>()
+ private val startsWith = mutableListOf<String>()
+ private val endsWith = mutableListOf<String>()
+ private val contains = mutableListOf<String>()
+ private val containsWord = mutableListOf<String>()
fun load(hideNpcSell: JsonObject) {
equals.clear()
startsWith.clear()
endsWith.clear()
contains.clear()
+ containsWord.clear()
fill(hideNpcSell, "equals", equals)
fill(hideNpcSell, "startsWith", startsWith)
fill(hideNpcSell, "endsWith", endsWith)
fill(hideNpcSell, "contains", contains)
+ fill(hideNpcSell, "containsWord", containsWord)
}
private fun fill(jsonObject: JsonObject, key: String, list: MutableList<String>) {
@@ -27,12 +30,29 @@ class MultiFilter {
}
}
- fun match(name: String): Boolean {
- if (equals.contains(name)) return true
- if (startsWith.any { name.startsWith(it) }) return true
- if (endsWith.any { name.endsWith(it) }) return true
- if (contains.any { name.contains(it) }) return true
+ fun match(string: String): Boolean {
+ return matchResult(string) != null
+ }
+
+ fun matchResult(string: String): String? {
+ var result = equals.find { it == string }
+ if (result != null) return result
+ result = startsWith.find { string.startsWith(it) }
+ if (result != null) return result
+ result = endsWith.find { string.endsWith(it) }
+ if (result != null) return result
+ result = contains.find { string.contains(it) }
+ if (result != null) return result
+ result = containsWord.find { containsWord(string, it) }
+ if (result != null) return result
+
+ return null
+ }
+
+ private fun containsWord(message: String, word: String): Boolean =
+ message.startsWith("$word ") || message.endsWith(" $word") || message.contains(" $word ")
- return false
+ fun count(): Int {
+ return equals.size + startsWith.size + endsWith.size + contains.size + containsWord.size
}
} \ No newline at end of file