Dalay 24h for Command

Discussion in 'Plugin Development' started by Pigi0204, Jul 29, 2017.

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

    Pigi0204

    How do I do that a player can run a command only once every 24h???
     
  2. Offline

    Zombie_Striker

    @Pigi0204
    1. Store the time, in milliseconds, when the code be triggered. Figure this out using 1000*seconds+60,000*minutes+360,000*hours.
    2. Create a new BukkitRunnable. Run this every minute (20*60 ticks)
    3. Inside the runnable, see if the current time%86400000 (i.e, one day) is within 1 minute of the time from #1. If so, run the command.
     
  3. Offline

    Pigi0204

    uhm.. ok have you got a guide for this because my java is really bad? Thanks for reply
     
  4. Offline

    Caderape2

    @Pigi0204
    You might use file instead, the server can reboot.
    You can use 'system.CurrentTimeMillis() / 1000' for get the actual second.
    When the player perform the command, load the file and check if he's in. And if yes, substract the actual time by the time stored, and see if it's over 24H.
    Once you're done, add him back to the file with the new time.
    You can set the player uuid as key with the time as value.
     
  5. Offline

    Pigi0204

    uhm.. ok thanks try this
     
  6. Offline

    DoggyCode™

    You shouldn't constantly read/write to the file, it'll eventually get heavy. Store cache in memory and save/load when neccecary.
     
Thread Status:
Not open for further replies.

Share This Page