mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-04 13:55:03 +08:00
chore(platform): Try to support Velocity
This commit is contained in:
-5
@@ -3,17 +3,12 @@ package cc.carm.lib.mineconfiguration.bukkit;
|
|||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.CraftConfigBuilder;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
public static @NotNull CraftConfigBuilder builder() {
|
|
||||||
return new CraftConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CraftConfigValue(@NotNull ValueManifest<T> manifest) {
|
protected CraftConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||||
super(manifest);
|
super(manifest);
|
||||||
}
|
}
|
||||||
|
|||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.builder;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageBuilder;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.serializable.SerializableBuilder;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class CraftConfigBuilder extends ConfigBuilder {
|
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder createSound() {
|
|
||||||
return new SoundConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ItemConfigBuilder createItem() {
|
|
||||||
return new ItemConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull CraftMessageBuilder createMessage() {
|
|
||||||
return new CraftMessageBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull TitleConfigBuilder createTitle() {
|
|
||||||
return new TitleConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
|
||||||
return new SerializableBuilder<>(valueClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>2.9.3</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<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>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-velocity</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Velocity</name>
|
||||||
|
<description>轻松(做)配置,适用于Velocity的版本,可用JSON与YAML格式。</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>yamlcommentwriter</artifactId>
|
||||||
|
<version>${deps.yamlcommentwriter.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>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+123
@@ -0,0 +1,123 @@
|
|||||||
|
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.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> {
|
||||||
|
|
||||||
|
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 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,
|
||||||
|
@NotNull Configuration configRoot,
|
||||||
|
@NotNull Configuration messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull Plugin plugin,
|
||||||
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
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
@@ -0,0 +1,14 @@
|
|||||||
|
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
@@ -0,0 +1,42 @@
|
|||||||
|
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
@@ -0,0 +1,35 @@
|
|||||||
|
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
@@ -0,0 +1,35 @@
|
|||||||
|
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
@@ -0,0 +1,35 @@
|
|||||||
|
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
@@ -0,0 +1,107 @@
|
|||||||
|
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
@@ -0,0 +1,94 @@
|
|||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
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 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> {
|
||||||
|
|
||||||
|
@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 BungeeMessageValueBuilder<String> asString() {
|
||||||
|
return BungeeConfigValue.builder().createMessage().asStringValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString() {
|
||||||
|
return asString().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||||
|
return asString().defaults(defaultMessage).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||||
|
List<CommandSender> senders = new ArrayList<>();
|
||||||
|
senders.add(ProxyServer.getInstance().getConsole());
|
||||||
|
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||||
|
return senders;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
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