org.bukkit.configuration.serialization.ConfigurationSerialization Java Examples
The following examples show how to use
org.bukkit.configuration.serialization.ConfigurationSerialization.
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: SerializationHelper.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
/** * Parses through the input map to deal with serialized objects a la {@link * ConfigurationSerializable}. * * <p>Called recursively first on Maps and Lists before passing the parsed input over to {@link * ConfigurationSerialization#deserializeObject(java.util.Map)}. Basically this means it will * deserialize the most nested objects FIRST and the top level object LAST. * * @param input the input * @return the object that deserialize */ public static Object deserialize(@NotNull final Map<?, ?> input) { final Map<String, Object> output = new LinkedHashMap<>(input.size()); for (final Map.Entry<?, ?> e : input.entrySet()) { if (e.getValue() instanceof Map) { output.put(e.getKey().toString(), deserialize((Map<?, ?>) e.getValue())); } else if (e.getValue() instanceof List) { output.put(e.getKey().toString(), deserialize((List<?>) e.getValue())); } else { output.put(e.getKey().toString(), e.getValue()); } } if (output.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { try { return ConfigurationSerialization.deserializeObject(output); } catch (IllegalArgumentException ex) { throw new YAMLException("Could not deserialize object", ex); } } return output; }
Example #2
Source File: SerializationHelper.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
public static Object serialize(@NotNull Object value) { if (value instanceof Object[]) { value = new ArrayList<>(Arrays.asList((Object[]) value)); } if (value instanceof Set && !(value instanceof SerializableSet)) { value = new SerializableSet((Set) value); } if (value instanceof ConfigurationSection) { return buildMap(((ConfigurationSection) value).getValues(false)); } else if (value instanceof Map) { return buildMap((Map) value); } else if (value instanceof List) { return buildList((List) value); } else if (value instanceof ConfigurationSerializable) { ConfigurationSerializable serializable = (ConfigurationSerializable) value; Map<String, Object> values = new LinkedHashMap<>(); values.put( ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); values.putAll(serializable.serialize()); return buildMap(values); } else { return value; } }
Example #3
Source File: YamlConstructor.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public Object construct(Node node) { if (node.isTwoStepsConstruction()) { throw new YAMLException("Unexpected referential mapping structure. Node: " + node); } Map<?, ?> raw = (Map<?, ?>) super.construct(node); if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size()); for (Map.Entry<?, ?> entry : raw.entrySet()) { typed.put(entry.getKey().toString(), entry.getValue()); } try { return ConfigurationSerialization.deserializeObject(typed); } catch (IllegalArgumentException ex) { throw new YAMLException("Could not deserialize object", ex); } } return raw; }
Example #4
Source File: SkriptYamlConstructor.java From skript-yaml with MIT License | 6 votes |
@Override public Object construct(Node node) { if (node.isTwoStepsConstruction()) { throw new YAMLException("Unexpected referential mapping structure. Node: " + node); } Map<?, ?> raw = (Map<?, ?>) super.construct(node); if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size()); for (Map.Entry<?, ?> entry : raw.entrySet()) { typed.put(entry.getKey().toString(), entry.getValue()); } try { return ConfigurationSerialization.deserializeObject(typed); } catch (IllegalArgumentException ex) { throw new YAMLException("Could not deserialize object", ex); } } return raw; }
Example #5
Source File: NameTagChanger.java From NameTagChanger with MIT License | 6 votes |
/** * Enables NameTagChanger and creates necessary packet handlers. * Is done automatically by the constructor, so only use this method * if the disable() method has previously been called. */ public void enable() { if (plugin == null) { return; } if (!ReflectUtil.isVersionHigherThan(1, 7, 10)) { printMessage("NameTagChanger has detected that you are running 1.7 or lower. This probably means that NameTagChanger will not work or throw errors, but you are still free to try and use it.\nIf you are not a developer, please consider contacting the developer of " + plugin.getName() + " and informing them about this message."); } ConfigurationSerialization.registerClass(Skin.class); Validate.isTrue(!enabled, "NameTagChanger is already enabled"); if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) { packetHandler = new ProtocolLibPacketHandler(plugin); } else { packetHandler = new ChannelPacketHandler(plugin); } enabled = true; Metrics metrics = new Metrics(plugin); metrics.addCustomChart(new Metrics.SimplePie("packet_implementation", () -> packetHandler instanceof ProtocolLibPacketHandler ? "ProtocolLib" : "ChannelInjector")); }
Example #6
Source File: Serialization.java From PlayerVaults with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public static Object deserialize(Map<String, Object> map) { for (Entry<String, Object> entry : map.entrySet()) { if (entry.getValue() instanceof Map) { entry.setValue(deserialize((Map) entry.getValue())); } else if (entry.getValue() instanceof Iterable) { entry.setValue(convertIterable((Iterable) entry.getValue())); } else if (entry.getValue() instanceof Number) { entry.setValue(convertNumber((Number) entry.getValue())); } } return map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY) ? ConfigurationSerialization.deserializeObject(map) : map; }
Example #7
Source File: Variables.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Class<? extends ConfigurationSerializable> getClass(final @NonNull String id) { if (id.startsWith(configurationSerializablePrefix)) return ConfigurationSerialization.getClassByAlias(id.substring(configurationSerializablePrefix.length())); return null; }
Example #8
Source File: Variables.java From Skript with GNU General Public License v3.0 | 5 votes |
@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; }
Example #9
Source File: SkriptYamlRepresenter.java From skript-yaml with MIT License | 5 votes |
private Node representConfigurationSerializable(Object data) { ConfigurationSerializable serializable = (ConfigurationSerializable) data; Map<String, Object> values = new LinkedHashMap<String, Object>(); values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); values.putAll(serializable.serialize()); return super.representData(values); }
Example #10
Source File: BukkitTypeSerializer.java From helper with MIT License | 5 votes |
private static void deserializeChildren(Map<String, Object> map) { for (Map.Entry<String, Object> entry : map.entrySet()) { if (entry.getValue() instanceof Map) { try { //noinspection unchecked Map<String, Object> value = (Map) entry.getValue(); deserializeChildren(value); if (value.containsKey("==")) { entry.setValue(ConfigurationSerialization.deserializeObject(value)); } } catch (Exception e) { // ignore } } if (entry.getValue() instanceof Number) { double doubleVal = ((Number) entry.getValue()).doubleValue(); int intVal = (int) doubleVal; long longVal = (long) doubleVal; if (intVal == doubleVal) { entry.setValue(intVal); } else if (longVal == doubleVal) { entry.setValue(longVal); } else { entry.setValue(doubleVal); } } } }
Example #11
Source File: BukkitTypeSerializer.java From helper with MIT License | 5 votes |
@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); }
Example #12
Source File: BukkitSerializableAdapterFactory.java From helper with MIT License | 5 votes |
private void deserializeChildren(Map<String, Object> map) { for (Map.Entry<String, Object> entry : map.entrySet()) { if (entry.getValue() instanceof Map) { try { //noinspection unchecked Map<String, Object> value = (Map) entry.getValue(); deserializeChildren(value); if (value.containsKey("==")) { entry.setValue(ConfigurationSerialization.deserializeObject(value)); } } catch (Exception e) { // ignore } } if (entry.getValue() instanceof Number) { double doubleVal = ((Number) entry.getValue()).doubleValue(); int intVal = (int) doubleVal; long longVal = (long) doubleVal; if (intVal == doubleVal) { entry.setValue(intVal); } else if (longVal == doubleVal) { entry.setValue(longVal); } else { entry.setValue(doubleVal); } } } }
Example #13
Source File: BukkitSerializableAdapterFactory.java From helper with MIT License | 5 votes |
@Override public ConfigurationSerializable read(JsonReader in) { Map<String, Object> map = this.gson.fromJson(in, RAW_OUTPUT_TYPE); if (map == null) { return null; } deserializeChildren(map); return ConfigurationSerialization.deserializeObject(map); }
Example #14
Source File: BukkitSerializableAdapterFactory.java From helper with MIT License | 5 votes |
@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 #15
Source File: BukkitObjectInputStream.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override protected Object resolveObject(Object obj) throws IOException { if (obj instanceof Wrapper) { try { (obj = ConfigurationSerialization.deserializeObject(((Wrapper<?>) obj).map)).getClass(); // NPE } catch (Throwable ex) { throw newIOException("Failed to deserialize object", ex); } } return super.resolveObject(obj); }
Example #16
Source File: YamlRepresenter.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public Node representData(Object data) { ConfigurationSerializable serializable = (ConfigurationSerializable) data; Map<String, Object> values = new LinkedHashMap<String, Object>(); values.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(serializable.getClass())); values.putAll(serializable.serialize()); return super.representData(values); }
Example #17
Source File: JavaPluginLoader.java From Kettle with GNU General Public License v3.0 | 5 votes |
private void removeClass(String name) { Class<?> clazz = classes.remove(name); try { if ((clazz != null) && (ConfigurationSerializable.class.isAssignableFrom(clazz))) { Class<? extends ConfigurationSerializable> serializable = clazz.asSubclass(ConfigurationSerializable.class); ConfigurationSerialization.unregisterClass(serializable); } } catch (NullPointerException ex) { // Boggle! // (Native methods throwing NPEs is not fun when you can't stop it before-hand) } }
Example #18
Source File: JavaPluginLoader.java From Kettle with GNU General Public License v3.0 | 5 votes |
void setClass(String name, Class<?> clazz) { if (!classes.containsKey(name)) { classes.put(name, clazz); if (ConfigurationSerializable.class.isAssignableFrom(clazz)) { Class<? extends ConfigurationSerializable> serializable = clazz.asSubclass(ConfigurationSerializable.class); ConfigurationSerialization.registerClass(serializable); } } }
Example #19
Source File: BukkitTypeSerializer.java From helper with MIT License | 4 votes |
@Override public ConfigurationSerializable deserialize(TypeToken<?> type, ConfigurationNode from) throws ObjectMappingException { Map<String, Object> map = from.getValue(TYPE); deserializeChildren(map); return ConfigurationSerialization.deserializeObject(map); }
Example #20
Source File: Wrapper.java From Kettle with GNU General Public License v3.0 | 4 votes |
static Wrapper<ImmutableMap<String, ?>> newWrapper(ConfigurationSerializable obj) { return new Wrapper<ImmutableMap<String, ?>>(ImmutableMap.<String, Object>builder().put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(obj.getClass())).putAll(obj.serialize()).build()); }
Example #21
Source File: Main.java From NeuralNetworkAPI with GNU General Public License v3.0 | 4 votes |
/** * This class is used to make a Neural Network figure out whether a username * is valid */ public void onLoad() { ConfigurationSerialization.registerClass(NNBaseEntity.class); ConfigurationSerialization.registerClass(NNAI.class); ConfigurationSerialization.registerClass(Layer.class); ConfigurationSerialization.registerClass(Senses.class); ConfigurationSerialization.registerClass(Controler.class); ConfigurationSerialization.registerClass(Senses2D.class); ConfigurationSerialization.registerClass(Senses3D.class); ConfigurationSerialization.registerClass(Sensory2D_Booleans.class); ConfigurationSerialization.registerClass(Sensory2D_Letters.class); ConfigurationSerialization.registerClass(Sensory2D_Numbers.class); ConfigurationSerialization.registerClass(Sensory3D_Booleans.class); ConfigurationSerialization.registerClass(Sensory3D_Numbers.class); ConfigurationSerialization.registerClass(Neuron.class); ConfigurationSerialization.registerClass(InputNeuron.class); ConfigurationSerialization.registerClass(InputBlockNeuron.class); ConfigurationSerialization.registerClass(InputBooleanNeuron.class); ConfigurationSerialization.registerClass(InputLetterNeuron.class); ConfigurationSerialization.registerClass(InputNumberNeuron.class); ConfigurationSerialization.registerClass(InputTickNeuron.class); ConfigurationSerialization.registerClass(OutputNeuron.class); ConfigurationSerialization.registerClass(BiasNeuron.class); ConfigurationSerialization.registerClass(LogicalAND.class); ConfigurationSerialization.registerClass(LogicalOR.class); ConfigurationSerialization.registerClass(LogicalXOR.class); ConfigurationSerialization.registerClass(LogicalXNOR.class); ConfigurationSerialization.registerClass(LogicalNAND.class); ConfigurationSerialization.registerClass(LogicalInverted.class); ConfigurationSerialization.registerClass(LogicalNOR.class); ConfigurationSerialization.registerClass(BlackJackHelper.class); ConfigurationSerialization.registerClass(NumberAdder.class); ConfigurationSerialization.registerClass(BotGuesser.class); ConfigurationSerialization.registerClass(PrimeNumberBot.class); ConfigurationSerialization.registerClass(MusicBot.class); ConfigurationSerialization.registerClass(SwearBot.class); }
Example #22
Source File: BedwarsRel.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
private void registerConfigurationClasses() { ConfigurationSerialization.registerClass(ResourceSpawner.class, "RessourceSpawner"); ConfigurationSerialization.registerClass(Team.class, "Team"); ConfigurationSerialization.registerClass(PlayerStatistic.class, "PlayerStatistic"); }
Example #23
Source File: BannerMeta.java From Carbon with GNU Lesser General Public License v3.0 | 4 votes |
public static void init() { ConfigurationSerialization.registerClass(BannerPattern.class); }
Example #24
Source File: Serialization.java From PlayerVaults with GNU General Public License v3.0 | 4 votes |
@Deprecated public static Map<String, Object> serialize(ConfigurationSerializable cs) { Map<String, Object> returnVal = handleSerialization(cs.serialize()); returnVal.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass())); return returnVal; }