Anti-spam HELP

Discussion in 'Plugin Development' started by NickDEV, Sep 3, 2015.

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

    NickDEV

    How can I block that if a player writes:
    example: BLABLA and if his next message is the same to the first message it gets cancelled.

    I think I will use PlayerChatEvent for this action.
     
    Last edited: Sep 3, 2015
  2. Offline

    AcePilot10

    Yes, use PlayerChatEvent and use event.setMessage(new message);.
     
  3. Offline

    teej107

    @NickDEV Save each message that a players says and then compare later on to what they just said.
     
  4. Offline

    rbrick

  5. Offline

    AdobeGFX

    • Create a HashMap<Player, String>
    • Check if the hashmap is null, and does not compare to the latest message from the player
    • Then if it's null, and don't match then put the player, and the event.getMessage in the hashmap
    • else if it's not null, and compares to the latest message, then cancel
    You can remove the message from the hashmap using PlayerQuitEvent, because you don't want it to be there the next time the player connects.

    Also if you want it a bit more advanced, then you can use schedulers to remove the message after 3 seconds. That way the player would have to wait 3 seconds before typing the same message.. You can read more about schedulers here!

    also if you want, make a counter for how many times the player typed the same message, and Just add the message to the hashmap after 3 times
     
    Last edited: Sep 5, 2015
  6. Offline

    mine-care

    @AdobeGFX I assume you are not talking for a long term stored hashmap.
    If you do, you need to remind the op to handle the disconnects of the players apropriately.
     
    AdobeGFX likes this.
  7. Offline

    AdobeGFX

    @mine-care You are absolutely right! i forgot that part..
    I edited my first reply!
    @NickDEV
     
    mine-care likes this.
  8. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page