mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-04 13:55:03 +08:00
feat(value): 适配Manifest更新
This commit is contained in:
+1
-1
@@ -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>
|
||||
|
||||
+10
-1
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-1
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+20
-7
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user