Skip to content

Commit e04f488

Browse files
authored
Fix inventory behavior with new body/saddle slot (#6218)
There are new slots that are persistent in the player inventory, the saddle slot + the body slot, ignore them from our inventory calculations. Fixes #6216
1 parent dfd83cf commit e04f488

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Essentials/src/main/java/com/earth2me/essentials/craftbukkit/Inventories.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public final class Inventories {
1919
private static final int CHEST_SLOT = 38;
2020
private static final int LEG_SLOT = 37;
2121
private static final int BOOT_SLOT = 36;
22+
private static final int BODY_SLOT = 41;
23+
private static final int SADDLE_SLOT = 42;
2224
private static final boolean HAS_OFFHAND = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_9_R01);
2325
private static final int INVENTORY_SIZE = HAS_OFFHAND ? 41 : 40;
2426

@@ -224,6 +226,10 @@ public static int removeItems(final Player player, final Predicate<ItemStack> re
224226
int removedAmount = 0;
225227
final ItemStack[] items = player.getInventory().getContents();
226228
for (int i = 0; i < items.length; i++) {
229+
if (isContortedSlot(i)) {
230+
continue;
231+
}
232+
227233
if (!includeArmor && isArmorSlot(i)) {
228234
continue;
229235
}
@@ -251,6 +257,10 @@ public static boolean removeItemAmount(final Player player, final ItemStack toRe
251257
final ItemStack[] items = player.getInventory().getContents();
252258

253259
for (int i = 0; i < items.length; i++) {
260+
if (isContortedSlot(i)) {
261+
continue;
262+
}
263+
254264
final ItemStack item = items[i];
255265
if (isEmpty(item)) {
256266
continue;
@@ -342,6 +352,10 @@ private static InventoryData parseInventoryData(final Inventory inventory, final
342352
final HashMap<ItemStack, List<Integer>> partialSlots = new HashMap<>();
343353

344354
for (int i = 0; i < inventoryContents.length; i++) {
355+
if (isContortedSlot(i)) {
356+
continue;
357+
}
358+
345359
if (!includeArmor && isArmorSlot(i)) {
346360
continue;
347361
}
@@ -403,6 +417,10 @@ private static boolean isEmpty(final ItemStack stack) {
403417
return stack == null || MaterialUtil.isAir(stack.getType());
404418
}
405419

420+
public static boolean isContortedSlot(final int slot) {
421+
return slot == BODY_SLOT || slot == SADDLE_SLOT;
422+
}
423+
406424
private static boolean isArmorSlot(final int slot) {
407425
return slot == HELM_SLOT || slot == CHEST_SLOT || slot == LEG_SLOT || slot == BOOT_SLOT;
408426
}

0 commit comments

Comments
 (0)