mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-04 13:55:03 +08:00
feat(deps): Update with EasyConfiguration
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>3.0.2</version>
|
||||
<version>3.0.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
+33
-3
@@ -6,9 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnmodifiableView;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class BukkitSection implements ConfigureSection {
|
||||
|
||||
@@ -62,6 +60,38 @@ public class BukkitSection implements ConfigureSection {
|
||||
return Collections.unmodifiableMap(original);
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap(ConfigurationSection section) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
for (String key : section.getKeys(false)) {
|
||||
Object value = section.get(key);
|
||||
if (value instanceof ConfigurationSection) {
|
||||
map.put(key, toMap((ConfigurationSection) value));
|
||||
} else if (value instanceof BukkitSection) {
|
||||
map.put(key, toMap(((BukkitSection) value).data()));
|
||||
} else if (value instanceof List<?>) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
for (Object o : (List<?>) value) {
|
||||
if (o instanceof ConfigurationSection) {
|
||||
list.add(toMap((ConfigurationSection) o));
|
||||
} else if (o instanceof BukkitSection) {
|
||||
list.add(toMap(((BukkitSection) o).data()));
|
||||
} else {
|
||||
list.add(o);
|
||||
}
|
||||
}
|
||||
map.put(key, list);
|
||||
} else {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull @UnmodifiableView Map<String, Object> asMap() {
|
||||
return toMap(data());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
if (value instanceof BukkitSection) { // unwrap
|
||||
|
||||
+3
-3
@@ -4,12 +4,12 @@ import cc.carm.lib.configuration.adapter.ValueAdapter;
|
||||
import cc.carm.lib.configuration.adapter.ValueType;
|
||||
import cc.carm.lib.configuration.builder.AbstractConfigBuilder;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||
import cc.carm.lib.configuration.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||
import cc.carm.lib.configuration.value.text.function.ContentHandler;
|
||||
import com.cryptomorin.xseries.XItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@@ -32,8 +32,8 @@ public class ConfiguredItem extends ConfiguredValue<ItemStack> {
|
||||
public static final ValueAdapter<ItemStack> ITEM_ADAPTER = new ValueAdapter<>(ITEM_TYPE,
|
||||
(holder, type, value) -> XItemStack.serialize(value),
|
||||
(holder, type, value) -> {
|
||||
ConfigurationSection section = (ConfigurationSection) value;
|
||||
return XItemStack.deserialize(section);
|
||||
ConfigureSection section = (ConfigureSection) value;
|
||||
return XItemStack.deserialize(section.asMap());
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user