From 8c7c04034db4d3c56dee7e94dd6f8220fcd1e735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20St=C3=A4ding?= Date: Mon, 17 Apr 2023 01:24:22 +0200 Subject: [PATCH] Add paper support --- .../src/main/kotlin/org/example/ExamplePaperPlugin.kt | 9 +++++++-- paper/src/main/kotlin/org/example/PaperBridgeSource.kt | 10 ++++++---- paper/src/main/resources/paper-plugin.yml | 5 +++++ 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 paper/src/main/resources/paper-plugin.yml diff --git a/paper/src/main/kotlin/org/example/ExamplePaperPlugin.kt b/paper/src/main/kotlin/org/example/ExamplePaperPlugin.kt index c1fe4ba..80145e2 100644 --- a/paper/src/main/kotlin/org/example/ExamplePaperPlugin.kt +++ b/paper/src/main/kotlin/org/example/ExamplePaperPlugin.kt @@ -1,11 +1,16 @@ package org.example +import io.papermc.paper.command.brigadier.CommandBuilder +import org.anvilpowered.kbrig.brigadier.toBrigadier import org.bukkit.event.Listener import org.bukkit.plugin.java.JavaPlugin - +import org.example.command.PingCommand class ExamplePaperPlugin : JavaPlugin(), Listener { + @Suppress("UnstableApiUsage") override fun onEnable() { - // WTF? + CommandBuilder.of(this, "example") + .then(PingCommand.create().mapSource().toBrigadier()) + .register() } } diff --git a/paper/src/main/kotlin/org/example/PaperBridgeSource.kt b/paper/src/main/kotlin/org/example/PaperBridgeSource.kt index 782e915..686528f 100644 --- a/paper/src/main/kotlin/org/example/PaperBridgeSource.kt +++ b/paper/src/main/kotlin/org/example/PaperBridgeSource.kt @@ -1,13 +1,15 @@ +@file:Suppress("UnstableApiUsage") + package org.example +import io.papermc.paper.command.brigadier.CommandSourceStack import net.kyori.adventure.audience.Audience import net.kyori.adventure.audience.ForwardingAudience import org.anvilpowered.kbrig.tree.LiteralCommandNode import org.anvilpowered.kbrig.tree.mapSource -import org.bukkit.command.CommandSender -class PaperBridgeSource(private val paperCommandSource: CommandSender) : PluginSource, ForwardingAudience.Single { - override fun audience(): Audience = paperCommandSource +class PaperBridgeSource(private val paperCommandSource: CommandSourceStack) : PluginSource, ForwardingAudience.Single { + override fun audience(): Audience = paperCommandSource.bukkitSender } -fun LiteralCommandNode.mapSource(): LiteralCommandNode = mapSource { PaperBridgeSource(it) } +fun LiteralCommandNode.mapSource(): LiteralCommandNode = mapSource { PaperBridgeSource(it) } diff --git a/paper/src/main/resources/paper-plugin.yml b/paper/src/main/resources/paper-plugin.yml new file mode 100644 index 0000000..67bb767 --- /dev/null +++ b/paper/src/main/resources/paper-plugin.yml @@ -0,0 +1,5 @@ +name: example-plugin +version: '0.1.0-SNAPSHOT' +main: org.example.ExamplePaperPlugin +description: Paper Example Plugin +api-version: '1.19'