Coutdown timer api?

Discussion in 'Spigot Plugin Development' started by Flintbeker, Feb 20, 2016.

  1. Hello, i have a KitPVP plugin but now i want that you can use the normal kit every 30 seconds, the daily kit every 24 hours the hourly kit evrey 60 minutes, the weckly kit every 7days. I know i can make that with scheduler but i dont realy know how to make that for every player and difrent times. Do you know a API plugin or a API class that i can use?
  2. You can just use a HashMap with the Player as the Key and the currentTimeMillis as value.
    Than you can check if the currentTimeMillis when the player tries to select the kit again are higher than the old time millis + <cooldown time>.

    Thats the most simple way.
    • Agree Agree x 1
  3. ok, and how do i use CurrentTimeMillis? i cant realy figure out what that means ^^
  4. System.currentTimeMillis() = returns the time in milliseconds.
  5. System.currentTimeMillis();
    this returns your curent system time
  6. ok, so i have to safe the name and the System.currentTimeMillis(); and wehn a player tries a kit i check it? but how do i make the daylie and weekly kit?
  7. You'll have to store the current time via flatfile or a database. If you just store it in a map all the data will be deleted on a server restart.

    You need to do
    Code (Text):
    (System.currentTimeMillis() - initial) >= elapsed
  8. i know but how do i make something with thes milliseconds? xD
  9. 1000 millisecond = 1 second
    So If let's say a person has a kit regen every 5secs then you would get the time from the hashmap and see if:
    System.currentTimeMillis() - [time in hashmap] >= 5000
  10. Is there any way to easily convert to MS? Like Time#toMiliSeconds(Seconds)? Instead of seconds x 1000? If not. That's pretty stupid. But a LIB that would do that is a million dollar idea ;)
  11. When the player executes the kit command, you'll need to do add them to a HashMap and then
    TimeUnit.SECONDS.toMillis(long) ;)
  12. Why would you need a whole library to do a simple math problem?
  13. Well it obviously wouldn't only be one method. There could be other ones, changing hours to ms, minutes to days, stuff like that. And could simplify stuff like tempbans.
  14. kevin.


    That's basically just simple units conversions....
    • Agree Agree x 1
  15. Yes, I do understand. But when creating a tempban for example, you don't want make loads of equations and want to keep it simple especially if doing like a word time for example:
    /tempban <Player> 2w 5d 3h 9m 10s
  16. ok, that means wehn i would that a player can take a Kit very 7 Days i have to look if the time is = 6,048e+8?
  17. wehn i try to save it to mysql it says
    Code (Text):
    [08:27:29 WARN]: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Out of range value for column 'Normal' at row 1
  18. @Flintbeker what does your table look like (a CREATE TABLE statement would be useful), and what are you trying to insert/update.
  19. Code (Text):
            mysql.connect.Update("CREATE TABLE IF NOT EXISTS kits (UUID VARCHAR(50), Normal INTEGER)");
  20. @Flintbeker normal should be a BIGINT (which is a long). Also, uuids will never have 50 characters, they're always 36 characters.