First Java Plugin
Build a minimal HelloWorld plugin from scratch. At the end of this page, you will have a .jar file that Nukkit-MOT can load.
Step 1 of 4: create the project, add the dependency, and build the first plugin jar.
Next: Plugin Basics
What You Need
- Java 17 or newer
- IntelliJ IDEA Community or another Java IDE
- Maven
- A local Nukkit-MOT server folder for the next page
Create a Maven Project
Create a standard Maven project and use values similar to these:
| Setting | Value |
|---|---|
| GroupId | com.example |
| ArtifactId | hello-world-plugin |
| Name | HelloWorldPlugin |
| Package | com.example.helloworld |
| JDK | 17 |
After the project is created, replace pom.xml with this example. The repository URL and dependency coordinates match the current Nukkit-MOT README:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>hello-world-plugin</artifactId>
<version>1.0.0</version>
<name>HelloWorldPlugin</name>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>repo-lanink-cn</id>
<url>https://repo.lanink.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>cn.nukkit</groupId>
<artifactId>Nukkit</artifactId>
<version>MOT-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Project Layout
Create the following files:
hello-world-plugin/
├─ pom.xml
└─ src/
└─ main/
├─ java/
│ └─ com/
│ └─ example/
│ └─ helloworld/
│ └─ HelloWorldPlugin.java
└─ resources/
└─ plugin.yml
Create the Main Class
Create src/main/java/com/example/helloworld/HelloWorldPlugin.java:
package com.example.helloworld;
import cn.nukkit.plugin.PluginBase;
public final class HelloWorldPlugin extends PluginBase {
@Override
public void onEnable() {
this.getLogger().info("Hello from my first Nukkit-MOT plugin!");
}
}
onEnable() is the first lifecycle method most plugin authors use. When the server enables your plugin successfully, this method is called.
Create plugin.yml
Create src/main/resources/plugin.yml:
name: HelloWorldPlugin
main: com.example.helloworld.HelloWorldPlugin
version: "1.0.0"
api: ["1.0.0"]
author: YourName
description: My first Nukkit-MOT plugin
This file is required. Nukkit-MOT reads it from the jar and uses it to locate your plugin entry class.
main field carefullymain must exactly match your Java package name and class name. If it points to the wrong class, the plugin will not load.
Build the Plugin Jar
Run this command in the project root:
mvn clean package
If you prefer IntelliJ IDEA, open the Maven panel and run clean, then package.
The output is usually:
target/hello-world-plugin-1.0.0.jar
Because plugin.yml is under src/main/resources/, Maven copies it into the jar automatically.
Before You Continue
- If Maven cannot resolve
cn.nukkit:Nukkit:MOT-SNAPSHOT, re-check the repository URL and your network connection. - If the project builds successfully, continue to Plugin Basics.