Skip to content

Commit d170c80

Browse files
committed
Fixed inventory can hold checks
1 parent 94e5d28 commit d170c80

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/ch/njol/skript/aliases/ItemType.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ public boolean hasSpace(final Inventory invi) {
657657
if (getItem().types.size() != 1 || getItem().types.get(0).hasDataRange() || getItem().types.get(0).typeid == -1)
658658
return false;
659659
}
660-
return addTo(getCopiedContents(invi));
660+
return addTo(getStorageContents(invi));
661661
}
662662

663663
public final static ItemStack[] getCopiedContents(final Inventory invi) {
@@ -668,6 +668,23 @@ public final static ItemStack[] getCopiedContents(final Inventory invi) {
668668
return buf;
669669
}
670670

671+
/**
672+
* Gets copy of storage contents, i.e. ignores armor and off hand. This is due to Spigot 1.9
673+
* added armor slots, and off hand to default inventory index.
674+
* @param invi Inventory
675+
* @return Copied storage contents
676+
*/
677+
public final static ItemStack[] getStorageContents(final Inventory invi) {
678+
if (invi instanceof PlayerInventory) {
679+
final ItemStack[] buf = invi.getContents();
680+
final ItemStack[] tBuf = new ItemStack[36];
681+
for (int i = 0; i < 36; i++)
682+
if (buf[i] != null)
683+
tBuf[i] = buf[i].clone();
684+
return tBuf;
685+
} else return getCopiedContents(invi);
686+
}
687+
671688
/**
672689
* @return List of ItemDatas. The returned list is not modifiable, use {@link #add(ItemData)} and {@link #remove(ItemData)} if you need to change the list, or use the
673690
* {@link #iterator()}.

src/main/java/ch/njol/skript/conditions/CondCanHold.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public boolean check(final ItemType t) {
9191
}
9292
}, isNegated());
9393
}
94-
final ItemStack[] buf = ItemType.getCopiedContents(invi);
94+
final ItemStack[] buf = ItemType.getStorageContents(invi);
9595
return items.check(e, new Checker<ItemType>() {
9696
@Override
9797
public boolean check(final ItemType t) {

0 commit comments

Comments
 (0)