From e665990a3e14f66b071bd2c32c5b68674e9c2e16 Mon Sep 17 00:00:00 2001 From: StillLutto Date: Mon, 16 Dec 2024 22:05:06 +0100 Subject: [PATCH] feat(events): add StellarCommandRegisterEvent --- .../com/undefined/stellar/StellarCommand.kt | 3 +++ .../data/events/AbstractStellarEvent.kt | 19 +++++++++++++++++++ .../events/StellarCommandRegisterEvent.kt | 5 +++++ 3 files changed, 27 insertions(+) create mode 100644 api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt create mode 100644 api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt diff --git a/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt b/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt index 3dd1af3..a2bbe68 100644 --- a/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt +++ b/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt @@ -1,9 +1,11 @@ package com.undefined.stellar +import com.undefined.stellar.data.events.StellarCommandRegisterEvent import com.undefined.stellar.data.requirement.PermissionStellarRequirement import com.undefined.stellar.exception.UnsupportedVersionException import com.undefined.stellar.manager.CommandManager import com.undefined.stellar.util.NMSVersion +import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.plugin.java.JavaPlugin import org.jetbrains.annotations.ApiStatus @@ -22,6 +24,7 @@ class StellarCommand(name: String, permissions: List = listOf()) : Abstr val registrar = CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException() registrar.register(this) for (execution in this.registerExecutions) execution() + Bukkit.getPluginManager().callEvent(StellarCommandRegisterEvent(this)) } companion object { diff --git a/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt b/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt new file mode 100644 index 0000000..9a898b1 --- /dev/null +++ b/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt @@ -0,0 +1,19 @@ +package com.undefined.stellar.data.events + +import org.bukkit.event.Event +import org.bukkit.event.HandlerList + +abstract class AbstractStellarEvent : Event() { + override fun getHandlers(): HandlerList { + return HANDLERS_LIST + } + + companion object { + private val HANDLERS_LIST = HandlerList() + + @JvmStatic + fun getHandlerList(): HandlerList { + return HANDLERS_LIST + } + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt b/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt new file mode 100644 index 0000000..45bd521 --- /dev/null +++ b/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt @@ -0,0 +1,5 @@ +package com.undefined.stellar.data.events + +import com.undefined.stellar.StellarCommand + +class StellarCommandRegisterEvent(val command: StellarCommand) : AbstractStellarEvent()