Put this code on a timer

Discussion in 'Plugin Development' started by BrushPainter, Oct 12, 2014.

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


    I tried putting this code on a scheduled delayed timer but I get tons of errors which I can't happen to solve when I do it, but what I'm trying to achieve is that once per day each player can click on a trapped chest and get one of the items in the array. Here's my code:
    1. -snip-
  2. Offline


    Save the time the player clicked the trapped chest in a config with System.currentTimeMillis();. Check if the config contains the players name. If it doesn't that means they haven't clicked the trapped chest. If they have, compare the saved time and the current time to see if it's been a day. If it has been a day, allow them to open the chest and update the time. If it hasn't been a day, cancel the event and tell them that they have to wait longer.
  3. Offline


    Or you could save yourself some math by using Dates instead of milliseconds.
  4. Offline


    Huh, I've never used dates for saving times. Is it easier to incorporate instead of using milliseconds?
  5. Offline


    It gives you day, month, year, second, minute, etc. It saves you having to work with milliseconds.
  6. Offline


    I prefer working with MS, you can use System.currentTimeMillis() and just add milliseconds.

    1 day in milliseconds can be done as
    1 * 24 * 60 * 60 * 1000
Thread Status:
Not open for further replies.

Share This Page