diff --git a/api/src/main/kotlin/me/zodd/CommandManager.kt b/api/src/main/kotlin/me/zodd/CommandManager.kt index 4fba18e..501d78e 100644 --- a/api/src/main/kotlin/me/zodd/CommandManager.kt +++ b/api/src/main/kotlin/me/zodd/CommandManager.kt @@ -15,6 +15,7 @@ class CommandManager : DslArgument, DslContext { operator fun invoke(initializer: CommandManager.() -> Unit): List { this.initializer() + RegistrationHelper.registerCommand(CommandBuilder.builtCommands) return CommandBuilder.builtCommands } diff --git a/api/src/main/kotlin/me/zodd/RegistrationHelper.kt b/api/src/main/kotlin/me/zodd/RegistrationHelper.kt index 3f55b9a..65ea4dd 100644 --- a/api/src/main/kotlin/me/zodd/RegistrationHelper.kt +++ b/api/src/main/kotlin/me/zodd/RegistrationHelper.kt @@ -3,6 +3,7 @@ package me.zodd import io.leangen.geantyref.TypeToken import org.spongepowered.api.Sponge import org.spongepowered.api.command.Command +import org.spongepowered.api.command.Command.Parameterized import org.spongepowered.api.event.Event import org.spongepowered.api.event.EventListenerRegistration import org.spongepowered.api.event.Order @@ -24,6 +25,13 @@ object RegistrationHelper { inline fun registerListener(noinline executor: T.() -> Unit) = registerListener(typeToken(), executor) + fun registerCommand(command: List) { + val regToken = typeToken>() + registerListener(regToken) { + it.register(API.container, command) + } + } + //Allows easy creation of typeToken inline fun typeToken() = object : TypeToken() {} diff --git a/host/run/config/scripting-host/scripts/helloworld.plugin.kts b/host/run/config/scripting-host/scripts/helloworld.plugin.kts index b26f81a..34edde5 100644 --- a/host/run/config/scripting-host/scripts/helloworld.plugin.kts +++ b/host/run/config/scripting-host/scripts/helloworld.plugin.kts @@ -1,4 +1,6 @@ import me.zodd.* +import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.Component //Scripts automatically execute during plugin construction Logger.info("Hello World!") @@ -8,6 +10,7 @@ ScriptCommandManager { aliases += "baz" permission = "plugin.command.$it" executes { + this.sendMessage(Identity.nil(), Component.text("Hello World!")) success() } } diff --git a/host/run/config/scripting-host/scripts/multiEvent.plugin.kts b/host/run/config/scripting-host/scripts/multiEvent.plugin.kts index 1acff3f..6308d21 100644 --- a/host/run/config/scripting-host/scripts/multiEvent.plugin.kts +++ b/host/run/config/scripting-host/scripts/multiEvent.plugin.kts @@ -9,7 +9,6 @@ import me.zodd.onServerStarting */ //Scripts can do multiple things -//noinspection UnresolvedReference onServerStarted { Logger.info("Multi-Event-Server-Started") } diff --git a/host/run/config/scripting-host/scripts/scriptWithError.plugin.kts b/host/run/config/scripting-host/scripts/scriptWithError.plugin.kts index a0604b6..df0975d 100644 --- a/host/run/config/scripting-host/scripts/scriptWithError.plugin.kts +++ b/host/run/config/scripting-host/scripts/scriptWithError.plugin.kts @@ -1,5 +1,7 @@ //org.invalid is not on classpath so script will error //Despite this error other scripts will continue to load +import me.zodd.Logger +import me.zodd.onServerStarted import org.invalid onServerStarted { diff --git a/script-runtime/build.gradle.kts b/script-runtime/build.gradle.kts index 07f275f..e62122f 100644 --- a/script-runtime/build.gradle.kts +++ b/script-runtime/build.gradle.kts @@ -17,5 +17,6 @@ tasks.jar { } tasks.shadowJar { + archiveClassifier.set("") configurations.add(project.configurations.shadow.get()) } \ No newline at end of file