Toggleable Word Censor

Results 1 to 14 of 14
  1. #1
    Enthusiast Alicia is offline
    MemberRank
    Aug 2009 Join Date
    Peekaboo.Location
    35Posts

    Toggleable Word Censor

    Excessive swearing was becoming a problem in my server, so...

    In Maplecharacter.java

    After this line

    Code:
    private boolean hidden;
    Add this

    Code:
    private boolean censor;
    After this

    Code:
    setPosition(new Point(0, 0));
    Add this

    Code:
    censor = true;
    [Can change this to false if you just want to censor a temporarily, note: Censor will turn off after you chage channels if you change it to false]


    Add this

    Code:
    public boolean getCensor() {
            return censor;
        }
        
    public void setCensor(boolean setTo) {
            censor = setTo;
        }

    After

    Code:
        public void setMap(int PmapId) {
            this.mapid = PmapId;
        }
    In GeneralChathandler

    Add

    Code:
            if(c.getPlayer().getCensor()) {
                String[] badWords = {"fuck", "cunt", "fag", "nigger"};
                    if (c.getPlayer().getCensor()) {
                        for (int i = 0; i < 3; i++) {
                            if (text.toLowerCase().contains(badWords[i])) {
                                text = "I have a potty mouth.";
                            }
                        }
                    }  
            }
    
    
    
            }
    After

    Code:
        public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
            String text = slea.readMapleAsciiString();
    And Finally in

    GMCommands.java [commandprocessor.java, depends which source you're using]


    Add
    Code:
            } else if (splitted[0].equals("!censoron"))
                {
                    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                    victim.setCensor(false);
                    mc.dropMessage(victim.getName() + " is now censored.");
                    victim.dropMessage("You are now censored.");
    
    
    
    
            } else if (splitted[0].equals("!censoroff")) {
                    MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
                    victim.setCensor(true);
                    mc.dropMessage("You have censored " + victim.getName());
                    mc.dropMessage(victim.getName() + " is no longer censored.");
                    victim.dropMessage("You are no longer censored.");
    If anyone could help me make this case insensitive, it would be very helpful.
    Last edited by Alicia; 03-01-10 at 01:34 AM.


  2. #2
    Banned SpottedCow is offline
    BannedRank
    Nov 2009 Join Date
    wtfdddddLocation
    208Posts

    Re: Toggleable Word Censor

    loel naise rls person i don't know xdd, however the generalchathandler part can be shortened.
    Last edited by SpottedCow; 02-01-10 at 01:46 AM.

  3. #3
    Enthusiast Alicia is offline
    MemberRank
    Aug 2009 Join Date
    Peekaboo.Location
    35Posts

    Re: Toggleable Word Censor

    Thanks Moogra!

    GeneralchatHandler changed..

  4. #4
    Banned SpottedCow is offline
    BannedRank
    Nov 2009 Join Date
    wtfdddddLocation
    208Posts

    Re: Toggleable Word Censor

    Quote Originally Posted by Moogra View Post
    try
    if (text.toLowerCase().contains("INSERTWORDSHERELOL") {
    text = "I FAIL";
    }
    cool you got it moogra xdd

  5. #5
    Alpha Member watzmename is offline
    MemberRank
    Aug 2008 Join Date
    2,835Posts

    Re: Toggleable Word Censor

    Just use ||
    PHP Code:
            if(c.getPlayer().getCensor()) {
                if (
    text.toLowerCase().contains("fuck") || text.toLowerCase().contains("cunt") || text.toLowerCase().contains("fag") || text.toLowerCase().contains("nigger")) {
                    
    text "I have a potty mouth.";
                }
            } 
    or just use arrays.
    PHP Code:
    String[] badWords = {"fuck""cunt""fag""nigger"};
            if (
    c.getPlayer().getCensor()) {
                for (
    int i 0badWords.length(); i++) {
                    if (
    text.toLowerCase().contains(badWords[i])) {
                        
    text "I have a potty mouth.";
                    }
                }
            } 

  6. #6
    Infraction Banned rice is offline
    MemberRank
    Nov 2009 Join Date
    2,905Posts

    Re: Toggleable Word Censor

    I figure this could be done with a string.contains thing in the gch.
    Also, shouldn't there be an Ignore Case thing?

    Anyways, good job. I <3 the potty mouth thing!

  7. #7
    Valued Member khcastro is offline
    MemberRank
    Mar 2009 Join Date
    112Posts

    Re: Toggleable Word Censor

    quick quesion ~~ can you use the command like !censoron <charname> ?

    n00b = me

  8. #8
    Enthusiast Alicia is offline
    MemberRank
    Aug 2009 Join Date
    Peekaboo.Location
    35Posts

    Re: Toggleable Word Censor

    The !censoron/off are supposed to be singlepeople only.

    I might make a !censorall command or something.

  9. #9
    Valued Member khcastro is offline
    MemberRank
    Mar 2009 Join Date
    112Posts

    Re: Toggleable Word Censor

    Quote Originally Posted by Alicia View Post
    The !censoron/off are supposed to be singlepeople only.

    I might make a !censorall command or something.
    oh sorry for being newb but i thought it censord the whole word o-o
    yes i did not look but now that i do i see that

    a censorall command would be nice :D

    i would do it if i knew how -.-

  10. #10
    Enthusiast Alicia is offline
    MemberRank
    Aug 2009 Join Date
    Peekaboo.Location
    35Posts

    Re: Toggleable Word Censor

    Here's the censor on /off for the whole world

    Censor everyone that is online:

    Code:
    } else if (splitted[0].equals("!censorworld")) {
        for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {         
            mch.setCensor(true);
            mc.dropMessage("You have censored the world.");
            mch.dropMessage("You have been censored.");
    }
    Uncensor everyone that's online

    Code:
    } else if (splitted[0].equals("!uncensorworld")) {
        for (MapleCharacter mch : cserv.getPlayerStorage().getAllCharacters()) {
            mch.setCensor(false);
            mc.dropMessage("You have uncensored the world.");
            mch.dropMessage("You are no longed censored.")
        }
    }
    Note : If "censor = true;" in Maplecharacter.java, then once someone changes channels or relogs, they will be censored again. If the censor was false, they will be censored again once they change channels or relog.
    Last edited by Alicia; 04-01-10 at 05:56 AM.

  11. #11
    Account Upgraded | Title Enabled! xJvlaplex is offline
    MemberRank
    Mar 2009 Join Date
    478Posts

    Re: Toggleable Word Censor

    even better:

    Code:
    String censor(String text) {
    StringBuilder sb = new StringBuilder(text);
    Pattern p = Pattern.compile("f.*u.*c.*k");
    Matcher m = p.matcher();
    while (m.find()) {
        char c[] = new char[m.end() - m.start()];
        Arrays.fill(c, '*');
        sb.replace(m.start(), m.end(), String.valueOf(c));
    }
    return sb.toString();
    }
    this finds even "fuuuck", "fck", "fuccck", etc, and it also replaces it with stars

  12. #12
    Alpha Member Hennessy`' is offline
    MemberRank
    Dec 2009 Join Date
    in a CaveLocation
    2,298Posts

    Re: Toggleable Word Censor

    nice
    Posted via Mobile Device

  13. #13
    Valued Member khcastro is offline
    MemberRank
    Mar 2009 Join Date
    112Posts

    Re: Toggleable Word Censor

    is mch.dropMessage supposed to be mc.dropMessage >_>

  14. #14
    Enthusiast Alicia is offline
    MemberRank
    Aug 2009 Join Date
    Peekaboo.Location
    35Posts

    Re: Toggleable Word Censor

    PHP Code:
        for (MapleCharacter mch cserv.getPlayerStorage().getAllCharacters()) { 
    mch = All the players in the game.

    so mch.dropMessage sends a message to everyone in the game.



Advertisement