1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2026-06-04 13:55:03 +08:00

[1.3.0] 版本更新

1. 更新 EasyConfiguration 到 3.0.0 (破坏性更新)。
2. 添加 ConfiguredTitle 用于快捷向玩家发送title消息。
3. 为 ConfiguredItem 添加name和lore的原生params变量支持。
4. 添加 ProtocolLibHelper 用于支持多版本情况下的部分功能。(如需使用请安装 ProtocolLib 插件)
This commit is contained in:
2022-05-19 01:45:16 +08:00
parent af614deae6
commit 98ee47f676
51 changed files with 895 additions and 370 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
@@ -1,6 +1,7 @@
package cc.carm.lib.configuration;
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
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;
@@ -37,6 +38,14 @@ public class MineConfiguration {
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));
}
@@ -53,6 +62,13 @@ public class MineConfiguration {
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));
@@ -70,5 +86,12 @@ public class MineConfiguration {
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);
}
}
@@ -3,21 +3,23 @@ package cc.carm.lib.configuration.bungee;
import cc.carm.lib.configuration.bungee.builder.BungeeConfigBuilder;
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
import cc.carm.lib.configuration.bungee.source.BungeeSectionWrapper;
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
public static @NotNull BungeeConfigBuilder builder() {
return new BungeeConfigBuilder();
}
public BungeeConfigValue(@Nullable BungeeConfigProvider provider,
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
super(provider, configPath, comments, defaultValue);
public BungeeConfigValue(@Nullable BungeeConfigProvider provider, @Nullable String configPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@Nullable T defaultValue) {
super(provider, configPath, headerComments, inlineComments, defaultValue);
}
public BungeeConfigProvider getBukkitProvider() {
@@ -3,6 +3,7 @@ package cc.carm.lib.configuration.bungee.builder.message;
import cc.carm.lib.configuration.bungee.data.MessageText;
import cc.carm.lib.configuration.bungee.value.ConfiguredMessageList;
import cc.carm.lib.configuration.common.builder.message.MessageListBuilder;
import cc.carm.lib.configuration.common.utils.ParamsUtils;
import net.md_5.bungee.api.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -26,9 +27,10 @@ public class BungeeMessageListBuilder<M>
@Override
public @NotNull ConfiguredMessageList<M> build() {
return new ConfiguredMessageList<>(
this.provider, this.path, buildComments(),
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
buildParams(), this.messageParser, this.sendFunction
ParamsUtils.formatParams(this.paramFormatter, this.params),
this.messageParser, this.sendFunction
);
}
}
@@ -3,6 +3,7 @@ package cc.carm.lib.configuration.bungee.builder.message;
import cc.carm.lib.configuration.bungee.data.MessageText;
import cc.carm.lib.configuration.bungee.value.ConfiguredMessage;
import cc.carm.lib.configuration.common.builder.message.MessageValueBuilder;
import cc.carm.lib.configuration.common.utils.ParamsUtils;
import net.md_5.bungee.api.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,9 +26,10 @@ public class BungeeMessageValueBuilder<M>
@Override
public @NotNull ConfiguredMessage<M> build() {
return new ConfiguredMessage<>(
this.provider, this.path, buildComments(),
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
buildParams(), this.messageParser, this.sendHandler
ParamsUtils.formatParams(this.paramFormatter, this.params),
this.messageParser, this.sendHandler
);
}
@@ -1,15 +1,16 @@
package cc.carm.lib.configuration.bungee.source;
import cc.carm.lib.configuration.core.ConfigInitializer;
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
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 org.jetbrains.annotations.Unmodifiable;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
@@ -43,13 +44,23 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
}
@Override
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
// BungeeCord version doesn't support comments
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
}
@Override
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
return null; // BungeeCord version doesn't support comments
public void setInlineComment(@NotNull String path, @Nullable String comment) {
}
@Override
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
return null;
}
@Override
public @Nullable String getInlineComment(@NotNull String path) {
return null;
}
@Override
@@ -4,13 +4,13 @@ import cc.carm.lib.configuration.bungee.BungeeConfigValue;
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageValueBuilder;
import cc.carm.lib.configuration.bungee.data.MessageText;
import cc.carm.lib.configuration.common.value.ConfigMessage;
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
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.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
@@ -34,15 +34,15 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
return asString().defaults(defaultMessage).build();
}
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull MessageText defaultMessage, @NotNull String[] params,
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
super(provider, sectionPath, comments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
}
@Override
public void broadcast(@NotNull Map<String, Object> placeholders) {
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
send(ProxyServer.getInstance().getConsole(), placeholders);
@@ -4,7 +4,6 @@ import cc.carm.lib.configuration.bungee.BungeeConfigValue;
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageListBuilder;
import cc.carm.lib.configuration.bungee.data.MessageText;
import cc.carm.lib.configuration.common.value.ConfigMessageList;
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
@@ -31,12 +30,12 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
return asStrings().defaults(defaultMessages).build();
}
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull List<MessageText> messages, @NotNull String[] params,
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
super(provider, sectionPath, comments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
}
public void broadcast(@NotNull Map<String, Object> placeholders) {