From 867e59ba3d28a260ac4b40edf31ad23802337b33 Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 14 Apr 2016 18:53:51 -0400 Subject: [PATCH] Parse empty sign lines as empty JSON strings. Since the server doesn't bother validating sign text, and the client validates it by crashing. Note that this attempts to wrap strings as JSON, but hasn't been fully tested. --- .../com/sk89q/worldedit/blocks/SignBlock.java | 17 ++++++++++++++--- .../com/sk89q/worldedit/util/gson/GsonUtil.java | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java index a0c1d303b..73d328fc8 100644 --- a/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java +++ b/worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/SignBlock.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.blocks; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.util.gson.GsonUtil; import java.util.HashMap; import java.util.Map; @@ -33,6 +34,8 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { private String[] text; + private static String EMPTY = "{\"text\":\"\"}"; + /** * Construct the sign without text. * @@ -41,7 +44,7 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { */ public SignBlock(int type, int data) { super(type, data); - this.text = new String[] { "", "", "", "" }; + this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY }; } /** @@ -54,7 +57,15 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { public SignBlock(int type, int data, String[] text) { super(type, data); if (text == null) { - this.text = new String[] { "", "", "", "" }; + this.text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY }; + return; + } + for (int i = 0; i < text.length; i++) { + if (text[i].isEmpty()) { + text[i] = EMPTY; + } else { + text[i] = "{\"text\":\"" + GsonUtil.stringValue(text[i]) + "\"}"; + } } this.text = text; } @@ -110,7 +121,7 @@ public class SignBlock extends BaseBlock implements TileEntityBlock { Tag t; - text = new String[] { "", "", "", "" }; + text = new String[] { EMPTY, EMPTY, EMPTY, EMPTY }; t = values.get("id"); if (!(t instanceof StringTag) || !((StringTag) t).getValue().equals("Sign")) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java index 8d14f03b5..8d6d4dd2b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.util.gson; +import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.sk89q.worldedit.Vector; @@ -41,4 +42,8 @@ public final class GsonUtil { return gsonBuilder; } + private static final Gson gson = new Gson(); + public static String stringValue(String s) { + return gson.toJson(s); + } }