From 56dd6556bdbca61fb1da90612df00130af3044d5 Mon Sep 17 00:00:00 2001 From: DaMachinator Date: Thu, 15 Feb 2018 08:30:36 -0500 Subject: [PATCH] Added $uptime command, abstracted command registration into core --- .../src/main/kotlin/matterlink/MatterLink.kt | 2 +- .../src/main/kotlin/matterlink/MatterLink.kt | 2 +- .../src/main/kotlin/matterlink/MatterLink.kt | 2 +- .../src/main/kotlin/matterlink/IMatterLink.kt | 8 +++++++ .../bridge/command/UptimeCommand.kt | 21 +++++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 core/src/main/kotlin/matterlink/bridge/command/UptimeCommand.kt diff --git a/1.10.2/src/main/kotlin/matterlink/MatterLink.kt b/1.10.2/src/main/kotlin/matterlink/MatterLink.kt index bd6369c..76f9b54 100644 --- a/1.10.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.10.2/src/main/kotlin/matterlink/MatterLink.kt @@ -43,7 +43,7 @@ object MatterLink : IMatterLink() { @Mod.EventHandler fun init(event: FMLInitializationEvent) { - BridgeCommandRegistry.registerAll(PlayerListCommand, HelpCommand) + this.registerBridgeCommands() } @Mod.EventHandler diff --git a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt index f9f01d2..897ab84 100644 --- a/1.11.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.11.2/src/main/kotlin/matterlink/MatterLink.kt @@ -43,7 +43,7 @@ object MatterLink : IMatterLink() { @Mod.EventHandler fun init(event: FMLInitializationEvent) { - BridgeCommandRegistry.registerAll(PlayerListCommand, HelpCommand) + this.registerBridgeCommands() } @Mod.EventHandler diff --git a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt index b2ee0b7..84706d6 100644 --- a/1.12.2/src/main/kotlin/matterlink/MatterLink.kt +++ b/1.12.2/src/main/kotlin/matterlink/MatterLink.kt @@ -41,7 +41,7 @@ object MatterLink : IMatterLink() { @Mod.EventHandler fun init(event: FMLInitializationEvent) { - BridgeCommandRegistry.registerAll(PlayerListCommand, HelpCommand) + this.registerBridgeCommands() } @Mod.EventHandler diff --git a/core/src/main/kotlin/matterlink/IMatterLink.kt b/core/src/main/kotlin/matterlink/IMatterLink.kt index 6575036..5386204 100644 --- a/core/src/main/kotlin/matterlink/IMatterLink.kt +++ b/core/src/main/kotlin/matterlink/IMatterLink.kt @@ -1,6 +1,10 @@ package matterlink import matterlink.bridge.MessageHandler +import matterlink.bridge.command.BridgeCommandRegistry +import matterlink.bridge.command.HelpCommand +import matterlink.bridge.command.PlayerListCommand +import matterlink.bridge.command.UptimeCommand import matterlink.config.cfg lateinit var instance: IMatterLink @@ -53,4 +57,8 @@ abstract class IMatterLink { return "${day}d${hr}hr${min}m${sec}s" } + + fun registerBridgeCommands() { + BridgeCommandRegistry.registerAll(HelpCommand,PlayerListCommand,UptimeCommand) + } } \ No newline at end of file diff --git a/core/src/main/kotlin/matterlink/bridge/command/UptimeCommand.kt b/core/src/main/kotlin/matterlink/bridge/command/UptimeCommand.kt new file mode 100644 index 0000000..6100ec8 --- /dev/null +++ b/core/src/main/kotlin/matterlink/bridge/command/UptimeCommand.kt @@ -0,0 +1,21 @@ +package matterlink.bridge.command + +import matterlink.bridge.ApiMessage +import matterlink.bridge.MessageHandler +import matterlink.config.cfg +import matterlink.instance + +object UptimeCommand : IBridgeCommand { + override val name: String = "uptime" + override val help: String = "Get server uptime." + + override fun call(args: String): Boolean { + if (args.isNotBlank()) return false + MessageHandler.transmit(ApiMessage( + username = cfg!!.relay.systemUser, + text = instance.getUptimeAsString() + )) + return true + } + +} \ No newline at end of file