3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Merge pull request #131 from StamBoom/patch

Fix book formatting and invalid book tag at empty book
Dieser Commit ist enthalten in:
Myles 2016-03-05 19:18:39 +00:00
Commit 653c3d3984

Datei anzeigen

@ -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,27 @@ 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);
page.setValue(OutgoingTransformer.fixJson(page.getValue()));
}
item.tag = tag;
}
} }
} }