mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 11:49:12 +00:00
Truncate contents length for 36 to playerInventory
This commit is contained in:
parent
5968a6bc27
commit
844a4a0574
1 changed files with 9 additions and 1 deletions
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -34,7 +35,14 @@ public final class InventoryWorkaround {
|
|||
// This will will abort if it couldn't store all items
|
||||
public static Map<Integer, ItemStack> addAllItems(final Inventory inventory, final ItemStack... items) {
|
||||
final Inventory fakeInventory = Bukkit.getServer().createInventory(null, inventory.getType());
|
||||
fakeInventory.setContents(inventory.getContents());
|
||||
ItemStack[] contents = inventory.getContents();
|
||||
try {
|
||||
fakeInventory.setContents(contents);
|
||||
} catch (IllegalArgumentException e) {
|
||||
ItemStack[] truncatedContents = new ItemStack[36];
|
||||
System.arraycopy(contents, 0, truncatedContents, 0, truncatedContents.length);
|
||||
fakeInventory.setContents(truncatedContents);
|
||||
}
|
||||
Map<Integer, ItemStack> overFlow = addItems(fakeInventory, items);
|
||||
if (overFlow.isEmpty()) {
|
||||
addItems(inventory, items);
|
||||
|
|
Loading…
Reference in a new issue