This commit is contained in:
libraryaddict 2019-04-19 16:52:56 +12:00
parent 3d4ee8a020
commit 4df20dbd4c
2 changed files with 35 additions and 14 deletions

View File

@ -171,16 +171,15 @@ public class FlagWatcher {
if (newHealth > 0 && hasDied) {
hasDied = false;
Bukkit.getScheduler()
.scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(),
getDisguise());
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
try {
DisguiseUtilities
.sendSelfDisguise((Player) getDisguise().getEntity(), getDisguise());
}
catch (Exception ex) {
ex.printStackTrace();
}
}, 2);
} else if (newHealth <= 0 && !hasDied) {
hasDied = true;
}

View File

@ -1,10 +1,18 @@
package me.libraryaddict.disguise.utilities.json;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.mojang.authlib.properties.PropertyMap;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
import org.bukkit.inventory.ItemStack;
import sun.reflect.generics.tree.BaseType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@ -15,14 +23,28 @@ import java.util.Map;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, JsonSerializer<FlagWatcher>, InstanceCreator<FlagWatcher> {
public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, JsonSerializer<FlagWatcher>,
InstanceCreator<FlagWatcher> {
private Gson gson;
public SerializerFlagWatcher() {
GsonBuilder gsonBuilder = new GsonBuilder();
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(PropertyMap.class, new PropertyMap.Serializer());
gsonBuilder.registerTypeAdapter(ItemStack.class, new SerializerItemStack());
gson = gsonBuilder.create();
}
@Override
public FlagWatcher deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
try {
FlagWatcher watcher = context.deserialize(json,
Class.forName(((JsonObject) json).get("flagType").getAsString()));
FlagWatcher watcher = (FlagWatcher) gson
.fromJson(json, Class.forName(((JsonObject) json).get("flagType").getAsString()));
DisguiseType entity = DisguiseType.valueOf(((JsonObject) json).get("entityType").getAsString());
@ -79,7 +101,7 @@ public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, Jso
@Override
public JsonElement serialize(FlagWatcher src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject obj = (JsonObject) context.serialize(src);
JsonObject obj = (JsonObject) gson.toJsonTree(src);
obj.addProperty("flagType", src.getClass().getName());