Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Censoring

Code
@SuppressWarnings("deprecation")
public class PlayerListener implements Listener {

    private AdminPlugin plugin;

    public PlayerListener(AdminPlugin pl) {
        plugin = pl;
    }

    String[] disapprovedWords = { "fag", "shit", "bitch", "cock", "fuck",
            "cunt", "whore", "penis", "vagina", "nice person", "nigga", "faggot" };
    String replacement = "*****";

    @EventHandler
    public void onPlayerChat(PlayerChatEvent event) {
        String sentMessage = event.getMessage();
        String censoredString = null;
        if (plugin.isCensored()) {

            for (String s : disapprovedWords) {

                censoredString = censoredString.replaceAll(s, replacement);
            }
            event.setMessage(censoredString);
        }
        if (plugin.getHiddenPlayers().contains(event.getPlayer())) {
            event.setCancelled(true);
        }
    }
}

I'm trying to censor the words in the disapprovedWords array but I can't remember how to make it ignore the case.
I tried using toLowerCase() but then the whole message is lowercase, which is pretty annoying.

Help? :/
Use some simple regex with the Matcher and Pattern classes.
What about the Java.lang.String.equalsIgnoreCase(String str) function?

Would that work

Knowledge is power and the only source of knowledge is experience.



Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by OdusApr 21, 2015 03:59 AM 20 1,650 Apr 21, 2015 03:59 AM
Last Post: Stаlkеr