From 560b407435ae3b4a76f301fa5dc435f52fb4b058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Thu, 16 May 2019 23:43:10 +0800 Subject: [PATCH] + fixed TSerializer --- build.gradle | 2 +- .../common/serialize/TSerializer.java | 19 +++++++++++++++++++ .../serialize/TSerializerElementGeneral.java | 9 ++++----- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 23036cf..cd86c99 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'com.github.johnrengelman.shadow' version '4.0.4' } group = 'me.skymc' -version = '4.78' +version = '4.79' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java index 95b385d..aa9dfe2 100644 --- a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java +++ b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializer.java @@ -2,6 +2,8 @@ package me.skymc.taboolib.common.serialize; import ch.njol.skript.classes.ConfigurationSerializer; import com.google.gson.*; +import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.serialization.ConfigurationSerializable; import java.lang.reflect.Field; @@ -149,4 +151,21 @@ public class TSerializer { } return jsonArray.toString(); } + + public static String serializeCS(ConfigurationSerializable o) { + YamlConfiguration y = new YamlConfiguration(); + y.set("value", o); + return y.saveToString(); + } + + public static T deserializeCS(String s, Class c) { + YamlConfiguration y = new YamlConfiguration(); + try { + y.loadFromString(s); + } catch (InvalidConfigurationException var4) { + return null; + } + Object o = y.get("value"); + return !c.isInstance(o) ? null : (T) o; + } } diff --git a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElementGeneral.java b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElementGeneral.java index c6bd743..cd6de92 100644 --- a/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElementGeneral.java +++ b/src/main/scala/me/skymc/taboolib/common/serialize/TSerializerElementGeneral.java @@ -1,6 +1,5 @@ package me.skymc.taboolib.common.serialize; -import ch.njol.skript.classes.ConfigurationSerializer; import me.skymc.taboolib.other.NumberUtils; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; @@ -173,12 +172,12 @@ public enum TSerializerElementGeneral { @Override public ItemStack read(String value) { - return ConfigurationSerializer.deserializeCS(value, ItemStack.class); + return TSerializer.deserializeCS(value, ItemStack.class); } @Override public String write(Object value) { - return ConfigurationSerializer.serializeCS((ItemStack) value); + return TSerializer.serializeCS((ItemStack) value); } @Override @@ -191,12 +190,12 @@ public enum TSerializerElementGeneral { @Override public Location read(String value) { - return ConfigurationSerializer.deserializeCS(value, Location.class); + return TSerializer.deserializeCS(value, Location.class); } @Override public String write(Object value) { - return ConfigurationSerializer.serializeCS((Location) value); + return TSerializer.serializeCS((Location) value); } @Override