Frederico Rocha
📎 1 file 6,157 chars
📄
pasted-code-1788615605807.txt
txt 234 lines
▶
Create a complete, production-ready **Paper Minecraft plugin** called **BigBundle** for **Minecraft Java Edition 26.2**.

The plugin is intended for a public server with **90+ concurrent players**, so prioritize reliability, performance, concurrency safety, item-duplication prevention, and persistent data.

## Main feature

Add a new item called **Big Bundle**.

The Big Bundle should be based on the vanilla `minecraft:bundle`.

Players obtain it by using a **Smithing Table** with:

* Template: **Chest**
* Base: **Bundle**
* Addition: **Leather**

The result must be a Big Bundle.

## Big Bundle behavior

When a player right-clicks a Big Bundle, open a real **9-slot custom inventory GUI** titled:

`Big Bundle`

The GUI should look and behave like a small chest inventory.

Players can:

* Put items into the 9 slots.
* Remove items.
* Move items normally between their inventory and the Big Bundle.
* Use normal mouse interactions where safe.

The Big Bundle's contents must persist **inside that specific Big Bundle item**.

For example:

Big Bundle A:

* Stone
* Iron
* Bread

Big Bundle B:

* Diamonds
* Tools

These must remain completely independent.

A player must be able to:

* Drop the Big Bundle.
* Put it inside a chest.
* Give it to another player.
* Trade it.
* Move it between worlds.
* Log out and return later.

Its contents must remain attached to the item.

## Data storage

Use modern Paper/Minecraft APIs appropriate for **Paper 26.2**.

Do NOT use:

* Java `ObjectOutputStream`
* `BukkitObjectOutputStream`
* Temporary chest blocks
* A global map as the permanent storage mechanism
* A database unless absolutely necessary

Use Paper's modern ItemStack serialization/data-component APIs where appropriate.

Give every Big Bundle a **unique UUID** in persistent item data so individual bundles can always be distinguished.

Store the 9 inventory slots in the item itself.

## Security / anti-duplication

This is extremely important because the plugin will run on a 90+ player server.

Handle and test:

* Normal clicks
* Shift-clicks
* Number-key/hotbar swapping
* Double-click item collection
* Drag events
* Offhand interactions
* Dropping the item
* Moving the item between inventory slots
* Closing the GUI
* Player disconnecting
* Player dying
* Server shutdown
* Server restart
* Reload/plugin disable where applicable
* Opening another Big Bundle while one is already open
* Attempting to put a Big Bundle inside itself
* Attempting to put a Big Bundle inside another Big Bundle
* Inventory manipulation by unusual Bukkit/Paper inventory actions

The plugin must never duplicate, delete, or overwrite items because of GUI interactions.

Do not allow a player to manipulate the physical Big Bundle item that is currently being opened.

When the GUI is open, track the exact:

* Player UUID
* Inventory slot
* Hand
* Big Bundle UUID

Before saving, verify that the same Big Bundle is still being used.

If the original item is no longer present, safely handle the situation rather than writing the GUI contents into another item.

## Performance

The server may have 90+ players.

Therefore:

* No repeating task for every player.
* No polling every tick.
* No unnecessary database queries.
* No expensive loops running continuously.
* Only process a Big Bundle when it is opened, modified, or closed.
* Keep the plugin lightweight.

## GUI

Use a proper custom `InventoryHolder` to identify the Big Bundle GUI.

Do NOT identify the GUI only by its title.

The inventory should contain exactly 9 storage slots.

The player inventory should remain separate.

## Item appearance

Name:

`Big Bundle`

Give it a suitable lore such as:

`9-slot portable storage`

Use persistent custom data to identify the item.

Do not rely only on its display name because players can rename items.

## Smithing recipe

Register a proper Paper/Bukkit smithing transform recipe:

Template = Chest
Base = Bundle
Addition = Leather
Result = Big Bundle

The recipe must be registered automatically when the plugin starts.

Use a namespaced key such as:

`bigbundle:big_bundle`

## Project requirements

Create the COMPLETE IntelliJ IDEA Gradle project.

Use:

* Java 25
* Gradle
* Kotlin Gradle build script (`build.gradle.kts`)
* Paper API for Minecraft 26.2
* `plugin.yml`

The project must compile without modification.

Include the complete directory structure:

