JustLukaBraza
📎 1 file 3,784 chars
📄
pasted-code-1772018996595.txt
txt 152 lines
▶
You are a senior Minecraft plugin developer specialized in Paper API (1.20.6 – 1.21+) and modern Java.

I want you to create a fully production-ready, optimized, scalable region-based block regeneration plugin written in Java 21.

CRITICAL REQUIREMENTS:
• Must compile with Java 21
• Use modern Java features where appropriate (records, switch expressions, pattern matching, Optional, etc.)
• Must follow clean architecture principles
• Must be written for Paper (not legacy Spigot API)
• Must support Minecraft 1.20.6 – 1.21+
• Must be fully compatible with ItemsAdder (100% integration)

--------------------------------------------------
JAVA 21 REQUIREMENTS
--------------------------------------------------

• Source/Target version: 21
• Use modern language features
• No deprecated API usage
• No legacy Bukkit patterns
• Use CompletableFuture where async needed
• Use proper thread handling
• Use modern collections
• Use records for data objects where suitable
• Use sealed classes if helpful

--------------------------------------------------
ITEMSADDER FULL INTEGRATION (MANDATORY)
--------------------------------------------------

The plugin MUST:

• Soft-depend on ItemsAdder
• Detect if ItemsAdder is installed
• Use ItemsAdder API to:
    - Detect custom blocks
    - Get namespace:id
    - Remove custom block correctly
    - Place custom block correctly
    - Drop custom items properly
• Store namespace:id for IA blocks
• Regenerate IA blocks safely
• Preserve block data and custom states
• Support custom ores and custom crops
• Never use block.setType() on IA blocks
• Fallback to vanilla if ItemsAdder not installed

--------------------------------------------------
CORE SYSTEM
--------------------------------------------------

Region-based cuboid regeneration system.

Each region must store:

• id
• world
• pos1
• pos2
• regen delay
• drop item (vanilla or IA)
• exp
• money reward
• enabled flag
• block mode (ALL / WHITELIST / SPECIFIC)

On BlockBreakEvent:

1. Detect region
2. Detect if IA block
3. Cancel vanilla drops
4. Give configured drops
5. Schedule regeneration
6. Restore original block (vanilla or IA)

Each block regeneration must be independent.

--------------------------------------------------
PERFORMANCE REQUIREMENTS
--------------------------------------------------

• O(1) region lookup
• No scanning entire region every break
• Use spatial containment checks only
• Async-safe saving
• Chunk-load safe regeneration
• No lag spikes in large farms

--------------------------------------------------
INVENTORY GUI SYSTEM
--------------------------------------------------

Modern inventory INVENTORY GUI system.

Features:

• Region list
• Region editor
• Edit delay
• Edit drop
• Edit exp
• Edit money
• Toggle region
• Detect IA item when clicked
• Proper event cancellation

--------------------------------------------------
SOFT DEPENDENCIES
--------------------------------------------------

• Vault (economy)
• PlaceholderAPI (optional)
• ItemsAdder (full support)

--------------------------------------------------
PROJECT STRUCTURE
--------------------------------------------------

Maven project.

Java 21.

Paper API dependency.

Packages:

com.yourname.regen
 ├── RegenPlugin
 ├── region
 ├── INVENTORY GUI
 ├── commands
 ├── listeners
 ├── itemsadder
 ├── storage
 ├── economy
 ├── utils

--------------------------------------------------
FILES REQUIRED IN OUTPUT
--------------------------------------------------

1. pom.xml (Java 21)
2. plugin.yml
3. Full source code (all classes)
4. config.yml
5. messages.yml
6. Instructions how to compile with Maven
7. Explanation of ItemsAdder integration
8. Explanation of regeneration scheduling logic

Do NOT summarize.
Write complete working production-ready code.
Kodari AI
KodariFeb 25 at 11:36 am 53,733 (v2)

Let me plan the full plugin architecture before writing any code.

Classes to create:

  • Main plugin + managers (RegionManager, RegenManager, EconomyManager, GUIManager)

  • Region data (RegionData, BlockSnapshot records)

  • ItemsAdder integration (IAHook)

  • Storage (RegionStorage)

  • Listeners (BlockBreakListener, GUIListener)

  • GUI system (InventoryGUI, InventoryButton, InventoryHandler, GUIManager + impls)

  • Commands (RegenCommand)

  • Utils (ColorUtil, ItemBuilder)

This is a Gradle project (per system rules, not Maven despite the request). Let me build everything out.

