0

I'm censoring the chat. Censorship works, but the plugin replaces the word, even if this word does not need to be blocked.

For example: Blocking the word "port" The plugin blocks as follows: Tele****ing

What check should I add to this method to make it work? swearList() this is the get method for the config.yml

private String returnCorrected(String str) {
    JsonObject jsonObject = (new JsonParser()).parse(str).getAsJsonObject();
    JsonArray element = jsonObject.get("extra").getAsJsonArray();
    for (JsonElement objects : element) {
        if (objects instanceof JsonObject) {
            JsonObject actual = (JsonObject)objects;
            String text = actual.get("text").getAsString();
            for (String badWord : swearList()) {
                if (text.contains(badWord)) {
                    String repeat = StringUtils.repeat("*", badWord.length());
                    text = text.replace(badWord, repeat);
                }
            }
            actual.addProperty("text", text);
        }
    }
    return jsonObject.toString();
}

I tried to do it through Listener, but then I need to rewrite completely OnEnable. And I would just like to do a check in private String returnCorrected(String str)

Lucan
  • 2,907
  • 2
  • 16
  • 30
DiceMa
  • 11
  • 1
  • 5
    Ah yes, the traditional https://en.wikipedia.org/wiki/Scunthorpe_problem . Depends on what you want to achieve. You could limit yourself to entire words (regexp with `\b`). Or you could check the flagged word against a dictionary. Or you could embrace the crappy censorship. Add some innocuous words for extra memes... – teapot418 Aug 23 '23 at 15:11
  • I agree with teapot. It would be useful to know how you wish the word matching to function. – Lucan Aug 23 '23 at 21:37
  • Consider also the substitution of visually similar characters to avoid detection, for example the Cyrillic letter `с` and the Latin letter `c`. – Bohemian Aug 23 '23 at 21:56

0 Answers0