1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2026-06-05 06:51:49 +08:00

Compare commits

...

8 Commits

Author SHA1 Message Date
carm 425d61834b chore: 移除重复方法 2022-09-10 01:33:47 +08:00
carm c9a272d052 fix(repo): 添加sonatype-repo 2022-09-10 01:23:23 +08:00
carm 327484cd53 feat(source): 为 ConfigurationWrapper 添加 getSource() 方法以获取源实现内容。 2022-09-10 01:17:10 +08:00
carm 99090929dd feat(source): 为 ConfigurationWrapper 添加 getSource() 方法以获取源实现内容。 2022-09-10 01:04:14 +08:00
carm 8437c4c904 feat(source): 为 ConfigurationWrapper 添加 getSource() 方法以获取源实现内容。 2022-09-10 01:04:04 +08:00
dependabot[bot] 21f7742d78 chore(deps): bump maven-javadoc-plugin from 3.4.0 to 3.4.1 (#9)
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.0 to 3.4.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.0...maven-javadoc-plugin-3.4.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-16 21:04:11 +08:00
dependabot[bot] 68e6280c94 chore(deps): bump placeholderapi from 2.11.1 to 2.11.2 (#7)
Bumps placeholderapi from 2.11.1 to 2.11.2.

---
updated-dependencies:
- dependency-name: me.clip:placeholderapi
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-05 14:44:26 +08:00
carm 9a8e6395bb fix(text): 令 AbstractText#parse 返回值不得为null,避免在List类型循环parse时出现异常。 2022-06-21 05:03:16 +08:00
22 changed files with 170 additions and 237 deletions
+4 -3
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.0.1</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
@@ -17,12 +17,13 @@
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<groupId>cc.carm.lib</groupId>
<artifactId>easyconfiguration-core</artifactId>
<version>${easyconfiguration.version}</version>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
@@ -28,16 +28,14 @@ public abstract class AbstractText<R> {
return this.message;
}
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
return parse(parser, receiver, ParamsUtils.buildParams(params, values));
}
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
String message = getMessage();
if (message.isEmpty()) return null; // No further processing
else return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
}
@@ -1,10 +1,10 @@
package cc.carm.lib.mineconfiguration.common.value;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,7 +24,6 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
protected final @NotNull Function<String, T> textBuilder;
@SuppressWarnings("NullableProblems")
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-bukkit-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.0.1</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
@@ -1,8 +1,10 @@
package cc.carm.lib.mineconfiguration.bukkit.data;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
@@ -126,7 +128,11 @@ public class ItemConfig {
return map;
}
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
return deserialize(CraftSectionWrapper.of(section));
}
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
String typeName = section.getString("type");
if (typeName == null) throw new NullPointerException("Item type name is null");
@@ -156,7 +162,7 @@ public class ItemConfig {
return flags;
}
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper section) {
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper<?> section) {
Map<Enchantment, Integer> enchantments = new LinkedHashMap<>();
if (section == null) return enchantments;
section.getKeys(false).forEach(key -> {
@@ -61,7 +61,7 @@ public class TitleConfig {
return map;
}
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper section) {
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
return of(section.getString("line1"), section.getString("line2"));
}
@@ -10,61 +10,62 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
public class CraftSectionWrapper implements ConfigurationWrapper {
public class CraftSectionWrapper implements ConfigurationWrapper<ConfigurationSection> {
protected final ConfigurationSection section;
protected final ConfigurationSection configuration;
protected CraftSectionWrapper(ConfigurationSection section) {
this.section = section;
protected CraftSectionWrapper(ConfigurationSection configuration) {
this.configuration = configuration;
}
public ConfigurationSection getSourceSection() {
return section;
@Override
public @NotNull ConfigurationSection getSource() {
return this.configuration;
}
@Override
public @NotNull Set<String> getKeys(boolean deep) {
return this.section.getKeys(deep);
return this.configuration.getKeys(deep);
}
@Override
public @NotNull Map<String, Object> getValues(boolean deep) {
return this.section.getValues(deep);
return this.configuration.getValues(deep);
}
@Override
public void set(@NotNull String path, @Nullable Object value) {
this.section.set(path, value);
this.configuration.set(path, value);
}
@Override
public boolean contains(@NotNull String path) {
return this.section.contains(path);
return this.configuration.contains(path);
}
@Override
public @Nullable Object get(@NotNull String path) {
return this.section.get(path);
return this.configuration.get(path);
}
@Override
public boolean isList(@NotNull String path) {
return this.section.isList(path);
return this.configuration.isList(path);
}
@Override
public @Nullable List<?> getList(@NotNull String path) {
return this.section.getList(path);
return this.configuration.getList(path);
}
@Override
public boolean isConfigurationSection(@NotNull String path) {
return this.section.isConfigurationSection(path);
return this.configuration.isConfigurationSection(path);
}
@Override
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
return Optional.ofNullable(section.getConfigurationSection(path))
public @Nullable CraftSectionWrapper getConfigurationSection(@NotNull String path) {
return Optional.ofNullable(configuration.getConfigurationSection(path))
.map(CraftSectionWrapper::of).orElse(null);
}
@@ -1,13 +1,13 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -33,14 +33,17 @@ public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
protected final @NotNull String[] params;
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
public ConfiguredItem(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
super(provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue, getItemParser(), ItemConfig::serialize);
super(
provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue,
getItemParser(), ItemConfig::serialize
);
this.params = params;
}
public static ConfigValueParser<ConfigurationWrapper, ItemConfig> getItemParser() {
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
return (s, d) -> ItemConfig.deserialize(s);
}
@@ -1,14 +1,14 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -103,7 +103,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
}
public static ConfigValueParser<ConfigurationWrapper, TitleConfig> getTitleParser() {
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
return (s, d) -> TitleConfig.deserialize(s);
}
}
+3 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-bukkit-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.0.1</version>
<version>2.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
@@ -16,6 +16,8 @@
<artifactId>mineconfiguration-bukkit</artifactId>
<packaging>jar</packaging>
<name>MineConfiguration-Bukkit</name>
<dependencies>
<dependency>
@@ -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);
}
}
@@ -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);
+2 -2
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.0.1</version>
<version>2.1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -35,7 +35,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<version>2.11.2</version>
<scope>provided</scope>
</dependency>
+3 -10
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.0.1</version>
<version>2.1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -22,8 +22,8 @@
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easyconfiguration-core</artifactId>
<version>${easyconfiguration.version}</version>
<artifactId>mineconfiguration-common</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
@@ -43,13 +43,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>mineconfiguration-common</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.function.BiFunction;
@SuppressWarnings("deprecation")
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
@@ -1,13 +1,13 @@
package cc.carm.lib.mineconfiguration.bungee.source;
import cc.carm.lib.configuration.core.ConfigInitializer;
import cc.carm.lib.configuration.core.source.ConfigurationComments;
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.io.BufferedWriter;
import java.io.File;
@@ -16,7 +16,6 @@ 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 BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
@@ -52,6 +51,11 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
this.configuration = getLoader().load(file);
}
@Override
public @Nullable ConfigurationComments getComments() {
return this.comments;
}
@Override
public void save() throws Exception {
getLoader().save(configuration, file);
@@ -67,26 +71,6 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
}
}
@Override
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
this.comments.setHeaderComments(path, comments);
}
@Override
public void setInlineComment(@NotNull String path, @Nullable String comment) {
this.comments.setInlineComment(path, comment);
}
@Override
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
return this.comments.getHeaderComment(path);
}
@Override
public @Nullable String getInlineComment(@NotNull String path) {
return this.comments.getInlineComment(path);
}
@Override
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
return this.initializer;
@@ -11,12 +11,12 @@ import java.util.stream.Collectors;
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
public class BungeeSectionWrapper implements ConfigurationWrapper {
public class BungeeSectionWrapper implements ConfigurationWrapper<Configuration> {
private final Configuration section;
private final Configuration configuration;
private BungeeSectionWrapper(@NotNull Configuration section) {
this.section = section;
this.configuration = section;
}
@Contract("!null->!null")
@@ -37,34 +37,39 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
return keys;
}
@Override
public @NotNull Configuration getSource() {
return this.configuration;
}
@Override
public @NotNull Set<String> getKeys(boolean deep) {
if (deep) {
return new LinkedHashSet<>(getAllKeys(section));
return new LinkedHashSet<>(getAllKeys(configuration));
} else {
return new LinkedHashSet<>(section.getKeys());
return new LinkedHashSet<>(configuration.getKeys());
}
}
@Override
public @NotNull Map<String, Object> getValues(boolean deep) {
return getKeys(deep).stream()
.collect(Collectors.toMap(key -> key, section::get, (a, b) -> b, LinkedHashMap::new));
.collect(Collectors.toMap(key -> key, configuration::get, (a, b) -> b, LinkedHashMap::new));
}
@Override
public void set(@NotNull String path, @Nullable Object value) {
this.section.set(path, value);
this.configuration.set(path, value);
}
@Override
public boolean contains(@NotNull String path) {
return this.section.contains(path);
return this.configuration.contains(path);
}
@Override
public @Nullable Object get(@NotNull String path) {
return this.section.get(path);
return this.configuration.get(path);
}
@Override
@@ -74,7 +79,7 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
@Override
public @Nullable List<?> getList(@NotNull String path) {
return this.section.getList(path);
return this.configuration.getList(path);
}
@Override
@@ -83,7 +88,7 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
}
@Override
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
return of(this.section.getSection(path));
public @Nullable BungeeSectionWrapper getConfigurationSection(@NotNull String path) {
return of(this.configuration.getSection(path));
}
}
@@ -1,60 +1,23 @@
package cc.carm.lib.mineconfiguration.bungee.source;
import cc.carm.lib.configuration.core.source.ConfigurationComments;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.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.io.StringWriter;
import java.util.*;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
public class BungeeYAMLComments {
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 BungeeYAMLComments extends ConfigurationComments {
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
List<String> comments = getHeaderComment(path);
@@ -144,7 +107,7 @@ public class BungeeYAMLComments {
* @param key 键
* @return 该键的缩进文本
*/
protected static String getIndents(String key) {
protected static String getIndents(@NotNull String key) {
String[] splitKey = key.split("[" + SEPARATOR + "]");
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
}
+4 -2
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-parent</artifactId>
<version>2.0.1</version>
<version>2.1.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -17,6 +17,8 @@
<artifactId>mineconfiguration-spigot</artifactId>
<packaging>jar</packaging>
<name>MineConfiguration-Spigot</name>
<dependencies>
<dependency>
@@ -38,7 +40,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<version>2.11.2</version>
<scope>provided</scope>
</dependency>
@@ -1,15 +1,13 @@
package cc.carm.lib.mineconfiguration.spigot.source;
import cc.carm.lib.configuration.core.ConfigInitializer;
import cc.carm.lib.configuration.core.source.ConfigurationComments;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.io.File;
import java.util.Collections;
import java.util.List;
public class SpigotConfigProvider extends CraftConfigProvider {
@@ -17,38 +15,18 @@ public class SpigotConfigProvider extends CraftConfigProvider {
super(file);
}
protected SpigotYAMLComments comments = null;
@Override
public void initializeConfig() {
this.configuration = YamlConfiguration.loadConfiguration(file);
this.comments = new SpigotYAMLComments(configuration);
this.initializer = new ConfigInitializer<>(this);
}
@Override
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
if (path == null) {
this.configuration.options().setHeader(comments);
} else {
this.configuration.setComments(path, comments);
}
public @Nullable ConfigurationComments getComments() {
return this.comments;
}
@Override
public void setInlineComment(@NotNull String path, @Nullable String comment) {
if (comment == null) {
this.configuration.setInlineComments(path, null);
} else {
this.configuration.setComments(path, Collections.singletonList(comment));
}
}
@Override
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
if (path == null) return Collections.unmodifiableList(this.configuration.options().getHeader());
else return this.configuration.getComments(path);
}
@Override
public @Nullable String getInlineComment(@NotNull String path) {
return String.join(" ", this.configuration.getInlineComments(path));
}
}
@@ -0,0 +1,48 @@
package cc.carm.lib.mineconfiguration.spigot.source;
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.util.Collections;
import java.util.List;
public class SpigotYAMLComments extends ConfigurationComments {
protected final YamlConfiguration configuration;
public SpigotYAMLComments(YamlConfiguration configuration) {
this.configuration = configuration;
}
@Override
public void setHeaderComments(@Nullable String path, @Nullable List<String> comments) {
if (path == null) {
this.configuration.options().setHeader(comments);
} else {
this.configuration.setComments(path, comments);
}
}
@Override
public void setInlineComment(@NotNull String path, @Nullable String comment) {
if (comment == null) {
this.configuration.setInlineComments(path, null);
} else {
this.configuration.setComments(path, Collections.singletonList(comment));
}
}
@Override
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
if (path == null) return Collections.unmodifiableList(this.configuration.options().getHeader());
else return this.configuration.getComments(path);
}
@Override
public @Nullable String getInlineComment(@NotNull String path) {
return String.join(" ", this.configuration.getInlineComments(path));
}
}
+14 -10
View File
@@ -9,12 +9,11 @@
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<easyconfiguration.version>3.1.0</easyconfiguration.version>
</properties>
<groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-parent</artifactId>
<version>2.0.1</version>
<version>2.1.0</version>
<packaging>pom</packaging>
<modules>
<module>common</module>
@@ -65,9 +64,13 @@
<repositories>
<repository>
<id>carm-repo</id>
<name>Carm's Repo</name>
<url>https://repo.carm.cc/repository/maven-public/</url>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
@@ -76,13 +79,14 @@
</repository>
<repository>
<id>nexus</id>
<id>lumine</id>
<url>https://mvn.lumine.io/repository/maven-public/</url>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<id>carm-repo</id>
<name>Carm's Repo</name>
<url>https://repo.carm.cc/repository/maven-public/</url>
</repository>
</repositories>
@@ -190,7 +194,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<classifier>javadoc</classifier>
<detectJavaApiLink>false</detectJavaApiLink>