implement getUptime
This commit is contained in:
parent
0b5abf8a1e
commit
74f7c9ec65
|
@ -54,7 +54,7 @@ object MatterLink : IMatterLink() {
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
fun serverStarting(event: FMLServerStartingEvent) {
|
||||||
logger.debug("Registering server commands")
|
logger.debug("Registering server commands")
|
||||||
event.registerServerCommand(CommandMatterlink())
|
event.registerServerCommand(CommandMatterlink())
|
||||||
|
serverStartTime = System.currentTimeMillis()
|
||||||
connect()
|
connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ object MatterLink : IMatterLink() {
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
fun serverStarting(event: FMLServerStartingEvent) {
|
||||||
logger.debug("Registering server commands")
|
logger.debug("Registering server commands")
|
||||||
event.registerServerCommand(CommandMatterlink())
|
event.registerServerCommand(CommandMatterlink())
|
||||||
|
serverStartTime = System.currentTimeMillis()
|
||||||
connect()
|
connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package matterlink
|
package matterlink
|
||||||
|
|
||||||
import matterlink.bridge.MessageHandler
|
|
||||||
import matterlink.bridge.command.BridgeCommandRegistry
|
import matterlink.bridge.command.BridgeCommandRegistry
|
||||||
import matterlink.bridge.command.HelpCommand
|
import matterlink.bridge.command.HelpCommand
|
||||||
import matterlink.bridge.command.PlayerListCommand
|
import matterlink.bridge.command.PlayerListCommand
|
||||||
|
@ -53,7 +52,7 @@ object MatterLink : IMatterLink() {
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
fun serverStarting(event: FMLServerStartingEvent) {
|
||||||
logger.debug("Registering server commands")
|
logger.debug("Registering server commands")
|
||||||
event.registerServerCommand(CommandMatterlink())
|
event.registerServerCommand(CommandMatterlink())
|
||||||
|
serverStartTime = System.currentTimeMillis()
|
||||||
connect()
|
connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,4 +73,5 @@ object MatterLink : IMatterLink() {
|
||||||
|
|
||||||
override fun log(level: String, formatString: String, vararg data: Any) =
|
override fun log(level: String, formatString: String, vararg data: Any) =
|
||||||
logger.log(Level.toLevel(level, Level.INFO),formatString, *data)
|
logger.log(Level.toLevel(level, Level.INFO),formatString, *data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,4 +36,21 @@ abstract class IMatterLink {
|
||||||
log("INFO", "TRACE: " + formatString.replace("\n", "\nTRACE: "), *data)
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue