TempBan Help

Discussion in 'Plugin Development' started by IcyRelic, Apr 14, 2013.

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

    IcyRelic

    im making a private ban plugin and i need a bit of help with the tempban times im going to make the command like this

    /tempban <player> <time><mon,w,d,h,min,s> <reason>

    (mon:Month, w:Week, d: day, h:Hour, min:Minute, s:Second)

    so lets say i type "/tempban IcyRelic 5d This should be a 5 day ban"

    i should be banned for 5 days with a reason "This should be a 5 day ban" i can do all this but the times i dont exactly know how to calculate anything but minutes in timestamps and when to convert or what here is how i can calculate minutes passed or left


    Code:
            //Current Time
            Date start = new Date(System.currentTimeMillis());
         
            //Time when ban ends (30 Minutes)
            Date end = new Date(System.currentTimeMillis() + 1000*60*30);
         
            //Get time left or passed
            long x = (((end.getTime() - start.getTime()) / 1000)/60);
    Now that will return 30 and thats minutes how do i know when to convert and when to not convert because as i said i want to cover months, weeks, days, hours, minutes, and seconds

    Do i have to convert everything into seconds?

    Like this?
    Code:
                    if(timeFormat.equals("month")){
                        time = ((((time*60)*60)*24)*7)*30;
                    }else if(timeFormat.equals("week")){
                        time = (((time*60)*60)*24)*7;
                    }else if(timeFormat.equals("day")){
                        time = ((time*60)*60)*24;
                    }else if(timeFormat.equals("hour")){
                        time = (time*60)*60;
                    }else if(timeFormat.equals("minute")){
                        time = time*60;
                    }else if(timeFormat.equals("second")){
                        time = time+0;
                    }else{
                        admin.sendMessage("Invalid Time Format");
                    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    SnipsRevival

    Let's use your example command of /tempban <player> 5d
    I would take the d and multiply it by 24*60*60 to give you the number of seconds in a day. Then you multiply that number by 5 to get the number of seconds in 5 days.
    Then what I would do is set the unban time as
    Code:
    (System.currentTimeMillis()/1000) + whatever number you got from the above math
    If you save that info to a file, you can then set up a login listener that will check to see
    Code:
    if(System.currentTimeMillis()/1000 >= whatever time you saved earlier) {
    //unban the player
    }
     
  3. Offline

    Qwahchees

    Very useful information, I've been meaning to create a plugin that uses timestamps.
     
Thread Status:
Not open for further replies.

Share This Page