diff --git a/api/build.gradle.kts b/api/build.gradle.kts deleted file mode 100644 index 8ea3552..0000000 --- a/api/build.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -plugins { - `java-library` - kotlin("jvm") version "1.9.22" - id("com.gradleup.shadow") version "8.3.5" -} - -val versionVar = version -val groupIdVar = "com.undefined" -val artifactIdVar = "stellar" - -group = groupIdVar -version = versionVar - -publishing { - publications { - register("maven") { - groupId = groupIdVar - artifactId = artifactIdVar - version = versionVar.toString() - - from(components["java"]) - } - } -} - -dependencies { - compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") - implementation(project(":common")) - implementation(project(":v1_13")) - implementation(project(":v1_13_1")) - implementation(project(":v1_13_2")) - implementation(project(":v1_14_1")) - implementation(project(":v1_14_2")) - implementation(project(":v1_14_3")) - implementation(project(":v1_14_4")) - implementation(project(":v1_15")) - implementation(project(":v1_15_1")) - implementation(project(":v1_15_2")) - implementation(project(":v1_16_1")) - implementation(project(":v1_16_2")) - implementation(project(":v1_16_3")) - implementation(project(":v1_16_4")) - implementation(project(":v1_16_5")) - implementation(project(":v1_17")) - implementation(project(":v1_17_1")) - 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")) - implementation(project(":v1_20_1")) - implementation(project(":v1_20_2")) - implementation(project(":v1_20_4")) - implementation(project(":v1_20_6")) - implementation(project(":v1_21_1")) - implementation(project(":v1_21_3")) - implementation(project(":v1_21_4")) - implementation(kotlin("reflect")) -} - -tasks { - compileKotlin { - kotlinOptions.jvmTarget = "1.8" - } - compileJava { - options.release.set(8) - } -} - -kotlin { - jvmToolchain(21) -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index d6da3f1..5a3d07b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,12 +5,11 @@ plugins { kotlin("jvm") version "1.9.22" `maven-publish` id("com.gradleup.shadow") version "8.3.5" - id("io.papermc.paperweight.userdev") version "2.0.0-beta.8" apply false } apply(plugin = "maven-publish") val projectGroupId = "com.undefined" -val projectVersion = "0.0.39" +val projectVersion = "0.0.43" val projectArtifactId = "stellar" group = projectGroupId @@ -21,14 +20,6 @@ val minecraftVersion = "1.20.6" repositories { mavenCentral() mavenLocal() - maven { - name = "spigotmc-repo" - url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") - } - maven { - name = "minecraft-repo" - url = uri("https://libraries.minecraft.net/") - } maven("https://repo.codemc.io/repository/maven-snapshots/") } @@ -43,7 +34,6 @@ publishing { } } } - publications { register("maven") { groupId = projectGroupId @@ -64,7 +54,11 @@ allprojects { repositories { mavenCentral() - maven("https://repo.papermc.io/repository/maven-public/") + mavenLocal() + maven { + name = "minecraft-repo" + url = uri("https://libraries.minecraft.net/") + } } dependencies { @@ -77,14 +71,17 @@ allprojects { } dependencies { - implementation(project(":api")) + implementation(project(":spigot:api")) implementation(project(":common")) } tasks { + publish { + finalizedBy(project(":paper:common").tasks["publish"]) + } withType { - archiveFileName.set("${project.name}-${project.version}.jar") - archiveClassifier.set("mapped") + archiveFileName = "${project.name}-${project.version}.jar" + archiveClassifier = "spigot" } compileKotlin { kotlinOptions.jvmTarget = "1.8" diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 90f2da4..27d8c9b 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -6,20 +6,8 @@ val versionVar = version val groupIdVar = "com.undefined" val artifactIdVar = "stellar" -publishing { - publications { - register("maven") { - groupId = groupIdVar - artifactId = artifactIdVar - version = versionVar.toString() - - from(components["java"]) - } - } -} - dependencies { - compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT") api("com.mojang:authlib:1.5.21") } @@ -28,10 +16,10 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } kotlin { jvmToolchain(21) -} +} \ No newline at end of file diff --git a/paper/api/build.gradle.kts b/paper/api/build.gradle.kts new file mode 100644 index 0000000..f7250ba --- /dev/null +++ b/paper/api/build.gradle.kts @@ -0,0 +1,61 @@ +plugins { + `java-library` + kotlin("jvm") version "1.9.22" + id("com.gradleup.shadow") version "8.3.5" +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +val versionVar = version +val groupIdVar = "com.undefined" +val artifactIdVar = "stellar" + +group = groupIdVar +version = versionVar + +publishing { + repositories { + maven { + name = "UndefinedCreations" + url = uri("https://repo.undefinedcreations.com/releases") + credentials(PasswordCredentials::class) { + username = System.getenv("MAVEN_NAME") + password = System.getenv("MAVEN_SECRET") + } + } + } + publications { + register("maven") { + groupId = groupIdVar + artifactId = artifactIdVar + version = versionVar.toString() + + from(components["java"]) + } + } +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") + implementation(project(":paper:common")) + implementation(project(":paper:v1_17_1")) + implementation(kotlin("reflect")) +} + +tasks { + shadowJar { + archiveClassifier = "paper" + } + compileKotlin { + kotlinOptions.jvmTarget = "1.8" + } + compileJava { + options.release = 8 + } +} + +kotlin { + jvmToolchain(21) +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt b/paper/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt similarity index 99% rename from api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt index e7a9d16..222ecf9 100644 --- a/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt +++ b/paper/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt @@ -39,4 +39,4 @@ abstract class BaseStellarCommand(val name: String, val description: String = "" hasBeenRegistered = true } -} +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt b/paper/api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt diff --git a/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt b/paper/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt diff --git a/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt b/paper/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt diff --git a/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt b/paper/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt diff --git a/api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt b/paper/api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt diff --git a/paper/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt b/paper/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt new file mode 100644 index 0000000..1275adc --- /dev/null +++ b/paper/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt @@ -0,0 +1,22 @@ +package com.undefined.stellar.manager + +import com.undefined.stellar.listener.StellarListener +import com.undefined.stellar.registrar.AbstractCommandRegistrar +import org.bukkit.Bukkit +import org.bukkit.plugin.java.JavaPlugin +import org.jetbrains.annotations.ApiStatus +import kotlin.reflect.KClass + +@ApiStatus.Internal +object CommandManager { + val registrars: Map> = mapOf( + "1.17.1" to com.undefined.stellar.v1_17_1.CommandRegistrar::class, + ) + + private val initializedPlugins: MutableList = mutableListOf() + fun initialize(plugin: JavaPlugin) { + if (initializedPlugins.contains(plugin)) return + initializedPlugins.add(plugin) + Bukkit.getPluginManager().registerEvents(StellarListener, plugin) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/undefined/stellar/util/Builders.kt b/paper/api/src/main/kotlin/com/undefined/stellar/util/Builders.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/util/Builders.kt rename to paper/api/src/main/kotlin/com/undefined/stellar/util/Builders.kt diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts new file mode 100644 index 0000000..9b81d67 --- /dev/null +++ b/paper/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + java + kotlin("jvm") version "1.9.22" + id("com.gradleup.shadow") version "8.3.5" + id("io.papermc.paperweight.userdev") version "2.0.0-beta.13" apply false +} + +allprojects { + repositories { + maven("https://repo.papermc.io/repository/maven-public/") + } +} \ No newline at end of file diff --git a/paper/common/build.gradle.kts b/paper/common/build.gradle.kts new file mode 100644 index 0000000..3cc5718 --- /dev/null +++ b/paper/common/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + kotlin("jvm") version "1.9.22" +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") + api("com.mojang:authlib:1.5.21") + api(project(":common")) +} + +tasks { + compileKotlin { + kotlinOptions.jvmTarget = "1.8" + } + compileJava { + options.release = 8 + } +} + +java { + disableAutoTargetJvm() +} + +kotlin { + jvmToolchain(21) +} \ No newline at end of file diff --git a/v1_21_3/build.gradle.kts b/paper/v1_17_1/build.gradle.kts similarity index 62% rename from v1_21_3/build.gradle.kts rename to paper/v1_17_1/build.gradle.kts index a24a3c0..4c7de5d 100644 --- a/v1_21_3/build.gradle.kts +++ b/paper/v1_17_1/build.gradle.kts @@ -6,8 +6,7 @@ plugins { paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION dependencies { - paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") - implementation("com.mojang:brigadier:1.2.9") + paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") compileOnly(project(":common")) } @@ -16,12 +15,10 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } paperweight { - javaLauncher.set( - project.javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(21)) } - ) + javaLauncher = project.javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion.of(17)) } } } diff --git a/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt b/paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt similarity index 100% rename from v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt rename to paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt diff --git a/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt b/paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt rename to paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt diff --git a/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt b/paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt similarity index 94% rename from v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt rename to paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt index 6bfb6dd..98509ce 100644 --- a/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt +++ b/paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt b/paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt similarity index 100% rename from v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt rename to paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt diff --git a/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt b/paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt similarity index 100% rename from v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt rename to paper/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt diff --git a/server/build.gradle.kts b/server/build.gradle.kts index df273e1..988ab32 100644 --- a/server/build.gradle.kts +++ b/server/build.gradle.kts @@ -10,8 +10,7 @@ val artifactIdVar = "stellar" dependencies { compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT") - - implementation(project(":api")) + implementation(project(":spigot:api")) } tasks { diff --git a/settings.gradle.kts b/settings.gradle.kts index 4a12f32..30a5c39 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,35 +1,39 @@ rootProject.name = "stellar" include( - "server", - "api", - "common", - "v1_13", - "v1_13_1", - "v1_13_2", - "v1_14_1", - "v1_14_2", - "v1_14_3", - "v1_14_4", - "v1_15", - "v1_15_1", - "v1_15_2", - "v1_16_1", - "v1_16_2", - "v1_16_3", - "v1_16_4", - "v1_16_5", - "v1_17", - "v1_17_1", - "v1_18_1", - "v1_18_2", - "v1_19_2", - "v1_19_3", - "v1_19_4", - "v1_20_1", - "v1_20_2", - "v1_20_4", - "v1_20_6", - "v1_21_1", - "v1_21_3", - "v1_21_4" + ":server", + ":common", + ":spigot:api", + ":spigot:common", + ":spigot:v1_13", + ":spigot:v1_13_1", + ":spigot:v1_13_2", + ":spigot:v1_14_1", + ":spigot:v1_14_2", + ":spigot:v1_14_3", + ":spigot:v1_14_4", + ":spigot:v1_15", + ":spigot:v1_15_1", + ":spigot:v1_15_2", + ":spigot:v1_16_1", + ":spigot:v1_16_2", + ":spigot:v1_16_3", + ":spigot:v1_16_4", + ":spigot:v1_16_5", + ":spigot:v1_17", + ":spigot:v1_17_1", + ":spigot:v1_18_1", + ":spigot:v1_18_2", + ":spigot:v1_19_2", + ":spigot:v1_19_3", + ":spigot:v1_19_4", + ":spigot:v1_20_1", + ":spigot:v1_20_2", + ":spigot:v1_20_4", + ":spigot:v1_20_6", + ":spigot:v1_21_1", + ":spigot:v1_21_3", + ":spigot:v1_21_4", + ":paper:api", + ":paper:common", + ":paper:v1_17_1", ) \ No newline at end of file diff --git a/spigot/api/build.gradle.kts b/spigot/api/build.gradle.kts new file mode 100644 index 0000000..ece9b44 --- /dev/null +++ b/spigot/api/build.gradle.kts @@ -0,0 +1,72 @@ +plugins { + `java-library` + kotlin("jvm") version "1.9.22" + id("com.gradleup.shadow") version "8.3.5" +} + +val versionVar = version +val groupIdVar = "com.undefined" +val artifactIdVar = "stellar" + +group = groupIdVar +version = versionVar + +publishing { + publications { + register("maven") { + groupId = groupIdVar + artifactId = artifactIdVar + version = versionVar.toString() + + from(components["java"]) + } + } +} + +dependencies { + compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT") + implementation(project(":spigot:common")) + implementation(project(":spigot:v1_13")) + implementation(project(":spigot:v1_13_1")) + implementation(project(":spigot:v1_13_2")) + implementation(project(":spigot:v1_14_1")) + implementation(project(":spigot:v1_14_2")) + implementation(project(":spigot:v1_14_3")) + implementation(project(":spigot:v1_14_4")) + implementation(project(":spigot:v1_15")) + implementation(project(":spigot:v1_15_1")) + implementation(project(":spigot:v1_15_2")) + implementation(project(":spigot:v1_16_1")) + implementation(project(":spigot:v1_16_2")) + implementation(project(":spigot:v1_16_3")) + implementation(project(":spigot:v1_16_4")) + implementation(project(":spigot:v1_16_5")) + implementation(project(":spigot:v1_17")) + implementation(project(":spigot:v1_17_1")) + implementation(project(":spigot:v1_18_1")) + implementation(project(":spigot:v1_18_2")) + implementation(project(":spigot:v1_19_2")) + implementation(project(":spigot:v1_19_3")) + implementation(project(":spigot:v1_19_4")) + implementation(project(":spigot:v1_20_1")) + implementation(project(":spigot:v1_20_2")) + implementation(project(":spigot:v1_20_4")) + implementation(project(":spigot:v1_20_6")) + implementation(project(":spigot:v1_21_1")) + implementation(project(":spigot:v1_21_3")) + implementation(project(":spigot:v1_21_4")) + implementation(kotlin("reflect")) +} + +tasks { + compileKotlin { + kotlinOptions.jvmTarget = "1.8" + } + compileJava { + options.release = 8 + } +} + +kotlin { + jvmToolchain(21) +} \ No newline at end of file diff --git a/spigot/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt new file mode 100644 index 0000000..222ecf9 --- /dev/null +++ b/spigot/api/src/main/kotlin/com/undefined/stellar/BaseStellarCommand.kt @@ -0,0 +1,42 @@ +package com.undefined.stellar + +import org.bukkit.plugin.java.JavaPlugin + +abstract class BaseStellarCommand(val name: String, val description: String = "", val permissions: List = listOf()) { + + var hasInitializedArguments = false + private set + private var hasBeenRegistered = false + + val command: StellarCommand by lazy { + setup().apply { addRequirements(*permissions.toTypedArray()) } + } + + private fun initializeArguments() { + if (hasInitializedArguments) return + hasInitializedArguments = true + for (argument in arguments()) command.addArgument(argument.getFullArgument()) + } + + abstract fun setup(): StellarCommand + open fun arguments(): List = listOf() + + fun createCommand(init: StellarCommand.() -> Unit): StellarCommand { + val command = StellarCommand(name, permissions) + command.setDescription(description) + command.init() + return command + } + + fun getFullCommand(): StellarCommand { + initializeArguments() + return command + } + + fun register(plugin: JavaPlugin) { + if (hasBeenRegistered) return + getFullCommand().register(plugin) + hasBeenRegistered = true + } + +} \ No newline at end of file diff --git a/spigot/api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt new file mode 100644 index 0000000..743ecfb --- /dev/null +++ b/spigot/api/src/main/kotlin/com/undefined/stellar/StellarArgument.kt @@ -0,0 +1,25 @@ +package com.undefined.stellar + +import com.undefined.stellar.argument.AbstractStellarArgument + +abstract class StellarArgument(val type: AbstractStellarArgument<*>, val permissions: List) { + + constructor(type: AbstractStellarArgument<*>, vararg permissions: String) : this(type, permissions.toList()) + + val argument: AbstractStellarArgument<*> by lazy { + setup().apply { addRequirements(*permissions.toTypedArray()) } + } + + abstract fun setup(): AbstractStellarArgument<*> + open fun arguments(): List = listOf() + + fun createArgument(init: AbstractStellarArgument<*>.() -> Unit): AbstractStellarArgument<*> = type.apply { init() } + + fun getFullArgument(): AbstractStellarArgument<*> { + val command = setup() + command.addRequirements(*permissions.toTypedArray()) + for (argument in arguments()) command.addArgument(argument.getFullArgument()) + return command + } + +} diff --git a/spigot/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt new file mode 100644 index 0000000..f5e66a6 --- /dev/null +++ b/spigot/api/src/main/kotlin/com/undefined/stellar/StellarCommand.kt @@ -0,0 +1,45 @@ +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 + +class StellarCommand(name: String, permissions: List = listOf(), aliases: List = listOf()) : AbstractStellarCommand(name) { + + constructor(name: String, vararg aliases: String) : this(name, aliases = aliases.toList()) + constructor(name: String, permission: String, vararg aliases: String) : this(name, listOf(permission), aliases.toList()) + constructor(name: String, permission: String, aliases: List) : this(name, listOf(permission), aliases) + + init { + this.permissionRequirements.addAll(permissions.map { PermissionStellarRequirement(1, it) }) + this.aliases.addAll(aliases) + } + + private var registered = false + + override fun register(plugin: JavaPlugin) { + if (registered) return + registered = true + StellarCommands.commands.add(this) + CommandManager.initialize(plugin) + val registrar = (CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException()).objectInstance + registrar?.register(this, plugin) + for (execution in this.registerExecutions) execution() + Bukkit.getPluginManager().callEvent(StellarCommandRegisterEvent(this)) + } + + companion object { + @ApiStatus.Internal + fun parseAndReturnCancelled(sender: CommandSender, input: String): Boolean { + val registrar = (CommandManager.registrars[NMSVersion.version] ?: throw UnsupportedVersionException()).objectInstance + return registrar?.handleCommandFailure(sender, input) ?: false + } + } + +} \ No newline at end of file diff --git a/spigot/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/data/events/AbstractStellarEvent.kt new file mode 100644 index 0000000..9a898b1 --- /dev/null +++ b/spigot/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/spigot/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/data/events/StellarCommandRegisterEvent.kt new file mode 100644 index 0000000..45bd521 --- /dev/null +++ b/spigot/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() diff --git a/spigot/api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt new file mode 100644 index 0000000..de598dc --- /dev/null +++ b/spigot/api/src/main/kotlin/com/undefined/stellar/listener/StellarListener.kt @@ -0,0 +1,23 @@ +package com.undefined.stellar.listener + +import com.undefined.stellar.StellarCommand +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerCommandPreprocessEvent +import org.bukkit.event.server.ServerCommandEvent +import org.jetbrains.annotations.ApiStatus + +@ApiStatus.Internal +object StellarListener : Listener { + + @EventHandler + fun onPlayerCommandPreprocess(event: PlayerCommandPreprocessEvent) { + event.isCancelled = StellarCommand.parseAndReturnCancelled(event.player, event.message.removePrefix("/")) + } + + @EventHandler + fun onServerCommand(event: ServerCommandEvent) { + event.isCancelled = StellarCommand.parseAndReturnCancelled(event.sender, event.command.removePrefix("/")) + } + +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt similarity index 100% rename from api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt rename to spigot/api/src/main/kotlin/com/undefined/stellar/manager/CommandManager.kt diff --git a/spigot/api/src/main/kotlin/com/undefined/stellar/util/Builders.kt b/spigot/api/src/main/kotlin/com/undefined/stellar/util/Builders.kt new file mode 100644 index 0000000..d2b5ada --- /dev/null +++ b/spigot/api/src/main/kotlin/com/undefined/stellar/util/Builders.kt @@ -0,0 +1,16 @@ +package com.undefined.stellar.util + +import com.undefined.stellar.StellarCommand + +fun command(name: String, description: String, permissions: List, aliases: List, builder: StellarCommand.() -> Unit): StellarCommand { + val command = StellarCommand(name, permissions, aliases) + command.setDescription(description) + command.builder() + return command +} + +fun command(name: String, description: String, builder: StellarCommand.() -> Unit): StellarCommand = command(name, description, listOf(), listOf(), builder) +fun command(name: String, description: String, permissions: List, builder: StellarCommand.() -> Unit): StellarCommand = command(name, description, permissions, listOf(), builder) +fun command(name: String, permissions: List, builder: StellarCommand.() -> Unit): StellarCommand = command(name, "", permissions, listOf(), builder) +fun command(name: String, permissions: List, aliases: List, builder: StellarCommand.() -> Unit): StellarCommand = command(name, "", permissions, aliases, builder) +fun command(name: String, builder: StellarCommand.() -> Unit): StellarCommand = command(name, "", builder) \ No newline at end of file diff --git a/spigot/build.gradle.kts b/spigot/build.gradle.kts new file mode 100644 index 0000000..2092547 --- /dev/null +++ b/spigot/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + java + kotlin("jvm") version "1.9.22" + id("com.gradleup.shadow") version "8.3.5" +} + +allprojects { + repositories { + maven { + name = "spigotmc-repo" + url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + } + } +} \ No newline at end of file diff --git a/spigot/common/build.gradle.kts b/spigot/common/build.gradle.kts new file mode 100644 index 0000000..ff12135 --- /dev/null +++ b/spigot/common/build.gradle.kts @@ -0,0 +1,22 @@ +plugins { + kotlin("jvm") version "1.9.22" +} + +dependencies { + compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT") + api("com.mojang:authlib:1.5.21") + api(project(":common")) +} + +tasks { + compileKotlin { + kotlinOptions.jvmTarget = "1.8" + } + compileJava { + options.release = 8 + } +} + +kotlin { + jvmToolchain(21) +} \ No newline at end of file diff --git a/v1_13/build.gradle.kts b/spigot/v1_13/build.gradle.kts similarity index 82% rename from v1_13/build.gradle.kts rename to spigot/v1_13/build.gradle.kts index 63f2378..2ef06a6 100644 --- a/v1_13/build.gradle.kts +++ b/spigot/v1_13/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.13-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/ArgumentHelper.kt b/spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/ArgumentHelper.kt similarity index 100% rename from v1_13/src/main/kotlin/com/undefined/stellar/v1_13/ArgumentHelper.kt rename to spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/ArgumentHelper.kt diff --git a/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/BrigadierCommandHelper.kt b/spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/BrigadierCommandHelper.kt similarity index 100% rename from v1_13/src/main/kotlin/com/undefined/stellar/v1_13/BrigadierCommandHelper.kt rename to spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/BrigadierCommandHelper.kt diff --git a/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandAdapter.kt b/spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandAdapter.kt similarity index 94% rename from v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandAdapter.kt rename to spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandAdapter.kt index 659bbe4..aeb801a 100644 --- a/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandAdapter.kt +++ b/spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_13_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandContextAdapter.kt b/spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandContextAdapter.kt similarity index 100% rename from v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandContextAdapter.kt rename to spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandContextAdapter.kt diff --git a/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandRegistrar.kt b/spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandRegistrar.kt similarity index 100% rename from v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandRegistrar.kt rename to spigot/v1_13/src/main/kotlin/com/undefined/stellar/v1_13/CommandRegistrar.kt diff --git a/v1_13_1/build.gradle.kts b/spigot/v1_13_1/build.gradle.kts similarity index 82% rename from v1_13_1/build.gradle.kts rename to spigot/v1_13_1/build.gradle.kts index 4349315..79a2f48 100644 --- a/v1_13_1/build.gradle.kts +++ b/spigot/v1_13_1/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.13.1-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/ArgumentHelper.kt b/spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/ArgumentHelper.kt similarity index 100% rename from v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/ArgumentHelper.kt rename to spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/ArgumentHelper.kt diff --git a/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/BrigadierCommandHelper.kt b/spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/BrigadierCommandHelper.kt rename to spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/BrigadierCommandHelper.kt diff --git a/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandAdapter.kt b/spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandAdapter.kt similarity index 97% rename from v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandAdapter.kt rename to spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandAdapter.kt index 64a9212..1dd7a83 100644 --- a/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandAdapter.kt +++ b/spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandAdapter.kt @@ -13,6 +13,7 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_13_R2.CommandListenerWrapper +import org.bukkit.Bukkit import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,7 +38,7 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin) { BrigadierCommandHelper.handleExecutions(command, context) } 1 @@ -79,7 +80,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin) { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { diff --git a/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandContextAdapter.kt b/spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandContextAdapter.kt similarity index 100% rename from v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandContextAdapter.kt rename to spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandContextAdapter.kt diff --git a/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandRegistrar.kt b/spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandRegistrar.kt similarity index 100% rename from v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandRegistrar.kt rename to spigot/v1_13_1/src/main/kotlin/com/undefined/stellar/v1_13_1/CommandRegistrar.kt diff --git a/v1_13_2/build.gradle.kts b/spigot/v1_13_2/build.gradle.kts similarity index 82% rename from v1_13_2/build.gradle.kts rename to spigot/v1_13_2/build.gradle.kts index ca75704..5bf3987 100644 --- a/v1_13_2/build.gradle.kts +++ b/spigot/v1_13_2/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.13.2-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/ArgumentHelper.kt b/spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/ArgumentHelper.kt similarity index 100% rename from v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/ArgumentHelper.kt rename to spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/ArgumentHelper.kt diff --git a/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/BrigadierCommandHelper.kt b/spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/BrigadierCommandHelper.kt rename to spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/BrigadierCommandHelper.kt diff --git a/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandAdapter.kt b/spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandAdapter.kt similarity index 94% rename from v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandAdapter.kt rename to spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandAdapter.kt index 83778ca..a2230a4 100644 --- a/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandAdapter.kt +++ b/spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_13_R2.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandContextAdapter.kt b/spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandContextAdapter.kt similarity index 100% rename from v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandContextAdapter.kt rename to spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandContextAdapter.kt diff --git a/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandRegistrar.kt b/spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandRegistrar.kt similarity index 100% rename from v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandRegistrar.kt rename to spigot/v1_13_2/src/main/kotlin/com/undefined/stellar/v1_13_2/CommandRegistrar.kt diff --git a/v1_14_1/build.gradle.kts b/spigot/v1_14_1/build.gradle.kts similarity index 82% rename from v1_14_1/build.gradle.kts rename to spigot/v1_14_1/build.gradle.kts index c0f7906..3ef3192 100644 --- a/v1_14_1/build.gradle.kts +++ b/spigot/v1_14_1/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.14.1-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/ArgumentHelper.kt b/spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/ArgumentHelper.kt similarity index 100% rename from v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/ArgumentHelper.kt rename to spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/ArgumentHelper.kt diff --git a/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/BrigadierCommandHelper.kt b/spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/BrigadierCommandHelper.kt rename to spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/BrigadierCommandHelper.kt diff --git a/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandAdapter.kt b/spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandAdapter.kt similarity index 94% rename from v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandAdapter.kt rename to spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandAdapter.kt index bf1fa02..3b11733 100644 --- a/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandAdapter.kt +++ b/spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_14_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandContextAdapter.kt b/spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandContextAdapter.kt similarity index 100% rename from v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandContextAdapter.kt rename to spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandContextAdapter.kt diff --git a/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandRegistrar.kt b/spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandRegistrar.kt similarity index 100% rename from v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandRegistrar.kt rename to spigot/v1_14_1/src/main/kotlin/com/undefined/stellar/v1_14_1/CommandRegistrar.kt diff --git a/v1_14_2/build.gradle.kts b/spigot/v1_14_2/build.gradle.kts similarity index 82% rename from v1_14_2/build.gradle.kts rename to spigot/v1_14_2/build.gradle.kts index c0f7906..3ef3192 100644 --- a/v1_14_2/build.gradle.kts +++ b/spigot/v1_14_2/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.14.1-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/ArgumentHelper.kt b/spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/ArgumentHelper.kt similarity index 100% rename from v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/ArgumentHelper.kt rename to spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/ArgumentHelper.kt diff --git a/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/BrigadierCommandHelper.kt b/spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/BrigadierCommandHelper.kt rename to spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/BrigadierCommandHelper.kt diff --git a/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandAdapter.kt b/spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandAdapter.kt similarity index 96% rename from v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandAdapter.kt rename to spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandAdapter.kt index dc3f941..bf3ae7c 100644 --- a/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandAdapter.kt +++ b/spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandAdapter.kt @@ -13,6 +13,7 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_14_R1.CommandListenerWrapper +import org.bukkit.Bukkit import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +38,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { BrigadierCommandHelper.handleExecutions(command, context) - } + }) 1 } brigadierCommand.requires { source -> @@ -79,7 +80,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +89,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandContextAdapter.kt b/spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandContextAdapter.kt similarity index 100% rename from v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandContextAdapter.kt rename to spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandContextAdapter.kt diff --git a/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandRegistrar.kt b/spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandRegistrar.kt similarity index 100% rename from v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandRegistrar.kt rename to spigot/v1_14_2/src/main/kotlin/com/undefined/stellar/v1_14_2/CommandRegistrar.kt diff --git a/v1_14_3/build.gradle.kts b/spigot/v1_14_3/build.gradle.kts similarity index 82% rename from v1_14_3/build.gradle.kts rename to spigot/v1_14_3/build.gradle.kts index faa4df5..4ae02ef 100644 --- a/v1_14_3/build.gradle.kts +++ b/spigot/v1_14_3/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.14.3-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/ArgumentHelper.kt b/spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/ArgumentHelper.kt similarity index 100% rename from v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/ArgumentHelper.kt rename to spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/ArgumentHelper.kt diff --git a/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/BrigadierCommandHelper.kt b/spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/BrigadierCommandHelper.kt similarity index 100% rename from v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/BrigadierCommandHelper.kt rename to spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/BrigadierCommandHelper.kt diff --git a/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandAdapter.kt b/spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandAdapter.kt similarity index 94% rename from v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandAdapter.kt rename to spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandAdapter.kt index f6a216e..e242aaf 100644 --- a/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandAdapter.kt +++ b/spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_14_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandContextAdapter.kt b/spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandContextAdapter.kt similarity index 100% rename from v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandContextAdapter.kt rename to spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandContextAdapter.kt diff --git a/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandRegistrar.kt b/spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandRegistrar.kt similarity index 100% rename from v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandRegistrar.kt rename to spigot/v1_14_3/src/main/kotlin/com/undefined/stellar/v1_14_3/CommandRegistrar.kt diff --git a/v1_14_4/build.gradle.kts b/spigot/v1_14_4/build.gradle.kts similarity index 82% rename from v1_14_4/build.gradle.kts rename to spigot/v1_14_4/build.gradle.kts index 4f8bfec..af801aa 100644 --- a/v1_14_4/build.gradle.kts +++ b/spigot/v1_14_4/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.14.4-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/ArgumentHelper.kt b/spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/ArgumentHelper.kt similarity index 100% rename from v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/ArgumentHelper.kt rename to spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/ArgumentHelper.kt diff --git a/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/BrigadierCommandHelper.kt b/spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/BrigadierCommandHelper.kt similarity index 100% rename from v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/BrigadierCommandHelper.kt rename to spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/BrigadierCommandHelper.kt diff --git a/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandAdapter.kt b/spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandAdapter.kt similarity index 94% rename from v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandAdapter.kt rename to spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandAdapter.kt index 665ee59..24447c6 100644 --- a/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandAdapter.kt +++ b/spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_14_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandContextAdapter.kt b/spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandContextAdapter.kt similarity index 100% rename from v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandContextAdapter.kt rename to spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandContextAdapter.kt diff --git a/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandRegistrar.kt b/spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandRegistrar.kt similarity index 100% rename from v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandRegistrar.kt rename to spigot/v1_14_4/src/main/kotlin/com/undefined/stellar/v1_14_4/CommandRegistrar.kt diff --git a/v1_15/build.gradle.kts b/spigot/v1_15/build.gradle.kts similarity index 82% rename from v1_15/build.gradle.kts rename to spigot/v1_15/build.gradle.kts index 8b339f4..d0302cb 100644 --- a/v1_15/build.gradle.kts +++ b/spigot/v1_15/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.15-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/ArgumentHelper.kt b/spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/ArgumentHelper.kt similarity index 100% rename from v1_15/src/main/kotlin/com/undefined/stellar/v1_15/ArgumentHelper.kt rename to spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/ArgumentHelper.kt diff --git a/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/BrigadierCommandHelper.kt b/spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/BrigadierCommandHelper.kt similarity index 100% rename from v1_15/src/main/kotlin/com/undefined/stellar/v1_15/BrigadierCommandHelper.kt rename to spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/BrigadierCommandHelper.kt diff --git a/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandAdapter.kt b/spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandAdapter.kt similarity index 94% rename from v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandAdapter.kt rename to spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandAdapter.kt index 4a1b2ca..5635927 100644 --- a/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandAdapter.kt +++ b/spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_15_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandContextAdapter.kt b/spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandContextAdapter.kt similarity index 100% rename from v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandContextAdapter.kt rename to spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandContextAdapter.kt diff --git a/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandRegistrar.kt b/spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandRegistrar.kt similarity index 100% rename from v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandRegistrar.kt rename to spigot/v1_15/src/main/kotlin/com/undefined/stellar/v1_15/CommandRegistrar.kt diff --git a/v1_15_1/build.gradle.kts b/spigot/v1_15_1/build.gradle.kts similarity index 82% rename from v1_15_1/build.gradle.kts rename to spigot/v1_15_1/build.gradle.kts index a1c6e86..669c26a 100644 --- a/v1_15_1/build.gradle.kts +++ b/spigot/v1_15_1/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.15.1-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/ArgumentHelper.kt b/spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/ArgumentHelper.kt similarity index 100% rename from v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/ArgumentHelper.kt rename to spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/ArgumentHelper.kt diff --git a/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/BrigadierCommandHelper.kt b/spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/BrigadierCommandHelper.kt rename to spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/BrigadierCommandHelper.kt diff --git a/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandAdapter.kt b/spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandAdapter.kt similarity index 94% rename from v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandAdapter.kt rename to spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandAdapter.kt index 5e9eef5..e53cd81 100644 --- a/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandAdapter.kt +++ b/spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_15_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandContextAdapter.kt b/spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandContextAdapter.kt similarity index 100% rename from v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandContextAdapter.kt rename to spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandContextAdapter.kt diff --git a/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandRegistrar.kt b/spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandRegistrar.kt similarity index 100% rename from v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandRegistrar.kt rename to spigot/v1_15_1/src/main/kotlin/com/undefined/stellar/v1_15_1/CommandRegistrar.kt diff --git a/v1_15_2/build.gradle.kts b/spigot/v1_15_2/build.gradle.kts similarity index 82% rename from v1_15_2/build.gradle.kts rename to spigot/v1_15_2/build.gradle.kts index b25ffea..bf99d5a 100644 --- a/v1_15_2/build.gradle.kts +++ b/spigot/v1_15_2/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/ArgumentHelper.kt b/spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/ArgumentHelper.kt similarity index 100% rename from v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/ArgumentHelper.kt rename to spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/ArgumentHelper.kt diff --git a/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/BrigadierCommandHelper.kt b/spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/BrigadierCommandHelper.kt rename to spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/BrigadierCommandHelper.kt diff --git a/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandAdapter.kt b/spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandAdapter.kt similarity index 94% rename from v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandAdapter.kt rename to spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandAdapter.kt index 4617e97..041efa0 100644 --- a/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandAdapter.kt +++ b/spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_15_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandContextAdapter.kt b/spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandContextAdapter.kt similarity index 100% rename from v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandContextAdapter.kt rename to spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandContextAdapter.kt diff --git a/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandRegistrar.kt b/spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandRegistrar.kt similarity index 100% rename from v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandRegistrar.kt rename to spigot/v1_15_2/src/main/kotlin/com/undefined/stellar/v1_15_2/CommandRegistrar.kt diff --git a/v1_16_1/build.gradle.kts b/spigot/v1_16_1/build.gradle.kts similarity index 82% rename from v1_16_1/build.gradle.kts rename to spigot/v1_16_1/build.gradle.kts index 57f17bd..cea88e4 100644 --- a/v1_16_1/build.gradle.kts +++ b/spigot/v1_16_1/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/ArgumentHelper.kt b/spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/ArgumentHelper.kt similarity index 100% rename from v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/ArgumentHelper.kt rename to spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/ArgumentHelper.kt diff --git a/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/BrigadierCommandHelper.kt b/spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/BrigadierCommandHelper.kt rename to spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/BrigadierCommandHelper.kt diff --git a/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandAdapter.kt b/spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandAdapter.kt similarity index 94% rename from v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandAdapter.kt rename to spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandAdapter.kt index 0e50a26..e9b5682 100644 --- a/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandAdapter.kt +++ b/spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_16_R1.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandContextAdapter.kt b/spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandContextAdapter.kt similarity index 100% rename from v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandContextAdapter.kt rename to spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandContextAdapter.kt diff --git a/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandRegistrar.kt b/spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandRegistrar.kt similarity index 100% rename from v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandRegistrar.kt rename to spigot/v1_16_1/src/main/kotlin/com/undefined/stellar/v1_16_1/CommandRegistrar.kt diff --git a/v1_16_2/build.gradle.kts b/spigot/v1_16_2/build.gradle.kts similarity index 82% rename from v1_16_2/build.gradle.kts rename to spigot/v1_16_2/build.gradle.kts index c1f9edd..d3ba5cf 100644 --- a/v1_16_2/build.gradle.kts +++ b/spigot/v1_16_2/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.16.2-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/ArgumentHelper.kt b/spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/ArgumentHelper.kt similarity index 100% rename from v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/ArgumentHelper.kt rename to spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/ArgumentHelper.kt diff --git a/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/BrigadierCommandHelper.kt b/spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/BrigadierCommandHelper.kt rename to spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/BrigadierCommandHelper.kt diff --git a/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandAdapter.kt b/spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandAdapter.kt similarity index 94% rename from v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandAdapter.kt rename to spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandAdapter.kt index 71dabb4..5f727f9 100644 --- a/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandAdapter.kt +++ b/spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_16_R2.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandContextAdapter.kt b/spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandContextAdapter.kt similarity index 100% rename from v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandContextAdapter.kt rename to spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandContextAdapter.kt diff --git a/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandRegistrar.kt b/spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandRegistrar.kt similarity index 100% rename from v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandRegistrar.kt rename to spigot/v1_16_2/src/main/kotlin/com/undefined/stellar/v1_16_2/CommandRegistrar.kt diff --git a/v1_16_3/build.gradle.kts b/spigot/v1_16_3/build.gradle.kts similarity index 82% rename from v1_16_3/build.gradle.kts rename to spigot/v1_16_3/build.gradle.kts index a95c372..e3e7940 100644 --- a/v1_16_3/build.gradle.kts +++ b/spigot/v1_16_3/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/ArgumentHelper.kt b/spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/ArgumentHelper.kt similarity index 100% rename from v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/ArgumentHelper.kt rename to spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/ArgumentHelper.kt diff --git a/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/BrigadierCommandHelper.kt b/spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/BrigadierCommandHelper.kt similarity index 100% rename from v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/BrigadierCommandHelper.kt rename to spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/BrigadierCommandHelper.kt diff --git a/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandAdapter.kt b/spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandAdapter.kt similarity index 94% rename from v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandAdapter.kt rename to spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandAdapter.kt index b587c31..9016c50 100644 --- a/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandAdapter.kt +++ b/spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_16_R2.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandContextAdapter.kt b/spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandContextAdapter.kt similarity index 100% rename from v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandContextAdapter.kt rename to spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandContextAdapter.kt diff --git a/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandRegistrar.kt b/spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandRegistrar.kt similarity index 100% rename from v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandRegistrar.kt rename to spigot/v1_16_3/src/main/kotlin/com/undefined/stellar/v1_16_3/CommandRegistrar.kt diff --git a/v1_16_4/build.gradle.kts b/spigot/v1_16_4/build.gradle.kts similarity index 82% rename from v1_16_4/build.gradle.kts rename to spigot/v1_16_4/build.gradle.kts index 2297679..9ae0503 100644 --- a/v1_16_4/build.gradle.kts +++ b/spigot/v1_16_4/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/ArgumentHelper.kt b/spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/ArgumentHelper.kt similarity index 100% rename from v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/ArgumentHelper.kt rename to spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/ArgumentHelper.kt diff --git a/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/BrigadierCommandHelper.kt b/spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/BrigadierCommandHelper.kt similarity index 100% rename from v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/BrigadierCommandHelper.kt rename to spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/BrigadierCommandHelper.kt diff --git a/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandAdapter.kt b/spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandAdapter.kt similarity index 94% rename from v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandAdapter.kt rename to spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandAdapter.kt index 8cddaac..b45ec2a 100644 --- a/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandAdapter.kt +++ b/spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_16_R3.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandContextAdapter.kt b/spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandContextAdapter.kt similarity index 100% rename from v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandContextAdapter.kt rename to spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandContextAdapter.kt diff --git a/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandRegistrar.kt b/spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandRegistrar.kt similarity index 100% rename from v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandRegistrar.kt rename to spigot/v1_16_4/src/main/kotlin/com/undefined/stellar/v1_16_4/CommandRegistrar.kt diff --git a/v1_16_5/build.gradle.kts b/spigot/v1_16_5/build.gradle.kts similarity index 82% rename from v1_16_5/build.gradle.kts rename to spigot/v1_16_5/build.gradle.kts index 1fa35e6..9168d82 100644 --- a/v1_16_5/build.gradle.kts +++ b/spigot/v1_16_5/build.gradle.kts @@ -8,7 +8,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } } diff --git a/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/ArgumentHelper.kt b/spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/ArgumentHelper.kt similarity index 100% rename from v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/ArgumentHelper.kt rename to spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/ArgumentHelper.kt diff --git a/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/BrigadierCommandHelper.kt b/spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/BrigadierCommandHelper.kt similarity index 100% rename from v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/BrigadierCommandHelper.kt rename to spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/BrigadierCommandHelper.kt diff --git a/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandAdapter.kt b/spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandAdapter.kt similarity index 94% rename from v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandAdapter.kt rename to spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandAdapter.kt index 290a13b..625c7ce 100644 --- a/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandAdapter.kt +++ b/spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.server.v1_16_R3.CommandListenerWrapper +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -37,9 +39,9 @@ object CommandAdapter { private fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandContextAdapter.kt b/spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandContextAdapter.kt similarity index 100% rename from v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandContextAdapter.kt rename to spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandContextAdapter.kt diff --git a/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandRegistrar.kt b/spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandRegistrar.kt similarity index 100% rename from v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandRegistrar.kt rename to spigot/v1_16_5/src/main/kotlin/com/undefined/stellar/v1_16_5/CommandRegistrar.kt diff --git a/v1_17/build.gradle.kts b/spigot/v1_17/build.gradle.kts similarity index 87% rename from v1_17/build.gradle.kts rename to spigot/v1_17/build.gradle.kts index cb5240d..f7bdeab 100644 --- a/v1_17/build.gradle.kts +++ b/spigot/v1_17/build.gradle.kts @@ -9,7 +9,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.17-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -20,7 +20,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.17") diff --git a/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/ArgumentHelper.kt b/spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/ArgumentHelper.kt similarity index 100% rename from v1_17/src/main/kotlin/com/undefined/stellar/v1_17/ArgumentHelper.kt rename to spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/ArgumentHelper.kt diff --git a/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/BrigadierCommandHelper.kt b/spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/BrigadierCommandHelper.kt similarity index 100% rename from v1_17/src/main/kotlin/com/undefined/stellar/v1_17/BrigadierCommandHelper.kt rename to spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/BrigadierCommandHelper.kt diff --git a/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandAdapter.kt b/spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandAdapter.kt similarity index 94% rename from v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandAdapter.kt rename to spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandAdapter.kt index 87b9965..855a4ea 100644 --- a/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandAdapter.kt +++ b/spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandContextAdapter.kt b/spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandContextAdapter.kt similarity index 100% rename from v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandContextAdapter.kt rename to spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandContextAdapter.kt diff --git a/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandRegistrar.kt b/spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandRegistrar.kt similarity index 100% rename from v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandRegistrar.kt rename to spigot/v1_17/src/main/kotlin/com/undefined/stellar/v1_17/CommandRegistrar.kt diff --git a/v1_17_1/build.gradle.kts b/spigot/v1_17_1/build.gradle.kts similarity index 86% rename from v1_17_1/build.gradle.kts rename to spigot/v1_17_1/build.gradle.kts index 796e7ae..86716b7 100644 --- a/v1_17_1/build.gradle.kts +++ b/spigot/v1_17_1/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.17.1") diff --git a/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt new file mode 100644 index 0000000..d967e9f --- /dev/null +++ b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/ArgumentHelper.kt @@ -0,0 +1,443 @@ +@file:Suppress("DEPRECATION") + +package com.undefined.stellar.v1_17_1 + +import com.mojang.brigadier.arguments.* +import com.mojang.brigadier.builder.ArgumentBuilder +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.builder.RequiredArgumentBuilder +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.context.ParsedArgument +import com.mojang.brigadier.context.StringRange +import com.mojang.brigadier.exceptions.CommandSyntaxException +import com.mojang.brigadier.suggestion.SuggestionProvider +import com.undefined.stellar.argument.AbstractStellarArgument +import com.undefined.stellar.argument.LiteralStellarArgument +import com.undefined.stellar.argument.types.block.BlockDataArgument +import com.undefined.stellar.argument.types.custom.CustomArgument +import com.undefined.stellar.argument.types.custom.ListArgument +import com.undefined.stellar.argument.types.entity.* +import com.undefined.stellar.argument.types.item.* +import com.undefined.stellar.argument.types.math.AxisArgument +import com.undefined.stellar.argument.types.misc.NamespacedKeyArgument +import com.undefined.stellar.argument.types.misc.UUIDArgument +import com.undefined.stellar.argument.types.player.GameModeArgument +import com.undefined.stellar.argument.types.primitive.* +import com.undefined.stellar.argument.types.registry.* +import com.undefined.stellar.argument.types.scoreboard.DisplaySlotArgument +import com.undefined.stellar.argument.types.scoreboard.ScoreHolderType +import com.undefined.stellar.argument.types.structure.LootTableArgument +import com.undefined.stellar.argument.types.structure.MirrorArgument +import com.undefined.stellar.argument.types.structure.StructureRotationArgument +import com.undefined.stellar.argument.types.world.* +import com.undefined.stellar.data.argument.Anchor +import com.undefined.stellar.data.argument.Operation +import com.undefined.stellar.data.argument.ParticleData +import com.undefined.stellar.exception.ArgumentVersionMismatchException +import com.undefined.stellar.exception.LiteralArgumentMismatchException +import com.undefined.stellar.exception.UnsupportedArgumentException +import com.undefined.stellar.util.NMSVersion +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.SharedSuggestionProvider +import net.minecraft.commands.arguments.* +import net.minecraft.commands.arguments.DimensionArgument +import net.minecraft.commands.arguments.EntityAnchorArgument +import net.minecraft.commands.arguments.EntityArgument +import net.minecraft.commands.arguments.ParticleArgument +import net.minecraft.commands.arguments.blocks.BlockPredicateArgument +import net.minecraft.commands.arguments.blocks.BlockStateArgument +import net.minecraft.commands.arguments.coordinates.* +import net.minecraft.commands.arguments.item.ItemArgument +import net.minecraft.commands.arguments.item.ItemPredicateArgument +import net.minecraft.commands.synchronization.SuggestionProviders +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.core.Registry +import net.minecraft.core.particles.* +import net.minecraft.network.chat.Component +import net.minecraft.resources.ResourceKey +import net.minecraft.server.level.ColumnPos +import net.minecraft.world.inventory.MenuType +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.state.pattern.BlockInWorld +import net.minecraft.world.level.gameevent.BlockPositionSource +import net.minecraft.world.phys.Vec2 +import net.minecraft.world.phys.Vec3 +import org.bukkit.* +import org.bukkit.block.Block +import org.bukkit.block.data.BlockData +import org.bukkit.craftbukkit.v1_17_R1.CraftParticle +import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData +import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack +import org.bukkit.event.inventory.InventoryType +import org.bukkit.inventory.ItemStack +import org.bukkit.scoreboard.DisplaySlot +import java.util.* +import java.util.function.Predicate + +@Suppress("UNCHECKED_CAST") +object ArgumentHelper { + + fun getLiteralArguments(argument: AbstractStellarArgument<*>): List> { + val arguments: MutableList> = mutableListOf() + for (name in argument.aliases + argument.name) + arguments.add(LiteralArgumentBuilder.literal(name)) + return arguments + } + + fun getRequiredArgumentBuilder(argument: AbstractStellarArgument<*>): RequiredArgumentBuilder { + val argumentBuilder: RequiredArgumentBuilder = RequiredArgumentBuilder.argument(argument.name, getArgumentType(argument)) + getSuggestions(argument)?.let { argumentBuilder.suggests(it) } + return argumentBuilder + } + + private fun > getSuggestions(argument: T): SuggestionProvider? = + when (argument) { + is GameEventArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.GAME_EVENT.keySet(), builder) + } + is PotionEffectTypeArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.MOB_EFFECT.keySet(), builder) + } + is VillagerProfessionArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.VILLAGER_PROFESSION.keySet(), builder) + } + is VillagerTypeArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.VILLAGER_TYPE.keySet(), builder) + } + is AttributeArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.ATTRIBUTE.keySet(), builder) + } + is FluidArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.FLUID.keySet(), builder) + } + is SoundArgument -> SuggestionProvider { context, builder -> + SuggestionProviders.AVAILABLE_SOUNDS.getSuggestions(context, builder) + } + is BiomeArgument -> SuggestionProvider { context, builder -> + SuggestionProviders.AVAILABLE_BIOMES.getSuggestions(context, builder) + } + is EntityTypeArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.ENTITY_TYPE.keySet(), builder) + } + is MemoryKeyArgument -> SuggestionProvider { _, builder -> + SharedSuggestionProvider.suggestResource(Registry.MEMORY_MODULE_TYPE.keySet(), builder) + } + else -> null + } + + private fun > getArgumentType(argument: T): ArgumentType<*> = + when (argument) { + is ListArgument<*> -> getArgumentType(argument.type) + is CustomArgument<*> -> getArgumentType(argument.type) + is StringArgument -> brigadier(argument.type) + is PhraseArgument -> brigadier(StringType.PHRASE) + is IntegerArgument -> IntegerArgumentType.integer(argument.min, argument.max) + is LongArgument -> LongArgumentType.longArg(argument.min, argument.max) + is FloatArgument -> FloatArgumentType.floatArg(argument.min, argument.max) + is DoubleArgument -> DoubleArgumentType.doubleArg(argument.min, argument.max) + is BooleanArgument -> BoolArgumentType.bool() + is com.undefined.stellar.argument.types.entity.EntityArgument -> brigadier(argument.type) + is com.undefined.stellar.argument.types.player.GameProfileArgument -> GameProfileArgument.gameProfile() + is LocationArgument -> when (argument.type) { + LocationType.LOCATION_3D -> BlockPosArgument.blockPos() + LocationType.LOCATION_2D -> ColumnPosArgument.columnPos() + LocationType.PRECISE_LOCATION_2D -> Vec3Argument.vec3() + LocationType.PRECISE_LOCATION_3D -> Vec2Argument.vec2() + } + is BlockDataArgument -> BlockStateArgument.block() + is com.undefined.stellar.argument.types.block.BlockPredicateArgument -> BlockPredicateArgument.blockPredicate() + is com.undefined.stellar.argument.types.item.ItemArgument -> ItemArgument.item() + is com.undefined.stellar.argument.types.item.ItemPredicateArgument -> ItemPredicateArgument.itemPredicate() + is com.undefined.stellar.argument.types.text.ColorArgument -> ColorArgument.color() + is com.undefined.stellar.argument.types.text.ComponentArgument -> ComponentArgument.textComponent() + is com.undefined.stellar.argument.types.text.StyleArgument -> throwArgumentVersionException(argument) + is com.undefined.stellar.argument.types.text.MessageArgument -> MessageArgument.message() + is com.undefined.stellar.argument.types.scoreboard.ObjectiveArgument -> ObjectiveArgument.objective() + is com.undefined.stellar.argument.types.scoreboard.ObjectiveCriteriaArgument -> ObjectiveCriteriaArgument.criteria() + is com.undefined.stellar.argument.types.math.OperationArgument -> OperationArgument.operation() + is com.undefined.stellar.argument.types.world.ParticleArgument -> ParticleArgument.particle() + is com.undefined.stellar.argument.types.math.AngleArgument -> AngleArgument.angle() + is com.undefined.stellar.argument.types.math.RotationArgument -> RotationArgument.rotation() + is DisplaySlotArgument -> ScoreboardSlotArgument.displaySlot() + is com.undefined.stellar.argument.types.scoreboard.ScoreHolderArgument -> when (argument.type) { + ScoreHolderType.SINGLE -> ScoreHolderArgument.scoreHolder() + ScoreHolderType.MULTIPLE -> ScoreHolderArgument.scoreHolders() + } + is AxisArgument -> SwizzleArgument.swizzle() + is com.undefined.stellar.argument.types.scoreboard.TeamArgument -> TeamArgument.team() + is ItemSlotArgument -> SlotArgument.slot() + is ItemSlotsArgument -> throwArgumentVersionException(argument) + is NamespacedKeyArgument -> ResourceLocationArgument.id() + is com.undefined.stellar.argument.types.entity.EntityAnchorArgument -> EntityAnchorArgument.anchor() + is com.undefined.stellar.argument.types.math.RangeArgument -> RangeArgument.intRange() + is com.undefined.stellar.argument.types.world.DimensionArgument -> DimensionArgument.dimension() + is GameModeArgument -> throwArgumentVersionException(argument) + is com.undefined.stellar.argument.types.math.TimeArgument -> TimeArgument.time() + is MirrorArgument -> throwArgumentVersionException(argument) + is StructureRotationArgument -> throwArgumentVersionException(argument) + is HeightMapArgument -> throwArgumentVersionException(argument) + is LootTableArgument -> throwArgumentVersionException(argument) + is UUIDArgument -> UuidArgument.uuid() + is GameEventArgument -> ResourceLocationArgument.id() + is StructureTypeArgument -> throwArgumentVersionException(argument) + is PotionEffectTypeArgument -> throwArgumentVersionException(argument) + is BlockTypeArgument -> throwArgumentVersionException(argument) + is ItemTypeArgument -> throwArgumentVersionException(argument) + is CatTypeArgument -> throwArgumentVersionException(argument) + is FrogVariantArgument -> throwArgumentVersionException(argument) + is VillagerProfessionArgument -> ResourceLocationArgument.id() + is VillagerTypeArgument -> ResourceLocationArgument.id() + is MapDecorationTypeArgument -> throwArgumentVersionException(argument) + is InventoryTypeArgument -> throwArgumentVersionException(argument) + is AttributeArgument -> ResourceLocationArgument.id() + is FluidArgument -> ResourceLocationArgument.id() + is SoundArgument -> ResourceLocationArgument.id() + is BiomeArgument -> ResourceLocationArgument.id() + is StructureArgument -> throwArgumentVersionException(argument) + is TrimMaterialArgument -> throwArgumentVersionException(argument) + is TrimPatternArgument -> throwArgumentVersionException(argument) + is DamageTypeArgument -> throwArgumentVersionException(argument) + is WolfVariantArgument -> throwArgumentVersionException(argument) + is PatternTypeArgument -> throwArgumentVersionException(argument) + is ArtArgument -> throwArgumentVersionException(argument) + is InstrumentArgument -> throwArgumentVersionException(argument) + is EntityTypeArgument -> ResourceLocationArgument.id() + is PotionArgument -> throwArgumentVersionException(argument) + is MemoryKeyArgument -> ResourceLocationArgument.id() + else -> throw UnsupportedArgumentException(argument) + } + + fun > getParsedArgument(context: CommandContext, argument: T): Any? { + return when (argument) { + is LiteralStellarArgument -> throw LiteralArgumentMismatchException() + is CustomArgument<*> -> argument.parse(CommandContextAdapter.getStellarCommandContext(context)) + is StringArgument -> StringArgumentType.getString(context, argument.name) + is IntegerArgument -> IntegerArgumentType.getInteger(context, argument.name) + is LongArgument -> LongArgumentType.getLong(context, argument.name) + is FloatArgument -> FloatArgumentType.getFloat(context, argument.name) + is DoubleArgument -> DoubleArgumentType.getDouble(context, argument.name) + is BooleanArgument -> BoolArgumentType.getBool(context, argument.name) + is ListArgument<*> -> argument.parse(getParsedArgument(context, argument)) + is com.undefined.stellar.argument.types.entity.EntityArgument -> EntityArgument.getEntities(context, argument.name) + .map { it.bukkitEntity }.toMutableList() + .addAll(listOf(EntityArgument.getEntity(context, argument.name).bukkitEntity)) + is com.undefined.stellar.argument.types.player.GameProfileArgument -> GameProfileArgument.getGameProfiles(context, argument.name) + is LocationArgument -> getLocation(context, argument) + is BlockDataArgument -> CraftBlockData.fromData(BlockStateArgument.getBlock(context, argument.name).state) + is com.undefined.stellar.argument.types.block.BlockPredicateArgument -> Predicate { block: Block -> + BlockPredicateArgument.getBlockPredicate(context, argument.name).test(BlockInWorld( + context.source.level, + BlockPos(block.x, block.y, block.z), true + )) + } + is com.undefined.stellar.argument.types.item.ItemArgument -> CraftItemStack.asBukkitCopy(ItemArgument.getItem(context, argument.name).createItemStack(1, false)) + is com.undefined.stellar.argument.types.item.ItemPredicateArgument -> Predicate { item: ItemStack -> + ItemPredicateArgument.getItemPredicate(context, argument.name).test(CraftItemStack.asNMSCopy(item)) + } + is com.undefined.stellar.argument.types.text.ColorArgument -> ChatColor.getByChar(ColorArgument.getColor(context, argument.name).char) + is com.undefined.stellar.argument.types.text.ComponentArgument -> GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(ComponentArgument.getComponent(context, argument.name))) + is com.undefined.stellar.argument.types.text.StyleArgument -> GsonComponentSerializer.gson().deserialize( + getArgumentInput(context, argument.name) ?: return null).style() + is com.undefined.stellar.argument.types.text.MessageArgument -> GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(MessageArgument.getMessage(context, argument.name))) + is com.undefined.stellar.argument.types.scoreboard.ObjectiveArgument -> Bukkit.getScoreboardManager()!!.mainScoreboard.getObjective(ObjectiveArgument.getObjective(context, argument.name).name) + is com.undefined.stellar.argument.types.scoreboard.ObjectiveCriteriaArgument -> ObjectiveCriteriaArgument.getCriteria(context, argument.name).name + is com.undefined.stellar.argument.types.math.OperationArgument -> Operation.getOperation(getArgumentInput(context, argument.name) ?: return null) + is com.undefined.stellar.argument.types.world.ParticleArgument -> { + val particleOptions = ParticleArgument.getParticle(context, argument.name) + getParticleData(context, CraftParticle.toBukkit(particleOptions.type), particleOptions) + } + is com.undefined.stellar.argument.types.math.AngleArgument -> AngleArgument.getAngle(context, argument.name) + is com.undefined.stellar.argument.types.math.RotationArgument -> { + val rotation = RotationArgument.getRotation(context, argument.name).getPosition(context.source) + Location(context.source.level.world, rotation.x, rotation.y, rotation.z) + } + is DisplaySlotArgument -> getBukkitDisplaySlot(ScoreboardSlotArgument.getDisplaySlot(context, argument.name)) + is com.undefined.stellar.argument.types.scoreboard.ScoreHolderArgument -> when (argument.type) { + ScoreHolderType.SINGLE -> ScoreHolderArgument.getName(context, argument.name) + ScoreHolderType.MULTIPLE -> ScoreHolderArgument.getNames(context, argument.name) + } + is AxisArgument -> getBukkitAxis(SwizzleArgument.getSwizzle(context, argument.name)) + is com.undefined.stellar.argument.types.scoreboard.TeamArgument -> Bukkit.getScoreboardManager()!!.mainScoreboard.getTeam(TeamArgument.getTeam(context, argument.name).name) + is ItemSlotArgument -> SlotArgument.getSlot(context, argument.name) + is ItemSlotsArgument -> throwArgumentVersionException(argument) + is NamespacedKeyArgument -> NamespacedKey(ResourceLocationArgument.getId(context, argument.name).namespace, ResourceLocationArgument.getId(context, argument.name).path) + is com.undefined.stellar.argument.types.entity.EntityAnchorArgument -> Anchor.getFromName(getArgumentInput(context, argument.name) ?: return null) + is com.undefined.stellar.argument.types.math.RangeArgument -> { + val range = RangeArgument.Ints.getRange(context, argument.name) + IntRange(range.min ?: 1, range.max ?: 2) + } + is com.undefined.stellar.argument.types.world.DimensionArgument -> DimensionArgument.getDimension(context, argument.name).world.environment + is GameModeArgument -> throwArgumentVersionException(argument) + is com.undefined.stellar.argument.types.math.TimeArgument -> IntegerArgumentType.getInteger(context, argument.name).toLong() + is MirrorArgument -> throwArgumentVersionException(argument) + is StructureRotationArgument -> throwArgumentVersionException(argument) + is HeightMapArgument -> throwArgumentVersionException(argument) + is LootTableArgument -> throwArgumentVersionException(argument) + is UUIDArgument -> UuidArgument.getUuid(context, argument.name) + is GameEventArgument -> org.bukkit.Registry.GAME_EVENT.get(getId(context, argument.name)) + is StructureTypeArgument -> throwArgumentVersionException(argument) + is PotionEffectTypeArgument -> throwArgumentVersionException(argument) + is BlockTypeArgument -> throwArgumentVersionException(argument) + is ItemTypeArgument -> throwArgumentVersionException(argument) + is CatTypeArgument -> throwArgumentVersionException(argument) + is FrogVariantArgument -> throwArgumentVersionException(argument) + is VillagerProfessionArgument -> org.bukkit.Registry.VILLAGER_PROFESSION.get(getId(context, argument.name)) + is VillagerTypeArgument -> org.bukkit.Registry.VILLAGER_TYPE.get(getId(context, argument.name)) + is MapDecorationTypeArgument -> throwArgumentVersionException(argument) + is InventoryTypeArgument -> getInventoryType(Registry.MENU.getOrThrow(ResourceKey.create(Registry.MENU_REGISTRY, ResourceLocationArgument.getId(context, argument.name)))) + is AttributeArgument -> org.bukkit.Registry.ATTRIBUTE.get(getId(context, argument.name)) + is FluidArgument -> org.bukkit.Registry.FLUID.get(getId(context, argument.name)) + is SoundArgument -> org.bukkit.Registry.SOUNDS.get(getId(context, argument.name)) + is BiomeArgument -> org.bukkit.Registry.BIOME.get(getId(context, argument.name)) + is StructureArgument -> throwArgumentVersionException(argument) + is TrimMaterialArgument -> throwArgumentVersionException(argument) + is TrimPatternArgument -> throwArgumentVersionException(argument) + is DamageTypeArgument -> throwArgumentVersionException(argument) + is WolfVariantArgument -> throwArgumentVersionException(argument) + is PatternTypeArgument -> throwArgumentVersionException(argument) + is ArtArgument -> throwArgumentVersionException(argument) + is InstrumentArgument -> throwArgumentVersionException(argument) + is EntityTypeArgument -> org.bukkit.Registry.ENTITY_TYPE.get(getId(context, argument.name)) + is PotionArgument -> throwArgumentVersionException(argument) + is MemoryKeyArgument -> org.bukkit.Registry.MEMORY_MODULE_TYPE.get(getId(context, argument.name)) + else -> throw UnsupportedArgumentException(argument) + } + } + + fun getArgumentInput(context: CommandContext, name: String): String? { + val field = CommandContext::class.java.getDeclaredField("arguments") + field.isAccessible = true + val arguments: Map> = field.get(context) as Map> + val argument = arguments[name] ?: return null + val range = StringRange.between(argument.range.start, context.input.length) + return range.get(context.input) + } + + private fun getInventoryType(menu: MenuType<*>): InventoryType = when (menu) { + MenuType.GENERIC_9x1 -> InventoryType.CHEST + MenuType.GENERIC_9x2 -> InventoryType.CHEST + MenuType.GENERIC_9x3 -> InventoryType.CHEST + MenuType.GENERIC_9x4 -> InventoryType.CHEST + MenuType.GENERIC_9x5 -> InventoryType.CHEST + MenuType.GENERIC_9x6 -> InventoryType.CHEST + MenuType.GENERIC_3x3 -> InventoryType.WORKBENCH + MenuType.ANVIL -> InventoryType.ANVIL + MenuType.BEACON -> InventoryType.BEACON + MenuType.BLAST_FURNACE -> InventoryType.BLAST_FURNACE + MenuType.BREWING_STAND -> InventoryType.BREWING + MenuType.CRAFTING -> InventoryType.CRAFTING + MenuType.ENCHANTMENT -> InventoryType.ENCHANTING + MenuType.FURNACE -> InventoryType.FURNACE + MenuType.GRINDSTONE -> InventoryType.GRINDSTONE + MenuType.HOPPER -> InventoryType.HOPPER + MenuType.LECTERN -> InventoryType.LECTERN + MenuType.LOOM -> InventoryType.LOOM + MenuType.MERCHANT -> InventoryType.MERCHANT + MenuType.SHULKER_BOX -> InventoryType.SHULKER_BOX + MenuType.SMITHING -> InventoryType.SMITHING + MenuType.SMOKER -> InventoryType.SMOKER + MenuType.CARTOGRAPHY_TABLE -> InventoryType.CARTOGRAPHY + MenuType.STONECUTTER -> InventoryType.STONECUTTER + else -> throw IllegalStateException("No inventory type found! This is not intentional behaviour, please contact the developers.") + } + + @Throws(CommandSyntaxException::class) + private fun getId( + context: CommandContext, + name: String + ): NamespacedKey { + val key = ResourceLocationArgument.getId(context, name) + return NamespacedKey(key.namespace, key.path) + } + + private fun brigadier(type: StringType): StringArgumentType = when (type) { + StringType.WORD -> StringArgumentType.word() + StringType.QUOTABLE_PHRASE -> StringArgumentType.string() + StringType.PHRASE -> StringArgumentType.greedyString() + } + + private fun brigadier(type: EntityDisplayType): EntityArgument = when (type) { + EntityDisplayType.ENTITY -> EntityArgument.entity() + EntityDisplayType.ENTITIES -> EntityArgument.entities() + EntityDisplayType.PLAYER -> EntityArgument.player() + EntityDisplayType.PLAYERS -> EntityArgument.players() + } + + private fun getBukkitAxis(argument: EnumSet): EnumSet = + argument.mapTo(EnumSet.noneOf(Axis::class.java)) { + when (it) { + Direction.Axis.X -> Axis.X + Direction.Axis.Y -> Axis.Y + Direction.Axis.Z -> Axis.Z + null -> Axis.X + } + } + + private fun getBukkitDisplaySlot(slot: Int): DisplaySlot = when (slot) { + 0 -> DisplaySlot.PLAYER_LIST + 2 -> DisplaySlot.BELOW_NAME + else -> DisplaySlot.SIDEBAR + } + + private fun getParticleData(context: CommandContext, particle: Particle, particleOptions: ParticleOptions): ParticleData<*> = when (particleOptions) { + is SimpleParticleType -> ParticleData(particle, null) + is BlockParticleOption -> ParticleData(particle, CraftBlockData.fromData(particleOptions.state)) + is DustColorTransitionOptions -> { + val fromColor = Color.fromRGB( + (particleOptions.fromColor.x() * 255.0f).toInt(), + (particleOptions.fromColor.y() * 255.0f).toInt(), + (particleOptions.fromColor.z() * 255.0f).toInt() + ) + val toColor = Color.fromRGB( + (particleOptions.toColor.x() * 255.0f).toInt(), + (particleOptions.toColor.y() * 255.0f).toInt(), + (particleOptions.toColor.z() * 255.0f).toInt() + ) + ParticleData(particle, Particle.DustTransition(fromColor, toColor, particleOptions.scale)) + } + is DustParticleOptions -> ParticleData( + particle, + Particle.DustOptions(Color.fromRGB( + (particleOptions.color.x() * 255.0f).toInt(), + (particleOptions.color.y() * 255.0f).toInt(), (particleOptions.color.z() * 255.0f).toInt() + ), particleOptions.scale) + ) + is ItemParticleOption -> ParticleData( + particle, + CraftItemStack.asBukkitCopy(particleOptions.item) + ) + is VibrationParticleOption -> { + val level: Level = context.source.level + + if (particleOptions.vibrationPath.destination is BlockPositionSource) { + val to = particleOptions.vibrationPath.destination.getPosition(level).get().toLocation(level.world) + val destination = Vibration.Destination.BlockDestination(Location(level.world, to.x, to.y, to.z)) + ParticleData(particle, Vibration(to, destination, particleOptions.vibrationPath.arrivalInTicks)) + } else { + ParticleData(particle, null) + } + } + else -> ParticleData(particle, null) + } + + private fun getLocation(context: CommandContext, command: LocationArgument): Location { + val world = context.source.level.world + return when (command.type) { + LocationType.LOCATION_3D -> context.getArgument(command.name, Coordinates::class.java).getBlockPos(context.source).toLocation(world); + LocationType.LOCATION_2D -> ColumnPosArgument.getColumnPos(context, command.name).toLocation(world) + LocationType.PRECISE_LOCATION_3D -> Vec3Argument.getVec3(context, command.name).toLocation(world) + LocationType.PRECISE_LOCATION_2D -> Vec2Argument.getVec2(context, command.name).toLocation(world) + } + } + + private fun BlockPos.toLocation(world: World?) = Location(world, x.toDouble(), y.toDouble(), z.toDouble()) + private fun ColumnPos.toLocation(world: World?) = Location(world, x.toDouble(), 0.0, z.toDouble()) + private fun Vec3.toLocation(world: World?) = Location(world, x, y, z) + private fun Vec2.toLocation(world: World?) = Location(world, x.toDouble(), 0.0, y.toDouble()) + + private fun throwArgumentVersionException(argument: AbstractStellarArgument<*>): Nothing = + throw ArgumentVersionMismatchException(argument, NMSVersion.version) + +} \ No newline at end of file diff --git a/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt new file mode 100644 index 0000000..c6baa95 --- /dev/null +++ b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/BrigadierCommandHelper.kt @@ -0,0 +1,96 @@ +package com.undefined.stellar.v1_17_1 + +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.context.CommandContext +import com.mojang.brigadier.suggestion.Suggestions +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import com.mojang.brigadier.tree.LiteralCommandNode +import com.undefined.stellar.AbstractStellarCommand +import com.undefined.stellar.argument.AbstractStellarArgument +import com.undefined.stellar.data.help.CustomCommandHelpTopic +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.minecraft.commands.CommandSourceStack +import net.minecraft.server.MinecraftServer +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable +import java.util.concurrent.CompletableFuture + +object BrigadierCommandHelper { + + val COMMAND_SOURCE: CommandSourceStack by lazy { + MinecraftServer.getServer().createCommandSourceStack() + } + val dispatcher by lazy { MinecraftServer.getServer().functions.dispatcher } + + fun register(command: LiteralArgumentBuilder): LiteralCommandNode? = + dispatcher.register(command) + + fun handleHelpTopic(command: AbstractStellarCommand<*>) { + Bukkit.getServer().helpMap.addTopic( + CustomCommandHelpTopic(command.name, command.description, command.helpTopic) { + val context = MinecraftServer.getServer().createCommandSourceStack() + val requirements = command.requirements.all { it(this) } + val permissionRequirements = command.permissionRequirements.all { + if (it.permission.isEmpty()) context.hasPermission(it.level) + else context.hasPermission(it.level, it.permission) + } + requirements.and(permissionRequirements) + } + ) + } + + fun handleExecutions(command: AbstractStellarCommand<*>, context: CommandContext) { + val stellarContext = CommandContextAdapter.getStellarCommandContext(context) + + for (runnable in command.base.runnables) runnable(stellarContext) + val arguments = getArguments(command.base, context) + for (argument in arguments) for (runnable in argument.runnables) runnable(stellarContext) + for (execution in command.executions) execution(stellarContext) + } + + fun fulfillsRequirements(command: AbstractStellarCommand<*>, source: CommandSourceStack): Boolean { + val fulfillsExecutionRequirements = command.requirements.all { it(source.bukkitSender) } + val fulfillsPermissionRequirements = command.permissionRequirements.all { source.hasPermission(it.level, it.permission) } + return fulfillsExecutionRequirements.and(fulfillsPermissionRequirements) + } + + fun handleSuggestions( + command: AbstractStellarArgument<*>, + context: CommandContext, + builder: SuggestionsBuilder + ): CompletableFuture { + val stellarContext = CommandContextAdapter.getStellarCommandContext(context) + val completions: CompletableFuture> = CompletableFuture.supplyAsync { + val suggestions: MutableList = mutableListOf() + for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get()) + suggestions + } + return CommandAdapter.getMojangSuggestions(builder, completions) + } + + fun handleFailureMessageAndExecutions(command: AbstractStellarCommand<*>, context: CommandContext) { + for (execution in command.failureExecutions) execution(CommandContextAdapter.getStellarCommandContext(context)) + for (message in command.failureMessages) context.source.bukkitSender.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)) + for (message in command.globalFailureMessages) context.source.bukkitSender.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)) + } + + fun getArguments( + baseCommand: AbstractStellarCommand<*>, + context: CommandContext, + currentIndex: Int = 1, + listOfArguments: List> = emptyList() + ): List> { + if (listOfArguments.size == context.nodes.size - 1) return listOfArguments + for (argument in baseCommand.arguments) + if (argument.name == context.nodes[currentIndex].node.name) + return getArguments(argument, context, currentIndex + 1, listOfArguments + argument) + return emptyList() + } + +} + +fun sync(execution: () -> Unit) { + object : BukkitRunnable() { + override fun run() = execution() + }.runTask(CommandRegistrar.plugin) +} \ No newline at end of file diff --git a/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt new file mode 100644 index 0000000..98509ce --- /dev/null +++ b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandAdapter.kt @@ -0,0 +1,122 @@ +package com.undefined.stellar.v1_17_1 + +import com.mojang.brigadier.Command +import com.mojang.brigadier.builder.ArgumentBuilder +import com.mojang.brigadier.builder.LiteralArgumentBuilder +import com.mojang.brigadier.builder.RequiredArgumentBuilder +import com.mojang.brigadier.context.StringRange +import com.mojang.brigadier.suggestion.Suggestions +import com.mojang.brigadier.suggestion.SuggestionsBuilder +import com.undefined.stellar.AbstractStellarCommand +import com.undefined.stellar.argument.AbstractStellarArgument +import com.undefined.stellar.argument.LiteralStellarArgument +import com.undefined.stellar.argument.types.primitive.PhraseArgument +import com.undefined.stellar.data.suggestion.Suggestion +import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable +import java.util.concurrent.CompletableFuture + +object CommandAdapter { + + fun getBaseCommand(command: AbstractStellarCommand<*>, name: String = command.name): LiteralArgumentBuilder { + val brigadierCommand = LiteralArgumentBuilder.literal(name) + handleCommandFunctions(command, brigadierCommand) + handleArguments(command, brigadierCommand) + return brigadierCommand + } + + fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { + if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) + brigadierCommand.executes { context -> + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) + 1 + } + brigadierCommand.requires { source -> + BrigadierCommandHelper.fulfillsRequirements(command, source) + } + + if (command !is AbstractStellarArgument || command.suggestions.isEmpty() || brigadierCommand !is RequiredArgumentBuilder) return + brigadierCommand.suggests { context, builder -> + BrigadierCommandHelper.handleSuggestions(command, context, builder) + } + } + + fun handleArguments(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { + for (argument in command.arguments) { + when (argument) { + is LiteralStellarArgument -> handleLiteralArgument(argument, brigadierCommand) + is PhraseArgument-> handlePhraseArgument(argument, brigadierCommand) + else -> handleRequiredArgument(argument, brigadierCommand) + } + } + } + + fun getMojangSuggestions(builder: SuggestionsBuilder, suggestionsFuture: CompletableFuture>): CompletableFuture { + val range = StringRange.between(builder.start, builder.input.length) + val future = suggestionsFuture.thenApplyAsync { suggestions -> + Suggestions(range, suggestions.map { suggestion -> + com.mojang.brigadier.suggestion.Suggestion(range, suggestion.text) { suggestion.tooltip } + }) + } + return future + } + + private fun handleLiteralArgument(argument: LiteralStellarArgument, brigadierCommand: ArgumentBuilder) { + for (argumentBuilder in ArgumentHelper.getLiteralArguments(argument)) { + handleCommandFunctions(argument, argumentBuilder) + handleArguments(argument, argumentBuilder) + brigadierCommand.then(argumentBuilder) + } + } + + private fun handlePhraseArgument(argument: PhraseArgument, brigadierCommand: ArgumentBuilder) { + val argumentBuilder = ArgumentHelper.getRequiredArgumentBuilder(argument) + handleCommandFunctions(argument, argumentBuilder) + handleGreedyStringWordFunctions(argument, argumentBuilder) + brigadierCommand.then(argumentBuilder) + } + + private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { + argumentBuilder.executes { context -> + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { + val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) + + for (i in greedyContext.arguments.indices) { + val word = argument.words[i] ?: continue + for (runnable in word.runnables) runnable(greedyContext) + if (i == greedyContext.arguments.lastIndex) + for (execution in word.executions) execution(greedyContext) + } + }) + Command.SINGLE_SUCCESS + } + + argumentBuilder.suggests { context, builder -> + val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) + var prevChar = ' ' + val input = ArgumentHelper.getArgumentInput(context, argument.name) ?: "" + val amountOfSpaces: Int = if (input.isEmpty()) 0 else input.count { + if (prevChar == ' ' && it == ' ') return@count false + prevChar = it + it == ' ' + } + val newBuilder = builder.createOffset(builder.input.lastIndexOf(' ') + 1) + val word = argument.words[amountOfSpaces] ?: return@suggests newBuilder.buildFuture() + for (stellarSuggestion in word.suggestions) + for (suggestion in stellarSuggestion.get(greedyContext)) + newBuilder.suggest(suggestion.text) { suggestion.tooltip } + newBuilder.buildFuture() + } + } + + private fun handleRequiredArgument(argument: AbstractStellarArgument<*>, brigadierCommand: ArgumentBuilder) { + val argumentBuilder = ArgumentHelper.getRequiredArgumentBuilder(argument) + handleCommandFunctions(argument, argumentBuilder) + handleArguments(argument, argumentBuilder) + brigadierCommand.then(argumentBuilder) + } + +} diff --git a/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt new file mode 100644 index 0000000..b63b2f2 --- /dev/null +++ b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandContextAdapter.kt @@ -0,0 +1,89 @@ +package com.undefined.stellar.v1_17_1 + +import com.mojang.brigadier.context.CommandContext +import com.undefined.stellar.AbstractStellarCommand +import com.undefined.stellar.StellarCommands +import com.undefined.stellar.argument.AbstractStellarArgument +import com.undefined.stellar.argument.LiteralStellarArgument +import com.undefined.stellar.argument.types.custom.CustomArgument +import com.undefined.stellar.data.argument.CommandNode +import com.undefined.stellar.data.argument.PhraseCommandContext +import com.undefined.stellar.exception.DuplicateArgumentNameException +import com.undefined.stellar.exception.LiteralArgumentMismatchException +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.minecraft.commands.CommandSource +import net.minecraft.commands.CommandSourceStack +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.TextComponent +import net.minecraft.server.MinecraftServer +import net.minecraft.world.phys.Vec2 +import net.minecraft.world.phys.Vec3 +import org.bukkit.command.CommandSender +import java.util.* + +object CommandContextAdapter { + + fun getStellarCommandContext(context: CommandContext): com.undefined.stellar.data.argument.CommandContext { + val input = context.input.removePrefix("/") + val baseCommand: AbstractStellarCommand<*> = StellarCommands.getStellarCommand(context.nodes[0].node.name)!! + val arguments = BrigadierCommandHelper.getArguments(baseCommand, context) + if (arguments.filter { it !is LiteralStellarArgument }.groupingBy { it.name }.eachCount().any { it.value > 1 }) throw DuplicateArgumentNameException() + val parsedArguments: CommandNode = + BrigadierCommandHelper.getArguments(baseCommand, context) + .associate, String, (com.undefined.stellar.data.argument.CommandContext) -> Any?> { argument -> + if (argument is CustomArgument) return@associate Pair(argument.name) { argument.parse(it) } + if (argument is LiteralStellarArgument) return@associate Pair(argument.name) { throw LiteralArgumentMismatchException() } + Pair(argument.name) { + ArgumentHelper.getParsedArgument(context, argument) + } + } as CommandNode + return com.undefined.stellar.data.argument.CommandContext( + parsedArguments, + context.source.bukkitSender, + input + ) + } + + fun getGreedyCommandContext(context: CommandContext): PhraseCommandContext { + val input = context.input.removePrefix("/") + val words = input.split(' ').toMutableList() + + val totalOtherArguments = context.nodes.size - 1 + for (i in (1..totalOtherArguments)) words.removeFirst() + return PhraseCommandContext( + words, + context.source.bukkitSender, + input + ) + } + + fun getCommandSourceStack(sender: CommandSender): CommandSourceStack { + val overworld = MinecraftServer.getServer().overworld() + return CommandSourceStack( + Source(sender), + Vec3.atLowerCornerOf(overworld.getSharedSpawnPos()), + Vec2.ZERO, + overworld, + 4, + sender.name, + TextComponent(sender.name), + MinecraftServer.getServer(), + null + ) + } + + @Suppress("DEPRECATION") + private data class Source(val sender: CommandSender) : CommandSource { + override fun sendMessage(message: Component, uuid: UUID) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender + } + + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component)) + +} \ No newline at end of file diff --git a/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt new file mode 100644 index 0000000..c1c9f60 --- /dev/null +++ b/spigot/v1_17_1/src/main/kotlin/com/undefined/stellar/v1_17_1/CommandRegistrar.kt @@ -0,0 +1,41 @@ +package com.undefined.stellar.v1_17_1 + +import com.undefined.stellar.AbstractStellarCommand +import com.undefined.stellar.StellarCommands +import com.undefined.stellar.registrar.AbstractCommandRegistrar +import com.undefined.stellar.v1_17_1.BrigadierCommandHelper.dispatcher +import org.bukkit.command.CommandSender +import org.bukkit.plugin.java.JavaPlugin + +object CommandRegistrar : AbstractCommandRegistrar { + + lateinit var plugin: JavaPlugin + + override fun register(command: AbstractStellarCommand<*>, plugin: JavaPlugin) { + this.plugin = plugin + BrigadierCommandHelper.handleHelpTopic(command) + for (name in command.aliases + command.name) + BrigadierCommandHelper.register(CommandAdapter.getBaseCommand(command, name)) + } + + override fun handleCommandFailure(sender: CommandSender, input: String): Boolean { + val results = dispatcher.parse(input, BrigadierCommandHelper.COMMAND_SOURCE) + val context = results.context.withSource(CommandContextAdapter.getCommandSourceStack(sender)).build(input) + + if (results.reader.remainingLength == 0) return false + if (context.nodes.isEmpty()) return false + + val baseCommand: AbstractStellarCommand<*> = StellarCommands.getStellarCommand(context.nodes[0].node.name)!! + val argument = BrigadierCommandHelper.getArguments(baseCommand, context).lastOrNull() + argument?.let { + BrigadierCommandHelper.handleFailureMessageAndExecutions(argument, context) + if (argument.hideDefaultFailureMessages.hide) return true + } ?: run { + BrigadierCommandHelper.handleFailureMessageAndExecutions(baseCommand, context) + if (baseCommand.hideDefaultFailureMessages.hide) return true + } + + return baseCommand.hasGlobalHiddenDefaultFailureMessages() + } + +} \ No newline at end of file diff --git a/v1_18_1/build.gradle.kts b/spigot/v1_18_1/build.gradle.kts similarity index 86% rename from v1_18_1/build.gradle.kts rename to spigot/v1_18_1/build.gradle.kts index a799e76..d20ba5f 100644 --- a/v1_18_1/build.gradle.kts +++ b/spigot/v1_18_1/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.18.1") diff --git a/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/ArgumentHelper.kt b/spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/ArgumentHelper.kt similarity index 100% rename from v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/ArgumentHelper.kt rename to spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/ArgumentHelper.kt diff --git a/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/BrigadierCommandHelper.kt b/spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/BrigadierCommandHelper.kt rename to spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/BrigadierCommandHelper.kt diff --git a/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt b/spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt similarity index 94% rename from v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt rename to spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt index 2d97339..d5c7863 100644 --- a/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt +++ b/spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandContextAdapter.kt b/spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandContextAdapter.kt similarity index 100% rename from v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandContextAdapter.kt rename to spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandContextAdapter.kt diff --git a/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandRegistrar.kt b/spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandRegistrar.kt similarity index 100% rename from v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandRegistrar.kt rename to spigot/v1_18_1/src/main/kotlin/com/undefined/stellar/v1_18_1/CommandRegistrar.kt diff --git a/v1_18_2/build.gradle.kts b/spigot/v1_18_2/build.gradle.kts similarity index 86% rename from v1_18_2/build.gradle.kts rename to spigot/v1_18_2/build.gradle.kts index 7e54626..7cbe3da 100644 --- a/v1_18_2/build.gradle.kts +++ b/spigot/v1_18_2/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.18.2") diff --git a/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/ArgumentHelper.kt b/spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/ArgumentHelper.kt similarity index 100% rename from v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/ArgumentHelper.kt rename to spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/ArgumentHelper.kt diff --git a/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/BrigadierCommandHelper.kt b/spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/BrigadierCommandHelper.kt rename to spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/BrigadierCommandHelper.kt diff --git a/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt b/spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt similarity index 94% rename from v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt rename to spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt index fbb3472..3a15be8 100644 --- a/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt +++ b/spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandContextAdapter.kt b/spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandContextAdapter.kt similarity index 100% rename from v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandContextAdapter.kt rename to spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandContextAdapter.kt diff --git a/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandRegistrar.kt b/spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandRegistrar.kt similarity index 100% rename from v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandRegistrar.kt rename to spigot/v1_18_2/src/main/kotlin/com/undefined/stellar/v1_18_2/CommandRegistrar.kt diff --git a/v1_19_2/build.gradle.kts b/spigot/v1_19_2/build.gradle.kts similarity index 86% rename from v1_19_2/build.gradle.kts rename to spigot/v1_19_2/build.gradle.kts index 6810c34..34977c6 100644 --- a/v1_19_2/build.gradle.kts +++ b/spigot/v1_19_2/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.19.2") diff --git a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/ArgumentHelper.kt b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/ArgumentHelper.kt similarity index 100% rename from v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/ArgumentHelper.kt rename to spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/ArgumentHelper.kt diff --git a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/BrigadierCommandHelper.kt b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/BrigadierCommandHelper.kt rename to spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/BrigadierCommandHelper.kt diff --git a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt similarity index 94% rename from v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt rename to spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt index 691fd6d..1a9d626 100644 --- a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt +++ b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt similarity index 83% rename from v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt rename to spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt index 263a335..7144c3f 100644 --- a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt +++ b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandContextAdapter.kt @@ -10,8 +10,8 @@ import com.undefined.stellar.data.argument.CommandNode import com.undefined.stellar.data.argument.PhraseCommandContext import com.undefined.stellar.exception.DuplicateArgumentNameException import com.undefined.stellar.exception.LiteralArgumentMismatchException -import io.papermc.paper.adventure.PaperAdventure -import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.minecraft.commands.CommandSource import net.minecraft.commands.CommandSourceStack import net.minecraft.network.chat.Component @@ -73,25 +73,15 @@ object CommandContextAdapter { @Suppress("DEPRECATION") private data class Source(val sender: CommandSender) : CommandSource { - override fun sendSystemMessage(message: Component) { - sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) - } - - override fun acceptsSuccess(): Boolean { - return true - } - - override fun acceptsFailure(): Boolean { - return true - } - - override fun shouldInformAdmins(): Boolean { - return false - } - - override fun getBukkitSender(stack: CommandSourceStack): CommandSender { - return this.sender - } + override fun sendSystemMessage(message: Component) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender } + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component)) + } \ No newline at end of file diff --git a/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandRegistrar.kt b/spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandRegistrar.kt similarity index 100% rename from v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandRegistrar.kt rename to spigot/v1_19_2/src/main/kotlin/com/undefined/stellar/v1_19_2/CommandRegistrar.kt diff --git a/v1_19_3/build.gradle.kts b/spigot/v1_19_3/build.gradle.kts similarity index 86% rename from v1_19_3/build.gradle.kts rename to spigot/v1_19_3/build.gradle.kts index f4df40f..9a8193a 100644 --- a/v1_19_3/build.gradle.kts +++ b/spigot/v1_19_3/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.19.3") diff --git a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/ArgumentHelper.kt b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/ArgumentHelper.kt similarity index 100% rename from v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/ArgumentHelper.kt rename to spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/ArgumentHelper.kt diff --git a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/BrigadierCommandHelper.kt b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/BrigadierCommandHelper.kt similarity index 100% rename from v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/BrigadierCommandHelper.kt rename to spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/BrigadierCommandHelper.kt diff --git a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandAdapter.kt b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandAdapter.kt similarity index 94% rename from v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandAdapter.kt rename to spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandAdapter.kt index 76c0f34..f9e8ce6 100644 --- a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandAdapter.kt +++ b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandContextAdapter.kt b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandContextAdapter.kt similarity index 83% rename from v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandContextAdapter.kt rename to spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandContextAdapter.kt index db5ce7d..628d36a 100644 --- a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandContextAdapter.kt +++ b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandContextAdapter.kt @@ -10,8 +10,8 @@ import com.undefined.stellar.data.argument.CommandNode import com.undefined.stellar.data.argument.PhraseCommandContext import com.undefined.stellar.exception.DuplicateArgumentNameException import com.undefined.stellar.exception.LiteralArgumentMismatchException -import io.papermc.paper.adventure.PaperAdventure -import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.minecraft.commands.CommandSource import net.minecraft.commands.CommandSourceStack import net.minecraft.network.chat.Component @@ -73,25 +73,15 @@ object CommandContextAdapter { @Suppress("DEPRECATION") private data class Source(val sender: CommandSender) : CommandSource { - override fun sendSystemMessage(message: Component) { - sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) - } - - override fun acceptsSuccess(): Boolean { - return true - } - - override fun acceptsFailure(): Boolean { - return true - } - - override fun shouldInformAdmins(): Boolean { - return false - } - - override fun getBukkitSender(stack: CommandSourceStack): CommandSender { - return this.sender - } + override fun sendSystemMessage(message: Component) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender } + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component)) + } \ No newline at end of file diff --git a/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandRegistrar.kt b/spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandRegistrar.kt similarity index 100% rename from v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandRegistrar.kt rename to spigot/v1_19_3/src/main/kotlin/com/undefined/stellar/v1_19_3/CommandRegistrar.kt diff --git a/v1_19_4/build.gradle.kts b/spigot/v1_19_4/build.gradle.kts similarity index 87% rename from v1_19_4/build.gradle.kts rename to spigot/v1_19_4/build.gradle.kts index a40db35..8ce192e 100644 --- a/v1_19_4/build.gradle.kts +++ b/spigot/v1_19_4/build.gradle.kts @@ -9,7 +9,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -20,7 +20,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.19.4") diff --git a/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/ArgumentHelper.kt b/spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/ArgumentHelper.kt similarity index 100% rename from v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/ArgumentHelper.kt rename to spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/ArgumentHelper.kt diff --git a/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/BrigadierCommandHelper.kt b/spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/BrigadierCommandHelper.kt similarity index 100% rename from v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/BrigadierCommandHelper.kt rename to spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/BrigadierCommandHelper.kt diff --git a/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandAdapter.kt b/spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandAdapter.kt similarity index 94% rename from v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandAdapter.kt rename to spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandAdapter.kt index 9b4d5c7..ffffc3e 100644 --- a/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandAdapter.kt +++ b/spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandContextAdapter.kt b/spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandContextAdapter.kt similarity index 100% rename from v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandContextAdapter.kt rename to spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandContextAdapter.kt diff --git a/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandRegistrar.kt b/spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandRegistrar.kt similarity index 100% rename from v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandRegistrar.kt rename to spigot/v1_19_4/src/main/kotlin/com/undefined/stellar/v1_19_4/CommandRegistrar.kt diff --git a/v1_20_1/build.gradle.kts b/spigot/v1_20_1/build.gradle.kts similarity index 86% rename from v1_20_1/build.gradle.kts rename to spigot/v1_20_1/build.gradle.kts index 96625f6..2f63b1f 100644 --- a/v1_20_1/build.gradle.kts +++ b/spigot/v1_20_1/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.20.1") diff --git a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/ArgumentHelper.kt b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/ArgumentHelper.kt similarity index 100% rename from v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/ArgumentHelper.kt rename to spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/ArgumentHelper.kt diff --git a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/BrigadierCommandHelper.kt b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/BrigadierCommandHelper.kt rename to spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/BrigadierCommandHelper.kt diff --git a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandAdapter.kt b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandAdapter.kt similarity index 94% rename from v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandAdapter.kt rename to spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandAdapter.kt index 9572be4..76435c4 100644 --- a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandAdapter.kt +++ b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandContextAdapter.kt b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandContextAdapter.kt similarity index 83% rename from v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandContextAdapter.kt rename to spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandContextAdapter.kt index d2f0368..150937e 100644 --- a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandContextAdapter.kt +++ b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandContextAdapter.kt @@ -10,8 +10,8 @@ import com.undefined.stellar.data.argument.CommandNode import com.undefined.stellar.data.argument.PhraseCommandContext import com.undefined.stellar.exception.DuplicateArgumentNameException import com.undefined.stellar.exception.LiteralArgumentMismatchException -import io.papermc.paper.adventure.PaperAdventure -import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.minecraft.commands.CommandSource import net.minecraft.commands.CommandSourceStack import net.minecraft.network.chat.Component @@ -74,25 +74,15 @@ CommandContextAdapter { @Suppress("DEPRECATION") private data class Source(val sender: CommandSender) : CommandSource { - override fun sendSystemMessage(message: Component) { - sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) - } - - override fun acceptsSuccess(): Boolean { - return true - } - - override fun acceptsFailure(): Boolean { - return true - } - - override fun shouldInformAdmins(): Boolean { - return false - } - - override fun getBukkitSender(stack: CommandSourceStack): CommandSender { - return this.sender - } + override fun sendSystemMessage(message: Component) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender } + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component)) + } \ No newline at end of file diff --git a/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandRegistrar.kt b/spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandRegistrar.kt similarity index 100% rename from v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandRegistrar.kt rename to spigot/v1_20_1/src/main/kotlin/com/undefined/stellar/v1_20_1/CommandRegistrar.kt diff --git a/v1_20_2/build.gradle.kts b/spigot/v1_20_2/build.gradle.kts similarity index 86% rename from v1_20_2/build.gradle.kts rename to spigot/v1_20_2/build.gradle.kts index 9c57f71..6ac66af 100644 --- a/v1_20_2/build.gradle.kts +++ b/spigot/v1_20_2/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.20.2") diff --git a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/ArgumentHelper.kt b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/ArgumentHelper.kt similarity index 100% rename from v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/ArgumentHelper.kt rename to spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/ArgumentHelper.kt diff --git a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/BrigadierCommandHelper.kt b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/BrigadierCommandHelper.kt similarity index 100% rename from v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/BrigadierCommandHelper.kt rename to spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/BrigadierCommandHelper.kt diff --git a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandAdapter.kt b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandAdapter.kt similarity index 94% rename from v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandAdapter.kt rename to spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandAdapter.kt index 137fbe3..363a716 100644 --- a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandAdapter.kt +++ b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { if (argument.executions.isNotEmpty() || argument.executions.isNotEmpty()) argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandContextAdapter.kt b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandContextAdapter.kt similarity index 83% rename from v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandContextAdapter.kt rename to spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandContextAdapter.kt index 13c285e..66ad60e 100644 --- a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandContextAdapter.kt +++ b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandContextAdapter.kt @@ -10,8 +10,8 @@ import com.undefined.stellar.data.argument.CommandNode import com.undefined.stellar.data.argument.PhraseCommandContext import com.undefined.stellar.exception.DuplicateArgumentNameException import com.undefined.stellar.exception.LiteralArgumentMismatchException -import io.papermc.paper.adventure.PaperAdventure -import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.minecraft.commands.CommandSource import net.minecraft.commands.CommandSourceStack import net.minecraft.network.chat.Component @@ -73,25 +73,15 @@ object CommandContextAdapter { @Suppress("DEPRECATION") private data class Source(val sender: CommandSender) : CommandSource { - override fun sendSystemMessage(message: Component) { - sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) - } - - override fun acceptsSuccess(): Boolean { - return true - } - - override fun acceptsFailure(): Boolean { - return true - } - - override fun shouldInformAdmins(): Boolean { - return false - } - - override fun getBukkitSender(stack: CommandSourceStack): CommandSender { - return this.sender - } + override fun sendSystemMessage(message: Component) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender } + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component)) + } \ No newline at end of file diff --git a/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandRegistrar.kt b/spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandRegistrar.kt similarity index 100% rename from v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandRegistrar.kt rename to spigot/v1_20_2/src/main/kotlin/com/undefined/stellar/v1_20_2/CommandRegistrar.kt diff --git a/v1_20_4/build.gradle.kts b/spigot/v1_20_4/build.gradle.kts similarity index 86% rename from v1_20_4/build.gradle.kts rename to spigot/v1_20_4/build.gradle.kts index 33aa161..a487bc9 100644 --- a/v1_20_4/build.gradle.kts +++ b/spigot/v1_20_4/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.20.4") diff --git a/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/ArgumentHelper.kt b/spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/ArgumentHelper.kt similarity index 100% rename from v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/ArgumentHelper.kt rename to spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/ArgumentHelper.kt diff --git a/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/BrigadierCommandHelper.kt b/spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/BrigadierCommandHelper.kt similarity index 100% rename from v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/BrigadierCommandHelper.kt rename to spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/BrigadierCommandHelper.kt diff --git a/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandAdapter.kt b/spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandAdapter.kt similarity index 94% rename from v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandAdapter.kt rename to spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandAdapter.kt index f823f76..fde8bd9 100644 --- a/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandAdapter.kt +++ b/spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { if (argument.executions.isNotEmpty() || argument.executions.isNotEmpty()) argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandContextAdapter.kt b/spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandContextAdapter.kt similarity index 100% rename from v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandContextAdapter.kt rename to spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandContextAdapter.kt diff --git a/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandRegistrar.kt b/spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandRegistrar.kt similarity index 100% rename from v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandRegistrar.kt rename to spigot/v1_20_4/src/main/kotlin/com/undefined/stellar/v1_20_4/CommandRegistrar.kt diff --git a/v1_20_6/build.gradle.kts b/spigot/v1_20_6/build.gradle.kts similarity index 86% rename from v1_20_6/build.gradle.kts rename to spigot/v1_20_6/build.gradle.kts index a056be2..fdc7efb 100644 --- a/v1_20_6/build.gradle.kts +++ b/spigot/v1_20_6/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.20.6") diff --git a/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/ArgumentHelper.kt b/spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/ArgumentHelper.kt similarity index 100% rename from v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/ArgumentHelper.kt rename to spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/ArgumentHelper.kt diff --git a/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/BrigadierCommandHelper.kt b/spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/BrigadierCommandHelper.kt similarity index 100% rename from v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/BrigadierCommandHelper.kt rename to spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/BrigadierCommandHelper.kt diff --git a/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandAdapter.kt b/spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandAdapter.kt similarity index 94% rename from v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandAdapter.kt rename to spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandAdapter.kt index 19b46cd..75c8ceb 100644 --- a/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandAdapter.kt +++ b/spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandContextAdapter.kt b/spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandContextAdapter.kt similarity index 100% rename from v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandContextAdapter.kt rename to spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandContextAdapter.kt diff --git a/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandRegistrar.kt b/spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandRegistrar.kt similarity index 100% rename from v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandRegistrar.kt rename to spigot/v1_20_6/src/main/kotlin/com/undefined/stellar/v1_20_6/CommandRegistrar.kt diff --git a/v1_21_1/build.gradle.kts b/spigot/v1_21_1/build.gradle.kts similarity index 86% rename from v1_21_1/build.gradle.kts rename to spigot/v1_21_1/build.gradle.kts index 9ba30e9..2b39acf 100644 --- a/v1_21_1/build.gradle.kts +++ b/spigot/v1_21_1/build.gradle.kts @@ -5,7 +5,7 @@ plugins { dependencies { compileOnly("org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -16,7 +16,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.21.1") diff --git a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/ArgumentHelper.kt b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/ArgumentHelper.kt similarity index 100% rename from v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/ArgumentHelper.kt rename to spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/ArgumentHelper.kt diff --git a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/BrigadierCommandHelper.kt b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/BrigadierCommandHelper.kt similarity index 100% rename from v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/BrigadierCommandHelper.kt rename to spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/BrigadierCommandHelper.kt diff --git a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandAdapter.kt b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandAdapter.kt similarity index 94% rename from v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandAdapter.kt rename to spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandAdapter.kt index 61bba1b..ee734fb 100644 --- a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandAdapter.kt +++ b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { if (argument.executions.isNotEmpty() || argument.executions.isNotEmpty()) argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandContextAdapter.kt b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandContextAdapter.kt similarity index 82% rename from v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandContextAdapter.kt rename to spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandContextAdapter.kt index 6a296b5..f0a1ca7 100644 --- a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandContextAdapter.kt +++ b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandContextAdapter.kt @@ -10,8 +10,8 @@ import com.undefined.stellar.data.argument.CommandNode import com.undefined.stellar.data.argument.PhraseCommandContext import com.undefined.stellar.exception.DuplicateArgumentNameException import com.undefined.stellar.exception.LiteralArgumentMismatchException -import io.papermc.paper.adventure.PaperAdventure -import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.minecraft.commands.CommandSource import net.minecraft.commands.CommandSourceStack import net.minecraft.network.chat.Component @@ -73,25 +73,15 @@ object CommandContextAdapter { @Suppress("DEPRECATION") private data class Source(val sender: CommandSender) : CommandSource { - override fun sendSystemMessage(message: Component) { - sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) - } - - override fun acceptsSuccess(): Boolean { - return true - } - - override fun acceptsFailure(): Boolean { - return true - } - - override fun shouldInformAdmins(): Boolean { - return false - } - - override fun getBukkitSender(stack: CommandSourceStack): CommandSender { - return this.sender - } + override fun sendSystemMessage(message: Component) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender } + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component, BrigadierCommandHelper.COMMAND_SOURCE.registryAccess())) + } \ No newline at end of file diff --git a/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandRegistrar.kt b/spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandRegistrar.kt similarity index 100% rename from v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandRegistrar.kt rename to spigot/v1_21_1/src/main/kotlin/com/undefined/stellar/v1_21_1/CommandRegistrar.kt diff --git a/spigot/v1_21_3/build.gradle.kts b/spigot/v1_21_3/build.gradle.kts new file mode 100644 index 0000000..1daf0cf --- /dev/null +++ b/spigot/v1_21_3/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + kotlin("jvm") version "1.9.22" + id("com.undefinedcreations.mapper") version "1.1.1" +} + +dependencies { + compileOnly("org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT:remapped-mojang") + compileOnly(project(":spigot:common")) +} + +tasks { + jar { + finalizedBy(remap) + } + compileKotlin { + kotlinOptions.jvmTarget = "1.8" + } + compileJava { + options.release = 8 + } + remap { + minecraftVersion("1.21.3") + } +} + +java { + disableAutoTargetJvm() +} + +kotlin { + jvmToolchain(21) +} \ No newline at end of file diff --git a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/ArgumentHelper.kt b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/ArgumentHelper.kt similarity index 100% rename from v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/ArgumentHelper.kt rename to spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/ArgumentHelper.kt diff --git a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/BrigadierCommandHelper.kt b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/BrigadierCommandHelper.kt similarity index 100% rename from v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/BrigadierCommandHelper.kt rename to spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/BrigadierCommandHelper.kt diff --git a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandAdapter.kt b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandAdapter.kt similarity index 94% rename from v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandAdapter.kt rename to spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandAdapter.kt index 4acb13a..59d9e94 100644 --- a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandAdapter.kt +++ b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -79,7 +81,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -88,7 +90,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandContextAdapter.kt b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandContextAdapter.kt similarity index 82% rename from v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandContextAdapter.kt rename to spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandContextAdapter.kt index 5b0264e..bfed9ed 100644 --- a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandContextAdapter.kt +++ b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandContextAdapter.kt @@ -10,8 +10,8 @@ import com.undefined.stellar.data.argument.CommandNode import com.undefined.stellar.data.argument.PhraseCommandContext import com.undefined.stellar.exception.DuplicateArgumentNameException import com.undefined.stellar.exception.LiteralArgumentMismatchException -import io.papermc.paper.adventure.PaperAdventure -import net.kyori.adventure.identity.Identity +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer import net.minecraft.commands.CommandSource import net.minecraft.commands.CommandSourceStack import net.minecraft.network.chat.Component @@ -73,25 +73,15 @@ object CommandContextAdapter { @Suppress("DEPRECATION") private data class Source(val sender: CommandSender) : CommandSource { - override fun sendSystemMessage(message: Component) { - sender.sendMessage(Identity.nil(), PaperAdventure.asAdventure(message)) - } - - override fun acceptsSuccess(): Boolean { - return true - } - - override fun acceptsFailure(): Boolean { - return true - } - - override fun shouldInformAdmins(): Boolean { - return false - } - - override fun getBukkitSender(stack: CommandSourceStack): CommandSender { - return this.sender - } + override fun sendSystemMessage(message: Component) = + this.sender.sendMessage(LegacyComponentSerializer.legacySection().serialize(asAdventure(message))) + override fun acceptsSuccess(): Boolean = true + override fun acceptsFailure(): Boolean = true + override fun shouldInformAdmins(): Boolean = false + override fun getBukkitSender(stack: CommandSourceStack): CommandSender = this.sender } + fun asAdventure(component: Component): net.kyori.adventure.text.Component = + GsonComponentSerializer.gson().deserialize(Component.Serializer.toJson(component, BrigadierCommandHelper.COMMAND_SOURCE.registryAccess())) + } \ No newline at end of file diff --git a/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandRegistrar.kt b/spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandRegistrar.kt similarity index 100% rename from v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandRegistrar.kt rename to spigot/v1_21_3/src/main/kotlin/com/undefined/stellar/v1_21_3/CommandRegistrar.kt diff --git a/v1_21_4/build.gradle.kts b/spigot/v1_21_4/build.gradle.kts similarity index 87% rename from v1_21_4/build.gradle.kts rename to spigot/v1_21_4/build.gradle.kts index 1786c84..95f9bc0 100644 --- a/v1_21_4/build.gradle.kts +++ b/spigot/v1_21_4/build.gradle.kts @@ -9,7 +9,7 @@ repositories { dependencies { compileOnly("org.spigotmc:spigot:1.21.4-R0.1-SNAPSHOT:remapped-mojang") - compileOnly(project(":common")) + compileOnly(project(":spigot:common")) } tasks { @@ -20,7 +20,7 @@ tasks { kotlinOptions.jvmTarget = "1.8" } compileJava { - options.release.set(8) + options.release = 8 } remap { minecraftVersion("1.21.4") diff --git a/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/ArgumentHelper.kt b/spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/ArgumentHelper.kt similarity index 100% rename from v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/ArgumentHelper.kt rename to spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/ArgumentHelper.kt diff --git a/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/BrigadierCommandHelper.kt b/spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/BrigadierCommandHelper.kt similarity index 100% rename from v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/BrigadierCommandHelper.kt rename to spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/BrigadierCommandHelper.kt diff --git a/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandAdapter.kt b/spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandAdapter.kt similarity index 94% rename from v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandAdapter.kt rename to spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandAdapter.kt index dacdb1e..7c0b845 100644 --- a/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandAdapter.kt +++ b/spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandAdapter.kt @@ -13,6 +13,8 @@ import com.undefined.stellar.argument.LiteralStellarArgument import com.undefined.stellar.argument.types.primitive.PhraseArgument import com.undefined.stellar.data.suggestion.Suggestion import net.minecraft.commands.CommandSourceStack +import org.bukkit.Bukkit +import org.bukkit.scheduler.BukkitRunnable import java.util.concurrent.CompletableFuture object CommandAdapter { @@ -27,9 +29,9 @@ object CommandAdapter { fun handleCommandFunctions(command: AbstractStellarCommand<*>, brigadierCommand: ArgumentBuilder) { if (command.executions.isNotEmpty() || command.executions.isNotEmpty()) brigadierCommand.executes { context -> - sync { - BrigadierCommandHelper.handleExecutions(command, context) - } + object : BukkitRunnable() { + override fun run() = BrigadierCommandHelper.handleExecutions(command, context) + }.runTask(CommandRegistrar.plugin) 1 } brigadierCommand.requires { source -> @@ -82,7 +84,7 @@ object CommandAdapter { private fun handleGreedyStringWordFunctions(argument: PhraseArgument, argumentBuilder: RequiredArgumentBuilder) { if (argument.executions.isNotEmpty() || argument.executions.isNotEmpty()) argumentBuilder.executes { context -> - sync { + Bukkit.getScheduler().runTask(CommandRegistrar.plugin, Runnable { val greedyContext = CommandContextAdapter.getGreedyCommandContext(context) for (i in greedyContext.arguments.indices) { @@ -91,7 +93,7 @@ object CommandAdapter { if (i == greedyContext.arguments.lastIndex) for (execution in word.executions) execution(greedyContext) } - } + }) Command.SINGLE_SUCCESS } diff --git a/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandContextAdapter.kt b/spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandContextAdapter.kt similarity index 100% rename from v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandContextAdapter.kt rename to spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandContextAdapter.kt diff --git a/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandRegistrar.kt b/spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandRegistrar.kt similarity index 100% rename from v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandRegistrar.kt rename to spigot/v1_21_4/src/main/kotlin/com/undefined/stellar/v1_21_4/CommandRegistrar.kt