mercera1

Specification: Advanced Stacking Spawner System Plugin

Core Objective

Develop a high-performance Spigot/Paper optimization plugin for Minecraft versions 1.20+ that allows players to stack identical spawners together to increase loot/experience scaling, manage upgrades via an interactive INVENTORY GUI, and securely mine them using specific tools.

---

1. Mechanics & Interactions

A. Spawner Stacking via Left-Click

* Trigger: When a player left-clicks an existing placed spawner while holding an identical spawner item in their main hand, intercept the block damage event. * Logic: * Verify the entity type of both spawners matches perfectly. * Increment the stack count of the placed spawner by 1. * Consolidate and decrement the item stack in the player's hand. * Display an ActionBar notification: &a+1 Stacked! New Level: [Current_Stack]/[Max_Stack]. * Duplication/Break Prevention: Cancel the default block-breaking animation/logic during this specific left-click stacking interaction.

B. Silk Touch Retrieval

* Requirement: Spawners must ONLY drop as items if mined with a Pickaxe enchanted with Silk Touch. * Logic: * If mined without Silk Touch, the spawner is permanently destroyed (drops standard XP only). * If a stacked spawner is broken with Silk Touch, drop one spawner item with NBT data indicating its stack size, OR decrement the stack by 1 and drop a single spawner (make this behavior a toggle in config.yml).

C. Universal Compatibility

* Universal Support: The system must dynamically adapt to all valid Minecraft EntityType identifiers (e.g., ZOMBIE, SKELETON, BLAZE) without requiring manual registration for every single mob type. * Persistent Data Storage: Use the PersistentDataContainer (PDC) API to store the entity type and stack count directly on the block state and dropped item stacks. Do not rely on unstable block metadata.

---

2. Configurable Spawn Scales & Logic

The plugin must dynamically scale standard Minecraft Spawner task loops based on the stack size:

Loot & XP Multiplier Formula: Standard_Output (Stack_Size * Modifier). * Dynamic Spawn Rates: Allow configuration to decrease the spawn delay interval or increase the maximum nearby entities dynamically per stack level to optimize server performance (spawning fewer physical entities but multiplying their value upon death).

---

3. Interactive Management INVENTORY GUI

* Trigger: Right-clicking a spawner opens a 9x3 or 9x5 inventory interface. * INVENTORY GUI Features: * Information Panel: Displays current Mob Type, Stack Size, Next Upgrade Requirements, and projected Loot/XP multipliers. * Unstack/Retrieve Button: Allows players to safely click an item to pull 1 or more spawners out of the stack back into their inventory (if space permits). * Stats Tracker: Displays total items/XP farmed by this specific spawner block.

---

4. Robustness & Anti-Grief Exploit Prevention

* Grief Prevention Hook: Ensure the left-click stacking and right-click INVENTORY GUI systems respect region management plugins (WorldGuard, GriefPrevention, Towny). If a player cannot build in a region, block all interactions. * Thread-Safe Logic: Use asynchronous execution tasks for data tracking and configuration reads to keep the primary server tick thread perfectly stable at 20.0 TPS.

---

5. Configuration File Template (config.yml)

