I want to create a Minecraft plugin for Paper version 1.21.1 (Java). The plugin should have the following functionality:
Detect when a player places 5 TNT blocks in a straight line (horizontal or vertical).
Once the 5 TNT blocks are placed correctly:
Remove those TNT blocks.
Spawn a charged creeper at the center of the formation.
Additionally, reward the player who placed the final TNT block with a random armor trim.
The trim should be randomly selected from available trim patterns.
Apply the trim to a random piece of armor in the player’s inventory (or give a new trimmed armor piece if easier).
Technical requirements:
Use the Paper API (latest for 1.21.1).
Write the plugin in Java.
Include event listeners (e.g., BlockPlaceEvent).
Make the detection efficient and avoid false positives.
Structure the code cleanly with a main plugin class and separate listener class.
Include comments explaining key parts of the code.
Optional:
Add a cooldown to prevent spam.
Add a config file to enable/disable features.
Please provide:
Full source code plugin.yml
Planning class dependencies:
TNTCreeper(main) → holdsCooldownManager,TrimManager, registersTNTListenerTNTListener→ callsplugin.getCooldownManager(),plugin.getTrimManager(), spawns Creeper, removes blocksCooldownManager→ standalone, no plugin ref neededTrimManager→ needs plugin ref for config, usesRegistry.TRIM_PATTERN/TRIM_MATERIAL,ArmorMetaAll XMaterial calls use
matchXMaterial(String)→Optional<XMaterial>, store as static finals for TNT & AIR
Here’s what was built:
TNTCreeper.java— Main plugin class with@GetterforCooldownManagerandTrimManager, loads config, registers listener on enable.TNTListener.java—BlockPlaceEventhandler; for each placed TNT it scans all 3 axes (±X, ±Y, ±Z) for exactly 5 consecutive TNT. If found, removes all 5 blocks, spawns a chargedCreeperat the center slot (index 2), triggers the trim reward, then starts the cooldown.CooldownManager.java— Lightweight UUID → expiry-timestamp map withisOnCooldown,getRemainingSeconds, andsetCooldown.TrimManager.java— IteratesRegistry.TRIM_PATTERNandRegistry.TRIM_MATERIAL, picks random entries for each, wraps them in anArmorTrim, and applies it to an existingArmorMetapiece in the player’s armor slots — or gives a new leather chestplate if they have none.config.yml— Toggles for enabled, charged-creeper-enabled, trim-reward-enabled, cooldown-seconds, and all player-facing messages with placeholder support.
import zipfile
pack_name = "charged_creeper_ritual"
files = { f"{pack_name}/pack.mcmeta": """{ "pack": { "pack_format": 48, "description": "Charged Creeper Ritual (Gunpowder SMP)" } }""",
f"{pack_name}/data/minecraft/tags/functions/tick.json": """{ "values": ["ccr:tick", "ccr:loop"] }""",
f"{pack_name}/data/ccr/functions/tick.mcfunction": """ execute as @e[type=item,nbt={Item:{id:"minecraft:gunpowder",Count:10b}}] at @s if block ~ ~-1 ~ minecraft:lightning_rod run function ccr:start """,
f"{pack_name}/data/ccr/functions/start.mcfunction": """ execute as @e[type=creeper,distance=..3,limit=1,sort=nearest] run tag @s add ccr_target kill @s """,
f"{pack_name}/data/ccr/functions/loop.mcfunction": """ scoreboard players add @e[tag=ccr_target] ccr_timer 1 execute as @e[tag=ccr_target] at @s run particle minecraft:dust 1 0 0 1 ~ ~1 ~ 0.3 0.5 0.3 0 10 execute as @e[tag=ccr_target,scores={ccr_timer=100..}] at @s run function ccr:finish """,
f"{pack_name}/data/ccr/functions/finish.mcfunction": """ summon minecraft:lightning_bolt ~ ~ ~ data merge entity @s {powered:1b} tag @s remove ccr_target scoreboard players reset @s ccr_timer """ }
zip_name = "charged_creeper_ritual.zip"
with zipfile.ZipFile(zip_name, "w") as zipf: for path, content in files.items(): zipf.writestr(path, content.strip())
print("Datapack created:", zip_name)
Let me read all the existing files before making any changes.
The user wants to integrate this datapack into the plugin as a bundled resource that gets automatically installed to the world’s datapacks/ folder on enable. I’ll:
Bundle all datapack files under
src/main/resources/datapack/Add a missing
load.mcfunction+load.jsontag to create the requiredccr_timerscoreboard (the original datapack omits this, causing a silent failure)Create a
DatapackManagerthat extracts/installs the datapack on plugin enableWire everything into the main class and config
Here is a full breakdown of every change made and why:
Datapack resource files (src/main/resources/datapack/)
File | Purpose |
|---|---|
pack.mcmeta | Pack format 48 (1.21.x), declares the datapack identity |
data/minecraft/tags/functions/tick.json | Runs ccr:tick and ccr:loop every game tick |
data/minecraft/tags/functions/load.json | New — runs ccr:load once on world load |
data/ccr/functions/load.mcfunction | New — bug fix. Creates the ccr_timer dummy scoreboard objective. The original script omitted this entirely; without it scoreboard players add silently fails every tick and creepers never charge |
data/ccr/functions/tick.mcfunction | Detects a stack of exactly 10 gunpowder sitting on a lightning rod and triggers ccr:start |
data/ccr/functions/start.mcfunction | Tags the nearest creeper within 3 blocks as ccr_target and destroys the gunpowder item |
data/ccr/functions/loop.mcfunction | Increments ccr_timer, spawns red dust particles, and fires ccr:finish once the timer hits 100 (5 seconds) |
data/ccr/functions/finish.mcfunction | Strikes lightning, sets powered:1b on the creeper to charge it, removes the tag, and resets the timer |
DatapackManager.java
On
installDatapack(), resolves the first overworld’s folder and targets<world>/datapacks/charged_creeper_ritual/Handles both IDE classpath mode (plain
file://URI) and jar mode (jar://URI) usingFileSystems.newFileSystemso deployment works correctly in productionUses
REPLACE_EXISTINGso a plugin reload always pushes the latest bundled versionSkips silently when
datapack-enabled: falsein configLogs the exact path installed to and reminds the admin to run
/datapack enable "file/charged_creeper_ritual"(required once per world, then auto-enabled on future boots)
How the two mechanics interact
Mechanic | Trigger | Result |
|---|---|---|
Plugin (Java) | 5 TNT placed in a straight line | Instantly spawns a pre-charged creeper |
Datapack (mcfunction) | 10 gunpowder dropped on a lightning rod near a creeper | Charges a natural creeper over 5 seconds with a visual effect |
They are completely independent — the datapack charges existing creepers, the plugin spawns new ones.
Make a datapack of it not a plugin
Here is a self-contained Python script that builds the .zip ready to drop into any world’s datapacks/ folder:
import zipfile
PACK_NAME = "charged_creeper_ritual"
ZIP_NAME = f"{PACK_NAME}.zip"
files = {
f"{PACK_NAME}/pack.mcmeta": """\
{
"pack": {
"pack_format": 48,
"description": "Charged Creeper Ritual (Gunpowder SMP)"
}
}""",
# ── function tags ────────────────────────────────────────────────────────
f"{PACK_NAME}/data/minecraft/tags/functions/load.json": """\
{
"values": ["ccr:load"]
}""",
f"{PACK_NAME}/data/minecraft/tags/functions/tick.json": """\
{
"values": ["ccr:tick", "ccr:loop"]
}""",
# ── ccr functions ────────────────────────────────────────────────────────
# Runs once on world load — creates the scoreboard so the rest works.
# Without this, 'scoreboard players add' silently fails every tick.
f"{PACK_NAME}/data/ccr/functions/load.mcfunction": """\
scoreboard objectives add ccr_timer dummy""",
# Every tick: look for a stack of exactly 10 gunpowder resting on a
# lightning rod, then hand off to start.
f"{PACK_NAME}/data/ccr/functions/tick.mcfunction": """\
execute as @e[type=item,nbt={Item:{id:"minecraft:gunpowder",Count:10b}}] \
at @s if block ~ ~-1 ~ minecraft:lightning_rod run function ccr:start""",
# Tag the nearest creeper within 3 blocks, then consume the gunpowder.
f"{PACK_NAME}/data/ccr/functions/start.mcfunction": """\
execute as @e[type=creeper,distance=..3,limit=1,sort=nearest] run tag @s add ccr_target
kill @s""",
# Every tick: advance the timer, show red-dust particles, finish at t=100 (5 s).
f"{PACK_NAME}/data/ccr/functions/loop.mcfunction": """\
scoreboard players add @e[tag=ccr_target] ccr_timer 1
execute as @e[tag=ccr_target] at @s run particle minecraft:dust 1 0 0 1 ~ ~1 ~ 0.3 0.5 0.3 0 10
execute as @e[tag=ccr_target,scores={ccr_timer=100..}] at @s run function ccr:finish""",
# Strike the lightning, charge the creeper, then clean up.
f"{PACK_NAME}/data/ccr/functions/finish.mcfunction": """\
summon minecraft:lightning_bolt ~ ~ ~
data merge entity @s {powered:1b}
tag @s remove ccr_target
scoreboard players reset @s ccr_timer""",
}
with zipfile.ZipFile(ZIP_NAME, "w", compression=zipfile.ZIP_DEFLATED) as zf:
for path, content in files.items():
zf.writestr(path, content)
print(f"Datapack created: {ZIP_NAME}")
print()
print("Installation:")
print(f" 1. Copy {ZIP_NAME} into <world>/datapacks/")
print(f" 2. Run in-game: /datapack enable \"file/{ZIP_NAME}\"")
print(f" (only needed once — auto-enabled on future boots)")
print(f" 3. Run: /reload (or restart the server)")
How to install after running the script
<world folder>/
└── datapacks/
└── charged_creeper_ritual.zip ← drop it here
/datapack enable "file/charged_creeper_ritual.zip"
/reload
Full mechanic recap
Step | What happens |
|---|---|
Drop 10 gunpowder on a lightning rod near a creeper | ccr:tick detects the item every tick |
ccr:start fires | Nearest creeper ≤ 3 blocks gets tagged ccr_target; gunpowder item is killed |
ccr:loop runs each tick for 5 seconds (100 ticks) | Red dust particles spiral around the creeper |
ccr:finish fires at t = 100 | Lightning bolt strikes, creeper gets powered:1b, tag + timer reset |
How I install it
Since you already have a plugin project (not a standalone datapack), you have two options:
Option A — Use the plugin (easiest, datapack auto-installs)
The plugin bundles the datapack and deploys it automatically. Just:
Build the jar:
./gradlew buildDrop the
.jarinto your server’splugins/folderStart/restart the server — done
Option B — Extract the datapack manually (no plugin needed)
Navigate to
src/main/resources/datapack/in your projectZip the contents of that folder (so
pack.mcmetais at the root of the zip, not inside a subfolder)Name it anything, e.g.
charged_creeper_ritual.zipDrop it into your world’s
datapacks/folder:Plain Text<server>/world/datapacks/charged_creeper_ritual.zipIn-game or console:
Plain Text/reloadVerify it loaded:
Plain Text/datapack listYou should see it listed as enabled.
⚠️ Important zip structure
The zip must look like this internally:
charged_creeper_ritual.zip
├── pack.mcmeta
└── data/
├── ccr/functions/...
└── minecraft/tags/functions/...
Not with an extra root folder inside the zip — that’s the most common mistake that causes datapacks to silently fail.
package com.tntcreeper;
import com.tntcreeper.listener.TNTListener;
import com.tntcreeper.manager.CooldownManager;
import com.tntcreeper.manager.DatapackManager;
import com.tntcreeper.manager.TrimManager;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class TNTCreeper extends JavaPlugin {
private CooldownManager cooldownManager;
private TrimManager trimManager;
private DatapackManager datapackManager;
@Override
public void onEnable() {
saveDefaultConfig();
this.cooldownManager = new CooldownManager();
this.trimManager = new TrimManager(this);
this.datapackManager = new DatapackManager(this);
this.datapackManager.installDatapack();
getServer().getPluginManager().registerEvents(new TNTListener(this), this);
getLogger().info("TNTCreeper has been enabled.");
}
@Override
public void onDisable() {
getLogger().info("TNTCreeper has been disabled.");
}
}