Ryan Bonner

can you make a simpl, lightweight plugin for minecraft for paper 1.21.11 that lets bundles hold 8 stacks worth of items instead of just 1 stack

Kodari AI
KodariOct 18 at 7:34 pm 1
BundleCapacityExpander
A lightweight Paper 1.21.11 plugin that increases bundle item capacity from one stack to eight stacks. The plugin intercepts bundle interactions and modifies the internal item storage logic to allow storing up to eight stacks of any item type. It works seamlessly with vanilla bundles, preserving all existing functionality while expanding storage capacity. The plugin uses a simple event listener approach to detect bundle usage and applies the increased capacity dynamically without requiring configuration or database storage. Players can store more items in a single bundle, making inventory management more efficient. The plugin is designed to be minimal and performant, with no external dependencies beyond the Paper API.

Plan:

  1. Check Paper 1.21.11’s bundle APIs for a supported capacity setting.

  2. Create a minimal plugin and descriptor using the supported approach.

Created BundleCapacity for Paper 1.21.11. It lets a bundle hold up to 512 capacity units—eight full stacks of 64-stack items. With a bundle on your cursor, left-click an item stack to add as much as fits; right-click to add half.

Added the plugin class, plugin.yml, and Gradle build configuration.

Ryan Bonner

it doesnt let me put anything past 1 stack, make sure i can put up to a total of 512 items, so 8 stacks, and unstackable items count as 64 where things that stack to 16 count as 4 each, also make a command to configer the amount of items i can put in it

Kodari AI
KodariOct 18 at 8:26 pm 1
  1. Fix bundle capacity so stack size affects the item-unit cost as requested.

  2. Add a command to configure the capacity, with permission and usage in the plugin descriptor.

Updated bundle capacity to use weighted units: stackable-to-64 items cost 1 each, stackable-to-16 items cost 4 each, and unstackable items cost 64 each. The default capacity is 512 units.

Use /bundlecapacity <amount> to change and save the capacity; /bundlecapacity shows the current value. The command requires the bundlecapacity.admin permission, granted to operators by default.

Ryan Bonner

it still doesnt work make sure it works on 1.21.11 paper servers

Kodari AI
KodariOct 18 at 8:30 pm 1
  • The current handler only recognizes a bundle on the cursor, so clicks with an item on the cursor and the bundle in a slot bypass the capacity logic.

  • I’ll handle both click directions and keep the same configurable weighted capacity, updating the correct bundle and item stacks.

Fixed the inventory handler: it now adds items whether the bundle is on your cursor or in the clicked slot, and updates the bundle and leftover stack accordingly. The 512-unit default and /bundlecapacity <amount> setting remain in place, with stack-size weighting unchanged.

On Paper 1.21.11, restart the server or reload the plugin to apply the update.

Ryan Bonner

the command works, but it doesnt change anything about the bundles, make sure that it works on a paper 1.21.11 minecraft server, the bundle still only hold 64 items doesnt go over when i set the number higher and doesnt go lower when i set the number lower

Kodari AI
KodariOct 19 at 6:27 am 1

The bundle’s 64-unit limit is enforced by Minecraft itself, so changing BundleMeta contents cannot raise it. I’m replacing that storage path with plugin-managed bundle contents and a small inventory interface, so the configured capacity applies above and below vanilla’s limit while preserving items already stored.

Replaced the native BundleMeta capacity approach: Minecraft enforces its own 64-unit bundle limit, so changing that metadata could never raise the limit. The plugin now stores bundle contents separately and uses a custom inventory to manage them.

Right-click a bundle to open its contents. Add items by clicking an item stack onto the bundle in your inventory; left-click adds as much as fits, and right-click adds half. In the contents menu, left-click takes a full stack and right-click takes half.

The configured capacity now limits additions above or below the vanilla limit. Lowering capacity won’t delete items already stored; you’ll need to take items out until the bundle is under the new limit. Restart the Paper 1.21.11 server to load the update.

