HELP!! With my anti-swearing plugin

Discussion in 'Plugin Development' started by pixelated_me, Dec 14, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    pixelated_me

    Hey, im developing an anti swearing plugin and i have a problem,

    Code:
    if(message.contains("f***")){
                p.sendMessage(RED + "[Server] " + GREEN + p.getName() + WHITE + " DO NOT SWEAR!!");
                server.broadcastMessage(RED + "[Server] " + GREEN + p.getName() + WHITE + " Has said a bad word!");
                chat.setCancelled(true);
            }
    I have imported everything I need to, however I need the plugin to block words containing "f***" and for the plugin to block all possibilities e.g. "F***" or "F.*.*.*" or "f**K."

    how can i do this? is there a way? or should I copy and paste this loads of times?

    I am sorry about this, i am a newbie at making plugins, help would be much appreciated. thank you - Scott :)
     
  2. Offline

    Father Of Time

    NOTE: This post contains profanity!

    Funny enough I just started making one of these a few days ago because my eight year old nephew plays on my All out War server.

    The conclusion I came to was this... Take the string and remove ALL none letter characters including spaces and then set it to lowercase, what this will do is turn this:

    to

    Then simply do a String.Contains(“fuck”) to look for the curse words. When searching for sub strings within a string you don't need to worry about the spaces, because the above statement would flag.

    Yes some misspelled words may get through, but I constructed mine so that I can use the following command:


    To add additional words to the filter, so even if I miss one when hard coding I can simply add new ones on the fly as they slip past the system.

    I hope this helps, Good luck with your project!
     
    pixelated_me likes this.
  3. Offline

    halley

    Way back in 1996 or so, I had to write such a filter for an early MMORPG. Personally, I think this kind of filtering should be done on the prude's client, not on the community server, but Minecraft is not well organized for this.

    In that game, I made a two-stage regular expression engine. Given a bad word, it used a series of regular expressions to make another regular expression. Then these are all collected for a list of bad words. This was able to handle cursing combination tricks like $#!t fu[< 4ss|-|0L3 bbaassttaarrdd etc. It also understood that some things like massage are not bad words.

    But to be honest-- it's just better for everyone on a server if they (1) monitor things personally, both parents and moderators, (2) develop a culture that doesn't accept such things, rather than a technology. Technology to censor is just bad news for everyone.
     
  4. Offline

    bergerkiller

    Reminds me of a game where 'oo' and 'thi' were 'bad' words...lol
    Was one complete dictionary to learn to get around it. (Do you need help with somethng?)
     
  5. Offline

    pixelated_me



    Thank you so much, i have played around a bit but i'm still not 100% sure what changes need to be made.

    Code:
    public class ServerChatPlayerListener extends PlayerListener {
        public static StopThatSwearing plugin;
    
        public ServerChatPlayerListener(StopThatSwearing instance){
            plugin = instance;
            //shows that this is part of the plugin
        }
    
        public void onPlayerChat(PlayerChatEvent chat){
            Player p = chat.getPlayer();
            String message = chat.getMessage();
            ChatColor RED = ChatColor.RED;
            ChatColor WHITE = ChatColor.WHITE;
            ChatColor GREEN = ChatColor.GREEN;
            Server server = p.getServer();
    
            Logger log = Logger.getLogger("Minecraft");
    
            if(message.contains("fuck") ){
    
                p.sendMessage(RED + "[Server] " + GREEN + p.getName() + WHITE + " DO NOT SWEAR!!");
    
                server.broadcastMessage(RED + "[Server] " + GREEN + p.getName() + WHITE + " Has said a bad word!");
    
                chat.setCancelled(true);
            }
    
    }
        }
    
        
    this is my class file, if it is hard to explain, not to worry, thanks for your help!
     
  6. Offline

    Father Of Time

    The only change that I see immediately is this line:

    Code:
            if(message.contains("fuck") )
    String.contains is case sensitive, so if you said "Fuck":

    Code:
            if(message.contains("Fuck") )
    would catch it, where:

    Code:
            if(message.contains("fuck") )
    Would not. What I would so is squash the message variable to lower case for comparison sake:

    Code:
            String message = chat.getMessage().toLowerCase();
    outside of that I don't see anything else that needs to be revised (at a glance).

    Good luck, I hope you get this working! :D
     
  7. Offline

    pixelated_me

    THANK YOU SO MUCH! this really helped me i'm almost done with my first project! :D
     
  8. Offline

    Father Of Time

    That's fantastic, I'm happy to be of assistance. :p
     
  9. Offline

    hatstand

    This reminds me of an over-zealous admin I had, who used a filter we had to start correcting people's grammar and spelling - Issue was, the filter would filter things inside a word, so it messed up normal words as well.

    The per-client filtering could be done via a system where you opt out of filtered chat, or request to be. The plugin would intercept the chat events, send off the normal chat to the un-filtered clients, then send the filtered chat to all the filtered clients, similar to how you can put together a per-user ignore system by modifying the recipient list of the chat event.
     
    halley likes this.
  10. Offline

    halley

    I also wrote a spelling and grammar correcting web proxy -- which I worked pretty hard to ensure it didn't fuck up things in the middle of normal words. But I whole-heartedly agree, for every situation you propose a filter, that filter is not going to handle every case perfectly and it's annoying as all hell when a filter gets in your way.
     
Thread Status:
Not open for further replies.

Share This Page