Solved Detect time between messages

Discussion in 'Plugin Development' started by Asgernohns, Apr 12, 2014.

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

    Asgernohns

    hello

    I want to check how long time since the player wrote the last message in chat. Is it possible?
     
  2. Offline

    Derpiee

    You can store when they type using System.currentTimeMillis and then just subtract the two and get the difference.
     
  3. Offline

    Asgernohns

    Derpiee Please make an example of that :/ I don't quite understand it
     
  4. Offline

    zDylann

    Asgernohns
    Code:java
    1. //When they use a command:
    2. long firstCommand = System.currentTimeMillis();
    3. //You need to store this somehwere, IE: HashMap/Map
    4.  
    5. //When they try to use a command again run a check from the time you saved and the current time. 1000 = 1 second.
    6. //In this case we are using 5 seconds so the player can't use a command until it has been 5 seconds since the last commmand.
    7. if(System.currentTimeMillis() - firstCommand > 5000){
    8. //Let them do command
    9. } else {
    10. //Hasn't been 5 seconds so they can't use a command.
    11. }
     
  5. Offline

    Asgernohns

    zDylann ohh.. Nice. Thanks for the help :)
     
Thread Status:
Not open for further replies.

Share This Page