mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-04 21:58:16 +08:00
feat(source): 为 ConfigurationWrapper 添加 getSource() 方法以获取源实现内容。
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bukkit</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
|
||||
+5
-22
@@ -1,10 +1,10 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -12,13 +12,12 @@ import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
protected BukkitYAMLComments bukkitComments = new BukkitYAMLComments();
|
||||
protected @NotNull BukkitYAMLComments comments = new BukkitYAMLComments();
|
||||
|
||||
public BukkitConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
@@ -39,7 +38,7 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
configuration.save(getFile());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
this.bukkitComments.writeComments(configuration, new BufferedWriter(writer));
|
||||
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
||||
String value = writer.toString(); // config contents
|
||||
|
||||
Path toUpdatePath = getFile().toPath();
|
||||
@@ -49,24 +48,8 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||
this.bukkitComments.setHeaderComments(path, comments);
|
||||
public @Nullable ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
this.bukkitComments.setInlineComment(path, comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@Unmodifiable
|
||||
public List<String> getHeaderComment(@Nullable String path) {
|
||||
return this.bukkitComments.getHeaderComment(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return this.bukkitComments.getInlineComment(path);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-42
@@ -1,58 +1,20 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitYAMLComments {
|
||||
|
||||
protected final @NotNull Map<String, List<String>> headerComments = new HashMap<>();
|
||||
protected final @NotNull Map<String, String> inlineComments = new HashMap<>();
|
||||
|
||||
protected @NotNull Map<String, List<String>> getHeaderComments() {
|
||||
return headerComments;
|
||||
}
|
||||
|
||||
protected @NotNull Map<String, String> getInlineComments() {
|
||||
return inlineComments;
|
||||
}
|
||||
|
||||
public void setHeaderComments(@Nullable String path, @Nullable List<String> comments) {
|
||||
|
||||
if (comments == null) {
|
||||
getHeaderComments().remove(path);
|
||||
} else {
|
||||
getHeaderComments().put(path, comments);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
if (comment == null) {
|
||||
getInlineComments().remove(path);
|
||||
} else {
|
||||
getInlineComments().put(path, comment);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Unmodifiable
|
||||
public List<String> getHeaderComment(@Nullable String path) {
|
||||
return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return getInlineComments().get(path);
|
||||
}
|
||||
public class BukkitYAMLComments extends ConfigurationComments {
|
||||
|
||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||
List<String> comments = getHeaderComment(path);
|
||||
|
||||
Reference in New Issue
Block a user