Long, System#Currentime, YML's

Discussion in 'Spigot Plugin Development' started by Inkzzz, May 8, 2015.

  1. Inkzzz

    Resource Staff

    Ok, so I'm coding a small death ban plugin, however I've ran into a simple problem, which is messing with my head. What I'm trying to do is check the YML file, and get the time from the YML file, then compare it with the current time. If the current time is greater than the time in the YML file, then it will set the area / string in the YML file to null (removing it from the YML file). However I've tried something, but it's always setting the string in the YML file to null.

    Code:
    Code (Text):
    if (ban.getData().getLong(
                    p.getUniqueId().toString() + ".Time") < System.currentTimeMillis()) {
                ban.getData().set(p.getUniqueId().toString(), null);
                ban.saveData();
                return;
            }
    YML file:

    Code (Text):
    8dd35d38-8d97-4826-9be9-e7a50bf11288:
      Time: '143112109171210800000'
    Many thanks, Inkzzz.
     
  2. What about the part wwere you save the time? Because you might be doing following

    Code (Text):

    Player is banned
       save System.currentTimeMillis() to yml file

    ----

    Player logs in at any time AFTER that
      get saved Time and check to currentTimeMillis()
     
    Because if you do it like that it will ALWAYS be true. You need to add the ammount of time you want the user to be banned to System.currentTimeMilis() before saving it to the file.
    But all of the above is pure speculations as I don't know how you ahaed about banning them
     
    #2 L33m4n123, May 8, 2015
    Last edited: May 8, 2015
  3. Inkzzz

    Resource Staff

    I do System.currenttime.... + 10 minutes in milliseconds.
     
  4. Well. Sounds for me that somewhere between saving and grabbing the value something goes wrong. Without any more code I cannot really say what the issue is. So all I can suggest is debugging it and watching the value and if the value you actually write in the file is the one you want and the value it retireves is the one you actually want