Thread: [PI] Server UpTime

Results 1 to 7 of 7
  1. #1 [PI] Server UpTime 
    Registered Member
    Join Date
    Jul 2012
    Posts
    193
    Thanks given
    66
    Thanks received
    11
    Rep Power
    12
    Basically What This Does Is Just Tell You How Long The Server Has Been Up For

    Spoiler for V1:

    Server.java


    add
    Code:
    public static int uptime;
    then in
    Code:
    public static void main(java.lang.String args[])
    above
    Code:
    engineTimer.reset();
    add
    Code:
    uptime++;
    then add
    Code:
    public static String getUpTime(){
    long DAY = (uptime / 86400);
    long HR = (uptime / 3600) - (DAY * 24);
    long MIN = (uptime / 60) - (DAY * 1440) - (HR * 60);
    return ("Day: " + DAY + " Hr: " + HR + " Min: " + MIN + "");
    }
    Commands.java add
    Code:
    if (playerCommand.startsWith("uptime")) {
    c.sendMessage("Uptime: " + Server.getUpTime());
    }


    Server.java

    add
    Code:
    public static int uptime;
    public static long recordLogin = 0;
    then in
    Code:
    public static void main(java.lang.String args[])
    above
    Code:
    engineTimer.reset();
    add
    Code:
    uptime++;
    then add
    Code:
    public static long appendPlayTime(){
    return (System.currentTimeMillis() - recordLogin) + uptime;
    }
    
    public static long totalPlaytime(){
    return (appendPlayTime() / 1000);
    }
    
    public static String getUpTime(){
    long DAY = (totalPlaytime() / 86400);
    long HR = (totalPlaytime() / 3600) - (DAY * 24);
    long MIN = (totalPlaytime() / 60) - (DAY * 1440) - (HR * 60);
    long SEC = totalPlaytime() - (DAY * 86400) - (HR * 3600) - (MIN * 60);
    return ("Day: " + DAY + " Hr: " + HR + " Min: " + MIN + " Sec: " + SEC);
    }
    Commands.java add
    Code:
    if (playerCommand.startsWith("uptime")) {
    c.sendMessage("Uptime: " + Server.getUpTime());
    }
    If I Forgot Any Methods Tell Me And Ill Add Them

    Credits
    Me
    Slawth Baws
    Reply With Quote  
     

  2. #2  
    -Founder Off Returnofpk-


    Join Date
    Oct 2012
    Age
    28
    Posts
    655
    Thanks given
    97
    Thanks received
    211
    Rep Power
    303
    Quote Originally Posted by DarkAidz View Post
    Basically What This Does Is Just Tell You How Long The Server Has Been Up For

    Server.java

    add
    Code:
    public static int uptime;
    then in
    Code:
    public static void main(java.lang.String args[])
    above
    Code:
    engineTimer.reset();
    add
    Code:
    uptime++;
    then add
    Code:
    public static String getUpTime(){
    long DAY = (uptime / 86400);
    long HR = (uptime / 3600) - (DAY * 24);
    long MIN = (uptime / 60) - (DAY * 1440) - (HR * 60);
    return ("Days: " + DAY + " Hours: " + HR + " Minutes: " + MIN + "");
    }
    Commands.java add
    Code:
    if (playerCommand.startsWith("uptime")) {
    c.sendMessage("Uptime: " + Server.getUpTime());
    }
    thats only makes the server lagg

    and have being relesed many times
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member risgaard's Avatar
    Join Date
    Jul 2013
    Posts
    648
    Thanks given
    12
    Thanks received
    16
    Rep Power
    13
    how will this make lagg if i can ask ? i am still learning
    my grammar. aint pefect. but atleast you understand me

    did i help you ?
    i am not asking for rep but you can atleast say thanks
    Reply With Quote  
     

  4. #4  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Haha it definitely does not cause lag but this isn't the best way to do it. Upon startup you should set some variables like day, hour, minute, second to the current time. When you want to check the time online, related the current time to that of the time it started. Im sure some people might use this so good job.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Dec 2013
    Posts
    43
    Thanks given
    2
    Thanks received
    16
    Rep Power
    20
    Quote Originally Posted by sheepmonger View Post
    thats only makes the server lagg

    and have being relesed many times

    Is your head ok?
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Registered Member
    Join Date
    Jan 2014
    Posts
    13
    Thanks given
    3
    Thanks received
    13
    Rep Power
    24
    This will work but it will be been to calculate using the real system system.

    Look into System.currentTimeMillis();
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Jul 2012
    Posts
    193
    Thanks given
    66
    Thanks received
    11
    Rep Power
    12
    Quote Originally Posted by Jason View Post
    Haha it definitely does not cause lag but this isn't the best way to do it. Upon startup you should set some variables like day, hour, minute, second to the current time. When you want to check the time online, related the current time to that of the time it started. Im sure some people might use this so good job.
    yeah, i updated it so it does it like that, ill update this snippet with the newer one soon
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 40
    Last Post: 05-16-2010, 02:18 AM
  2. How to add server uptime in quest list
    By ragean in forum Requests
    Replies: 2
    Last Post: 05-15-2009, 01:49 PM
  3. Quest Tab - Server Uptime/Players Online
    By Netgear137 in forum Tutorials
    Replies: 29
    Last Post: 11-08-2008, 12:30 PM
  4. Server Uptime/Players Online
    By kojomba in forum Help
    Replies: 0
    Last Post: 10-25-2008, 09:12 AM
  5. Server -- uptime
    By bluurr in forum Tutorials
    Replies: 31
    Last Post: 09-07-2008, 05:29 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •