Skip to content

Commit

Permalink
finish up
Browse files Browse the repository at this point in the history
  • Loading branch information
vytskalt authored and dmulloy2 committed Jun 5, 2024
1 parent 9edc8f3 commit 976a0c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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;

/**
Expand Down Expand Up @@ -37,16 +37,16 @@ public WrappedComponentStyle(Object handle) {
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
@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;

Expand Down Expand Up @@ -49,10 +48,7 @@ public static boolean isSupported() {
}

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)) {
Expand All @@ -65,31 +61,28 @@ public static WrappedNumberFormat fromHandle(Object handle) {
}

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);
}
Expand Down

0 comments on commit 976a0c3

Please sign in to comment.