1.16.x Checking Last Login Event on Certain Day

Discussion in 'Spigot Plugin Development' started by XXDiamondPlayz, Oct 18, 2020 at 4:19 PM.

  1. Hi, I've been working on a plugin and I require to check the last time a player has logged in every month. So if a player has logged in within the month, then nothing happens. But if a player *hasn't* logged in within the month, a command is executed. I was going to use p.getLastJoin();, however I have a Database that stores the Players to check. So basically,

    if (Calendar.DAY_OF_MONTH == 1) {
    go thru database and check p.getLastJoin() and if > 30 execute this
    }

    what I needed to know is if there's some sort of listener that checks the Day of Month or something?
     
  2. You can use Player#getLastPlayed() (Returns the last login date in millis) and System.currentTimeMillis()
     
  3. Yeah, but is there like a Listener that only executes on a certain day? Because I don't want to check every second or something, I just want to check once a month.
     
  4. No, you need to check the current day by yourself. You still could schedule a task that runs every 1,728,000 ticks (result of 60 * 60 * 24 * 20 equals 1 day), check if the day is the first, and if so, do the stuff you need
     
  5. Yeah that would work, but what happens if the server restarts or something
     
  6. You start the scheduler while the plugin is being loaded, runs the first time after 1 ticks and then once every 60 * 60 * 24 * 20 ticks