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) { if (newHealth > 0 && hasDied) {
hasDied = false; hasDied = false;
Bukkit.getScheduler() Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> {
.scheduleSyncDelayedTask(LibsDisguises.getInstance(), () -> { try {
try { DisguiseUtilities
DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), .sendSelfDisguise((Player) getDisguise().getEntity(), getDisguise());
getDisguise()); }
} catch (Exception ex) {
catch (Exception ex) { ex.printStackTrace();
ex.printStackTrace(); }
} }, 2);
}, 2);
} else if (newHealth <= 0 && !hasDied) { } else if (newHealth <= 0 && !hasDied) {
hasDied = true; hasDied = true;
} }

View File

@ -1,10 +1,18 @@
package me.libraryaddict.disguise.utilities.json; 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.*;
import com.google.gson.reflect.TypeToken;
import com.mojang.authlib.properties.PropertyMap;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; 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.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -15,14 +23,28 @@ import java.util.Map;
/** /**
* Created by libraryaddict on 1/06/2017. * 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 @Override
public FlagWatcher deserialize(JsonElement json, Type typeOfT, public FlagWatcher deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException { JsonDeserializationContext context) throws JsonParseException {
try { try {
FlagWatcher watcher = context.deserialize(json, FlagWatcher watcher = (FlagWatcher) gson
Class.forName(((JsonObject) json).get("flagType").getAsString())); .fromJson(json, Class.forName(((JsonObject) json).get("flagType").getAsString()));
DisguiseType entity = DisguiseType.valueOf(((JsonObject) json).get("entityType").getAsString()); DisguiseType entity = DisguiseType.valueOf(((JsonObject) json).get("entityType").getAsString());
@ -79,7 +101,7 @@ public class SerializerFlagWatcher implements JsonDeserializer<FlagWatcher>, Jso
@Override @Override
public JsonElement serialize(FlagWatcher src, Type typeOfSrc, JsonSerializationContext context) { 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()); obj.addProperty("flagType", src.getClass().getName());