mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 17:08:15 +01:00
Fix book formatting and invalid book tag at empty book
This commit is contained in:
parent
d5e720fe09
commit
c56109a64c
@ -3,11 +3,15 @@ package us.myles.ViaVersion.slot;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import org.spacehq.opennbt.tag.builtin.ListTag;
|
||||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||||
|
import org.spacehq.opennbt.tag.builtin.Tag;
|
||||||
import us.myles.ViaVersion.CancelException;
|
import us.myles.ViaVersion.CancelException;
|
||||||
|
import us.myles.ViaVersion.transformers.OutgoingTransformer;
|
||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -116,6 +120,28 @@ public class ItemSlotRewriter {
|
|||||||
item.tag = tag;
|
item.tag = tag;
|
||||||
item.data = 0;
|
item.data = 0;
|
||||||
}
|
}
|
||||||
|
if (item.id == Material.WRITTEN_BOOK.getId()) {
|
||||||
|
CompoundTag tag = item.tag;
|
||||||
|
if (tag == null) {
|
||||||
|
tag = new CompoundTag("tag");
|
||||||
|
}
|
||||||
|
ListTag pages = tag.get("pages");
|
||||||
|
if (pages == null) {
|
||||||
|
pages = new ListTag("pages", Collections.<Tag>singletonList(new StringTag(OutgoingTransformer.fixJson(""))));
|
||||||
|
tag.put(pages);
|
||||||
|
item.tag = tag;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < pages.size(); i++) {
|
||||||
|
if (!(pages.get(i) instanceof StringTag))
|
||||||
|
continue;
|
||||||
|
StringTag page = pages.get(i);
|
||||||
|
System.out.println("page: " + page);
|
||||||
|
page.setValue(OutgoingTransformer.fixJson(page.getValue()));
|
||||||
|
}
|
||||||
|
item.tag = tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user