Java Code Examples for org.bukkit.configuration.serialization.ConfigurationSerializable#serialize()

The following examples show how to use org.bukkit.configuration.serialization.ConfigurationSerializable#serialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemStackFlag.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
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);
		}
	}
}
 
Example 2
Source File: BukkitSerializableAdapterFactory.java    From helper with MIT License 5 votes vote down vote up
@Override
public void write(JsonWriter out, ConfigurationSerializable value) {
    if (value == null) {
        this.gson.toJson(null, RAW_OUTPUT_TYPE, out);
        return;
    }
    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);

    this.gson.toJson(map, RAW_OUTPUT_TYPE, out);
}
 
Example 3
Source File: BukkitTypeSerializer.java    From helper with MIT License 5 votes vote down vote up
@Override
public void serialize(TypeToken<?> type, ConfigurationSerializable from, ConfigurationNode to) throws ObjectMappingException {
    Map<String, Object> serialized = from.serialize();

    Map<String, Object> map = new LinkedHashMap<>(serialized.size() + 1);
    map.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(from.getClass()));
    map.putAll(serialized);

    to.setValue(map);
}