001 package org.bukkit.configuration.file; 002 003 import java.util.LinkedHashMap; 004 import java.util.Map; 005 006 import org.bukkit.configuration.ConfigurationSection; 007 import org.bukkit.configuration.serialization.ConfigurationSerializable; 008 import org.bukkit.configuration.serialization.ConfigurationSerialization; 009 010 import org.yaml.snakeyaml.nodes.Node; 011 import org.yaml.snakeyaml.representer.Representer; 012 013 public class YamlRepresenter extends Representer { 014 015 public YamlRepresenter() { 016 this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection()); 017 this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable()); 018 } 019 020 private class RepresentConfigurationSection extends RepresentMap { 021 @Override 022 public Node representData(Object data) { 023 return super.representData(((ConfigurationSection) data).getValues(false)); 024 } 025 } 026 027 private class RepresentConfigurationSerializable extends RepresentMap { 028 @Override 029 public Node representData(Object data) { 030 ConfigurationSerializable serializable = (ConfigurationSerializable) data; 031 Map<String, Object> values = new LinkedHashMap<String, Object>(); 032 values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); 033 values.putAll(serializable.serialize()); 034 035 return super.representData(values); 036 } 037 } 038 }