Fix particle serialization
This commit is contained in:
parent
d2decad8d5
commit
b5e41f3144
@ -1238,11 +1238,13 @@ public class DisguiseUtilities {
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
|
||||
gsonBuilder.disableHtmlEscaping();
|
||||
gsonBuilder.setPrettyPrinting();
|
||||
|
||||
gsonBuilder.registerTypeAdapter(MetaIndex.class, new SerializerMetaIndex());
|
||||
gsonBuilder.registerTypeAdapter(WrappedGameProfile.class, new SerializerGameProfile());
|
||||
gsonBuilder.registerTypeAdapter(WrappedBlockData.class, new SerializerWrappedBlockData());
|
||||
gsonBuilder.registerTypeAdapter(WrappedChatComponent.class, new SerializerChatComponent());
|
||||
gsonBuilder.registerTypeAdapter(WrappedParticle.class, new SerializerParticle());
|
||||
gsonBuilder.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer());
|
||||
gsonBuilder.registerTypeHierarchyAdapter(ItemStack.class, new SerializerItemStack());
|
||||
|
||||
|
@ -1,9 +1,13 @@
|
||||
package me.libraryaddict.disguise.utilities.json;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedParticle;
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.internal.LinkedTreeMap;
|
||||
import me.libraryaddict.disguise.disguisetypes.*;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle;
|
||||
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -46,7 +50,7 @@ public class SerializerFlagWatcher
|
||||
}
|
||||
|
||||
private void correct(FlagWatcher watcher, Class<? extends FlagWatcher> flagWatcher, String name)
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
throws NoSuchFieldException, IllegalAccessException, DisguiseParseException {
|
||||
Field field = FlagWatcher.class.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
HashMap<Integer, Object> map = (HashMap<Integer, Object>) field.get(watcher);
|
||||
@ -69,6 +73,11 @@ public class SerializerFlagWatcher
|
||||
} else if (def instanceof Byte) {
|
||||
entry.setValue(((Double) entry.getValue()).byteValue());
|
||||
}
|
||||
} else if (entry.getValue() instanceof String) {
|
||||
if (index.getDefault() instanceof WrappedParticle) {
|
||||
entry.setValue(((ParamInfoParticle) ParamInfoManager.getParamInfo(WrappedParticle.class))
|
||||
.fromString((String) entry.getValue()));
|
||||
}
|
||||
} else if (entry.getValue() instanceof LinkedTreeMap) { // If it's deserialized incorrectly as a map
|
||||
// If the default value is not VillagerData
|
||||
if (index.getDefault() instanceof VillagerData) {
|
||||
|
@ -0,0 +1,19 @@
|
||||
package me.libraryaddict.disguise.utilities.json;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedParticle;
|
||||
import com.google.gson.*;
|
||||
import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Created by libraryaddict on 5/12/2020.
|
||||
*/
|
||||
public class SerializerParticle implements JsonSerializer<WrappedParticle> {
|
||||
@Override
|
||||
public JsonElement serialize(WrappedParticle src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return context.serialize(ParamInfoManager.getParamInfo(WrappedParticle.class).toString(src));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user