BlockRegenX
A region-based block regeneration plugin for Paper 1.20.6–1.21+. Supports cuboid regions with configurable regen delay, custom drops, EXP, and money rewards. Full ItemsAdder integration for custom block detection, removal, and placement. Features O(1) region lookup, chunk-load-safe async scheduling, Vault economy support, PlaceholderAPI, and a full inventory GUI editor for managing regions and their properties.

Now I have everything I need. Let me plan the complete architecture:

  • Core: RegenPlugin, RegionData, BlockMode, BlockSnapshot (record), RegionManager, RegenManager

  • Storage: RegionStorage (async YAML)

  • Hooks: IAHook (ItemsAdder), EconomyManager (Vault)

  • Listeners: BlockBreakListener, IABlockBreakListener

  • GUI: Full InventoryHandler/Button/GUI framework + RegionListGUI, RegionEditorGUI, GUIManager, GUIListener

  • Commands: RegenCommand

  • Utils: ColorUtil, ItemBuilder

BlockRegenX
A region-based block regeneration plugin for Paper 1.20.6–1.21+. Supports cuboid regions with configurable regen delay, custom drops, EXP, and money rewards. Full ItemsAdder integration for custom block detection, removal, and placement. Features O(1) region lookup, chunk-load-safe async scheduling, Vault economy support, PlaceholderAPI, and a full inventory GUI editor for managing regions and their properties.

Now everything is written. Let me verify the main plugin class references getIaHook() which needs to match the field name:

Good. Now let me create all the files:

All 28 files have been created. Here is a complete summary of what was built:


BlockRegenX — Complete Plugin

Project Structure

Plain Text
BlockRegenX/
├── build.gradle                          (Java 21, Paper + Vault + IA + PAPI)
├── settings.gradle
└── src/main/
    ├── resources/
    │   ├── plugin.yml
    │   ├── config.yml
    │   └── messages.yml
    └── java/com/blockregen/
        ├── RegenPlugin.java              (Main class, @Getter managers)
        ├── region/
        │   ├── BlockMode.java            (ALL / WHITELIST / SPECIFIC)
        │   ├── BlockSnapshot.java        (record: location, blockData, iaId)
        │   ├── RegionData.java           (@Getter/@Setter full region model)
        │   └── RegionManager.java        (O(1) HashMap lookup by id)
        ├── regen/
        │   └── RegenManager.java         (per-block scheduler, chunk-safe)
        ├── hooks/
        │   └── IAHook.java               (Full ItemsAdder integration)
        ├── economy/
        │   └── EconomyManager.java       (Vault soft-depend)
        ├── storage/
        │   └── RegionStorage.java        (Async-capable YAML persistence)
        ├── listeners/
        │   ├── BlockBreakListener.java   (Vanilla block break handler)
        │   ├── IABlockBreakListener.java (CustomBlockBreakEvent handler)
        │   └── WandListener.java         (Selection wand L/R click)
        ├── utils/
        │   ├── SelectionSession.java     (Pos1/Pos2 per-player sessions)
        │   ├── ColorUtil.java
        │   ├── ItemBuilder.java
        │   └── MessageUtil.java
        ├── inventory/
        │   ├── InventoryHandler.java
        │   ├── InventoryButton.java
        │   ├── InventoryGUI.java
        │   ├── gui/
        │   │   ├── GUIManager.java
        │   │   └── GUIListener.java
        │   └── impl/
        │       ├── RegionListGUI.java    (Paginated region list)
        │       └── RegionEditorGUI.java  (Full region editor)
        └── commands/
            └── RegenCommand.java         (Full command + tab completion)

Commands

Command
Description
/regen wand
Get selection wand (Blaze Rod)
/regen create <id>
Create region from wand selection
/regen delete <id>
Delete a region
/regen list
List all regions in chat
/regen gui
Open paginated GUI editor
/regen info <id>
Show full region info
/regen toggle <id>
Enable/disable region
/regen setdelay <id> <s>
Set regen delay
/regen setdrop <id> <item>
Set drop (vanilla or
ns:id
)
/regen setmoney <id> <amt>
Set money reward
/regen setexp <id> <amt>
Set EXP reward
/regen tp <id>
Teleport to region center
/regen reload
Reload config + regions

How to Compile

Shell
./gradlew build
# JAR will be at: build/libs/BlockRegenX-1.0.0.jar

