Coding a Chat plugin

Discussion in 'Plugin Development' started by AgentTripleC, Jan 12, 2013.

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

    AgentTripleC

    So, I see a lot of server where they have word blocking, caps and spamming control plugins.
    For example, a player says all caps, instead, the message turns out all lower case unless their is only 1 or 2 caps.
    EXAMPLE: Player tries to say "CAPS LOCK" and it comes out "caps lock"

    A player tries to say"hahahahaha" when it actually comes out as "haha".

    I need help on how you would start coding this kind of plugin. I'm trying to learn how to code custom plugins for my server.
     
  2. Offline

    LaxWasHere

  3. Offline

    zeeveener

    tremor - Maybe the author can help explain better than we could to OP
     
  4. Offline

    tremor

    Well with PwnFilter it was my first attempt at JAVA let alone making a Bukkit plugin so I was very noobish. What I did was I took a plugin which I had used on my server, that had gone inactive. That was RegexFilter. I learned the methods of how it listened to chat (at the time it was PlayerChatEvent and is now the ASyncPlayerChatEvent).

    The basis of these filters is usually some sort of Regular Expressions comparison or RegEx. I suggest the OP learn about RegEx as best they can... and that will explain how these chat plugins that match and alter things players say, work.

    As for my own plugin I'm still trying to figure out how to move from just chat and apply my listener to things like the emote /me command as well (and for some server owners by request private messaging). I assume for those it's a command listener that I will have to use.
     
  5. Offline

    xize

    I guess its something like this:

    Code:
    @EventHandler
    public void chat(PlayerChatEvent e) {
          if(e.getMessage().contains("hahaha")) {
              e.setMessage(e.getMessage().replace("hahaha", "haha");
        }
    }
    
    just make a array of filtering words like ArrayList<String, String> then make a foreach loop and add the args inside the contains and replace the args with the second string, maybe its just a idea:p
    edit
    also check to this:
    Code:
    e.setMessage(.e.getMessage().toLowercase().replace("hahaha", "haha");
    
    if I'm right it would convert the message to lowercase.
     
  6. Offline

    gomeow

    That wouldn't shorten it down completely, say they spam hahahahaha it would still be long
     
  7. Offline

    xize

    ah I see what your meaning, I gonna do some tests:p
     
  8. Offline

    teti100teti

    I would still think it would change it if you would just
    Code:
    @EventHandler
    public void chat(PlayerChatEvent e) {
          if(e.getMessage().contains("HA")) {
              e.setMessage(e.getMessage().replace("ha", "haha");
        }
    }
    So it would just replace anything that has HA in it i guess? so HAHAHA would be hahaha
     
  9. Offline

    xize

    nah that should double each "ha" to "haha" so if some player typs haha it gets replaced by "hahahaha", also it's not that handy because its still bypassable with spaces though, I whas thinking about adding them as a String[] args like the regex way in php code where you can filter arrays through the regex, but sadly enough I'm not good enough to find a way like strpos or preg_replace for the java way:p
     
  10. Offline

    DJSanderrr

    For (string str = "hahahaha"; str.contains("hahaha"); str.replace("hahaha", "haha"){

    }
     
  11. Offline

    Sagacious_Zed Bukkit Docs

    Just a reminder, it is not safe to check permissions in an asynchronous thread.
     
  12. Offline

    microgeek

    Erm, use a Regex?
    s.repalceAll(regex, "ha");
     
  13. Offline

    teti100teti

    oh k
     
Thread Status:
Not open for further replies.

Share This Page