add custom command: uptime to the defaults
This commit is contained in:
parent
172305482d
commit
f6b48085b0
|
@ -5,7 +5,6 @@ import matterlink.bridge.command.BridgeCommandRegistry
|
|||
import matterlink.bridge.command.IMinecraftCommandSender
|
||||
import matterlink.config.cfg
|
||||
import matterlink.update.UpdateChecker
|
||||
import java.time.Duration
|
||||
|
||||
lateinit var instance: IMatterLink
|
||||
|
||||
|
@ -52,20 +51,29 @@ abstract class IMatterLink {
|
|||
*/
|
||||
var serverStartTime: Long = 0
|
||||
|
||||
fun getUptimeInSeconds(): Int {
|
||||
return ((System.currentTimeMillis() - serverStartTime) / 1000).toInt()
|
||||
fun getUptimeInSeconds(): Long {
|
||||
return (System.currentTimeMillis() - serverStartTime) / 1000
|
||||
}
|
||||
|
||||
fun getUptimeAsString(): String {
|
||||
val duration = Duration.ofSeconds((System.currentTimeMillis() - serverStartTime) / 1000)
|
||||
return duration.toString()
|
||||
// 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"
|
||||
val total = this.getUptimeInSeconds()
|
||||
val s = total % 60
|
||||
val m = (total / 60) % 60
|
||||
val h = (total / 3600) % 24
|
||||
val d = total / 86400
|
||||
|
||||
fun timeFormat(unit: Long, name: String) = when {
|
||||
unit > 1L -> "$unit ${name}s "
|
||||
unit == 1L -> "$unit $name "
|
||||
else -> ""
|
||||
}
|
||||
|
||||
var result = ""
|
||||
result += timeFormat(d, "Day")
|
||||
result += timeFormat(h, "Hour")
|
||||
result += timeFormat(m, "Minute")
|
||||
result += timeFormat(s, "Second")
|
||||
return result
|
||||
}
|
||||
|
||||
fun registerBridgeCommands() {
|
||||
|
|
|
@ -49,9 +49,9 @@ data class CustomCommand(
|
|||
}
|
||||
|
||||
fun getReplacements(user: String, args: String): Map<String, () -> String> = mapOf(
|
||||
"{UPTIME}" to instance::getUptimeAsString,
|
||||
"{USER}" to { user },
|
||||
"{ARGS}" to { args }
|
||||
"{uptime}" to instance::getUptimeAsString,
|
||||
"{users}" to { user },
|
||||
"{args}" to { args }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,14 @@ object CommandConfig {
|
|||
execute = "seed",
|
||||
help = "Print server world seed",
|
||||
allowArgs = false
|
||||
),
|
||||
CustomCommand(
|
||||
alias = "uptime",
|
||||
type = CommandType.PASSTHROUGH,
|
||||
permLevel = 1,
|
||||
response = "{uptime}",
|
||||
help = "Print server world seed",
|
||||
allowArgs = false
|
||||
)
|
||||
)
|
||||
var commands: Array<CustomCommand> = default
|
||||
|
|
Loading…
Reference in New Issue