How can I make something expire.

Discussion in 'Plugin Development' started by VinexAx789, Oct 15, 2015.

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

    VinexAx789

    How can I make something expire in java. I want to make my kits that I've coded in my minigame expire monthly after the player has purchased it. Any help?
     
  2. @VinexAx789
    If you have some kind of player base, save the time until you want it to expire (milliseconds, System.currentTimeMillis() + (some time in milliseconds)). Later, check if the current time is later than the saved time: If it is, allow the use of the kit, if it's not, deny.
     
  3. Offline

    khave

    I've done this before. What I did was save a date to each player file I made. I then sometimes (for example on startup) check the dates and compare them to the current date. If it's older than 30 days then delete it.
     
  4. Offline

    VinexAx789

    Ok well, will this work if the server is offline and if the player is off the server?


    @khave @megamichiel
     
  5. Offline

    khave

    @VinexAx789 if you're looping through all the files with players, then yea.
     
  6. Offline

    Scimiguy

    @VinexAx789
    Why would it matter if they're offline though?
    Just check when they login or interact with them, if it's past the date then remove them
     
  7. Offline

    VinexAx789

    It matters because, wouldn't the time stop if the server is offline or they are offline? Ok khave I gotcha.

    @Scimiguy @khave
     
  8. Offline

    khave

    @VinexAx789 Don't use the thing Megamichel said. Use the date instead. His is viable if you plan on deleting it a few minutes or seconds later, but if you want to do it over days/months etc. you'll need to use something like dates.
     
  9. Offline

    Xerox262

    You can convert the Long milliseconds into a date :p. Hi @VinexAx789 :p
     
  10. @khave
    Why would milliseconds not be reliable? It can be used for years of time because milliseconds are unchanged. With a Date it could simply be saved into a string, with milliseconds you can save it in a long.
     
  11. Offline

    Xerox262

    Constructor for java.util.Date is Date(Long milliseconds); You could store the Long like you said then turn it into a Date, best of both worlds :D
     
    VinexAx789 likes this.
  12. @Xerox262
    Ik how Date works, silly .-.. I even know it's deprecated and that it's recommended to use the Calendar class instead. I was just asking @khave why saving milliseconds would be a bad thing.
     
  13. Offline

    Xerox262

    It's not deprecated? and I wasn't saying it was bad, I said it was the best to save it as a long and convert to a date to show someone when they expire. And I was more explaining it for Vine :p
     
  14. @Xerox262
    Prior to JDK 1.1, the class Date had two additional functions. It allowed the interpretation of dates as year, month, day, hour, minute, and second values. It also allowed the formatting and parsing of date strings. Unfortunately, the API for these functions was not amenable to internationalization. As of JDK 1.1, the Calendar class should be used to convert between dates and time fields and the DateFormat class should be used to format and parse date strings. The corresponding methods in Date are deprecated.

    I'm not against your opinion, just making some stuff clear
     
  15. Offline

    VinexAx789

Thread Status:
Not open for further replies.

Share This Page