+ fixed TSerializer
This commit is contained in:
parent
c711b8ae37
commit
560b407435
@ -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
|
||||
|
@ -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 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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user