mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-26 20:16:02 +01:00
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:
parent
33b4b3835f
commit
b55c0d0783
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -186,4 +186,11 @@ public interface ViaVersionConfig {
|
||||
* @return The integer id
|
||||
*/
|
||||
int getPistonReplacementId();
|
||||
|
||||
/**
|
||||
* Force json transform
|
||||
*
|
||||
* @return True if enabled
|
||||
*/
|
||||
boolean isForceJsonTransform();
|
||||
}
|
||||
|
@ -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) {
|
||||
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());
|
||||
|
@ -75,3 +75,5 @@ anti-xray-patch: true
|
||||
replace-pistons: false
|
||||
# What id should we replace with, default is air. (careful of players getting stuck standing on them)
|
||||
replacement-piston-id: 0
|
||||
# Force the string -> json transform
|
||||
force-json-transform: true
|
Loading…
Reference in New Issue
Block a user