Fix PlayerDataWrapper (don't store empty stacks as air stack)
This commit is contained in:
parent
add5d3bcd7
commit
6f310de32e
@ -113,8 +113,8 @@ public class PlayerDataWrapper {
|
|||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
CompoundTag itemTag = list.getCompound(i);
|
CompoundTag itemTag = list.getCompound(i);
|
||||||
int nbtSlot = itemTag.getByte("Slot") & 255;
|
int nbtSlot = itemTag.getByte("Slot") & 255;
|
||||||
ItemStack is = CraftItemStack.asCraftMirror(itemTag);
|
ItemStack is = filterStack(CraftItemStack.asCraftMirror(itemTag));
|
||||||
if (is != null && !is.getType().isAir()) {
|
if (is != null) {
|
||||||
stacks.put(nbtSlot, CraftItemStack.asCraftMirror(itemTag));
|
stacks.put(nbtSlot, CraftItemStack.asCraftMirror(itemTag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,7 +131,9 @@ public class PlayerDataWrapper {
|
|||||||
setRawInventoryContent(nbtKey, stacks);
|
setRawInventoryContent(nbtKey, stacks);
|
||||||
}
|
}
|
||||||
for (int bukkitSlot = 0; bukkitSlot < inv.getSize(); bukkitSlot++) {
|
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);
|
int nbtSlot = bukkitToNBTSlotconverter.applyAsInt(bukkitSlot);
|
||||||
stacks.put(nbtSlot, is);
|
stacks.put(nbtSlot, is);
|
||||||
}
|
}
|
||||||
@ -141,6 +143,9 @@ public class PlayerDataWrapper {
|
|||||||
private void setRawInventoryContent(String key, Map<Integer, ItemStack> stacks) {
|
private void setRawInventoryContent(String key, Map<Integer, ItemStack> stacks) {
|
||||||
ListTag list = new ListTag();
|
ListTag list = new ListTag();
|
||||||
for (Map.Entry<Integer, ItemStack> is : stacks.entrySet()) {
|
for (Map.Entry<Integer, ItemStack> is : stacks.entrySet()) {
|
||||||
|
ItemStack stack = filterStack(is.getValue());
|
||||||
|
if (stack == null)
|
||||||
|
continue;
|
||||||
CompoundTag itemTag = new CompoundTag();
|
CompoundTag itemTag = new CompoundTag();
|
||||||
CraftItemStack.asNMSCopy(is.getValue()).save(itemTag);
|
CraftItemStack.asNMSCopy(is.getValue()).save(itemTag);
|
||||||
itemTag.putByte("Slot", is.getKey().byteValue());
|
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);
|
double levelAndExp = ExperienceUtil.getLevelFromExp(xp);
|
||||||
int level = (int) levelAndExp;
|
int level = (int) levelAndExp;
|
||||||
double expProgress = levelAndExp - level;
|
double expProgress = levelAndExp - level;
|
||||||
data.putInt("XPLevel", level);
|
data.putInt("XpLevel", level);
|
||||||
data.putFloat("XpP", (float) expProgress);
|
data.putFloat("XpP", (float) expProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user