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

Print erroneous json if parsing fails

Dieser Commit ist enthalten in:
KennyTV 2020-07-28 09:59:35 +02:00
Ursprung c326bb7b51
Commit 89c503dd92
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 22 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,8 @@ package us.myles.ViaVersion.api.rewriters;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -99,9 +101,14 @@ public class ComponentRewriter {
} }
public JsonElement processText(String value) { public JsonElement processText(String value) {
JsonElement root = GsonUtil.getJsonParser().parse(value); try {
processText(root); JsonElement root = GsonUtil.getJsonParser().parse(value);
return root; processText(root);
return root;
} catch (JsonSyntaxException e) {
Via.getPlatform().getLogger().severe("Error when trying to parse json: " + value);
throw e;
}
} }
public void processText(JsonElement element) { public void processText(JsonElement element) {

Datei anzeigen

@ -1,7 +1,9 @@
package us.myles.ViaVersion.api.type.types; package us.myles.ViaVersion.api.type.types;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
@ -14,7 +16,13 @@ public class ComponentType extends Type<JsonElement> {
@Override @Override
public JsonElement read(ByteBuf buffer) throws Exception { public JsonElement read(ByteBuf buffer) throws Exception {
return GsonUtil.getJsonParser().parse(STRING_TAG.read(buffer)); String s = STRING_TAG.read(buffer);
try {
return GsonUtil.getJsonParser().parse(s);
} catch (JsonSyntaxException e) {
Via.getPlatform().getLogger().severe("Error when trying to parse json: " + s);
throw e;
}
} }
@Override @Override

Datei anzeigen

@ -613,8 +613,9 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
} }
if (Via.getConfig().is1_13TeamColourFix()) { if (Via.getConfig().is1_13TeamColourFix()) {
colour = getLastColor(prefix).ordinal(); ChatColor lastColor = getLastColor(prefix);
suffix = getLastColor(prefix).toString() + suffix; colour = lastColor.ordinal();
suffix = lastColor.toString() + suffix;
} }
wrapper.write(Type.VAR_INT, colour); wrapper.write(Type.VAR_INT, colour);