1
mirror of https://github.com/CarmJos/MineConfiguration.git synced 2024-09-19 20:05:49 +00:00

feat(value): 适配Manifest更新

This commit is contained in:
Carm Jos 2023-03-15 22:51:06 +08:00
parent ce205e10fe
commit 3d1639362b
30 changed files with 139 additions and 124 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>

View File

@ -1,16 +1,18 @@
package cc.carm.lib.mineconfiguration.common.builder.message;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
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.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
@ -67,4 +69,11 @@ public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B exte
@Override
public abstract @NotNull ConfigMessageList<M, T, R> build();
protected @NotNull ValueManifest<List<T>> buildManifest(@NotNull List<T> emptyValue) {
return new ValueManifest<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(emptyValue)
);
}
}

View File

@ -1,13 +1,15 @@
package cc.carm.lib.mineconfiguration.common.builder.message;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
@ -64,4 +66,10 @@ public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B ext
@Override
public abstract @NotNull ConfigMessage<M, T, R> build();
protected @NotNull ValueManifest<T> buildManifest(@NotNull T emptyValue) {
return new ValueManifest<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(emptyValue)
);
}
}

View File

@ -41,21 +41,21 @@ public interface BaseMessage<R, M> {
/**
* 为某位接收者解析此消息
*
* @param sender 接收者
* @param receiver 接收者
* @param placeholders 消息中的变量与对应参数
* @return 解析变量后的消息内容
*/
@Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders);
@Nullable M parse(@Nullable R receiver, @NotNull Map<String, Object> placeholders);
/**
* 为某位接收者解析此消息
*
* @param sender 接收者
* @param values 已定变量的对应参数
* @param receiver 接收者
* @param values 已定变量的对应参数
* @return 解析变量后的消息内容
*/
default @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
return parse(sender, ParamsUtils.buildParams(getParams(), values));
default @Nullable M parse(@Nullable R receiver, @Nullable Object... values) {
return parse(receiver, ParamsUtils.buildParams(getParams(), values));
}
/**

View File

@ -1,13 +1,12 @@
package cc.carm.lib.mineconfiguration.common.value;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
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;
@ -22,15 +21,15 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
protected final @NotNull Function<String, T> textBuilder;
public ConfigMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
public ConfigMessage(@NotNull ValueManifest<T> manifest,
@NotNull Class<T> textClazz, @NotNull String[] params,
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
@NotNull Function<String, T> textBuilder) {
super(
provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
manifest, textClazz,
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)),
AbstractText::getMessage
);
this.params = params;
this.messageParser = messageParser;
@ -62,5 +61,5 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
protected T buildText(String value) {
return textBuilder.apply(value);
}
}

View File

@ -1,7 +1,7 @@
package cc.carm.lib.mineconfiguration.common.value;
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
import org.jetbrains.annotations.NotNull;
@ -24,15 +24,15 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
protected final @NotNull Function<String, T> textBuilder;
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,
public ConfigMessageList(@NotNull ValueManifest<List<T>> manifest,
@NotNull Class<T> textClazz, @NotNull String[] params,
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
@NotNull Function<String, @NotNull T> textBuilder) {
super(
provider, sectionPath, headerComments, inlineComments, textClazz, messages,
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
manifest, textClazz,
ConfigDataFunction.castToString().andThen(textBuilder::apply),
AbstractText::getMessage
);
this.params = params;
this.messageParser = messageParser;
@ -68,12 +68,25 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
.collect(Collectors.toList());
}
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
List<T> list = get();
if (list.isEmpty()) return null;
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
if (String.join("", messages).isEmpty()) return null;
String combined = String.join("\n", messages);
T text = textBuilder.apply(combined);
return text.parse(this.messageParser, receiver, placeholders);
}
public void setMessages(@NotNull String... values) {
setMessages(values.length == 0 ? null : Arrays.asList(values));
}
public void setMessages(@Nullable List<String> values) {
if (values == null || values.isEmpty()) {
if (values == null) {
set(null);
} else {
set(buildText(values));

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -1,6 +1,7 @@
package cc.carm.lib.mineconfiguration.bukkit;
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.bukkit.builder.CraftConfigBuilder;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
@ -16,10 +17,8 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
return new CraftConfigBuilder();
}
public CraftConfigValue(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@Nullable T defaultValue) {
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
public CraftConfigValue(@NotNull ValueManifest<T> manifest) {
super(manifest);
}
public CraftConfigProvider getBukkitProvider() {

View File

@ -1,5 +1,6 @@
package cc.carm.lib.mineconfiguration.bukkit.builder.item;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
@ -110,8 +111,12 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
@Override
public @NotNull ConfiguredItem build() {
ItemConfig defaultItem = Optional.ofNullable(this.defaultValue).orElse(buildDefault());
return new ConfiguredItem(this.provider, this.path, this.headerComments, this.inlineComment, defaultItem, buildParams());
return new ConfiguredItem(
new ValueManifest<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(buildDefault())
), buildParams()
);
}
protected final String[] buildParams() {

View File

@ -1,5 +1,6 @@
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
@ -8,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Optional;
import java.util.function.BiFunction;
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {

View File

@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Optional;
import java.util.function.BiFunction;
public class CraftMessageListBuilder<M>
@ -27,8 +26,7 @@ public class CraftMessageListBuilder<M>
@Override
public @NotNull ConfiguredMessageList<M> build() {
return new ConfiguredMessageList<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of(new ArrayList<>())),
buildManifest(TextConfig.of(new ArrayList<>())),
ParamsUtils.formatParams(this.paramFormatter, this.params),
this.messageParser, this.sendFunction
);

View File

@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
import java.util.function.BiFunction;
public class CraftMessageValueBuilder<M>
@ -26,8 +25,7 @@ public class CraftMessageValueBuilder<M>
@Override
public @NotNull ConfiguredMessage<M> build() {
return new ConfiguredMessage<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of("")),
buildManifest(TextConfig.of("")),
ParamsUtils.formatParams(this.paramFormatter, this.params),
this.messageParser, this.sendHandler
);

View File

@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
@Override
public @NotNull ConfiguredSerializable<T> build() {
return new ConfiguredSerializable<>(this.provider, this.path, this.headerComments, this.inlineComment, this.valueClass, this.defaultValue);
return new ConfiguredSerializable<>(buildManifest(), valueClass);
}
}

View File

@ -40,7 +40,7 @@ public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundC
@Override
public @NotNull ConfiguredSound build() {
return new ConfiguredSound(this.provider, this.path, this.headerComments, this.inlineComment, this.defaultValue);
return new ConfiguredSound(buildManifest());
}
}

View File

@ -89,8 +89,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
@Override
public @NotNull ConfiguredTitle build() {
return new ConfiguredTitle(
this.provider, this.path, this.headerComments, this.inlineComment,
this.defaultValue, ParamsUtils.formatParams(this.paramFormatter, this.params),
buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params),
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
);
}

View File

@ -2,11 +2,11 @@ package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.configuration.core.value.ValueManifest;
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;
@ -14,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
@ -33,11 +32,9 @@ public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
protected final @NotNull String[] params;
public ConfiguredItem(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
public ConfiguredItem(@NotNull ValueManifest<ItemConfig> manifest, @NotNull String[] params) {
super(
provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue,
manifest, ItemConfig.class,
getItemParser(), ItemConfig::serialize
);
this.params = params;

View File

@ -1,6 +1,6 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
@ -35,12 +35,10 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
return asString().defaults(defaultMessage).build();
}
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull TextConfig defaultMessage, @NotNull String[] params,
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(provider, sectionPath, headerComments, inlineComments, TextConfig.class, defaultMessage, params, messageParser, sendFunction, TextConfig::of);
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
}
@Override

View File

@ -1,6 +1,6 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
@ -31,12 +31,10 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, C
return asStrings().defaults(defaultMessages).build();
}
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull List<TextConfig> messages, @NotNull String[] params,
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(provider, sectionPath, headerComments, inlineComments, TextConfig.class, messages, params, messageParser, sendFunction, TextConfig::of);
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
}
@Override

View File

@ -1,12 +1,11 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
@ -22,10 +21,8 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
protected final @NotNull Class<T> valueClass;
public ConfiguredSerializable(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
public ConfiguredSerializable(@NotNull ValueManifest<T> manifest, @NotNull Class<T> valueClass) {
super(manifest);
this.valueClass = valueClass;
}

View File

@ -1,7 +1,7 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
import cc.carm.lib.configuration.core.function.ConfigValueParser;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
@ -9,9 +9,7 @@ import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
@ -44,10 +42,8 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
return CraftConfigValue.builder().createSound().defaults(soundName, volume, pitch).build();
}
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@Nullable SoundConfig defaultValue) {
super(provider, sectionPath, headerComments, inlineComments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
public ConfiguredSound(@NotNull ValueManifest<SoundConfig> manifest) {
super(manifest, SoundConfig.class, getSoundParser(), SoundConfig::serialize);
}
public void setSound(@NotNull Sound sound) {

View File

@ -1,8 +1,8 @@
package cc.carm.lib.mineconfiguration.bukkit.value;
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.ValueManifest;
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;
@ -15,8 +15,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
@ -40,12 +42,10 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
protected final int stay;
protected final int fadeOut;
public ConfiguredTitle(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@Nullable TitleConfig defaultValue, @NotNull String[] params,
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
@NotNull TitleSendConsumer sendConsumer,
int fadeIn, int stay, int fadeOut) {
super(provider, sectionPath, headerComments, inlineComments, TitleConfig.class, defaultValue, getTitleParser(), TitleConfig::serialize);
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
this.sendConsumer = sendConsumer;
this.params = params;
this.fadeIn = fadeIn;
@ -102,6 +102,16 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> send(onlinePlayer, placeholders));
}
public void sendToEach(@NotNull Function<@NotNull Player, Object[]> eachValues) {
sendToEach(null, eachValues);
}
public void sendToEach(@Nullable Predicate<Player> limiter,
@NotNull Function<@NotNull Player, Object[]> eachValues) {
Predicate<Player> predicate = Optional.ofNullable(limiter).orElse(r -> true);
Bukkit.getOnlinePlayers().stream().filter(predicate)
.forEach(r -> send(r, ParamsUtils.buildParams(params, eachValues.apply(r))));
}
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
return (s, d) -> TitleConfig.deserialize(s);

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>mineconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>2.4.0</version>
<version>2.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -1,14 +1,12 @@
package cc.carm.lib.mineconfiguration.bungee;
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.bungee.builder.BungeeConfigBuilder;
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
import cc.carm.lib.mineconfiguration.bungee.source.BungeeSectionWrapper;
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> {
@ -16,10 +14,8 @@ public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
return new BungeeConfigBuilder();
}
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 BungeeConfigValue(@NotNull ValueManifest<T> manifest) {
super(manifest);
}
public BungeeConfigProvider getBukkitProvider() {

View File

@ -1,7 +1,7 @@
package cc.carm.lib.mineconfiguration.bungee.builder.message;
import cc.carm.lib.easyplugin.utils.ColorParser;
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
import net.md_5.bungee.api.CommandSender;
import org.jetbrains.annotations.NotNull;
@ -10,11 +10,11 @@ import org.jetbrains.annotations.Nullable;
import java.util.function.BiFunction;
@SuppressWarnings("deprecation")
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
public BungeeMessageBuilder() {
super(CommandSender.class, MessageText.class);
super(CommandSender.class, TextConfig.class);
}
@Override

View File

@ -1,6 +1,7 @@
package cc.carm.lib.mineconfiguration.bungee.builder.message;
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessageList;
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
@ -13,10 +14,10 @@ import java.util.Optional;
import java.util.function.BiFunction;
public class BungeeMessageListBuilder<M>
extends MessageListBuilder<M, CommandSender, MessageText, BungeeMessageListBuilder<M>> {
extends MessageListBuilder<M, CommandSender, TextConfig, BungeeMessageListBuilder<M>> {
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
super(CommandSender.class, MessageText::of, parser);
super(CommandSender.class, TextConfig::of, parser);
}
@Override
@ -27,8 +28,7 @@ public class BungeeMessageListBuilder<M>
@Override
public @NotNull ConfiguredMessageList<M> build() {
return new ConfiguredMessageList<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
buildManifest(TextConfig.of(new ArrayList<>())),
ParamsUtils.formatParams(this.paramFormatter, this.params),
this.messageParser, this.sendFunction
);

View File

@ -1,6 +1,6 @@
package cc.carm.lib.mineconfiguration.bungee.builder.message;
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessage;
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
@ -8,14 +8,13 @@ import net.md_5.bungee.api.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
import java.util.function.BiFunction;
public class BungeeMessageValueBuilder<M>
extends MessageValueBuilder<M, CommandSender, MessageText, BungeeMessageValueBuilder<M>> {
extends MessageValueBuilder<M, CommandSender, TextConfig, BungeeMessageValueBuilder<M>> {
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
super(CommandSender.class, MessageText::new, parser);
super(CommandSender.class, TextConfig::new, parser);
}
@Override
@ -26,8 +25,7 @@ public class BungeeMessageValueBuilder<M>
@Override
public @NotNull ConfiguredMessage<M> build() {
return new ConfiguredMessage<>(
this.provider, this.path, this.headerComments, this.inlineComment,
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
buildManifest(TextConfig.of("")),
ParamsUtils.formatParams(this.paramFormatter, this.params),
this.messageParser, this.sendHandler
);

View File

@ -11,24 +11,24 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class MessageText extends AbstractText<CommandSender> {
public class TextConfig extends AbstractText<CommandSender> {
public MessageText(@NotNull String message) {
public TextConfig(@NotNull String message) {
super(CommandSender.class, message);
}
@Contract("!null,-> !null")
public static @Nullable MessageText of(@Nullable String message) {
public static @Nullable TextConfig of(@Nullable String message) {
if (message == null) return null;
else return new MessageText(message);
else return new TextConfig(message);
}
public static @NotNull List<MessageText> of(@Nullable List<String> messages) {
public static @NotNull List<TextConfig> of(@Nullable List<String> messages) {
if (messages == null || messages.isEmpty()) return new ArrayList<>();
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
else return messages.stream().map(TextConfig::of).collect(Collectors.toList());
}
public static @NotNull List<MessageText> of(@NotNull String... messages) {
public static @NotNull List<TextConfig> of(@NotNull String... messages) {
return of(Arrays.asList(messages));
}

View File

@ -1,9 +1,9 @@
package cc.carm.lib.mineconfiguration.bungee.value;
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
@ -16,7 +16,7 @@ import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
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) {
@ -35,12 +35,10 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
return asString().defaults(defaultMessage).build();
}
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull MessageText defaultMessage, @NotNull String[] params,
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(provider, sectionPath, headerComments, inlineComments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
}
@Override

View File

@ -1,10 +1,10 @@
package cc.carm.lib.mineconfiguration.bungee.value;
import cc.carm.lib.configuration.core.value.ValueManifest;
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageListBuilder;
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
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;
@ -13,11 +13,10 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
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) {
@ -32,12 +31,10 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
return asStrings().defaults(defaultMessages).build();
}
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
@Nullable List<String> headerComments, @Nullable String inlineComments,
@NotNull List<MessageText> messages, @NotNull String[] params,
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(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
}
@Override

View File

@ -10,13 +10,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<deps.easyconfifuration.version>3.4.0</deps.easyconfifuration.version>
<deps.easyconfifuration.version>3.5.0</deps.easyconfifuration.version>
<deps.easyplugin.version>1.5.4</deps.easyplugin.version>
</properties>
<groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-parent</artifactId>
<version>2.4.0</version>
<version>2.5.0</version>
<packaging>pom</packaging>
<modules>
<module>common</module>