Skip to content

Commit

Permalink
Fixed inventory can hold checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Mar 25, 2016
1 parent 94e5d28 commit d170c80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/main/java/ch/njol/skript/aliases/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public boolean hasSpace(final Inventory invi) {
if (getItem().types.size() != 1 || getItem().types.get(0).hasDataRange() || getItem().types.get(0).typeid == -1)
return false;
}
return addTo(getCopiedContents(invi));
return addTo(getStorageContents(invi));
}

public final static ItemStack[] getCopiedContents(final Inventory invi) {
Expand All @@ -668,6 +668,23 @@ public final static ItemStack[] getCopiedContents(final Inventory invi) {
return buf;
}

/**
* Gets copy of storage contents, i.e. ignores armor and off hand. This is due to Spigot 1.9
* added armor slots, and off hand to default inventory index.
* @param invi Inventory
* @return Copied storage contents
*/
public final static ItemStack[] getStorageContents(final Inventory invi) {
if (invi instanceof PlayerInventory) {
final ItemStack[] buf = invi.getContents();
final ItemStack[] tBuf = new ItemStack[36];
for (int i = 0; i < 36; i++)
if (buf[i] != null)
tBuf[i] = buf[i].clone();
return tBuf;
} else return getCopiedContents(invi);
}

/**
* @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
* {@link #iterator()}.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/conditions/CondCanHold.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public boolean check(final ItemType t) {
}
}, isNegated());
}
final ItemStack[] buf = ItemType.getCopiedContents(invi);
final ItemStack[] buf = ItemType.getStorageContents(invi);
return items.check(e, new Checker<ItemType>() {
@Override
public boolean check(final ItemType t) {
Expand Down

0 comments on commit d170c80

Please sign in to comment.