From 05dc7b7b0927b5f22bed16d7a8861f70fcb53d2f Mon Sep 17 00:00:00 2001 From: StillLutto Date: Sat, 21 Dec 2024 14:44:26 +0100 Subject: [PATCH] feat(version-support): add 1.18.1 and 1.18.2 support --- api/build.gradle.kts | 2 + .../com/undefined/stellar/StellarCommand.kt | 2 +- .../stellar/manager/CommandManager.kt | 5 + build.gradle.kts | 5 + .../registrar/AbstractCommandRegistrar.kt | 3 +- .../com/undefined/stellar/util/NMSVersion.kt | 2 +- server/build.gradle.kts | 8 +- .../main/kotlin/com/undefined/stellar/Main.kt | 9 +- server/src/main/resources/plugin.yml | 2 +- settings.gradle.kts | 2 +- v1_18_1/build.gradle.kts | 26 + .../stellar/v1_18_1/ArgumentHelper.kt | 469 ++++++++++++++++++ .../stellar/v1_18_1/BrigadierCommandHelper.kt | 80 +++ .../stellar/v1_18_1/CommandAdapter.kt | 116 +++++ .../stellar/v1_18_1/CommandContextAdapter.kt | 100 ++++ .../stellar/v1_18_1/CommandRegistrar.kt | 43 ++ v1_18_2/build.gradle.kts | 26 + .../stellar/v1_18_2/ArgumentHelper.kt | 453 +++++++++++++++++ .../stellar/v1_18_2/BrigadierCommandHelper.kt | 73 +++ .../stellar/v1_18_2/CommandAdapter.kt | 109 ++++ .../stellar/v1_18_2/CommandContextAdapter.kt | 100 ++++ .../stellar/v1_18_2/CommandRegistrar.kt | 41 ++ .../stellar/v1_19_2/ArgumentHelper.kt | 4 +- .../stellar/v1_19_2/CommandRegistrar.kt | 6 +- .../stellar/v1_19_3/ArgumentHelper.kt | 4 +- .../stellar/v1_19_3/CommandRegistrar.kt | 6 +- .../stellar/v1_19_4/ArgumentHelper.kt | 3 +- .../stellar/v1_19_4/CommandRegistrar.kt | 6 +- .../undefined/stellar/v1_20/ArgumentHelper.kt | 4 +- .../stellar/v1_20/CommandRegistrar.kt | 6 +- .../stellar/v1_20_1/ArgumentHelper.kt | 4 +- .../stellar/v1_20_1/CommandRegistrar.kt | 6 +- .../stellar/v1_20_2/ArgumentHelper.kt | 4 +- .../stellar/v1_20_2/BrigadierCommandHelper.kt | 1 - .../stellar/v1_20_2/CommandRegistrar.kt | 6 +- .../stellar/v1_20_4/ArgumentHelper.kt | 5 +- .../stellar/v1_20_4/BrigadierCommandHelper.kt | 1 - .../stellar/v1_20_4/CommandRegistrar.kt | 6 +- .../stellar/v1_20_6/CommandRegistrar.kt | 6 +- .../stellar/v1_21/CommandRegistrar.kt | 6 +- .../stellar/v1_21_1/CommandRegistrar.kt | 6 +- .../stellar/v1_21_3/CommandRegistrar.kt | 6 +- .../stellar/v1_21_4/CommandRegistrar.kt | 6 +- 43 files changed, 1738 insertions(+), 40 deletions(-) rename {api => common}/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt (99%) create mode 100644 v1_18_1/build.gradle.kts create mode 100644 v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/ArgumentHelper.kt create mode 100644 v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/BrigadierCommandHelper.kt create mode 100644 v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt create mode 100644 v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandContextAdapter.kt create mode 100644 v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandRegistrar.kt create mode 100644 v1_18_2/build.gradle.kts create mode 100644 v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/ArgumentHelper.kt create mode 100644 v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/BrigadierCommandHelper.kt create mode 100644 v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt create mode 100644 v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandContextAdapter.kt create mode 100644 v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandRegistrar.kt diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 3b25b2e..88df406 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -14,6 +14,8 @@ version = versionVar dependencies { compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") implementation(project(":common")) + implementation(project(":v1_18_1")) + implementation(project(":v1_18_2")) implementation(project(":v1_19_2")) implementation(project(":v1_19_3")) implementation(project(":v1_19_4")) diff --git a/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt b/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt index 76b7f57..9dbfe7c 100644 --- a/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt +++ b/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt @@ -26,7 +26,7 @@ class StellarCommand(name: String, permissions: List = listOf()) : Abstr StellarCommands.commands.add(this) CommandManager.initialize(plugin) val registrar = CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException() - registrar.register(this) + registrar.register(this, plugin) for (execution in this.registerExecutions) execution() Bukkit.getPluginManager().callEvent(StellarCommandRegisterEvent(this)) } diff --git a/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt b/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt index 16fc60a..09ead43 100644 --- a/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt +++ b/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt @@ -9,6 +9,11 @@ import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal object CommandManager { val registrars: Map = mapOf( + "1.18" to com.undefined.stellar.v1_18_1.CommandRegistrar, + "1.18.1" to com.undefined.stellar.v1_18_1.CommandRegistrar, + "1.18.2" to com.undefined.stellar.v1_18_2.CommandRegistrar, + "1.19" to com.undefined.stellar.v1_19_2.CommandRegistrar, + "1.19.1" to com.undefined.stellar.v1_19_2.CommandRegistrar, "1.19.2" to com.undefined.stellar.v1_19_2.CommandRegistrar, "1.19.3" to com.undefined.stellar.v1_19_3.CommandRegistrar, "1.19.4" to com.undefined.stellar.v1_19_4.CommandRegistrar, diff --git a/build.gradle.kts b/build.gradle.kts index 9c4dc3a..61e61bb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -48,6 +48,8 @@ allprojects { apply(plugin = "java-library") apply(plugin = "maven-publish") + version = projectVersion + repositories { mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") @@ -77,6 +79,9 @@ allprojects { dependencies { implementation(project(":api")) implementation(project(":common")) + implementation(project(":v1_18_1:", "reobf")) + implementation(project(":v1_18_2:", "reobf")) + implementation(project(":v1_19_2:", "reobf")) implementation(project(":v1_19_3:", "reobf")) implementation(project(":v1_19_4:", "reobf")) implementation(project(":v1_20", "reobf")) diff --git a/common/src/main/kotlin/com/undefined/stellar/registrar/AbstractCommandRegistrar.kt b/common/src/main/kotlin/com/undefined/stellar/registrar/AbstractCommandRegistrar.kt index 2562e96..1e44180 100644 --- a/common/src/main/kotlin/com/undefined/stellar/registrar/AbstractCommandRegistrar.kt +++ b/common/src/main/kotlin/com/undefined/stellar/registrar/AbstractCommandRegistrar.kt @@ -2,8 +2,9 @@ package com.undefined.stellar.registrar import com.undefined.stellar.AbstractStellarCommand import org.bukkit.command.CommandSender +import org.bukkit.plugin.java.JavaPlugin interface AbstractCommandRegistrar { - fun register(command: AbstractStellarCommand<*>) + fun register(command: AbstractStellarCommand<*>, plugin: JavaPlugin) fun handleCommandFailure(sender: CommandSender, input: String): Boolean } \ No newline at end of file diff --git a/api/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt b/common/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt similarity index 99% rename from api/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt rename to common/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt index bee34f3..7084f0e 100644 --- a/api/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt +++ b/common/src/main/kotlin/com/undefined/stellar/util/NMSVersion.kt @@ -6,4 +6,4 @@ import org.jetbrains.annotations.ApiStatus @ApiStatus.Internal object NMSVersion { val version by lazy { Bukkit.getBukkitVersion().split("-")[0] } -} +} \ No newline at end of file diff --git a/server/build.gradle.kts b/server/build.gradle.kts index 87beec1..fdc3613 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -9,10 +9,12 @@ val groupIdVar = "com.undefined" val artifactIdVar = "stellar" dependencies { - compileOnly("org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT") implementation(project(":api")) implementation(project(":common")) + implementation(project(":v1_18_1:", "reobf")) + implementation(project(":v1_18_2:", "reobf")) implementation(project(":v1_19_2:", "reobf")) implementation(project(":v1_19_3:", "reobf")) implementation(project(":v1_19_4:", "reobf")) @@ -25,7 +27,7 @@ dependencies { implementation(project(":v1_21_1:", "reobf")) implementation(project(":v1_21_3:", "reobf")) implementation(project(":v1_21_4:", "reobf")) - implementation(project(":v1_20")) + implementation(project(":v1_18_1")) } tasks { @@ -42,7 +44,7 @@ tasks { } runServer { - minecraftVersion("1.20") + minecraftVersion("1.18.1") jvmArgs("-Xmx2G") } } diff --git a/server/src/main/kotlin/com/undefined/stellar/Main.kt b/server/src/main/kotlin/com/undefined/stellar/Main.kt index 71f033a..d1549b3 100644 --- a/server/src/main/kotlin/com/undefined/stellar/Main.kt +++ b/server/src/main/kotlin/com/undefined/stellar/Main.kt @@ -1,5 +1,7 @@ package com.undefined.stellar +import net.kyori.adventure.text.format.Style +import org.bukkit.Color import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack @@ -9,11 +11,10 @@ import java.util.function.Predicate class Main : JavaPlugin() { override fun onEnable() { - StellarCommand("isItem") - .addItemArgument(name = "item") + StellarCommand("test") + .addColorArgument(name = "item") .addExecution { - val predicate = getArgument>("item") - sender.inventory.setItem() + sender.sendMessage(getArgument