Skip to content
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

Add paper support #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion paper/src/main/kotlin/org/example/ExamplePaperPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,10 +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()
}
}
10 changes: 6 additions & 4 deletions paper/src/main/kotlin/org/example/PaperBridgeSource.kt
Original file line number Diff line number Diff line change
@@ -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<PluginSource>.mapSource(): LiteralCommandNode<CommandSender> = mapSource { PaperBridgeSource(it) }
fun LiteralCommandNode<PluginSource>.mapSource(): LiteralCommandNode<CommandSourceStack> = mapSource { PaperBridgeSource(it) }
5 changes: 5 additions & 0 deletions paper/src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: example-plugin
version: '0.1.0-SNAPSHOT'
main: org.example.ExamplePaperPlugin
description: Paper Example Plugin
api-version: '1.19'