```yaml settings: max-stack-size: 64 require-silk-touch: true drop-entire-stack-on-break: false # If false, drops 1 spawner item and reduces block stack by 1

economy-upgrades: xp-multiplier-per-stack: 1.0 loot-multiplier-per-stack: 1.0

messages: stacked: "&#FF6B00&lZaratic &r&8» &7Spawner stacked successfully! (&e%stack%&7/&e%max%&7)" no-permission: "&cYou do not have permission to modify this spawner." no-silk: "&cYou must use a Silk Touch pickaxe to retrieve this spawner!"

Kodari AI
KodariJun 25 at 9:46 pm 50
StackingSpawners
A high-performance Spigot/Paper 1.20+ optimization plugin that lets players stack identical spawners together to scale loot and XP output. Features PDC-based persistent storage, Silk Touch enforcement for retrieval, a fully interactive GUI for managing stack info and unstacking, per-spawner kill/XP statistics, configurable loot and XP multipliers via EntityDeathEvent, and built-in soft hooks for WorldGuard, GriefPrevention, and Towny.

Here’s a summary of every system built:

Core

  • StackingSpawners — main class, initializes all managers and registers listeners; includes a static colorize() that handles both legacy & codes and &#RRGGBB hex

  • ConfigManager — typed getters backed by config.yml with all defaults

  • SpawnerManager — all PDC read/write for block state (stack size, entity type, total kills/XP) and item PDC + BlockStateMeta for cross-version spawner type detection

Listener (SpawnerListener)

  • PlayerInteractEvent LEFT_CLICK → stacks matching spawner with 300 ms cooldown + anti-grief gate

  • PlayerInteractEvent RIGHT_CLICK → opens SpawnerGUI

  • BlockDamageEvent → cancels mining when holding a spawner on a spawner

  • BlockBreakEvent → enforces Silk Touch, handles per-config drop (whole stack as 1 NBT item, OR single spawner + block decrement)

  • BlockPlaceEvent → copies entity type + stack size PDC from item to block on placement

  • EntityDeathEvent → filters for SPAWNER-spawned mobs, scans a 16-block radius for a matching spawner, multiplies drops/XP by stackSize × configMultiplier, and records stats

Anti-Grief Hooks — WorldGuard, GriefPrevention, Towny all wrapped in try/catch soft-dependency hooks registered only when the plugin is present

GUI — full button-based InventoryGUI framework with a SpawnerGUI showing an info panel (type, stack size, multipliers), a statistics panel (kills/XP), and an unstack button that pops one spawner into the player’s inventory

mercera1

make it so if they tryto mine withouth silk touch it stays there and doesnt dissapear same whenever they try to left click on it with the same spawner make it automaticly combine and maek sure it doesn tbreak and make it so it automaticly gathers items it should spawn the enemy at all it should have the items in the item INVENTORY GUI and they can either collect or sell it and make it better overall

mercera1

make it so if they tryto mine withouth silk touch it stays there and doesnt dissapear same whenever they try to left click on it with the same spawner make it automaticly combine and maek sure it doesn tbreak and make it so it automaticly gathers items it should spawn the enemy at all it should have the items in the item INVENTORY INVENTORY GUI and they can either collect or sell it and make it better overall

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
17 1,029
src/main/java/com/zaratic/stackingspawners/StackingSpawners.java
package com.zaratic.stackingspawners;

import com.zaratic.stackingspawners.hook.HookManager;
import com.zaratic.stackingspawners.inventory.gui.GUIListener;
import com.zaratic.stackingspawners.inventory.gui.GUIManager;
import com.zaratic.stackingspawners.listener.SpawnerListener;
import lombok.Getter;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StackingSpawners extends JavaPlugin {

    @Getter private static StackingSpawners instance;
    @Getter private ConfigManager configManager;
    @Getter private SpawnerManager spawnerManager;
    @Getter private GUIManager guiManager;
    @Getter private HookManager hookManager;

    private static final Pattern HEX_PATTERN = Pattern.compile("&#([A-Fa-f0-9]{6})");

    @Override
    public void onEnable() {
        instance = this;
        saveDefaultConfig();

        configManager = new ConfigManager(this);
        spawnerManager = new SpawnerManager(this);
        guiManager = new GUIManager();
        hookManager = new HookManager(this);

        getServer().getPluginManager().registerEvents(new SpawnerListener(this), this);
        getServer().getPluginManager().registerEvents(new GUIListener(guiManager), this);

        getLogger().info("StackingSpawners v" + getDescription().getVersion() + " enabled.");
    }

    @Override
    public void onDisable() {
        getLogger().info("StackingSpawners disabled.");
    }

    public static String colorize(String text) {
        if (text == null) return "";
        Matcher matcher = HEX_PATTERN.matcher(text);
        StringBuffer buffer = new StringBuffer();
        while (matcher.find()) {
            String hex = matcher.group(1);
            StringBuilder replacement = new StringBuilder("§x");
            for (char c : hex.toCharArray()) {
                replacement.append('§').append(c);
            }
            matcher.appendReplacement(buffer, replacement.toString());
        }
        matcher.appendTail(buffer);
        return ChatColor.translateAlternateColorCodes('&', buffer.toString());
    }
}