I am creating a profanity filter, and I have now created a more efficent way of reading words.
This is the Word model.
package me.xemu.xemchatprotection.word;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@AllArgsConstructor
@Getter
@Setter
public class Word {
private String word;
private List<String> aliases;
private List<String> ignoreWith;
}
This is how I read the list over Words:
public static List<Word> getWords() {
List<Word> words = new ArrayList<>();
for (String w : XemChatProtection.INSTANCE.getWords().getSection("Profanity").keySet()) {
words.add(
new Word(w,
XemChatProtection.INSTANCE.getWords().getStringList("Profanity." + w + ".aliases"),
XemChatProtection.INSTANCE.getWords().getStringList("Profanity." + w + ".ignoreWith")));
}
return words;
}
But I want a way to read a string in this way:
- Check if string contains the main word
- Check if string contains a alias of the word, if it doesnt contain the main word
- Don't cancel the message (ignore the profanity) if the string contains a ignoreWith string.