-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/more bridges #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/more bridges #210
Changes from all commits
51983e2
d85621b
aa0e6f0
cdb7ae6
7d15043
31a7c36
29b6dc8
236cbe7
2d19afe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||
| import gradle.kotlin.dsl.accessors._bcd9a993373509de50154c5485fe667f.java | ||||||
| import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension | ||||||
|
|
||||||
| val javaVersion: String by project | ||||||
|
|
||||||
| plugins { | ||||||
| java | ||||||
| } | ||||||
|
|
||||||
| extensions.findByType<KotlinJvmProjectExtension>()?.apply { | ||||||
| jvmToolchain(javaVersion.toInt()) | ||||||
| } | ||||||
|
|
||||||
| java { | ||||||
| toolchain { | ||||||
| languageVersion.set(JavaLanguageVersion.of(javaVersion)) | ||||||
|
||||||
| languageVersion.set(JavaLanguageVersion.of(javaVersion)) | |
| languageVersion.set(JavaLanguageVersion.of(javaVersion.toInt())) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package dev.slne.surf.surfapi.bukkit.api.command.args | ||
|
|
||
| import com.mojang.brigadier.context.CommandContext | ||
| import dev.jorel.commandapi.CommandAPICommand | ||
| import dev.jorel.commandapi.CommandTree | ||
| import dev.jorel.commandapi.arguments.Argument | ||
| import dev.jorel.commandapi.arguments.CommandAPIArgumentType | ||
| import dev.jorel.commandapi.arguments.SafeOverrideableArgument | ||
| import dev.jorel.commandapi.executors.CommandArguments | ||
| import dev.slne.surf.surfapi.bukkit.api.nms.NmsUseWithCaution | ||
| import dev.slne.surf.surfapi.bukkit.api.nms.bridges.commandArgumentTypes | ||
| import net.kyori.adventure.nbt.CompoundBinaryTag | ||
| import net.kyori.adventure.nbt.TagStringIO | ||
|
|
||
| @OptIn(NmsUseWithCaution::class) | ||
| class AdventureCompoundBinaryTagArgument(nodeName: String) : | ||
| SafeOverrideableArgument<CompoundBinaryTag, CompoundBinaryTag>( | ||
| nodeName, commandArgumentTypes.compoundTag(), { TagStringIO.tagStringIO().asString(it) } | ||
| ) { | ||
| override fun getPrimitiveType(): Class<CompoundBinaryTag> { | ||
| return CompoundBinaryTag::class.java | ||
| } | ||
|
|
||
| override fun getArgumentType(): CommandAPIArgumentType { | ||
| return CommandAPIArgumentType.NBT_COMPOUND | ||
| } | ||
|
|
||
| override fun <Source> parseArgument( | ||
| ctx: CommandContext<Source>, | ||
| key: String, | ||
| previousArgs: CommandArguments | ||
| ): CompoundBinaryTag { | ||
| return commandArgumentTypes.getCompoundTag(ctx, key) | ||
| } | ||
| } | ||
|
|
||
| inline fun CommandTree.adventureCompoundBinaryTagArgument( | ||
| nodeName: String, | ||
| optional: Boolean = false, | ||
| block: Argument<*>.() -> Unit = {} | ||
| ): CommandTree = then(AdventureCompoundBinaryTagArgument(nodeName).setOptional(optional).apply(block)) | ||
|
|
||
| inline fun Argument<*>.adventureCompoundBinaryTagArgument( | ||
| nodeName: String, | ||
| optional: Boolean = false, | ||
| block: Argument<*>.() -> Unit = {} | ||
| ): Argument<*> = then(AdventureCompoundBinaryTagArgument(nodeName).setOptional(optional).apply(block)) | ||
|
|
||
|
|
||
| inline fun CommandAPICommand.adventureCompoundBinaryTagArgument( | ||
| nodeName: String, | ||
| optional: Boolean = false, | ||
| block: Argument<*>.() -> Unit = {} | ||
| ): CommandAPICommand = withArguments(AdventureCompoundBinaryTagArgument(nodeName).setOptional(optional).apply(block)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package dev.slne.surf.surfapi.bukkit.api.nms.bridges | ||
|
|
||
| import com.mojang.brigadier.arguments.ArgumentType | ||
| import com.mojang.brigadier.context.CommandContext | ||
| import dev.slne.surf.surfapi.bukkit.api.nms.NmsUseWithCaution | ||
| import dev.slne.surf.surfapi.core.api.util.requiredService | ||
| import net.kyori.adventure.nbt.CompoundBinaryTag | ||
|
|
||
| @NmsUseWithCaution | ||
| interface SurfBukkitNmsCommandArgumentTypesBridge { | ||
|
|
||
| fun compoundTag(): ArgumentType<*> | ||
| fun getCompoundTag(ctx: CommandContext<*>, key: String): CompoundBinaryTag | ||
|
|
||
| companion object : SurfBukkitNmsCommandArgumentTypesBridge by commandArgumentTypes { | ||
| val instance = commandArgumentTypes | ||
| } | ||
| } | ||
|
|
||
| @NmsUseWithCaution | ||
| val commandArgumentTypes = requiredService<SurfBukkitNmsCommandArgumentTypesBridge>() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package dev.slne.surf.surfapi.bukkit.api.nms.bridges | ||
|
|
||
| import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException | ||
| import dev.slne.surf.surfapi.bukkit.api.nms.NmsUseWithCaution | ||
| import dev.slne.surf.surfapi.core.api.util.requiredService | ||
| import io.papermc.paper.math.FinePosition | ||
| import net.kyori.adventure.nbt.CompoundBinaryTag | ||
| import org.bukkit.World | ||
| import org.bukkit.entity.EntityType | ||
|
|
||
| @NmsUseWithCaution | ||
| interface SurfBukkitNmsEntityBridge { | ||
|
|
||
| @Throws(WrapperCommandSyntaxException::class) | ||
| fun createEntityByNbt(world: World, type: EntityType, pos: FinePosition, tag: CompoundBinaryTag) | ||
|
|
||
| companion object : SurfBukkitNmsEntityBridge by entityBridge { | ||
| val instance = entityBridge | ||
| } | ||
| } | ||
|
|
||
| @NmsUseWithCaution | ||
| val entityBridge = requiredService<SurfBukkitNmsEntityBridge>() |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| package dev.slne.surf.surfapi.bukkit.test.command.subcommands | ||||||
|
|
||||||
| import dev.jorel.commandapi.CommandAPICommand | ||||||
| import dev.jorel.commandapi.kotlindsl.entityTypeArgument | ||||||
| import dev.jorel.commandapi.kotlindsl.getValue | ||||||
| import dev.jorel.commandapi.kotlindsl.playerExecutor | ||||||
| import dev.slne.surf.surfapi.bukkit.api.command.args.adventureCompoundBinaryTagArgument | ||||||
| import dev.slne.surf.surfapi.bukkit.api.nms.bridges.entityBridge | ||||||
| import net.kyori.adventure.nbt.CompoundBinaryTag | ||||||
| import org.bukkit.entity.EntityType | ||||||
|
|
||||||
| class SummonCommandTest(name: String) : CommandAPICommand(name) { | ||||||
| init { | ||||||
| entityTypeArgument("type") | ||||||
| adventureCompoundBinaryTagArgument("nbt") | ||||||
|
|
||||||
| playerExecutor { sender, args -> | ||||||
| val type: EntityType by args | ||||||
| val nbt: CompoundBinaryTag by args | ||||||
|
|
||||||
| entityBridge.createEntityByNbt(sender.world, type, sender.location, nbt) | ||||||
|
||||||
| entityBridge.createEntityByNbt(sender.world, type, sender.location, nbt) | |
| entityBridge.createEntityByNbt(sender.world, type, sender.location.toFinePosition(), nbt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The precompiled script plugin imports an internal generated accessor (
gradle.kotlin.dsl.accessors._….java). This class name is Gradle-version-specific and can break the build when the accessor package changes; the plugin should not depend on it. Remove this import and rely on the normaljava { ... }DSL after applying thejavaplugin.