Add bad workaround for serializing optional

This commit is contained in:
libraryaddict 2021-12-14 21:47:01 +13:00
parent e6d40d95eb
commit 3d7be88524

View File

@ -9,9 +9,7 @@ import com.comphenix.protocol.wrappers.*;
import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtCompound;
import com.comphenix.protocol.wrappers.nbt.NbtList; import com.comphenix.protocol.wrappers.nbt.NbtList;
import com.google.gson.Gson; import com.google.gson.*;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.mojang.authlib.properties.PropertyMap; import com.mojang.authlib.properties.PropertyMap;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import lombok.Getter; import lombok.Getter;
@ -1396,6 +1394,7 @@ public class DisguiseUtilities {
// Gotta register all the flag watcher stuff before I make this one // Gotta register all the flag watcher stuff before I make this one
gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher(gsonBuilder.create())); gsonBuilder.registerTypeAdapter(FlagWatcher.class, new SerializerFlagWatcher(gsonBuilder.create()));
gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise()); gsonBuilder.registerTypeAdapter(Disguise.class, new SerializerDisguise());
gsonBuilder.registerTypeAdapter(Optional.class, (JsonSerializer<Optional>) (optional, type, jsonSerializationContext) -> jsonSerializationContext.serialize("<optional>(" + jsonSerializationContext.serialize(optional.orElse(null)) + ")"));
gson = gsonBuilder.create(); gson = gsonBuilder.create();