Skip to content

Commit f11f3ad

Browse files
committed
docs: Detail KPaperGradle plugin and command DSL caveats
1 parent 1dce8c5 commit f11f3ad

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Welcome to the comprehensive documentation for KPaper - a Kotlin utility library
1717
### API Guides
1818
- [Event System](api/events.md) - Event handling and custom events
1919
- [Command Framework](api/commands.md) - Creating commands with arguments
20+
- Tip: Using the official Gradle plugin? See the “Using KPaperGradle (recommended)” section in that page for auto‑registration (https://github.com/ModLabsCC/KPaperGradle).
2021
- [Inventory & GUI](api/inventory.md) - Item builders and GUI systems
2122
- [Extensions](api/extensions.md) - Kotlin extensions for Bukkit classes
2223
- [Utilities](api/utilities.md) - Helper functions and utilities

docs/api/commands.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,82 @@
11
# Command Framework
22

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+
380
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.
481

582
## Basic Command Creation

docs/examples/common-patterns.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ class AsyncShopGUI(player: Player) : KGUI() {
501501

502502
## Command Patterns
503503

504+
Note: The CommandBuilder DSL shown below is conceptual in this release. The current API exposes a `CommandBuilder` interface; a full fluent command DSL is planned. Treat these snippets as patterns, not drop‑in code.
505+
504506
### 1. Command Router Pattern
505507

506508
Route commands to appropriate handlers:

0 commit comments

Comments
 (0)