Skip to content

Commit cd5dcd4

Browse files
committed
Add documentation for running the CommandAPI on a Paper server
1 parent ae9cecd commit cd5dcd4

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

docssrc/src/setup_shading.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@ By default, the CommandAPI is written in the `dev.jorel.commandapi` package. It
107107

108108
-----
109109

110+
## A note about Paper 1.20.5+ servers
111+
112+
_If you are using the Spigot API, you can ignore this section and jump to [Shading with Maven](#shading-with-maven) or [Shading with Gradle](#shading-with-gradle)
113+
depending on the build tool you use._
114+
115+
<div class="warning">
116+
117+
**Developer's Note:**
118+
119+
Starting from Minecraft version 1.20.5, Paper will only ship mojang-mapped servers which use mojang-mapped class names and CraftBukkit classes without the version package.
120+
However, when starting the server, Paper will remap Spigot-mapped plugins so that they can run on a mojang-mapped server.
121+
122+
At this time, the CommandAPI is not able to provide a version that runs on a mojang-mapped server without being relocated so your plugin has top be marked as Spigot-mapped
123+
to make the server remap your plugin and your shaded CommandAPI version so that the CommandAPI is able to run on a 1.20.5 Paper server.
124+
125+
</div>
126+
127+
In the following section we distinguish between the use of the `Paper API`, in our context just the use of the `io.papermc.paper:paper-api:apiVersion` dependency
128+
without Paper's internal code ("NMS"), and the use of `paperweight-userdev` (Paper's internal code) because the use of either of them will decide what you have to
129+
do to make your plugin with the CommandAPI 1.20.5 Paper-compatible.
130+
131+
You now need to differentiate between certain configurations in order to make your plugin and the CommandAPI compatible with 1.20.5 servers:
132+
133+
| Build Tool | Paper | Plugin Flavour | What to do |
134+
|------------|------------------------|-------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
135+
| Maven | Paper API | `plugin.yml` | [Shading with Maven](#shading-with-maven) |
136+
| Maven | Paper API | `paper-plugin.yml` | <ol><li><a href="#shading-with-maven">Shading with Maven<a/></li><li><a href="#setting-the-manifest-value-maven">Setting the manifest value (Maven)</a></li></ol> |
137+
| Gradle | Paper API | `plugin.yml` | [Shading with Gradle](#shading-with-gradle) |
138+
| Gradle | Paper API | `paper-plugin.yml` | <ol><li><a href="#shading-with-gradle">Shading with Gradle</a></li><li><a href="#setting-the-manifest-value-gradle">Setting the manifest value (Gradle)</a></li></ol> |
139+
| Gradle | `paperweight-userdev` | `plugin.yml`<br>`paper-plugin.yml` | [Shading with Gradle (`paperweight-userdev`)](#shading-with-gradle-paperweight-userdev) |
140+
141+
-----
142+
110143
## Shading with Maven
111144

112145
To shade the CommandAPI into a maven project, you'll need to use the `commandapi-bukkit-shade` dependency, which is optimized for shading and doesn't include plugin-specific files _(such as `plugin.yml`)_. **You do not need to use `commandapi-bukkit-core` if you are shading**:
@@ -240,7 +273,7 @@ shadowJar {
240273
```
241274

242275
```kotlin,build.gradle.kts
243-
shadowJar {
276+
tasks.withType<ShadowJar> {
244277
dependencies {
245278
include(dependency("dev.jorel:commandapi-bukkit-shade:9.4.0-SNAPSHOT"))
246279
}
@@ -259,3 +292,78 @@ gradlew build shadowJar
259292
```
260293

261294
As we're shading the CommandAPI into your plugin, we **don't** need to add `depend: [CommandAPI]` to your `plugin.yml` file.
295+
296+
## Setting the manifest value (Maven)
297+
298+
> **Developer's Note:**
299+
>
300+
> This step is only necessary when targeting Paper servers while using a `paper-plugin.yml`
301+
302+
In order to tell Paper that your plugin should be remapped to Mojang mappings at runtime, you have to set a manifest value in the `maven-jar-plugin`. This step is necessary as
303+
Paper assumes that every plugin using a `paper-plugin.yml` already is mojang-mapped.
304+
305+
```xml
306+
<plugin>
307+
<groupId>org.apache.maven.plugins</groupId>
308+
<artifactId>maven-jar-plugin</artifactId>
309+
<version>3.4.1</version>
310+
<configuration>
311+
<archive>
312+
<manifestEntries>
313+
<paperweight-mappings-namespace>spigot</paperweight-mappings-namespace>
314+
</manifestEntries>
315+
</archive>
316+
</configuration>
317+
</plugin>
318+
```
319+
320+
This will mark your plugin as Spigot-mapped and Paper will remap your plugin at runtime.
321+
322+
## Setting the manifest value (Gradle)
323+
324+
> **Developer's Note:**
325+
>
326+
> This step is only necessary when targeting Paper servers while using a `paper-plugin.yml`
327+
328+
In order to tell Paper that your plugin should be remapped to Mojang mappings at runtime, you have to set a manifest value in the `shadowJar` task. This step is necessary as
329+
Paper assumes that every plugin using a `paper-plugin.yml` already is mojang-mapped.
330+
331+
```kotlin
332+
tasks.withType<ShadowJar> {
333+
manifest {
334+
attributes["paperweight-mappings-namespace"] = "spigot"
335+
}
336+
}
337+
```
338+
339+
This will mark your plugin as Spigot-mapped and Paper will remap your plugin at runtime.
340+
341+
## Shading with Gradle (`paperweight-userdev`)
342+
343+
> **Developer's Note:**
344+
>
345+
> This section assumes that you already have a project using `paperweight-userdev` set up.
346+
347+
<div class="warning">
348+
349+
When using `paperweight-userdev`, building your plugin using the `shadowJar` task is not recommended since that task builds the mojang-mapped jar but does not remap any dependencies
350+
you may have.
351+
352+
Because of that, the Paper server will see your plugin as mojang-mapped and will not try to remap your plugin resulting in a `NoClassDefFoundError` when calling the CommandAPI's
353+
`onLoad` method because this uses the versioned CraftBukkit classes while a Paper server doesn't have those anymore.
354+
355+
</div>
356+
357+
Instead, please follow these instructions to be able to run the CommandAPI while having made your plugin using `paperweight-userdev`:
358+
359+
1. Please add this to your build script:
360+
361+
```kotlin
362+
paperweight.reobfArtifactConfiguration = ReobfArtifactConfiguration.REOBF_PRODUCTION
363+
```
364+
365+
2. Only run the `reobfJar` task to build your plugin from now on. The main plugin artifact will be Spigot mapped and Paper will remap your plugin so that in the end
366+
running the CommandAPI works.
367+
368+
369+

0 commit comments

Comments
 (0)