BigBundle/
├── build.gradle.kts
├── settings.gradle.kts
└── src/
└── main/
├── java/
│   └── me/
│       └── ofrocha/
│           └── bigbundle/
│               ├── BigBundlePlugin.java
│               ├── BigBundleItem.java
│               ├── BigBundleGUI.java
│               ├── BigBundleHolder.java
│               └── BigBundleListener.java
└── resources/
└── plugin.yml

You may reorganize the classes if you have a better architecture, but keep the project clean and maintainable.

## Important

Do not give me a code explanation instead of the project.

Actually CREATE the complete project files and provide them as a **downloadable ZIP file** containing the complete IntelliJ/Gradle project.

Before providing the ZIP:

1. Verify that all imports are valid for Paper 26.2.
2. Verify that the Paper API version is correct for 26.2.
3. Verify that the Java version is correct.
4. Verify that the project compiles.
5. Fix all compilation errors.
6. Check for inventory duplication exploits.
7. Make sure the plugin.yml points to the correct main class.
8. Make sure the Smithing Table recipe works.
9. Make sure Big Bundle contents persist after closing/reopening.
10. Make sure contents persist after giving the item to another player.
11. Make sure two different Big Bundles never share their contents.

Finally, provide me with:

* The downloadable ZIP
* The plugin JAR if you compiled it successfully
* A short installation instruction explaining where to put the JAR on a Paper 26.2 server.

Do not leave placeholder code or TODOs.
Kodari AI
KodariSep 5 at 1:47 pm 2
BigBundle
Adds a craftable Big Bundle item (Bundle + Chest template + Leather via Smithing Table) that opens a persistent 9-slot GUI. Each bundle stores its contents in item data via a unique UUID, preventing duplication and cross-bundle mixing. Handles all inventory edge cases including shift-clicks, drags, hotbar swaps, self-containment prevention, and safe saving on close/disconnect.

Created the complete BigBundle Gradle project with:

  • Java 25 toolchain

  • Paper API 26.2-R0.1-SNAPSHOT

  • Persistent UUID-based Big Bundle item data

  • Nine-slot custom GUI using InventoryHolder

  • Smithing recipe

  • Inventory interaction protections

  • Close, quit, death, shutdown, drop, drag, hotbar, offhand, and hopper safeguards

  • plugin.yml pointing to me.ofrocha.bigbundle.BigBundlePlugin

I could not generate or attach a ZIP/JAR in this environment because archive creation and compilation tools are unavailable here.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle.kts
settings.gradle.kts
Code
8 692
src/main/java/me/ofrocha/bigbundle/BigBundlePlugin.java
package me.ofrocha.bigbundle;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.PrepareSmithingEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.SmithingTransformRecipe;
import org.bukkit.plugin.java.JavaPlugin;

