+ fixed TSerializer

This commit is contained in:
坏黑 2019-05-16 23:43:10 +08:00
parent c711b8ae37
commit 560b407435
3 changed files with 24 additions and 6 deletions

View File

@ -5,7 +5,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '4.0.4' id 'com.github.johnrengelman.shadow' version '4.0.4'
} }
group = 'me.skymc' group = 'me.skymc'
version = '4.78' version = '4.79'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
targetCompatibility = 1.8 targetCompatibility = 1.8

View File

@ -2,6 +2,8 @@ package me.skymc.taboolib.common.serialize;
import ch.njol.skript.classes.ConfigurationSerializer; import ch.njol.skript.classes.ConfigurationSerializer;
import com.google.gson.*; import com.google.gson.*;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -149,4 +151,21 @@ public class TSerializer {
} }
return jsonArray.toString(); return jsonArray.toString();
} }
public static String serializeCS(ConfigurationSerializable o) {
YamlConfiguration y = new YamlConfiguration();
y.set("value", o);
return y.saveToString();
}
public static <T extends ConfigurationSerializable> T deserializeCS(String s, Class<T> 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;
}
} }

View File

@ -1,6 +1,5 @@
package me.skymc.taboolib.common.serialize; package me.skymc.taboolib.common.serialize;
import ch.njol.skript.classes.ConfigurationSerializer;
import me.skymc.taboolib.other.NumberUtils; import me.skymc.taboolib.other.NumberUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -173,12 +172,12 @@ public enum TSerializerElementGeneral {
@Override @Override
public ItemStack read(String value) { public ItemStack read(String value) {
return ConfigurationSerializer.deserializeCS(value, ItemStack.class); return TSerializer.deserializeCS(value, ItemStack.class);
} }
@Override @Override
public String write(Object value) { public String write(Object value) {
return ConfigurationSerializer.serializeCS((ItemStack) value); return TSerializer.serializeCS((ItemStack) value);
} }
@Override @Override
@ -191,12 +190,12 @@ public enum TSerializerElementGeneral {
@Override @Override
public Location read(String value) { public Location read(String value) {
return ConfigurationSerializer.deserializeCS(value, Location.class); return TSerializer.deserializeCS(value, Location.class);
} }
@Override @Override
public String write(Object value) { public String write(Object value) {
return ConfigurationSerializer.serializeCS((Location) value); return TSerializer.serializeCS((Location) value);
} }
@Override @Override