diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedComponentStyle.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedComponentStyle.java index 0f4ff69b..f463a86f 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedComponentStyle.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedComponentStyle.java @@ -7,7 +7,7 @@ import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.wrappers.codecs.WrappedCodec; import com.comphenix.protocol.wrappers.codecs.WrappedDynamicOps; import com.google.gson.Gson; -import com.google.gson.JsonObject; +import com.google.gson.JsonElement; import com.google.gson.JsonParseException; /** @@ -37,16 +37,16 @@ public class WrappedComponentStyle extends AbstractWrapper { setHandle(handle); } - public JsonObject getJson() { + public JsonElement getJson() { if (CODEC != null) { - return (JsonObject) CODEC.encode(handle, WrappedDynamicOps.json(false)) + return (JsonElement) CODEC.encode(handle, WrappedDynamicOps.json(false)) .getOrThrow(JsonParseException::new); } else { - return (JsonObject) GSON.toJsonTree(handle); + return GSON.toJsonTree(handle); } } - public static WrappedComponentStyle fromJson(JsonObject json) { + public static WrappedComponentStyle fromJson(JsonElement json) { Object handle; if (CODEC != null) { handle = CODEC.parse(json, WrappedDynamicOps.json(false)) diff --git a/src/main/java/com/comphenix/protocol/wrappers/WrappedNumberFormat.java b/src/main/java/com/comphenix/protocol/wrappers/WrappedNumberFormat.java index bef76a79..3caa13df 100644 --- a/src/main/java/com/comphenix/protocol/wrappers/WrappedNumberFormat.java +++ b/src/main/java/com/comphenix/protocol/wrappers/WrappedNumberFormat.java @@ -15,7 +15,6 @@ import org.jetbrains.annotations.NotNull; */ @SuppressWarnings("OptionalGetWithoutIsPresent") public class WrappedNumberFormat extends AbstractWrapper { - private static final IllegalStateException UNSUPPORTED = new IllegalStateException("NumberFormat classes don't exist on this server version"); private static final Object BLANK; private static final ConstructorAccessor FIXED_CONSTRUCTOR, STYLED_CONSTRUCTOR; @@ -49,10 +48,7 @@ public class WrappedNumberFormat extends AbstractWrapper { } public static WrappedNumberFormat fromHandle(Object handle) { - if (!isSupported()) { - throw UNSUPPORTED; - } - + throwIfUnsupported(); if (MinecraftReflection.getBlankFormatClass().get().isInstance(handle)) { return new Blank(handle); } else if (MinecraftReflection.getFixedFormatClass().get().isInstance(handle)) { @@ -65,31 +61,28 @@ public class WrappedNumberFormat extends AbstractWrapper { } public static Blank blank() { - if (!isSupported()) { - throw UNSUPPORTED; - } - + throwIfUnsupported(); return new Blank(WrappedNumberFormat.BLANK); } public static Fixed fixed(@NotNull WrappedChatComponent content) { - if (!isSupported()) { - throw UNSUPPORTED; - } - + throwIfUnsupported(); Object handle = FIXED_CONSTRUCTOR.invoke(content.getHandle()); return new Fixed(handle); } public static Styled styled(@NotNull WrappedComponentStyle style) { - if (!isSupported()) { - throw UNSUPPORTED; - } - + throwIfUnsupported(); Object handle = STYLED_CONSTRUCTOR.invoke(style.getHandle()); return new Styled(handle); } + private static void throwIfUnsupported() { + if (!isSupported()) { + throw new IllegalStateException("NumberFormat classes don't exist on this server version"); + } + } + private WrappedNumberFormat(Class handleType) { super(handleType); }