Ryan Bonner

the bundle still doesnt hold more items no matter how i put them in, still only allows one stack worth of items

Kodari AI
KodariOct 19 at 6:31 am 1
  • Make the bundle contents menu accept items from the cursor and via shift-click, with the configured weighted capacity enforced.

  • Keep taking items out of the menu and update the held bundle after every transfer.

Fixed the missing transfer into the custom bundle storage. Before, the contents menu allowed taking items out but didn’t actually store items added to it.

Open the bundle, then click an item stack from your cursor onto a contents slot to add it. You can also shift-click items from your inventory. Both paths now apply the configured weighted capacity: regular items cost 1 unit each, 16-stack items cost 4, and unstackable items cost 64. Replace the plugin with the updated build and restart the Paper server.

Ryan Bonner

can you make it so that the amount of items that are in the bundle are shown in the bundle's ui (64/512)

Kodari AI
KodariOct 19 at 6:35 am 1
  • Show weighted stored capacity as used/capacity on the bundle tooltip and in its contents menu.

  • Refresh that display whenever contents change or the menu opens, so configured capacity is reflected.

Added a Stored: 64/512 indicator to the bundle’s tooltip and contents menu. It refreshes when you open the bundle or change its contents; the count uses the same weighted units as the capacity setting.

Ryan Bonner

can you make it so that when i put something in a bundle that already has the same item as before they stack, for example if there are 15 diamonds in a bundle, and i put 6 more in, it makes a stack, dont make them stack past 64

Kodari AI
KodariOct 20 at 3:59 pm 1
  • Merge all similar item stacks when adding, including older duplicate stacks already stored.

  • Split the combined amount into stacks capped at 64 (or the item’s lower native max).

Updated bundle storage so adding identical items merges them into existing stacks. For example, 15 diamonds plus 6 more now appear as one stack of 21. Stacks are capped at 64 (or the item’s lower native stack limit).

Replace the plugin with the updated build and restart the Paper server to apply it.

Ryan Bonner

everything put in the bundles got deleted instead of stacking

Kodari AI
KodariOct 20 at 4:12 pm 1
  • Prevent item consumption unless the updated bundle data saves successfully.

  • Make same-item merging preserve unrelated contents and cap each merged stack at 64.

Fixed the data-loss path: the plugin now leaves items in your inventory if saving the bundle contents fails. Same-item stacks are merged while unrelated contents are preserved, and merged stacks stay capped at 64.

Replace the plugin with the updated build and restart the Paper server. Items lost before this fix can’t be restored by the plugin.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 541
src/main/java/com/kodari/bundlecapacity/BundleCapacityPlugin.java
package com.kodari.bundlecapacity;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.BundleMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.UUID;

