From 6f310de32e8e7fcf0c36a15ee1eb373c0a947c96 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 22 Feb 2023 10:07:56 +0100 Subject: [PATCH] Fix PlayerDataWrapper (don't store empty stacks as air stack) --- .../lib/paper/util/PlayerDataWrapper.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/PlayerDataWrapper.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/PlayerDataWrapper.java index 5146ab7..0afa9bf 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/PlayerDataWrapper.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/PlayerDataWrapper.java @@ -113,8 +113,8 @@ public class PlayerDataWrapper { for (int i = 0; i < list.size(); i++) { CompoundTag itemTag = list.getCompound(i); int nbtSlot = itemTag.getByte("Slot") & 255; - ItemStack is = CraftItemStack.asCraftMirror(itemTag); - if (is != null && !is.getType().isAir()) { + ItemStack is = filterStack(CraftItemStack.asCraftMirror(itemTag)); + if (is != null) { stacks.put(nbtSlot, CraftItemStack.asCraftMirror(itemTag)); } } @@ -131,7 +131,9 @@ public class PlayerDataWrapper { setRawInventoryContent(nbtKey, stacks); } for (int bukkitSlot = 0; bukkitSlot < inv.getSize(); bukkitSlot++) { - ItemStack is = inv.getItem(bukkitSlot); + ItemStack is = filterStack(inv.getItem(bukkitSlot)); + if (is == null) + continue; int nbtSlot = bukkitToNBTSlotconverter.applyAsInt(bukkitSlot); stacks.put(nbtSlot, is); } @@ -141,6 +143,9 @@ public class PlayerDataWrapper { private void setRawInventoryContent(String key, Map stacks) { ListTag list = new ListTag(); for (Map.Entry is : stacks.entrySet()) { + ItemStack stack = filterStack(is.getValue()); + if (stack == null) + continue; CompoundTag itemTag = new CompoundTag(); CraftItemStack.asNMSCopy(is.getValue()).save(itemTag); itemTag.putByte("Slot", is.getKey().byteValue()); @@ -150,6 +155,11 @@ public class PlayerDataWrapper { } + private ItemStack filterStack(ItemStack is) { + return is == null || is.getType().isEmpty() || is.getAmount() == 0 ? null : is; + } + + @@ -194,7 +204,7 @@ public class PlayerDataWrapper { double levelAndExp = ExperienceUtil.getLevelFromExp(xp); int level = (int) levelAndExp; double expProgress = levelAndExp - level; - data.putInt("XPLevel", level); + data.putInt("XpLevel", level); data.putFloat("XpP", (float) expProgress); }