Fix book formatting and invalid book tag at empty book

This commit is contained in:
Mats 2016-03-05 11:30:17 +01:00
parent d5e720fe09
commit c56109a64c

View File

@ -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;
@ -104,7 +108,7 @@ public class ItemSlotRewriter {
if (tag == null) { if (tag == null) {
tag = new CompoundTag("tag"); tag = new CompoundTag("tag");
} }
if(item.data >= 16384){ if (item.data >= 16384) {
item.id = 438; // splash id item.id = 438; // splash id
item.data = (short) (item.data - 8192); item.data = (short) (item.data - 8192);
} }
@ -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;
}
} }
} }