import org.bukkit.inventory.EquipmentSlot;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class BigBundlePlugin extends JavaPlugin {
    private final Map<UUID, BundleSession> sessionsByPlayer = new HashMap<>();
    private final Map<UUID, BundleSession> sessionsByBundle = new HashMap<>();

    private BigBundleItem itemData;
    private NamespacedKey recipeKey;

    @Override
    public void onEnable() {
        itemData = new BigBundleItem(this);
        recipeKey = new NamespacedKey(this, "big_bundle");
        registerRecipe();
        getServer().getPluginManager().registerEvents(new BigBundleListener(this), this);
    }

    @Override
    public void onDisable() {
        for (BundleSession session : new ArrayList<>(sessionsByPlayer.values())) {
            closeSession(session);
        }
        sessionsByBundle.clear();
    }

    private void registerRecipe() {
        Bukkit.removeRecipe(recipeKey);
        Material chest = material("CHEST");
        Material bundle = material("BUNDLE");
        Material leather = material("LEATHER");
        SmithingTransformRecipe recipe = new SmithingTransformRecipe(
                recipeKey,
                itemData.create(),
                new RecipeChoice.MaterialChoice(chest),
                new RecipeChoice.MaterialChoice(bundle),
                new RecipeChoice.MaterialChoice(leather)
        );
        Bukkit.addRecipe(recipe);
    }

    private Material material(String name) {
        Material material = Material.matchMaterial(name);
        if (material == null) {
            throw new IllegalStateException("Missing required material: " + name);
        }
        return material;
    }

    public BigBundleItem itemData() {
        return itemData;
    }

    public void prepareSmithingResult(PrepareSmithingEvent event) {
        ItemStack result = event.getInventory().getResult();
        if (itemData.isBigBundle(result)) {
            event.setResult(itemData.create());
        }
    }

    public void openBundle(Player player, EquipmentSlot hand) {
        if (sessionsByPlayer.containsKey(player.getUniqueId())) {
            return;
        }

        int sourceSlot = hand == EquipmentSlot.OFF_HAND ? 40 : player.getInventory().getHeldItemSlot();
        ItemStack source = player.getInventory().getItem(sourceSlot);
        UUID bundleId = itemData.getBundleId(source);
        if (bundleId == null || source.getAmount() != 1 || sessionsByBundle.containsKey(bundleId)) {
            return;
        }

        ItemStack[] contents = itemData.readContents(source);
        for (ItemStack content : contents) {
            if (itemData.isBigBundle(content)) {
                getLogger().warning("Refused to open corrupted nested Big Bundle " + bundleId);
                return;
            }
        }

        BigBundleGUI gui = new BigBundleGUI(bundleId);
        gui.load(contents);
        BundleSession session = new BundleSession(this, player, sourceSlot, hand, bundleId, gui, contents);
        sessionsByPlayer.put(player.getUniqueId(), session);
        sessionsByBundle.put(bundleId, session);
        player.openInventory(gui.getInventory());
    }

    BundleSession sessionFor(Player player) {
        return sessionsByPlayer.get(player.getUniqueId());
    }

    void closeSession(BundleSession session) {
        if (sessionsByPlayer.remove(session.playerId, session)) {
            sessionsByBundle.remove(session.bundleId, session);
            session.finish();
        }
    }

    public static final class BundleSession {
        private final BigBundlePlugin plugin;
        private final Player player;
        private final UUID playerId;
        private final int sourceSlot;
        private final EquipmentSlot hand;
        private final UUID bundleId;
        private final BigBundleGUI gui;
        private final ItemStack[] initialContents;

        private BundleSession(BigBundlePlugin plugin, Player player, int sourceSlot, EquipmentSlot hand,
                              UUID bundleId, BigBundleGUI gui, ItemStack[] initialContents) {
            this.plugin = plugin;
            this.player = player;
            this.playerId = player.getUniqueId();
            this.sourceSlot = sourceSlot;
            this.hand = hand;
            this.bundleId = bundleId;
            this.gui = gui;
            this.initialContents = cloneContents(initialContents);
        }

        public Player player() {
            return player;
        }

        public int sourceSlot() {
            return sourceSlot;
        }

        public EquipmentSlot hand() {
            return hand;
        }

        public UUID bundleId() {
            return bundleId;
        }

        public BigBundleGUI gui() {
            return gui;
        }

        public boolean isSource(ItemStack item) {
            return item != null && item.getAmount() == 1 && bundleId.equals(plugin.itemData().getBundleId(item));
        }

        private void finish() {
            ItemStack[] contents = gui.contents();
            ItemStack source = player.getInventory().getItem(sourceSlot);
            boolean saved = isSource(source) && plugin.itemData().writeContents(source, contents);

            if (!saved) {
                int uniqueSlot = findUniqueBundleSlot();
                if (uniqueSlot >= 0) {
                    ItemStack movedSource = player.getInventory().getItem(uniqueSlot);
                    saved = plugin.itemData().writeContents(movedSource, contents);
                }
            }

            if (!saved) {
                recoverOnlyNewContents(contents);
                plugin.getLogger().warning("Could not verify Big Bundle " + bundleId
                        + " for player " + playerId + "; recovered only newly-added GUI contents.");
            }
            gui.clear();
        }

        private int findUniqueBundleSlot() {
            int found = -1;
            for (int slot = 0; slot < player.getInventory().getSize(); slot++) {
                if (!isSource(player.getInventory().getItem(slot))) {
                    continue;
                }
                if (found >= 0) {
                    return -1;
                }
                found = slot;
            }
            return found;
        }

        private void recoverOnlyNewContents(ItemStack[] contents) {
            ArrayList<ItemStack> remainingOriginal = new ArrayList<>();
            for (ItemStack original : initialContents) {
                if (original != null && !original.getType().isAir() && original.getAmount() > 0) {