public final class BundleCapacityPlugin extends JavaPlugin implements Listener {
    private static final int DEFAULT_CAPACITY = 8 * 64;
    private static final int CONTENT_SLOTS = 45;
    private static final String CONTENTS_LORE_PREFIX = ChatColor.GRAY + "Stored: ";
    private NamespacedKey contentsKey;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        contentsKey = new NamespacedKey(this, "contents");
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!command.getName().equalsIgnoreCase("bundlecapacity")) {
            return false;
        }
        if (!sender.hasPermission("bundlecapacity.admin")) {
            sender.sendMessage(ChatColor.RED + "You don't have permission to change bundle capacity.");
            return true;
        }
        if (args.length == 0) {
            sender.sendMessage(ChatColor.GREEN + "Bundle capacity: "
                    + ChatColor.YELLOW + getConfig().getInt("capacity", DEFAULT_CAPACITY)
                    + ChatColor.GREEN + " units.");
            return true;
        }
        if (args.length != 1) {
            sender.sendMessage(ChatColor.RED + "Usage: /bundlecapacity [amount]");
            return true;
        }

        int capacity;
        try {
            capacity = Integer.parseInt(args[0]);
        } catch (NumberFormatException exception) {
            sender.sendMessage(ChatColor.RED + "Capacity must be a positive whole number.");
            return true;
        }
        if (capacity <= 0) {
            sender.sendMessage(ChatColor.RED + "Capacity must be a positive whole number.");
            return true;
        }

        getConfig().set("capacity", capacity);
        saveConfig();
        sender.sendMessage(ChatColor.GREEN + "Bundle capacity set to "
                + ChatColor.YELLOW + capacity + ChatColor.GREEN + " units.");
        return true;
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onInventoryClick(InventoryClickEvent event) {
        if (event.getView().getTopInventory().getHolder() instanceof BundleInventory gui) {
            event.setCancelled(true);
            handleBundleInventoryClick(event, gui);
            return;
        }

        ItemStack cursor = event.getCursor();
        ItemStack clicked = event.getCurrentItem();
        boolean bundleOnCursor = isBundle(cursor);
        boolean bundleInSlot = isBundle(clicked);
        if (bundleOnCursor == bundleInSlot
                || (event.getClick() != ClickType.LEFT && event.getClick() != ClickType.RIGHT)) {
            return;
        }

        ItemStack bundle = bundleOnCursor ? cursor : clicked;
        ItemStack offered = bundleOnCursor ? clicked : cursor;
        if (offered == null || offered.getType().isAir() || isBundle(offered)) {
            return;
        }

        event.setCancelled(true);

        int requested = event.getClick() == ClickType.RIGHT
                ? (offered.getAmount() + 1) / 2
                : offered.getAmount();
        List<ItemStack> contents = readContents(bundle);
        int currentWeight = contents.stream().mapToInt(BundleCapacityPlugin::weight).sum();
        int capacity = getConfig().getInt("capacity", DEFAULT_CAPACITY);
        int maxStackSize = Math.max(1, offered.getMaxStackSize());
        int unitWeight = Math.max(1, (64 + maxStackSize - 1) / maxStackSize);
        int accepted = Math.min(requested, Math.max(0, capacity - currentWeight) / unitWeight);
        if (accepted <= 0) {
            if (bundleOnCursor) {
                event.setCursor(bundle);
            } else {
                event.setCurrentItem(bundle);
            }
            return;
        }

        ItemStack updatedBundle = bundle.clone();
        ItemStack stored = offered.clone();
        stored.setAmount(accepted);
        addToContents(contents, stored);
        if (!writeContents(updatedBundle, contents)) {
            ((Player) event.getWhoClicked()).sendMessage(ChatColor.RED + "Could not save the bundle contents; no items were moved.");
            return;
        }

        if (bundleOnCursor) {
            event.setCursor(updatedBundle);
            if (accepted == clicked.getAmount()) {
                event.setCurrentItem(null);
            } else {
                ItemStack remainder = clicked.clone();
                remainder.setAmount(clicked.getAmount() - accepted);
                event.setCurrentItem(remainder);
            }
        } else {
            event.setCurrentItem(updatedBundle);
            if (accepted == cursor.getAmount()) {
                event.setCursor(null);
            } else {
                ItemStack remainder = cursor.clone();
                remainder.setAmount(cursor.getAmount() - accepted);
                event.setCursor(remainder);
            }
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onBundleUse(PlayerInteractEvent event) {
        if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
            return;
        }
        if (event.getHand() == null || !isBundle(event.getItem())) {
            return;
        }

        event.setCancelled(true);
        openBundleInventory(event.getPlayer(), event.getHand(), 0);
    }

    @EventHandler
    public void onInventoryDrag(InventoryDragEvent event) {
        if (event.getView().getTopInventory().getHolder() instanceof BundleInventory) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onPlayerItemHeld(PlayerItemHeldEvent event) {
        if (hasOpenBundleInventory(event.getPlayer())) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
        if (hasOpenBundleInventory(event.getPlayer())) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onPlayerDropItem(PlayerDropItemEvent event) {
        if (hasOpenBundleInventory(event.getPlayer())) {