ItemsAdder Integration

  • IAHook soft-depends and detects IA on startup

  • Listens to ItemsAdderLoadDataEvent before using any IA API

  • CustomBlockBreakEvent is caught in IABlockBreakListener — the event is cancelled, CustomBlock.remove() is called manually, and drops are given via CustomBlock.getLoot()

  • Regeneration uses CustomBlock.place(namespacedId, location) for IA blocks, vanilla block.setBlockData() for normal blocks

  • Drop items support namespace:id format — detected via CustomStack.byItemStack() and given via CustomStack.getInstance()

Regeneration Logic

Each broken block schedules an independent BukkitTask with a configurable delay. Before regeneration fires, the chunk is checked for load — if unloaded, it retries after 2 seconds. A ConcurrentHashMap keyed by world:x:y:z prevents double-scheduling the same block. BlockSnapshot (a Java 21 record) stores the full BlockData and optional IA namespace ID for accurate restoration.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
29 1,977
src/main/java/com/blockregen/RegenPlugin.java
package com.blockregen;

import com.blockregen.commands.RegenCommand;
import com.blockregen.economy.EconomyManager;
import com.blockregen.hooks.IAHook;
import com.blockregen.inventory.gui.GUIListener;
import com.blockregen.inventory.gui.GUIManager;
import com.blockregen.listeners.BlockBreakListener;
import com.blockregen.listeners.IABlockBreakListener;
import com.blockregen.listeners.WandListener;
import com.blockregen.region.RegionManager;
import com.blockregen.regen.RegenManager;
import com.blockregen.storage.RegionStorage;
import com.blockregen.utils.ColorUtil;
import lombok.Getter;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;

@Getter
public class RegenPlugin extends JavaPlugin {

    @Getter
    private static RegenPlugin instance;

    private RegionManager regionManager;
    private RegenManager regenManager;
    private EconomyManager economyManager;
    private IAHook iaHook;
    private GUIManager guiManager;
    private RegionStorage regionStorage;

    private FileConfiguration messages;
    private Economy economy;

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

        saveDefaultConfig();
        loadMessages();

        this.regionStorage = new RegionStorage(this);
        this.regionManager = new RegionManager(this);
        this.regenManager = new RegenManager(this);
        this.guiManager = new GUIManager();
        this.iaHook = new IAHook(this);
        this.economyManager = new EconomyManager(this);

        regionStorage.loadAll();
        economyManager.setup();

        Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
        Bukkit.getPluginManager().registerEvents(new BlockBreakListener(this), this);
        Bukkit.getPluginManager().registerEvents(new WandListener(this), this);

        if (iaHook.isEnabled()) {
            Bukkit.getPluginManager().registerEvents(new IABlockBreakListener(this), this);
            getLogger().info("ItemsAdder hook enabled.");
        }

        RegenCommand regenCommand = new RegenCommand(this);
        getCommand("regen").setExecutor(regenCommand);
        getCommand("regen").setTabCompleter(regenCommand);

        scheduleSave();

        getLogger().info("BlockRegenX enabled successfully.");
    }

    @Override
    public void onDisable() {
        if (regenManager != null) {
            regenManager.cancelAll();
        }
        if (regionStorage != null) {
            regionStorage.saveAll();
        }
        getLogger().info("BlockRegenX disabled.");
    }

    public void reload() {
        reloadConfig();
        loadMessages();
        regionStorage.loadAll();
    }

    private void loadMessages() {
        File file = new File(getDataFolder(), "messages.yml");
        if (!file.exists()) {
            saveResource("messages.yml", false);
        }
        messages = YamlConfiguration.loadConfiguration(file);
    }

    public String getMessage(String key) {
        String prefix = ColorUtil.color(messages.getString("prefix", "&8[&6BlockRegenX&8] &r"));
        String msg = messages.getString(key, "&cMissing message: " + key);
        return prefix + ColorUtil.color(msg);
    }

    public String getMessage(String key, String... replacements) {
        String msg = getMessage(key);
        for (int i = 0; i + 1 < replacements.length; i += 2) {
            msg = msg.replace(replacements[i], replacements[i + 1]);
        }
        return msg;
    }

    public String getRawMessage(String key) {
        return ColorUtil.color(messages.getString(key, "&cMissing message: " + key));
    }

    private void scheduleSave() {
        int interval = getConfig().getInt("storage.save-interval", 300) * 20;
        Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> regionStorage.saveAll(), interval, interval);
    }

    public boolean isDebug() {
        return getConfig().getBoolean("debug", false);
    }

    private boolean setupEconomy() {
        if (Bukkit.getPluginManager().getPlugin("Vault") == null) return false;
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) return false;
        economy = rsp.getProvider();
        return economy != null;
    }
}