Solved Check whether the time of the player was changed with Player#setPlayerTime(long, boolean)

Discussion in 'Spigot Plugin Development' started by patri9ck, Mar 8, 2020.

  1. I need to check whether the time of the player was changed with Player#setPlayerTime(long, boolean).

    How can that be done?
     
  2. To be exact, I do not care whether the time was actually changed with Player#setPlayerTime(long, boolean). I only want to check whether the player has a custom time set in general.
     
  3. I do not want to check whether the player's time is relative to the server's time so Player#isPlayerTimeRelative() is no option. Player#getPlayerTimeOffset() will return the offset to the server's time if the player's time is relative and if not, it will simply return the player's time. How can I use that?
     
  4. After taking at the source of the CraftPlayer class, I think I have a solution. This the source of Player#resetPlayerTime():
    Code (Java):
    @Override
    public void resetPlayerTime() {
        setPlayerTime(0, true);
    }
    That means, I need to check whether Player#getPlayerTime() equals 0 and whether Player#isPlayerTimeRelative() equals true.

    I mark this thread as solved.
     
    #5 patri9ck, Mar 9, 2020
    Last edited: Mar 15, 2020