mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 21:19:00 +01:00
Properly return contents of Inventory. Fixes BUKKIT-3930
When an array of an inventory's contents is requested, we loop through the contents of the NMS inventory's ItemStacks in order to return Bukkit ItemStacks that can be used through the API. However, the NMS ItemStack can, in some cases, be larger than the physical size of the inventory. Using the size of the NMS array as a limit on the loop that follows can result in an ArrayIndexOutOfBoundsException because the Bukkit array's length is the actual size of the inventory, and thus will be smaller. With this commit we use the smaller of the two arrays' length as the limit in the loop, thus eliminating the possibility that the smaller array will be asked for an index higher than its length.
This commit is contained in:
parent
c33908509a
commit
743d0fb603
@ -54,7 +54,8 @@ public class CraftInventory implements Inventory {
|
||||
ItemStack[] items = new ItemStack[getSize()];
|
||||
net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();
|
||||
|
||||
for (int i = 0; i < mcItems.length; i++) {
|
||||
int size = Math.min(items.length, mcItems.length);
|
||||
for (int i = 0; i < size; i++) {
|
||||
items[i] = mcItems[i] == null ? null : CraftItemStack.asCraftMirror(mcItems[i]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user