Track how many times a player talkes?

Discussion in 'Plugin Development' started by masterofsixpack, May 9, 2014.

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

    masterofsixpack

    Hello,

    With the PlayerChatEvent, how can I get the # of messages sent by a player? For Ex. When a player sends 5 messages, then a player types another message after, it will give them an error, "You have to wait <TIME>." Basically a clean chat type of plugin.
     
  2. Offline

    Bobit

    A player can only send one message without pressing enter, and enter should call the playerChatEvent, right?
     
  3. Offline

    masterofsixpack

    The enter will call the PlayerChatEvent.
     
  4. Offline

    Bobit

    Yeah...so there's no way one playerChatEvent can produce more than one message.
    Or are you saying stop them if they've typed 5 messages recently? If so, it'd be a simple matter of increasing an integer and scheduling x seconds to decrease the integer, cancelling the event if the integer is large enough.
     
  5. Offline

    lukewizzy

    masterofsixpack

    Add them to a hashmap with the key as a string (player name) & the value as an int (times they've talked) and every time AsyncPlayerChatEvent is called, check which player it is, remove them from the hashmap and re-add them with the number one higher
     
  6. Offline

    masterofsixpack

    Im new to this. Could you tell me how I would do this?
     
  7. Offline

    Konkz

    www.google.com
     
    AoH_Ruthless likes this.
  8. Offline

    AoH_Ruthless

    masterofsixpack
    Well to start, you should pickup a book or learn online how to code in Java. Then, when you get to the part that discusses HashMaps, come back here. Your life will be about 5000x easier if you learn Java before trying to work with Bukkit.
     
    Konkz likes this.
  9. Offline

    Konkz

    From my previous reply I noticed I was a bit, erm... blunt

    Google things such as Hashmaps Java, Adding to a hashmap etc.

    Hint, you'd do
    HashMap<String, Integer> - this is old method. Not sure if HashMap<UUID,Integer> would work, I'm
    tired and did not try to even move onto the UUID's yet.

    Then you'd just add one to the integer every time they talk, if the integer equals 5 you send them a message
    and remove their message by cancelling it. Every 30 seconds you reset the hashmap from their name, done.
     
  10. Offline

    masterofsixpack

    How can I add one to the Integer in HashMap?
     
  11. Offline

    Konkz

    I shall quote the most useful reply in this thread for you, seeing you may of missed it.

     
  12. Offline

    Bobit

    Make a new HashMap<UUID,Integer>, here I'll call it "map".Hashmaps work like this:
    map.put(UUID, x)
    map.get(UUID)==x
    map.put(UUID, y)
    map.get(UUID) != x
     
Thread Status:
Not open for further replies.

Share This Page