From 381c89f8272b719fadb3d143b0bca4cdd045b49d Mon Sep 17 00:00:00 2001 From: Intybyte Date: Fri, 20 Dec 2024 22:05:41 +0100 Subject: [PATCH] Fix the issue --- .../commands/subcommands/GiveCommand.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java index fd4613e1ea..f894f67536 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/commands/subcommands/GiveCommand.java @@ -74,7 +74,8 @@ private void giveItem(CommandSender sender, Player p, SlimefunItem sfItem, Strin } Slimefun.getLocalization().sendMessage(p, "messages.given-item", true, msg -> msg.replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); - Map excess = p.getInventory().addItem(new CustomItemStack(sfItem.getItem(), amount)); + ItemStack[] items = parseStackArray(sfItem.getItem(), amount); + Map excess = p.getInventory().addItem(items); if (Slimefun.getCfg().getBoolean("options.drop-excess-sf-give-items") && !excess.isEmpty()) { for (ItemStack is : excess.values()) { p.getWorld().dropItem(p.getLocation(), is); @@ -84,6 +85,30 @@ private void giveItem(CommandSender sender, Player p, SlimefunItem sfItem, Strin Slimefun.getLocalization().sendMessage(sender, "messages.give-item", true, msg -> msg.replace(PLACEHOLDER_PLAYER, args[1]).replace(PLACEHOLDER_ITEM, sfItem.getItemName()).replace(PLACEHOLDER_AMOUNT, String.valueOf(amount))); } + private ItemStack[] parseStackArray(ItemStack itemStack, int amount) { + int stackSize = itemStack.getMaxStackSize(); + int stackAmount = amount / stackSize; + int excess = amount - stackAmount * stackSize; + + int totalSize = stackAmount; + if (excess != 0) { + totalSize++; + } + + ItemStack[] toGive = new ItemStack[totalSize]; + for (int i = 0; i < stackAmount; i++) { + toGive[i] = itemStack.clone(); + toGive[i].setAmount(stackSize); + } + + if (excess != 0) { + toGive[stackAmount] = itemStack.clone(); + toGive[stackAmount].setAmount(excess); + } + + return toGive; + } + private int parseAmount(String[] args) { int amount = 1;