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

[1.1.6] 修正泛型类型,避免方法令人混淆

This commit is contained in:
Carm Jos 2022-04-25 21:03:02 +08:00
parent 352ef107f9
commit a02efbf29c
10 changed files with 27 additions and 28 deletions

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package cc.carm.lib.configuration.craft.builder.message;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
import cc.carm.lib.configuration.craft.data.MessageText;
import cc.carm.lib.configuration.craft.value.ConfiguredMessageList;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@ -9,14 +10,14 @@ 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;
public class MessageListBuilder<M>
extends CommonConfigBuilder<String, MessageListBuilder<M>> {
extends CommonConfigBuilder<List<MessageText>, MessageListBuilder<M>> {
protected @NotNull List<String> messages;
protected @NotNull String[] params;
protected @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser;
protected @NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction;
@ -24,7 +25,6 @@ public class MessageListBuilder<M>
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
public MessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
this.messages = new ArrayList<>();
this.params = new String[0];
this.messageParser = parser;
this.paramFormatter = MessageValueBuilder.DEFAULT_PARAM_FORMATTER;
@ -37,8 +37,7 @@ public class MessageListBuilder<M>
}
public MessageListBuilder<M> contents(@NotNull List<String> messages) {
this.messages = new ArrayList<>(messages);
return this;
return defaults(new ArrayList<>(MessageText.of(messages)));
}
public MessageListBuilder<M> params(@NotNull String... params) {
@ -70,7 +69,8 @@ public class MessageListBuilder<M>
public @NotNull ConfiguredMessageList<M> build() {
return new ConfiguredMessageList<>(
this.provider, this.path, buildComments(),
this.messages, buildParams(), this.messageParser, this.sendFunction
Optional.ofNullable(this.defaultValue).orElse(new ArrayList<>()),
buildParams(), this.messageParser, this.sendFunction
);
}

View File

@ -1,6 +1,7 @@
package cc.carm.lib.configuration.craft.builder.message;
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
import cc.carm.lib.configuration.craft.data.MessageText;
import cc.carm.lib.configuration.craft.value.ConfiguredMessage;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@ -8,16 +9,16 @@ import org.jetbrains.annotations.Nullable;
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;
public class MessageValueBuilder<M>
extends CommonConfigBuilder<String, MessageValueBuilder<M>> {
extends CommonConfigBuilder<MessageText, MessageValueBuilder<M>> {
public static Function<@NotNull String, @NotNull String> DEFAULT_PARAM_FORMATTER = (s) -> "%(" + s + ")";
protected @NotNull String message;
protected @NotNull String[] params;
protected @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser;
protected @NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendHandler;
@ -25,7 +26,6 @@ public class MessageValueBuilder<M>
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
public MessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
this.message = "";
this.params = new String[0];
this.paramFormatter = DEFAULT_PARAM_FORMATTER;
this.messageParser = parser;
@ -34,8 +34,7 @@ public class MessageValueBuilder<M>
}
public MessageValueBuilder<M> content(@NotNull String message) {
this.message = message;
return this;
return defaults(MessageText.of(message));
}
public MessageValueBuilder<M> params(@NotNull String... params) {
@ -67,7 +66,8 @@ public class MessageValueBuilder<M>
public @NotNull ConfiguredMessage<M> build() {
return new ConfiguredMessage<>(
this.provider, this.path, buildComments(),
this.message, buildParams(), this.messageParser, this.sendHandler
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
buildParams(), this.messageParser, this.sendHandler
);
}

View File

@ -5,10 +5,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@ -20,14 +17,16 @@ public class MessageText {
else return new MessageText(message);
}
public static @NotNull List<MessageText> of(@NotNull List<String> messages) {
return messages.stream().map(MessageText::of).collect(Collectors.toList());
public static @NotNull List<MessageText> of(@Nullable List<String> messages) {
if (messages == null || messages.isEmpty()) return new ArrayList<>();
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
}
public static @NotNull List<MessageText> of(@NotNull String... messages) {
return Arrays.stream(messages).map(MessageText::of).collect(Collectors.toList());
return of(Arrays.asList(messages));
}
protected @NotNull String message;
public MessageText(@NotNull String message) {

View File

@ -41,10 +41,10 @@ public class ConfiguredMessage<M> extends ConfiguredValue<MessageText> {
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
@NotNull String message, @NotNull String[] params,
@NotNull MessageText message, @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, MessageText.of(message),
super(provider, sectionPath, comments, MessageText.class, message,
ConfigValueParser.castToString().andThen((s, d) -> MessageText.of(s)),
MessageText::getMessage
);

View File

@ -39,10 +39,10 @@ public class ConfiguredMessageList<M> extends ConfiguredList<MessageText> {
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
@NotNull List<String> messages, @NotNull String[] params,
@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, MessageText.of(messages),
super(provider, sectionPath, comments, MessageText.class, messages,
ConfigDataFunction.castToString().andThen(MessageText::new), MessageText::getMessage
);
this.params = params;

View File

@ -21,7 +21,7 @@
</properties>
<groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<packaging>pom</packaging>
<name>MineConfiguration</name>

View File

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