mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-08 16:12:18 -07:00
SPIGOT-6949: Configuration sections that are nested within Maps or Lists are not properly serialized.
This broke with the configuration changes in
ed8a152b3a
.
This commit reverts one of the changes of this other commit so that
nested configuration sections are serialized as Maps again.
Although the types of these nested configuration sections are not
preserved when reloading a configuration (they turn into Maps), their
contents should at least be preserved, as it has been the case in
earlier Bukkit versions.
By: blablubbabc <lukas@wirsindwir.de>
This commit is contained in:
@@ -2,6 +2,7 @@ package org.bukkit.configuration.file;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -11,12 +12,23 @@ import org.yaml.snakeyaml.representer.Representer;
|
||||
public class YamlRepresenter extends Representer {
|
||||
|
||||
public YamlRepresenter() {
|
||||
this.multiRepresenters.put(ConfigurationSection.class, new RepresentConfigurationSection());
|
||||
this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());
|
||||
// SPIGOT-6234: We could just switch YamlConstructor to extend Constructor rather than SafeConstructor, however there is a very small risk of issues with plugins treating config as untrusted input
|
||||
// So instead we will just allow future plugins to have their enums extend ConfigurationSerializable
|
||||
this.multiRepresenters.remove(Enum.class);
|
||||
}
|
||||
|
||||
// SPIGOT-6949: Used by configuration sections that are nested within lists or maps.
|
||||
private class RepresentConfigurationSection extends RepresentMap {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Node representData(@NotNull Object data) {
|
||||
return super.representData(((ConfigurationSection) data).getValues(false));
|
||||
}
|
||||
}
|
||||
|
||||
private class RepresentConfigurationSerializable extends RepresentMap {
|
||||
|
||||
@NotNull
|
||||
|
Reference in New Issue
Block a user