mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-04 13:55:03 +08:00
feat!(conf): Upgraded to latest EasyConfiguration with optimized.
This commit is contained in:
+13
-15
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.9.3</version>
|
||||
<version>3.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -21,6 +21,13 @@
|
||||
<name>MineConfiguration-Velocity</name>
|
||||
<description>轻松(做)配置,适用于Velocity的版本,可用JSON与YAML格式。</description>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
@@ -32,24 +39,15 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>yamlcommentwriter</artifactId>
|
||||
<version>${deps.yamlcommentwriter.version}</version>
|
||||
<artifactId>easyconfiguration-yaml</artifactId>
|
||||
<version>${deps.easyconfifuration.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>velocitycord-api</artifactId>
|
||||
<version>1.18-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>velocitycord-api</artifactId>
|
||||
<version>1.18-R0.1-SNAPSHOT</version>
|
||||
<type>javadoc</type>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.4.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.velocity.builder.VelocityConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeSectionWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||
|
||||
public static @NotNull VelocityConfigBuilder builder() {
|
||||
return new VelocityConfigBuilder();
|
||||
}
|
||||
|
||||
public BungeeConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||
super(manifest);
|
||||
}
|
||||
|
||||
public BungeeConfigProvider getBukkitProvider() {
|
||||
ConfigurationProvider<?> provider = getProvider();
|
||||
if (provider instanceof BungeeConfigProvider) return (BungeeConfigProvider) getProvider();
|
||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
||||
}
|
||||
|
||||
public BungeeSectionWrapper getBukkitConfig() {
|
||||
return getBukkitProvider().getConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
+14
-99
@@ -1,120 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity;
|
||||
|
||||
import cc.carm.lib.configuration.core.Configuration;
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.configuration.Configuration;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLConfigFactory;
|
||||
import cc.carm.lib.configuration.source.yaml.YAMLSource;
|
||||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.JsonConfiguration;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvider> {
|
||||
public class MineConfiguration extends AbstractConfiguration<ConfigurationHolder<YAMLSource>> {
|
||||
|
||||
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
|
||||
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
|
||||
try {
|
||||
provider.initializeFile(source);
|
||||
provider.initializeConfig();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return provider;
|
||||
public MineConfiguration(@NotNull File pluginDataFolder) {
|
||||
super(
|
||||
YAMLConfigFactory.from(pluginDataFolder, "config.yml").resourcePath("config.yml").build(),
|
||||
YAMLConfigFactory.from(pluginDataFolder, "messages.yml").resourcePath("messages.yml").build()
|
||||
);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(File file, String source) {
|
||||
return fromYAML(file, source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(File file) {
|
||||
return from(file, file.getName());
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(String fileName) {
|
||||
return from(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(String fileName, String source) {
|
||||
return from(new File(fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(Plugin plugin, String fileName) {
|
||||
return from(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(File file, String source) {
|
||||
return create(file, source, ConfigurationProvider.getProvider(YamlConfiguration.class));
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(String fileName, String source) {
|
||||
return fromYAML(new File(fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(File file) {
|
||||
return fromYAML(file, file.getName());
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(String fileName) {
|
||||
return fromYAML(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(Plugin plugin, String fileName) {
|
||||
return fromYAML(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(Plugin plugin, String fileName, String source) {
|
||||
return fromYAML(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(File file, String source) {
|
||||
return create(file, source, ConfigurationProvider.getProvider(JsonConfiguration.class));
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(String fileName, String source) {
|
||||
return fromJSON(new File(fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(File file) {
|
||||
return fromJSON(file, file.getName());
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(String fileName) {
|
||||
return fromJSON(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(Plugin plugin, String fileName) {
|
||||
return fromJSON(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(Plugin plugin, String fileName, String source) {
|
||||
return fromJSON(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin) {
|
||||
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin,
|
||||
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||
@NotNull Configuration configRoot,
|
||||
@NotNull Configuration messageRoot) {
|
||||
this(plugin);
|
||||
this(pluginDataFolder);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin,
|
||||
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||
@NotNull Class<? extends Configuration> configRoot,
|
||||
@NotNull Class<? extends Configuration> messageRoot) {
|
||||
this(plugin);
|
||||
this(pluginDataFolder);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.builder;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||
|
||||
public abstract class AbstractVelocityBuilder<T, B extends AbstractVelocityBuilder<T, B>>
|
||||
extends AbstractConfigBuilder<T, B, BungeeConfigProvider> {
|
||||
|
||||
public AbstractVelocityBuilder() {
|
||||
super(BungeeConfigProvider.class);
|
||||
}
|
||||
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.builder;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.velocity.builder.message.BungeeMessageBuilder;
|
||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class VelocityConfigBuilder extends ConfigBuilder {
|
||||
|
||||
public @NotNull BungeeMessageBuilder createMessage() {
|
||||
return new BungeeMessageBuilder();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.builder.message;
|
||||
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||
|
||||
|
||||
public BungeeMessageBuilder() {
|
||||
super(CommandSender.class, TextConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <M> BungeeMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
return new BungeeMessageValueBuilder<>(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <M> BungeeMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
return new BungeeMessageListBuilder<>(parser);
|
||||
}
|
||||
|
||||
public @NotNull BungeeMessageValueBuilder<String> asStringValue() {
|
||||
return asValue(defaultParser()).whenSend(CommandSender::sendMessage);
|
||||
}
|
||||
|
||||
public @NotNull BungeeMessageListBuilder<String> asStringList() {
|
||||
return asList(defaultParser()).whenSend((r, m) -> m.forEach(r::sendMessage));
|
||||
}
|
||||
|
||||
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
||||
return (receiver, message) -> ColorParser.parse(message);
|
||||
}
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.velocity.value.ConfiguredMessageList;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageListBuilder<M>
|
||||
extends MessageListBuilder<M, CommandSender, TextConfig, BungeeMessageListBuilder<M>> {
|
||||
|
||||
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, TextConfig::of, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull BungeeMessageListBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.velocity.value.ConfiguredMessage;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageValueBuilder<M>
|
||||
extends MessageValueBuilder<M, CommandSender, TextConfig, BungeeMessageValueBuilder<M>> {
|
||||
|
||||
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, TextConfig::new, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull BungeeMessageValueBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.data;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TextConfig extends AbstractText<CommandSender> {
|
||||
|
||||
public TextConfig(@NotNull String message) {
|
||||
super(CommandSender.class, message);
|
||||
}
|
||||
|
||||
@Contract("!null,-> !null")
|
||||
public static @Nullable TextConfig of(@Nullable String message) {
|
||||
if (message == null) return null;
|
||||
else return new TextConfig(message);
|
||||
}
|
||||
|
||||
public static @NotNull List<TextConfig> of(@Nullable List<String> messages) {
|
||||
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||
else return messages.stream().map(TextConfig::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static @NotNull List<TextConfig> of(@NotNull String... messages) {
|
||||
return of(Arrays.asList(messages));
|
||||
}
|
||||
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.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 cc.carm.lib.yamlcommentupdater.CommentedYAML;
|
||||
import cc.carm.lib.yamlcommentupdater.CommentedYAMLWriter;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> implements CommentedYAML {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
protected ConfigurationProvider loader;
|
||||
protected Configuration configuration;
|
||||
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
||||
|
||||
protected ConfigurationComments comments = new ConfigurationComments();
|
||||
|
||||
public BungeeConfigProvider(@NotNull File file, @NotNull ConfigurationProvider loader) {
|
||||
super(file);
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public BungeeConfigProvider(@NotNull File file, @NotNull Class<? extends ConfigurationProvider> providerClass) {
|
||||
this(file, ConfigurationProvider.getProvider(providerClass));
|
||||
}
|
||||
|
||||
public void initializeConfig() throws IOException {
|
||||
this.configuration = getLoader().load(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BungeeSectionWrapper getConfiguration() {
|
||||
return BungeeSectionWrapper.of(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReload() throws Exception {
|
||||
this.configuration = getLoader().load(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
try {
|
||||
CommentedYAMLWriter.writeWithComments(this, this.file);
|
||||
} catch (Exception ex) {
|
||||
getLoader().save(configuration, file);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
||||
return this.initializer;
|
||||
}
|
||||
|
||||
public ConfigurationProvider getLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeValue(@NotNull String key, @NotNull Object value) {
|
||||
Configuration tmp = new Configuration();// 该对象用于临时记录配置内容
|
||||
tmp.set(key, value);
|
||||
StringWriter tmpStr = new StringWriter();
|
||||
loader.save(tmp, tmpStr);
|
||||
return tmpStr.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(@Nullable String sectionKey, boolean deep) {
|
||||
if (sectionKey == null) return BungeeSectionWrapper.getAllKeys(this.configuration);
|
||||
|
||||
Configuration section = configuration.getSection(sectionKey);
|
||||
if (section == null) return null;
|
||||
|
||||
return new HashSet<>(section.getKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object getValue(@NotNull String key) {
|
||||
return configuration.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> getHeaderComments(@Nullable String key) {
|
||||
return comments.getHeaderComment(key);
|
||||
}
|
||||
|
||||
}
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cc.carm.lib.mineconfiguration.velocity.source.BungeeConfigProvider.SEPARATOR;
|
||||
|
||||
public class BungeeSectionWrapper implements ConfigurationWrapper<Configuration> {
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private BungeeSectionWrapper(@NotNull Configuration section) {
|
||||
this.configuration = section;
|
||||
}
|
||||
|
||||
@Contract("!null->!null")
|
||||
public static @Nullable BungeeSectionWrapper of(@Nullable Configuration section) {
|
||||
return section == null ? null : new BungeeSectionWrapper(section);
|
||||
}
|
||||
|
||||
protected static Set<String> getAllKeys(@NotNull Configuration config) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (String key : config.getKeys()) {
|
||||
keys.add(key);
|
||||
Object value = config.get(key);
|
||||
if (value instanceof Configuration) {
|
||||
getAllKeys((Configuration) value).stream()
|
||||
.map(subKey -> key + SEPARATOR + subKey).forEach(keys::add);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Configuration getSource() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
if (deep) {
|
||||
return new LinkedHashSet<>(getAllKeys(configuration));
|
||||
} else {
|
||||
return new LinkedHashSet<>(configuration.getKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return getKeys(deep).stream()
|
||||
.collect(Collectors.toMap(key -> key, configuration::get, (a, b) -> b, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
this.configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return this.configuration.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return get(path) instanceof List<?>;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return this.configuration.getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSection(@NotNull String path) {
|
||||
return get(path) instanceof Configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BungeeSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||
return of(this.configuration.getSection(path));
|
||||
}
|
||||
}
|
||||
+37
-30
@@ -1,52 +1,59 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.velocity.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.velocity.builder.message.BungeeMessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import cc.carm.lib.configuration.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.value.text.ConfiguredText;
|
||||
import cc.carm.lib.configuration.value.text.data.TextContents;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSender> {
|
||||
public class ConfiguredMessage extends ConfiguredText<Component, Audience> {
|
||||
|
||||
@NotNull
|
||||
public static <M> BungeeMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return BungeeConfigValue.builder().createMessage().asValue(messageParser);
|
||||
public static ConfiguredMessage.Builder create() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static BungeeMessageValueBuilder<String> asString() {
|
||||
return BungeeConfigValue.builder().createMessage().asStringValue();
|
||||
public static ConfiguredMessage ofString(@NotNull String... messages) {
|
||||
return create().defaults(messages).build();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString() {
|
||||
return asString().build();
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextContents> manifest,
|
||||
@NotNull BiFunction<Audience, String, String> parser,
|
||||
@NotNull BiFunction<Audience, String, Component> compiler,
|
||||
@NotNull BiConsumer<Audience, List<Component>> dispatcher,
|
||||
@NotNull String[] params) {
|
||||
super(manifest, parser, compiler, dispatcher, params);
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||
return asString().defaults(defaultMessage).build();
|
||||
public void sendActionBar(Audience audience, Object... values) {
|
||||
Component content = prepare(values).parseLine(audience, (sender, message) -> Component.text(message));
|
||||
if (content != null) audience.sendActionBar(content);
|
||||
}
|
||||
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
public static class Builder extends ConfiguredText.Builder<Component, Audience, Builder> {
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(ProxyServer.getInstance().getConsole());
|
||||
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||
return senders;
|
||||
public Builder() {
|
||||
super();
|
||||
this.parser = (receiver, message) -> ColorParser.parse(message);
|
||||
this.compiler = (receiver, message) -> Component.text(message);
|
||||
this.dispatcher = (receiver, message) -> message.forEach(receiver::sendMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage build() {
|
||||
return new ConfiguredMessage(buildManifest(), this.parser, this.compiler, this.dispatcher, this.params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage.Builder self() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.velocity.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.velocity.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.velocity.builder.message.BungeeMessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.velocity.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> BungeeMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return BungeeConfigValue.builder().createMessage().asList(messageParser);
|
||||
}
|
||||
|
||||
public static BungeeMessageListBuilder<String> asStrings() {
|
||||
return BungeeConfigValue.builder().createMessage().asStringList();
|
||||
}
|
||||
|
||||
public static ConfiguredMessageList<String> ofStrings(@NotNull String... defaultMessages) {
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(ProxyServer.getInstance().getConsole());
|
||||
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||
return senders;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user