From aaff4fc71027968f22100d216ff22edc42a96629 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Thu, 14 Jul 2022 11:42:26 -0700 Subject: Refactor: Use GSON to deserialize enum WorldKey Signed-off-by: Trumeet --- src/main/java/moe/ymc/acron/c2s/ReqSetConfig.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/main/java/moe/ymc/acron/c2s') diff --git a/src/main/java/moe/ymc/acron/c2s/ReqSetConfig.java b/src/main/java/moe/ymc/acron/c2s/ReqSetConfig.java index 8959403..fcddf35 100644 --- a/src/main/java/moe/ymc/acron/c2s/ReqSetConfig.java +++ b/src/main/java/moe/ymc/acron/c2s/ReqSetConfig.java @@ -33,9 +33,16 @@ public record ReqSetConfig(@SerializedName("id") int id, final int id = object.has("id") ? object.get("id").getAsInt() : -1; - final WorldKey world = object.has("world") ? - WorldKey.valueOf(object.get("world").getAsString().toUpperCase()) : - null; + final WorldKey world; + if (object.has("world")) { + world = context.deserialize(object.get("world"), WorldKey.class); + // https://stackoverflow.com/a/49574019 + if (world == null) { + throw new JsonParseException("Invalid world"); + } + } else { + world = null; + } final Vec3d pos = object.has("pos") ? context.deserialize(object.get("pos"), Vec3d.class) : null; -- cgit v1.2.3