implement getUptime

This commit is contained in:
DaMachinator 2018-02-15 08:19:34 -05:00
parent 0b5abf8a1e
commit 74f7c9ec65
4 changed files with 21 additions and 4 deletions

View File

@ -54,7 +54,7 @@ object MatterLink : IMatterLink() {
fun serverStarting(event: FMLServerStartingEvent) {
logger.debug("Registering server commands")
event.registerServerCommand(CommandMatterlink())
serverStartTime = System.currentTimeMillis()
connect()
}

View File

@ -54,7 +54,7 @@ object MatterLink : IMatterLink() {
fun serverStarting(event: FMLServerStartingEvent) {
logger.debug("Registering server commands")
event.registerServerCommand(CommandMatterlink())
serverStartTime = System.currentTimeMillis()
connect()
}

View File

@ -1,6 +1,5 @@
package matterlink
import matterlink.bridge.MessageHandler
import matterlink.bridge.command.BridgeCommandRegistry
import matterlink.bridge.command.HelpCommand
import matterlink.bridge.command.PlayerListCommand
@ -53,7 +52,7 @@ object MatterLink : IMatterLink() {
fun serverStarting(event: FMLServerStartingEvent) {
logger.debug("Registering server commands")
event.registerServerCommand(CommandMatterlink())
serverStartTime = System.currentTimeMillis()
connect()
}
@ -74,4 +73,5 @@ object MatterLink : IMatterLink() {
override fun log(level: String, formatString: String, vararg data: Any) =
logger.log(Level.toLevel(level, Level.INFO),formatString, *data)
}

View File

@ -36,4 +36,21 @@ abstract class IMatterLink {
log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data)
}
/**
* in milliseconds
*/
var serverStartTime : Long = 0
fun getUptimeInSeconds() : Int {
return ((System.currentTimeMillis() - serverStartTime) / 1000).toInt()
}
fun getUptimeAsString() : String {
val total = this.getUptimeInSeconds()
val sec = total % 60
val min = (total/60)%60
val hr = (total/3600)%24
val day = total/86400
return "${day}d${hr}hr${min}m${sec}s"
}
}