diff --git a/core/src/main/kotlin/matterlink/IMatterLink.kt b/core/src/main/kotlin/matterlink/IMatterLink.kt index 4950b74..af853e1 100644 --- a/core/src/main/kotlin/matterlink/IMatterLink.kt +++ b/core/src/main/kotlin/matterlink/IMatterLink.kt @@ -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() { diff --git a/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt b/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt index 1b9cb5b..1b13ecd 100644 --- a/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt +++ b/core/src/main/kotlin/matterlink/bridge/command/CustomCommand.kt @@ -49,9 +49,9 @@ data class CustomCommand( } fun getReplacements(user: String, args: String): Map String> = mapOf( - "{UPTIME}" to instance::getUptimeAsString, - "{USER}" to { user }, - "{ARGS}" to { args } + "{uptime}" to instance::getUptimeAsString, + "{users}" to { user }, + "{args}" to { args } ) } diff --git a/core/src/main/kotlin/matterlink/config/CommandConfig.kt b/core/src/main/kotlin/matterlink/config/CommandConfig.kt index 1848600..575a819 100644 --- a/core/src/main/kotlin/matterlink/config/CommandConfig.kt +++ b/core/src/main/kotlin/matterlink/config/CommandConfig.kt @@ -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 = default