本文整理匯總了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;
}