本文整理汇总了Java中org.bukkit.configuration.serialization.ConfigurationSerializable类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationSerializable类的具体用法?Java ConfigurationSerializable怎么用?Java ConfigurationSerializable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationSerializable类属于org.bukkit.configuration.serialization包,在下文中一共展示了ConfigurationSerializable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
if (map == null)
return null;
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
if (!(val instanceof Map))
continue;
Map<String, Object> subMap = (Map<String, Object>) val;
if (subMap.containsKey(SERIALIZED_TYPE_KEY)) {
map.put(key, deserialize(subMap));
}
}
return ConfigurationSerialization.deserializeObject(map);
}
示例2: create
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<?> rawType = type.getRawType();
TypeAdapter<Map> mapAdapter = gson.getAdapter(Map.class);
TypeAdapter<Collection> collectionAdapter = gson.getAdapter(Collection.class);
if (Location.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new LocationTypeAdapter();
} else if (ConfigurationSerializable.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new ConfigurationSerializableAdapter(mapAdapter);
} else if (GUISignature.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new GUISignatureTypeAdapter(mapAdapter, collectionAdapter);
} else if (MaterialAndData.class.isAssignableFrom(rawType)) {
return (TypeAdapter<T>) new MaterialAndDataAdapter();
}
return null;
}
示例3: PrimitiveComponent
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
public PrimitiveComponent() {
super( Integer.class,
Integer.TYPE,
String.class,
Float.class,
Float.TYPE,
Boolean.class,
Boolean.TYPE,
Double.class,
Double.TYPE,
Long.class,
Long.TYPE,
Short.class,
Short.TYPE,
Byte.class,
Byte.TYPE,
Character.class,
Character.TYPE,
ConfigurationSerializable.class);
}
示例4: load
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
/**
* Loads a previously serialized object from a given file using YAML.
*
* @param file File to load from
* @param clazz Class the object should be of
* @param exists Whether or not the file exists and the expensive
* {@link File#exists()} operation can be skipped
* @return The deserialized object, or null if the file does not exist
* @throws IllegalArgumentException If the file or class is null
* @throws IOException If the file cannot be read
* @throws InvalidConfigurationException If the given file is not a valid
* YAML configuration
* @see #save(ConfigurationSerializable, File)
*/
@SuppressWarnings("unchecked")
public static <T extends ConfigurationSerializable> T load(File file, Class<T> clazz, boolean exists) throws IOException, InvalidConfigurationException
{
Validate.notNull(file, "file cannot be null!");
Validate.notNull(clazz, "clazz cannot be null!");
if (! exists && ! file.exists())
return null;
YamlConfiguration config = new YamlConfiguration();
config.load(file);
Map<String, Object> map = config.getValues(true);
return (T) ConfigurationSerialization.deserializeObject(map, clazz);
}
示例5: save
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
/**
* Saves a serializable object to a given file.
*
* @param instance Object to seriaize
* @param file File to save to
* @throws IllegalArgumentException If the instance or file is null
* @throws IOException If the file cannot be written to
* @see #load(File, Class, boolean)
*/
public static void save(ConfigurationSerializable instance, File file) throws IOException
{
Validate.notNull(instance, "instance cannot be null!");
Validate.notNull(file, "file cannot be null!");
file.delete();
file.createNewFile();
YamlConfiguration config = new YamlConfiguration();
for (Entry<String, Object> entry : instance.serialize().entrySet())
{
config.set(entry.getKey(), entry.getValue());
}
config.save(file);
}
示例6: marshalSerializeable
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
static void marshalSerializeable(Element baseElement, ConfigurationSerializable serializeable) {
Map<String, Object> serialized = serializeable.serialize();
if (serializeable instanceof ItemMeta) {
baseElement.addAttribute("itemmeta", String.valueOf(true));
}
for (Entry<String, Object> entry : serialized.entrySet()) {
Element entryElement = baseElement.addElement(entry.getKey());
Object value = entry.getValue();
if (value instanceof ItemMeta) {
marshalSerializeable(entryElement, (ItemMeta) value);
} else {
serializeObject(value, entryElement);
}
}
}
示例7: handleSerialization
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@Deprecated
private static Map<String, Object> handleSerialization(Map<String, Object> map) {
Map<String, Object> serialized = recreateMap(map);
for (Entry<String, Object> entry : serialized.entrySet()) {
if (entry.getValue() instanceof ConfigurationSerializable) {
entry.setValue(serialize((ConfigurationSerializable) entry.getValue()));
} else if (entry.getValue() instanceof Iterable<?>) {
List<Object> newList = new ArrayList<>();
for (Object object : ((Iterable) entry.getValue())) {
if (object instanceof ConfigurationSerializable) {
object = serialize((ConfigurationSerializable) object);
}
newList.add(object);
}
entry.setValue(newList);
} else if (entry.getValue() instanceof Map<?, ?>) {
// unchecked cast here. If you're serializing to a non-standard Map you deserve ClassCastExceptions
entry.setValue(handleSerialization((Map<String, Object>) entry.getValue()));
}
}
return serialized;
}
示例8: create
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<? super T> clazz = type.getRawType();
if (!ConfigurationSerializable.class.isAssignableFrom(clazz)) {
return null;
}
//noinspection unchecked
return (TypeAdapter<T>) new Adapter(gson);
}
示例9: write
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@Override
public void write(JsonWriter out, ConfigurationSerializable value) {
Map<String, Object> serialized = value.serialize();
Map<String, Object> map = new LinkedHashMap<>(serialized.size() + 1);
map.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(value.getClass()));
map.putAll(serialized);
gson.toJson(map, RAW_OUTPUT_TYPE, out);
}
示例10: serialize
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
public static Map<String, Object> serialize(ConfigurationSerializable serializable) {
Map<String, Object> serialized = new HashMap<>();
serialized.putAll(serializable.serialize());
for (Map.Entry<String, Object> entry : serialized.entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
if (val instanceof ConfigurationSerializable) {
serialized.put(key, serialize((ConfigurationSerializable) val));
}
}
serialized.put(SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass()));
return serialized;
}
示例11: write
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@Override
public void write(JsonWriter out, ConfigurationSerializable value) throws IOException {
if (value != null)
mapAdapter.write(out, serialize(value));
else
out.nullValue();
}
示例12: deserializeCS
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Nullable
public final static <T extends ConfigurationSerializable> T deserializeCS(final String s, final Class<T> c) {
final YamlConfiguration y = new YamlConfiguration();
try {
y.loadFromString(s);
} catch (final InvalidConfigurationException e) {
return null;
}
final Object o = y.get("value");
if (!c.isInstance(o))
return null;
return (T) o;
}
示例13: deserializeCSOld
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Deprecated
@Nullable
public final static <T extends ConfigurationSerializable> T deserializeCSOld(final String s, final Class<T> c) {
final YamlConfiguration y = new YamlConfiguration();
try {
y.loadFromString(s.replace("\uFEFF", "\n"));
} catch (final InvalidConfigurationException e) {
return null;
}
final Object o = y.get("value");
if (!c.isInstance(o))
return null;
return (T) o;
}
示例14: getID
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
@Override
@Nullable
public String getID(final @NonNull Class<?> c) {
if (ConfigurationSerializable.class.isAssignableFrom(c) && Classes.getSuperClassInfo(c) == Classes.getExactClassInfo(Object.class))
return configurationSerializablePrefix + ConfigurationSerialization.getAlias((Class<? extends ConfigurationSerializable>) c);
return null;
}
示例15: getClass
import org.bukkit.configuration.serialization.ConfigurationSerializable; //导入依赖的package包/类
@Override
@Nullable
public Class<? extends ConfigurationSerializable> getClass(final @NonNull String id) {
if (id.startsWith(configurationSerializablePrefix))
return ConfigurationSerialization.getClassByAlias(id.substring(configurationSerializablePrefix.length()));
return null;
}