Possibility to force the json transformer (#455)

* Possibility to force the json transform

* Escape all the Strings. Who likes double quotes anyways.
This commit is contained in:
Mats 2016-06-26 22:47:08 +02:00 committed by Myles
parent 33b4b3835f
commit b55c0d0783
4 changed files with 28 additions and 6 deletions

View File

@ -164,4 +164,9 @@ public class ViaConfig implements ViaVersionConfig {
// Collision has to be enabled first
return isPreventCollision() && plugin.getConfig().getBoolean("auto-team", true);
}
@Override
public boolean isForceJsonTransform() {
return plugin.getConfig().getBoolean("force-json-transform", false);
}
}

View File

@ -186,4 +186,11 @@ public interface ViaVersionConfig {
* @return The integer id
*/
int getPistonReplacementId();
/**
* Force json transform
*
* @return True if enabled
*/
boolean isForceJsonTransform();
}

View File

@ -41,9 +41,7 @@ public class Protocol1_9TO1_8 extends Protocol {
line = "{\"text\":\"\"}";
} else {
if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{") || !line.endsWith("}"))) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", line);
return gson.toJson(jsonObject);
return constructJson(line);
}
if (line.startsWith("\"") && line.endsWith("\"")) {
line = "{\"text\":" + line + "}";
@ -52,12 +50,22 @@ public class Protocol1_9TO1_8 extends Protocol {
try {
gson.fromJson(line, JsonObject.class);
} catch (Exception e) {
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage());
return "{\"text\":\"\"}";
if (ViaVersion.getConfig().isForceJsonTransform()) {
return constructJson(line);
} else {
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage());
return "{\"text\":\"\"}";
}
}
return line;
}
private static String constructJson(String text) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", text);
return gson.toJson(jsonObject);
}
public static Item getHandItem(final UserConnection info) {
if (HandItemCache.CACHE) {
return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());

View File

@ -74,4 +74,6 @@ anti-xray-patch: true
# Should we replace extended pistons to fix 1.10.1 (Only on chunk load)
replace-pistons: false
# What id should we replace with, default is air. (careful of players getting stuck standing on them)
replacement-piston-id: 0
replacement-piston-id: 0
# Force the string -> json transform
force-json-transform: true