Using Maven
IntelliJ
Preparing workspace
First of all, create a new Java project. Make sure you select Maven as your build system and at least JDK 21.
Check Add sample code
and click on Create.
Adding PNX to your project
Open up the pom.xml
file of your project and add paste the following code into the project tag:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://www.jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.PowerNukkitX</groupId>
<artifactId>PowerNukkitX</artifactId>
<version>master-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Creating your plugin.yml
When using PowerNukkitX, you need a resource file containing information about your plugin.
This file can be called powernukkitx.yml
or plugin.yml
.
Simply create that file and paste in the following yml data. You might have to change a few values according to your project.
name: ExamplePlugin
main: org.powernukkitx.exampleplugin.Main
#remember version and api is string, don't write it like this: 1.0.0, or there will be an exception
version: "1.0.0"
api: "2.0.0"
load: POSTWORLD
author: PowerNukkitX Team
# Authors and author will be added together in one list.
authors: ["Example", "Another"]
description: Example plugin from PNX docs
website: https://docs.powernukkitx.org/
Writing your own code
With that done, you can finally start with your own code. To do that, open the generated Main.java from your project.
Delete the Main
class and replace it with the following:
public class ExamplePlugin extends PluginBase {
@Override
public void onLoad() {
this.getLogger().info(TextFormat.WHITE + "The example plugin has been loaded!");
}
@Override
public void onEnable() {
this.getLogger().info(TextFormat.DARK_GREEN + "The example plugin has been successfully launched!");
}
@Override
public void onDisable() {
this.getLogger().info(TextFormat.DARK_RED + "The example plugin has been disabled!");
}
}
Also make sure you import all the required classes:
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.TextFormat;
Congrats, you can now compile your plugin using mvn package
, move it inside the plugins
folder of your PNX server and restart it.
Need help?
If you need help, check out our Example plugin or join our discord server and ask for help.