Sure! Here's a simple Minecraft plugin example using Paper API 1.21.1. This plugin will register a command /heal that heals the player (sets their health to full) and sends a message.
🧱 Requirements
- Paper 1.21.1 server
- Java 17 or higher
- Maven or IDE support (e.g., IntelliJ IDEA or Eclipse)
📁 File Structure
HealPlugin/
├── src/
│ └── main/
│ ├── java/
│ │ └── com/
│ │ └── example/
│ │ └── healplugin/
│ │ ├── HealPlugin.java
│ │ └── commands/
│ │ └── HealCommand.java
│ └── resources/
│ └── plugin.yml
✅ plugin.yml
name: HealPlugin
version: 1.0
main: com.example.healplugin.HealPlugin
api-version: 1.21
commands:
heal:
description: Heals the player to full health.
usage: /heal
✅ HealPlugin.java
package com.example.healplugin;
import org.bukkit.plugin.java.JavaPlugin;
public class HealPlugin extends JavaPlugin {
@Override
public void onEnable() {
// Register command
getCommand("heal").setExecutor(new commands.HealCommand());
getLogger().info("HealPlugin has been enabled!");
}
@Override
public void onDisable() {
getLogger().info("HealPlugin has been disabled!");
}
}
✅ HealCommand.java
package com.example.healplugin.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HealCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
Player player = (Player) sender;
player.setHealth(player.getMaxHealth());
player.sendMessage("You have been healed!");
return true;
}
}
🔨 Build with Maven (Optional)
If you're using Maven, here's a basic pom.xml:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>HealPlugin</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
You may need to install Paper API manually if it's not in your repo:
mvn install:install-file -Dfile=paper-api-1.21.1-R0.1-SNAPSHOT.jar -DgroupId=io.papermc.paper -DartifactId=paper-api -Dversion=1.21.1-R0.1-SNAPSHOT -Dpackaging=jar
🧪 How to Use
- Compile the plugin (
mvn package or build with your IDE).
- Put the resulting
.jar in your plugins/ folder.
- Start the server.
- Run
/heal in-game.
Would you like a more advanced example (like events, permissions, or config files)?