O

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

Kodari AI
KodariApr 16 at 5:15 pm 11,618 (v2)
TNTCreeper
A Paper 1.21.1 plugin that detects when a player places 5 TNT blocks in a straight line (horizontal or vertical). Upon detection, it removes the TNT blocks, spawns a powered (charged) creeper at the center, and rewards the player with a randomly trimmed armor piece. Features a per-player cooldown system and a config file to toggle the charged creeper spawning, trim reward, and cooldown duration.

Planning class dependencies:

  • TNTCreeper (main) → holds CooldownManager, TrimManager, registers TNTListener

  • TNTListener → calls plugin.getCooldownManager(), plugin.getTrimManager(), spawns Creeper, removes blocks

  • CooldownManager → standalone, no plugin ref needed

  • TrimManager → needs plugin ref for config, uses Registry.TRIM_PATTERN/TRIM_MATERIAL, ArmorMeta

  • All 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 @Getter for CooldownManager and TrimManager, loads config, registers listener on enable.

  • TNTListener.java — BlockPlaceEvent handler; 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 charged Creeper at the center slot (index 2), triggers the trim reward, then starts the cooldown.

  • CooldownManager.java — Lightweight UUID → expiry-timestamp map with isOnCooldown, getRemainingSeconds, and setCooldown.

  • TrimManager.java — Iterates Registry.TRIM_PATTERN and Registry.TRIM_MATERIAL, picks random entries for each, wraps them in an ArmorTrim, and applies it to an existing ArmorMeta piece 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.

O

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)

Kodari AI
KodariApr 17 at 8:20 am 7,061 (v2)

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.json tag to create the required ccr_timer scoreboard (the original datapack omits this, causing a silent failure)

  • Create a DatapackManager that extracts/installs the datapack on plugin enable

  • Wire 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) using FileSystems.newFileSystem so deployment works correctly in production

  • Uses REPLACE_EXISTING so a plugin reload always pushes the latest bundled version

  • Skips silently when datapack-enabled: false in config

  • Logs 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.

O

Make a datapack of it not a plugin

Kodari AI
KodariApr 17 at 8:21 am 3,750 (v2)

Here is a self-contained Python script that builds the .zip ready to drop into any world’s datapacks/ folder:

Python
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

Plain Text
<world folder>/
└── datapacks/
    └── charged_creeper_ritual.zip   ← drop it here
Plain Text
/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
O

How I install it

Kodari AI
KodariApr 17 at 8:23 am 1,889 (v2)

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:

  1. Build the jar: ./gradlew build

  2. Drop the .jar into your server’s plugins/ folder

  3. Start/restart the server — done


Option B — Extract the datapack manually (no plugin needed)

  1. Navigate to src/main/resources/datapack/ in your project

  2. Zip the contents of that folder (so pack.mcmeta is at the root of the zip, not inside a subfolder)

  3. Name it anything, e.g. charged_creeper_ritual.zip

  4. Drop it into your world’s datapacks/ folder:

    Plain Text
    <server>/world/datapacks/charged_creeper_ritual.zip
    
  5. In-game or console:

    Plain Text
    /reload
    
  6. Verify it loaded:

    Plain Text
    /datapack list
    

    You should see it listed as enabled.


⚠️ Important zip structure

The zip must look like this internally:

Plain Text
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.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
17 413
src/main/java/com/tntcreeper/TNTCreeper.java
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.");
    }
}