|
1 | 1 | # Command Framework |
2 | 2 |
|
| 3 | +Note: The fluent CommandBuilder DSL used in some examples is not included in this build of KPaper. You can either implement the `CommandBuilder` interface directly (examples below) or install the companion Gradle plugin, KPaperGradle, which auto‑wires command registration for you. |
| 4 | + |
| 5 | +## Using KPaperGradle (recommended) |
| 6 | + |
| 7 | +Project page: https://github.com/ModLabsCC/KPaperGradle |
| 8 | + |
| 9 | +KPaperGradle automates KPaper setup, generates registration bootstrappers, and auto‑registers commands. It also discovers listeners (you call a one‑liner to register them). |
| 10 | + |
| 11 | +1) Add plugin repositories |
| 12 | + |
| 13 | +```kotlin |
| 14 | +// settings.gradle.kts |
| 15 | +pluginManagement { |
| 16 | + repositories { |
| 17 | + gradlePluginPortal() |
| 18 | + maven("https://nexus.modlabs.cc/repository/maven-public/") |
| 19 | + mavenLocal() |
| 20 | + } |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +2) Apply the plugin and configure |
| 25 | + |
| 26 | +```kotlin |
| 27 | +// build.gradle.kts (your Paper plugin) |
| 28 | +plugins { |
| 29 | + kotlin("jvm") version "2.0.0" |
| 30 | + id("cc.modlabs.kpaper-gradle") version "LATEST" // replace with latest |
| 31 | +} |
| 32 | + |
| 33 | +repositories { |
| 34 | + mavenCentral() |
| 35 | + maven("https://nexus.modlabs.cc/repository/maven-mirrors/") |
| 36 | +} |
| 37 | + |
| 38 | +kpaper { |
| 39 | + javaVersion.set(21) // toolchain + compiler --release |
| 40 | + registrationBasePackage.set("com.example.myplugin") // scanned for commands/listeners |
| 41 | + // Optional: deliver extra runtime libs via Paper's loader |
| 42 | + // deliver("com.github.ben-manes.caffeine:caffeine:3.1.8") |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +3) Register discovered listeners (commands are auto‑registered) |
| 47 | + |
| 48 | +```kotlin |
| 49 | +import cc.modlabs.kpaper.main.KPlugin |
| 50 | + |
| 51 | +class MyPlugin : KPlugin() { |
| 52 | + override fun startup() { |
| 53 | + cc.modlabs.registration.RegisterManager.registerListeners(this) |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +4) Implement commands under your `registrationBasePackage` |
| 59 | + |
| 60 | +```kotlin |
| 61 | +package com.example.myplugin.commands |
| 62 | + |
| 63 | +import cc.modlabs.kpaper.command.CommandBuilder |
| 64 | +import io.papermc.paper.command.brigadier.Commands |
| 65 | + |
| 66 | +class HelloCommand : CommandBuilder { |
| 67 | + override val description = "Say hello" |
| 68 | + override fun register() = |
| 69 | + Commands.literal("hello") |
| 70 | + .executes { |
| 71 | + it.source.sender.sendMessage("Hello from KPaper!") |
| 72 | + com.mojang.brigadier.Command.SINGLE_SUCCESS |
| 73 | + } |
| 74 | + .build() |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +That’s it — build as usual. The plugin generates the bootstrap classes, patches `paper-plugin.yml` as needed, and wires resources. |
| 79 | + |
3 | 80 | KPaper's command framework provides integration with Paper's Brigadier-based command system through the `CommandBuilder` interface, allowing you to create powerful commands with argument parsing, validation, and sub-command support. |
4 | 81 |
|
5 | 82 | ## Basic Command Creation |
|
0 commit comments