mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-14 00:01:10 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b31ee1318 | |||
| 9d6212e5ea | |||
| 8f3d574446 | |||
| 437e1d6d61 | |||
| a04b7c9c06 | |||
| 74e88a126c | |||
| 79a65a94bc | |||
| 6ba08f7a67 | |||
| 166b9fa0a8 | |||
| 6257cdd114 | |||
| c28ee7d57b | |||
| 3d1639362b | |||
| ce205e10fe | |||
| 8e4e712936 | |||
| c3d9c65a86 | |||
| ebddeff78d | |||
| afcdc2c378 |
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.4.0</version>
|
<version>2.6.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.common;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class AbstractConfiguration<P extends ConfigurationProvider<?>> {
|
||||||
|
|
||||||
|
private final P configProvider;
|
||||||
|
private final P messageProvider;
|
||||||
|
|
||||||
|
protected AbstractConfiguration(@NotNull P configProvider, @NotNull P messageProvider) {
|
||||||
|
this.configProvider = configProvider;
|
||||||
|
this.messageProvider = messageProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeConfig(@NotNull ConfigurationRoot configRoot) {
|
||||||
|
this.configProvider.initialize(configRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeMessage(@NotNull ConfigurationRoot messageRoot) {
|
||||||
|
this.messageProvider.initialize(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeConfig(@NotNull Class<? extends ConfigurationRoot> configRoot) {
|
||||||
|
this.configProvider.initialize(configRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeMessage(@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||||
|
this.messageProvider.initialize(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public P getConfigProvider() {
|
||||||
|
return configProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public P getMessageProvider() {
|
||||||
|
return messageProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload() throws Exception {
|
||||||
|
getConfigProvider().reload();
|
||||||
|
getMessageProvider().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() throws Exception {
|
||||||
|
getConfigProvider().save();
|
||||||
|
getMessageProvider().save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+10
-1
@@ -1,16 +1,18 @@
|
|||||||
package cc.carm.lib.mineconfiguration.common.builder.message;
|
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.data.AbstractText;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -67,4 +69,11 @@ public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B exte
|
|||||||
@Override
|
@Override
|
||||||
public abstract @NotNull ConfigMessageList<M, T, R> build();
|
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;
|
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.data.AbstractText;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -64,4 +66,10 @@ public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B ext
|
|||||||
@Override
|
@Override
|
||||||
public abstract @NotNull ConfigMessage<M, T, R> build();
|
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 消息中的变量与对应参数
|
* @param placeholders 消息中的变量与对应参数
|
||||||
* @return 解析变量后的消息内容
|
* @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 receiver 接收者
|
||||||
* @param values 已定变量的对应参数
|
* @param values 已定变量的对应参数
|
||||||
* @return 解析变量后的消息内容
|
* @return 解析变量后的消息内容
|
||||||
*/
|
*/
|
||||||
default @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
default @Nullable M parse(@Nullable R receiver, @Nullable Object... values) {
|
||||||
return parse(sender, ParamsUtils.buildParams(getParams(), values));
|
return parse(receiver, ParamsUtils.buildParams(getParams(), values));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+19
-11
@@ -1,13 +1,12 @@
|
|||||||
package cc.carm.lib.mineconfiguration.common.value;
|
package cc.carm.lib.mineconfiguration.common.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
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.configuration.core.value.type.ConfiguredValue;
|
||||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
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;
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
public ConfigMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfigMessage(@NotNull ValueManifest<T> manifest,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
@NotNull Class<T> textClazz, @NotNull String[] params,
|
||||||
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
|
||||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
||||||
@NotNull Function<String, T> textBuilder) {
|
@NotNull Function<String, T> textBuilder) {
|
||||||
super(
|
super(
|
||||||
provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
|
manifest, textClazz,
|
||||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)),
|
||||||
|
AbstractText::getMessage
|
||||||
);
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.messageParser = messageParser;
|
this.messageParser = messageParser;
|
||||||
@@ -48,11 +47,20 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
|||||||
sendFunction.accept(receiver, message);
|
sendFunction.accept(receiver, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected <N> @Nullable N parseTo(@Nullable R sender, @NotNull Map<String, Object> placeholders,
|
||||||
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable N> parser) {
|
||||||
T value = get();
|
T value = get();
|
||||||
if (value == null || value.getMessage().isEmpty()) return null;
|
if (value == null || value.getMessage().isEmpty()) return null;
|
||||||
else return value.parse(this.messageParser, sender, placeholders);
|
else return value.parse(parser, sender, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String parseString(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return parseTo(sender, placeholders, (r, s) -> s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return parseTo(sender, placeholders, this.messageParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable String value) {
|
public void set(@Nullable String value) {
|
||||||
@@ -62,5 +70,5 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
|||||||
protected T buildText(String value) {
|
protected T buildText(String value) {
|
||||||
return textBuilder.apply(value);
|
return textBuilder.apply(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-7
@@ -1,9 +1,10 @@
|
|||||||
package cc.carm.lib.mineconfiguration.common.value;
|
package cc.carm.lib.mineconfiguration.common.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
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.configuration.core.value.type.ConfiguredList;
|
||||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -24,15 +25,15 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
|
|||||||
|
|
||||||
protected final @NotNull Function<String, T> textBuilder;
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfigMessageList(@NotNull ValueManifest<List<T>> manifest,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
@NotNull Class<T> textClazz, @NotNull String[] params,
|
||||||
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
|
||||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
||||||
@NotNull Function<String, @NotNull T> textBuilder) {
|
@NotNull Function<String, @NotNull T> textBuilder) {
|
||||||
super(
|
super(
|
||||||
provider, sectionPath, headerComments, inlineComments, textClazz, messages,
|
manifest, textClazz,
|
||||||
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
|
ConfigDataFunction.castToString().andThen(textBuilder::apply),
|
||||||
|
AbstractText::getMessage
|
||||||
);
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.messageParser = messageParser;
|
this.messageParser = messageParser;
|
||||||
@@ -68,12 +69,33 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Object... values) {
|
||||||
|
return parseToLine(receiver, "\n", ParamsUtils.buildParams(this.params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return parseToLine(receiver, "\n", placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable M parseToLine(@Nullable R receiver, @NotNull String delimiter, @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(delimiter, messages);
|
||||||
|
T text = textBuilder.apply(combined);
|
||||||
|
|
||||||
|
return text.parse(this.messageParser, receiver, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
public void setMessages(@NotNull String... values) {
|
public void setMessages(@NotNull String... values) {
|
||||||
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessages(@Nullable List<String> values) {
|
public void setMessages(@Nullable List<String> values) {
|
||||||
if (values == null || values.isEmpty()) {
|
if (values == null) {
|
||||||
set(null);
|
set(null);
|
||||||
} else {
|
} else {
|
||||||
set(buildText(values));
|
set(buildText(values));
|
||||||
|
|||||||
+17
-11
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.4.0</version>
|
<version>2.6.2</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -30,11 +30,25 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>yamlcommentwriter</artifactId>
|
||||||
|
<version>${deps.yamlcommentwriter.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
|
<artifactId>XSeries</artifactId>
|
||||||
|
<version>9.3.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--suppress VulnerableLibrariesLocal -->
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -42,15 +56,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.2</version>
|
<version>2.11.3</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--ProtocolLib for general packet's function support-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
|
||||||
<artifactId>ProtocolLib</artifactId>
|
|
||||||
<version>4.8.0</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
+3
-7
@@ -1,14 +1,12 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit;
|
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.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.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;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
@@ -16,10 +14,8 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
|||||||
return new CraftConfigBuilder();
|
return new CraftConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftConfigValue(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
protected CraftConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
super(manifest);
|
||||||
@Nullable T defaultValue) {
|
|
||||||
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftConfigProvider getBukkitProvider() {
|
public CraftConfigProvider getBukkitProvider() {
|
||||||
|
|||||||
+25
-1
@@ -1,12 +1,16 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit;
|
package cc.carm.lib.mineconfiguration.bukkit;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
|
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MineConfiguration {
|
public class MineConfiguration extends AbstractConfiguration<BukkitConfigProvider> {
|
||||||
|
|
||||||
public static BukkitConfigProvider from(File file, String source) {
|
public static BukkitConfigProvider from(File file, String source) {
|
||||||
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
||||||
@@ -39,4 +43,24 @@ public class MineConfiguration {
|
|||||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull JavaPlugin plugin) {
|
||||||
|
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||||
|
@NotNull ConfigurationRoot configRoot,
|
||||||
|
@NotNull ConfigurationRoot messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||||
|
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
||||||
|
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-11
@@ -6,11 +6,8 @@ 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.serializable.SerializableBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class CraftConfigBuilder extends ConfigBuilder {
|
public class CraftConfigBuilder extends ConfigBuilder {
|
||||||
|
|
||||||
@@ -34,12 +31,4 @@ public class CraftConfigBuilder extends ConfigBuilder {
|
|||||||
return new SerializableBuilder<>(valueClass);
|
return new SerializableBuilder<>(valueClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ConfiguredItem ofItem() {
|
|
||||||
return createItem().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ConfiguredItem ofItem(@Nullable ItemConfig defaultItem) {
|
|
||||||
return createItem().defaults(defaultItem).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-7
@@ -1,19 +1,22 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.builder.item;
|
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.builder.AbstractCraftBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> {
|
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemStack, ItemConfigBuilder> {
|
||||||
|
|
||||||
protected Material type;
|
protected Material type;
|
||||||
protected short data = 0;
|
protected short data = 0;
|
||||||
@@ -83,7 +86,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
|
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemConfigBuilder formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
public ItemConfigBuilder formatParam(@NotNull UnaryOperator<String> paramFormatter) {
|
||||||
this.paramFormatter = paramFormatter;
|
this.paramFormatter = paramFormatter;
|
||||||
return getThis();
|
return getThis();
|
||||||
}
|
}
|
||||||
@@ -103,15 +106,30 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected @Nullable ItemConfig buildDefault() {
|
protected @Nullable ItemStack buildDefault() {
|
||||||
if (this.type == null) return null;
|
if (this.type == null) return null;
|
||||||
else return new ItemConfig(type, data, name, lore, enchants, flags);
|
|
||||||
|
ItemStack item = new ItemStack(type, 1, data);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return item;
|
||||||
|
|
||||||
|
Optional.ofNullable(this.name).ifPresent(meta::setDisplayName);
|
||||||
|
Optional.ofNullable(this.lore).ifPresent(meta::setLore);
|
||||||
|
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
|
||||||
|
flags.forEach(meta::addItemFlags);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredItem build() {
|
public @NotNull ConfiguredItem build() {
|
||||||
ItemConfig defaultItem = Optional.ofNullable(this.defaultValue).orElse(buildDefault());
|
return new ConfiguredItem(
|
||||||
return new ConfiguredItem(this.provider, this.path, this.headerComments, this.inlineComment, defaultItem, buildParams());
|
new ValueManifest<>(
|
||||||
|
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(buildDefault())
|
||||||
|
), buildParams()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final String[] buildParams() {
|
protected final String[] buildParams() {
|
||||||
|
|||||||
+1
-3
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class CraftMessageListBuilder<M>
|
public class CraftMessageListBuilder<M>
|
||||||
@@ -27,8 +26,7 @@ public class CraftMessageListBuilder<M>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredMessageList<M> build() {
|
public @NotNull ConfiguredMessageList<M> build() {
|
||||||
return new ConfiguredMessageList<>(
|
return new ConfiguredMessageList<>(
|
||||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||||
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of(new ArrayList<>())),
|
|
||||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
this.messageParser, this.sendFunction
|
this.messageParser, this.sendFunction
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-3
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class CraftMessageValueBuilder<M>
|
public class CraftMessageValueBuilder<M>
|
||||||
@@ -26,8 +25,7 @@ public class CraftMessageValueBuilder<M>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredMessage<M> build() {
|
public @NotNull ConfiguredMessage<M> build() {
|
||||||
return new ConfiguredMessage<>(
|
return new ConfiguredMessage<>(
|
||||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
buildManifest(TextConfig.of("")),
|
||||||
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of("")),
|
|
||||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
this.messageParser, this.sendHandler
|
this.messageParser, this.sendHandler
|
||||||
);
|
);
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredSerializable<T> build() {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredSound build() {
|
public @NotNull ConfiguredSound build() {
|
||||||
return new ConfiguredSound(this.provider, this.path, this.headerComments, this.inlineComment, this.defaultValue);
|
return new ConfiguredSound(buildManifest());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-15
@@ -3,10 +3,9 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.title;
|
|||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.utils.ProtocolLibHelper;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.bukkit.Bukkit;
|
import com.cryptomorin.xseries.messages.Titles;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Range;
|
import org.jetbrains.annotations.Range;
|
||||||
@@ -16,17 +15,7 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
|
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
|
||||||
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = (player, fadeIn, stay, fadeOut, line1, line2) -> {
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
|
||||||
try {
|
|
||||||
ProtocolLibHelper.sendTitle(player, fadeIn, stay, fadeOut, line1, line2);
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
player.sendTitle(line1, line2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
protected @NotNull String[] params = new String[0];
|
protected @NotNull String[] params = new String[0];
|
||||||
|
|
||||||
@@ -89,8 +78,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredTitle build() {
|
public @NotNull ConfiguredTitle build() {
|
||||||
return new ConfiguredTitle(
|
return new ConfiguredTitle(
|
||||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
this.defaultValue, ParamsUtils.formatParams(this.paramFormatter, this.params),
|
|
||||||
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
|
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -26,6 +26,8 @@ public class ItemConfig {
|
|||||||
protected @NotNull Map<Enchantment, Integer> enchants;
|
protected @NotNull Map<Enchantment, Integer> enchants;
|
||||||
protected @NotNull Set<ItemFlag> flags;
|
protected @NotNull Set<ItemFlag> flags;
|
||||||
|
|
||||||
|
protected int customModelData = 0;
|
||||||
|
|
||||||
public ItemConfig(@NotNull Material type, @Nullable String name) {
|
public ItemConfig(@NotNull Material type, @Nullable String name) {
|
||||||
this(type, name, Collections.emptyList());
|
this(type, name, Collections.emptyList());
|
||||||
}
|
}
|
||||||
@@ -131,7 +133,7 @@ public class ItemConfig {
|
|||||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
|
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
|
||||||
return deserialize(CraftSectionWrapper.of(section));
|
return deserialize(CraftSectionWrapper.of(section));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
|
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
|
||||||
String typeName = section.getString("type");
|
String typeName = section.getString("type");
|
||||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||||
|
|||||||
+7
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
@@ -40,6 +41,12 @@ public class SoundConfig {
|
|||||||
player.playSound(player.getLocation(), type, volume, pitch);
|
player.playSound(player.getLocation(), type, volume, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void playAt(Location location) {
|
||||||
|
if (type == null) return;
|
||||||
|
if (location.getWorld() == null) return;
|
||||||
|
location.getWorld().playSound(location, type, volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
public void playToAll() {
|
public void playToAll() {
|
||||||
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-17
@@ -2,22 +2,23 @@ package cc.carm.lib.mineconfiguration.bukkit.source;
|
|||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||||
|
import cc.carm.lib.yamlcommentupdater.CommentedYAML;
|
||||||
|
import cc.carm.lib.yamlcommentupdater.CommentedYAMLWriter;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.StringWriter;
|
import java.util.List;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.util.Set;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
public class BukkitConfigProvider extends CraftConfigProvider implements CommentedYAML {
|
||||||
|
|
||||||
protected static final char SEPARATOR = '.';
|
protected static final char SEPARATOR = '.';
|
||||||
|
|
||||||
protected @NotNull BukkitYAMLComments comments = new BukkitYAMLComments();
|
protected @NotNull ConfigurationComments comments = new ConfigurationComments();
|
||||||
|
|
||||||
public BukkitConfigProvider(@NotNull File file) {
|
public BukkitConfigProvider(@NotNull File file) {
|
||||||
super(file);
|
super(file);
|
||||||
@@ -35,21 +36,44 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws Exception {
|
public void save() throws Exception {
|
||||||
configuration.save(getFile());
|
try {
|
||||||
|
CommentedYAMLWriter.writeWithComments(this, this.file);
|
||||||
StringWriter writer = new StringWriter();
|
} catch (Exception ex) {
|
||||||
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
configuration.save(file);
|
||||||
String value = writer.toString(); // config contents
|
throw ex;
|
||||||
|
|
||||||
Path toUpdatePath = getFile().toPath();
|
|
||||||
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
|
||||||
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ConfigurationComments getComments() {
|
public @NotNull ConfigurationComments getComments() {
|
||||||
return this.comments;
|
return this.comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serializeValue(@NotNull String key, @NotNull Object value) {
|
||||||
|
FileConfiguration temp = new YamlConfiguration();
|
||||||
|
temp.set(key, value);
|
||||||
|
return temp.saveToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getKeys(@Nullable String sectionKey, boolean deep) {
|
||||||
|
if (sectionKey == null) return configuration.getKeys(deep);
|
||||||
|
|
||||||
|
ConfigurationSection section = configuration.getConfigurationSection(sectionKey);
|
||||||
|
if (section == null) return null;
|
||||||
|
|
||||||
|
return section.getKeys(deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-108
@@ -1,108 +0,0 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
public class BukkitYAMLComments extends ConfigurationComments {
|
|
||||||
|
|
||||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
|
||||||
List<String> comments = getHeaderComment(path);
|
|
||||||
if (comments == null || comments.size() == 0) return null;
|
|
||||||
|
|
||||||
StringJoiner joiner = new StringJoiner("\n");
|
|
||||||
for (String comment : comments) {
|
|
||||||
if (comment.length() == 0) joiner.add(" ");
|
|
||||||
else joiner.add(indents + "# " + comment);
|
|
||||||
}
|
|
||||||
return joiner + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从一个文件读取配置并写入注释到某个写入器中。
|
|
||||||
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
|
||||||
*
|
|
||||||
* @param source 源配置文件
|
|
||||||
* @param writer 配置写入器
|
|
||||||
* @throws IOException 当写入发生错误时抛出
|
|
||||||
*/
|
|
||||||
public void writeComments(@NotNull YamlConfiguration source, @NotNull BufferedWriter writer) throws IOException {
|
|
||||||
FileConfiguration temp = new YamlConfiguration(); // 该对象用于临时记录配置内容
|
|
||||||
|
|
||||||
String configHeader = buildHeaderComments(null, "");
|
|
||||||
if (configHeader != null) writer.write(configHeader);
|
|
||||||
|
|
||||||
for (String fullKey : source.getKeys(true)) {
|
|
||||||
Object currentValue = source.get(fullKey);
|
|
||||||
|
|
||||||
String indents = getIndents(fullKey);
|
|
||||||
String headerComments = buildHeaderComments(fullKey, indents);
|
|
||||||
String inlineComment = getInlineComment(fullKey);
|
|
||||||
|
|
||||||
if (headerComments != null) writer.write(headerComments);
|
|
||||||
|
|
||||||
String[] splitFullKey = fullKey.split("[" + CraftConfigProvider.SEPARATOR + "]");
|
|
||||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
|
||||||
|
|
||||||
if (currentValue instanceof ConfigurationSection) {
|
|
||||||
ConfigurationSection section = (ConfigurationSection) currentValue;
|
|
||||||
writer.write(indents + trailingKey + ":");
|
|
||||||
if (inlineComment != null && inlineComment.length() > 0) {
|
|
||||||
writer.write(" # " + inlineComment);
|
|
||||||
}
|
|
||||||
if (!section.getKeys(false).isEmpty()) {
|
|
||||||
writer.write("\n");
|
|
||||||
} else {
|
|
||||||
writer.write(" {}\n");
|
|
||||||
if (indents.length() == 0) writer.write("\n");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp.set(trailingKey, currentValue);
|
|
||||||
String yaml = temp.saveToString();
|
|
||||||
temp.set(trailingKey, null);
|
|
||||||
|
|
||||||
yaml = yaml.substring(0, yaml.length() - 1);
|
|
||||||
|
|
||||||
if (inlineComment != null && inlineComment.length() > 0) {
|
|
||||||
if (yaml.contains("\n")) {
|
|
||||||
// section为多行内容,需要 InlineComment 加在首行末尾
|
|
||||||
String[] splitLine = yaml.split("\n", 2);
|
|
||||||
yaml = splitLine[0] + " # " + inlineComment + "\n" + splitLine[1];
|
|
||||||
} else {
|
|
||||||
// 其他情况下就直接加载后面就好。
|
|
||||||
yaml += " # " + inlineComment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.write(indents + yaml.replace("\n", "\n" + indents) + "\n");
|
|
||||||
if (indents.length() == 0) writer.write("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到一个键的缩进。
|
|
||||||
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
* @return 该键的缩进文本
|
|
||||||
*/
|
|
||||||
protected static String getIndents(String key) {
|
|
||||||
String[] splitKey = key.split("[" + BukkitConfigProvider.SEPARATOR + "]");
|
|
||||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-41
@@ -1,41 +0,0 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
|
||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class ProtocolLibHelper {
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static void sendTitle(@NotNull Player player, long fadeIn, long stay, long fadeOut, String line1, String line2) throws Exception {
|
|
||||||
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
|
|
||||||
|
|
||||||
if (line1 != null) {
|
|
||||||
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
|
|
||||||
packet.getTitleActions().write(0, EnumWrappers.TitleAction.TITLE);
|
|
||||||
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line1));
|
|
||||||
pm.sendServerPacket(player, packet, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (line2 != null) {
|
|
||||||
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
|
|
||||||
packet.getTitleActions().write(0, EnumWrappers.TitleAction.SUBTITLE);
|
|
||||||
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line2));
|
|
||||||
pm.sendServerPacket(player, packet, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
PacketContainer timePacket = pm.createPacket(PacketType.Play.Server.TITLE);
|
|
||||||
timePacket.getTitleActions().write(0, EnumWrappers.TitleAction.TIMES);
|
|
||||||
timePacket.getIntegers()
|
|
||||||
.write(0, Math.toIntExact(fadeIn))
|
|
||||||
.write(1, Math.toIntExact(stay))
|
|
||||||
.write(2, Math.toIntExact(fadeOut));
|
|
||||||
pm.sendServerPacket(player, timePacket, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+74
-37
@@ -1,74 +1,111 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
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.builder.item.ItemConfigBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import com.cryptomorin.xseries.XItemStack;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.function.Consumer;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
public class ConfiguredItem extends ConfiguredSection<ItemStack> {
|
||||||
|
|
||||||
public static ItemConfigBuilder create() {
|
public static ItemConfigBuilder create() {
|
||||||
return CraftConfigValue.builder().createItem();
|
return new ItemConfigBuilder();
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfiguredItem of() {
|
|
||||||
return CraftConfigValue.builder().ofItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfiguredItem of(@Nullable ItemConfig defaultItem) {
|
|
||||||
return CraftConfigValue.builder().ofItem(defaultItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final @NotNull String[] params;
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
public ConfiguredItem(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
public ConfiguredItem(@NotNull ValueManifest<ItemStack> manifest, @NotNull String[] params) {
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
|
||||||
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
|
|
||||||
super(
|
super(
|
||||||
provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue,
|
manifest, ItemStack.class,
|
||||||
getItemParser(), ItemConfig::serialize
|
(data, v) -> XItemStack.deserialize((ConfigurationSection) data.getSource()),
|
||||||
|
XItemStack::serialize
|
||||||
);
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
|
|
||||||
return (s, d) -> ItemConfig.deserialize(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull String[] getParams() {
|
public @NotNull String[] getParams() {
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ItemStack getItem(@Nullable Player player) {
|
@Override
|
||||||
return getItem(player, 1);
|
public @Nullable ItemStack get() {
|
||||||
|
return Optional.ofNullable(super.get()).map(ItemStack::clone).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount) {
|
public void modifyItem(Consumer<ItemStack> modifier) {
|
||||||
return getItem(player, amount, new HashMap<>());
|
ItemStack item = get();
|
||||||
|
if (item == null) return;
|
||||||
|
modifier.accept(item);
|
||||||
|
set(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Object... values) {
|
public void modifyMeta(Consumer<ItemMeta> modifier) {
|
||||||
return getItem(player, amount, ParamsUtils.buildParams(params, values));
|
modifyItem(item -> {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
modifier.accept(meta);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull String[] params, @NotNull Object[] values) {
|
public void setName(@Nullable String name) {
|
||||||
return getItem(player, amount, ParamsUtils.buildParams(params, values));
|
modifyMeta(meta -> meta.setDisplayName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
|
public void setLore(@Nullable List<String> lore) {
|
||||||
return getOptional().map(item -> item.getItemStack(player, amount, placeholders)).orElse(null);
|
modifyMeta(meta -> meta.setLore(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLore(String... lore) {
|
||||||
|
if (lore.length == 0) setLore((List<String>) null);
|
||||||
|
else setLore(Arrays.asList(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player) {
|
||||||
|
return get(player, new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
|
||||||
|
return get(player, ParamsUtils.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
|
||||||
|
return get(player, ParamsUtils.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return get(item -> {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return;
|
||||||
|
|
||||||
|
List<String> lore = meta.getLore();
|
||||||
|
if (lore != null && !lore.isEmpty()) {
|
||||||
|
meta.setLore(TextParser.parseList(player, lore, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = meta.getDisplayName();
|
||||||
|
if (!name.isEmpty()) {
|
||||||
|
meta.setDisplayName(TextParser.parseText(player, name, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
|
||||||
|
return getOptional().map(item -> {
|
||||||
|
modifier.accept(item);
|
||||||
|
return item;
|
||||||
|
}).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-5
@@ -1,18 +1,22 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
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.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||||
|
import com.cryptomorin.xseries.messages.ActionBar;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -35,12 +39,18 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
|
|||||||
return asString().defaults(defaultMessage).build();
|
return asString().defaults(defaultMessage).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
|
||||||
@NotNull TextConfig defaultMessage, @NotNull String[] params,
|
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionBar(Player player, String... values) {
|
||||||
|
sendActionBar(player, ParamsUtils.buildParams(this.params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionBar(Player player, Map<String, Object> placeholders) {
|
||||||
|
ActionBar.sendActionBar(player, parseString(player, placeholders));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+3
-5
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
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.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
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();
|
return asStrings().defaults(defaultMessages).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
|
||||||
@NotNull List<TextConfig> messages, @NotNull String[] params,
|
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
@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
|
@Override
|
||||||
|
|||||||
+4
-7
@@ -1,12 +1,11 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
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.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
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;
|
protected final @NotNull Class<T> valueClass;
|
||||||
|
|
||||||
public ConfiguredSerializable(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
public ConfiguredSerializable(@NotNull ValueManifest<T> manifest, @NotNull Class<T> valueClass) {
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
super(manifest);
|
||||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
|
||||||
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
|
||||||
this.valueClass = valueClass;
|
this.valueClass = valueClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +35,7 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 出现了解析错误,提示并返回默认值。
|
// 出现了解析错误,提示并返回默认值。
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return useDefault();
|
return getDefaultValue();
|
||||||
}
|
}
|
||||||
} else return Optional.ofNullable(getCachedValue()).orElse(defaultValue);
|
} else return Optional.ofNullable(getCachedValue()).orElse(defaultValue);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-7
@@ -1,17 +1,16 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
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.configuration.core.value.type.ConfiguredValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||||
@@ -44,10 +43,8 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
|||||||
return CraftConfigValue.builder().createSound().defaults(soundName, volume, pitch).build();
|
return CraftConfigValue.builder().createSound().defaults(soundName, volume, pitch).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredSound(@NotNull ValueManifest<SoundConfig> manifest) {
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
super(manifest, SoundConfig.class, getSoundParser(), SoundConfig::serialize);
|
||||||
@Nullable SoundConfig defaultValue) {
|
|
||||||
super(provider, sectionPath, headerComments, inlineComments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSound(@NotNull Sound sound) {
|
public void setSound(@NotNull Sound sound) {
|
||||||
@@ -70,6 +67,10 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
|||||||
Optional.ofNullable(get()).ifPresent(SoundConfig::playToAll);
|
Optional.ofNullable(get()).ifPresent(SoundConfig::playToAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void playAt(Location location) {
|
||||||
|
Optional.ofNullable(get()).ifPresent(s -> s.playAt(location));
|
||||||
|
}
|
||||||
|
|
||||||
public static ConfigValueParser<Object, SoundConfig> getSoundParser() {
|
public static ConfigValueParser<Object, SoundConfig> getSoundParser() {
|
||||||
return ConfigValueParser.castToString().andThen((s, d) -> SoundConfig.deserialize(s));
|
return ConfigValueParser.castToString().andThen((s, d) -> SoundConfig.deserialize(s));
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-6
@@ -1,8 +1,8 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
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.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
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.Nullable;
|
||||||
import org.jetbrains.annotations.Range;
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||||
|
|
||||||
@@ -40,12 +42,10 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
|||||||
protected final int stay;
|
protected final int stay;
|
||||||
protected final int fadeOut;
|
protected final int fadeOut;
|
||||||
|
|
||||||
public ConfiguredTitle(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
|
||||||
@Nullable TitleConfig defaultValue, @NotNull String[] params,
|
|
||||||
@NotNull TitleSendConsumer sendConsumer,
|
@NotNull TitleSendConsumer sendConsumer,
|
||||||
int fadeIn, int stay, int fadeOut) {
|
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.sendConsumer = sendConsumer;
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.fadeIn = fadeIn;
|
this.fadeIn = fadeIn;
|
||||||
@@ -102,6 +102,16 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
|||||||
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> send(onlinePlayer, placeholders));
|
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() {
|
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
|
||||||
return (s, d) -> TitleConfig.deserialize(s);
|
return (s, d) -> TitleConfig.deserialize(s);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.4.0</version>
|
<version>2.6.2</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -30,6 +30,13 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>yamlcommentwriter</artifactId>
|
||||||
|
<version>${deps.yamlcommentwriter.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>bungeecord-api</artifactId>
|
||||||
|
|||||||
+5
-9
@@ -1,14 +1,12 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee;
|
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.builder.BungeeConfigBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeSectionWrapper;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
@@ -16,10 +14,8 @@ public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
|||||||
return new BungeeConfigBuilder();
|
return new BungeeConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BungeeConfigValue(@Nullable BungeeConfigProvider provider, @Nullable String configPath,
|
public BungeeConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
super(manifest);
|
||||||
@Nullable T defaultValue) {
|
|
||||||
super(provider, configPath, headerComments, inlineComments, defaultValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BungeeConfigProvider getBukkitProvider() {
|
public BungeeConfigProvider getBukkitProvider() {
|
||||||
|
|||||||
+26
-1
@@ -1,15 +1,18 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee;
|
package cc.carm.lib.mineconfiguration.bungee;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.JsonConfiguration;
|
import net.md_5.bungee.config.JsonConfiguration;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MineConfiguration {
|
public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvider> {
|
||||||
|
|
||||||
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
|
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
|
||||||
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
|
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
|
||||||
@@ -94,4 +97,26 @@ public class MineConfiguration {
|
|||||||
return fromJSON(new File(plugin.getDataFolder(), fileName), 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 ConfigurationRoot configRoot,
|
||||||
|
@NotNull ConfigurationRoot messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull Plugin plugin,
|
||||||
|
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
||||||
|
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
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 cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -10,11 +10,11 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||||
|
|
||||||
|
|
||||||
public BungeeMessageBuilder() {
|
public BungeeMessageBuilder() {
|
||||||
super(CommandSender.class, MessageText.class);
|
super(CommandSender.class, TextConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+5
-5
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
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.bungee.value.ConfiguredMessageList;
|
||||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
|
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
@@ -13,10 +14,10 @@ import java.util.Optional;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class BungeeMessageListBuilder<M>
|
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) {
|
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
super(CommandSender.class, MessageText::of, parser);
|
super(CommandSender.class, TextConfig::of, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,8 +28,7 @@ public class BungeeMessageListBuilder<M>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredMessageList<M> build() {
|
public @NotNull ConfiguredMessageList<M> build() {
|
||||||
return new ConfiguredMessageList<>(
|
return new ConfiguredMessageList<>(
|
||||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
|
||||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
this.messageParser, this.sendFunction
|
this.messageParser, this.sendFunction
|
||||||
);
|
);
|
||||||
|
|||||||
+4
-6
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
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.bungee.value.ConfiguredMessage;
|
||||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class BungeeMessageValueBuilder<M>
|
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) {
|
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||||
super(CommandSender.class, MessageText::new, parser);
|
super(CommandSender.class, TextConfig::new, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,8 +25,7 @@ public class BungeeMessageValueBuilder<M>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredMessage<M> build() {
|
public @NotNull ConfiguredMessage<M> build() {
|
||||||
return new ConfiguredMessage<>(
|
return new ConfiguredMessage<>(
|
||||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
buildManifest(TextConfig.of("")),
|
||||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
|
||||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
this.messageParser, this.sendHandler
|
this.messageParser, this.sendHandler
|
||||||
);
|
);
|
||||||
|
|||||||
+7
-7
@@ -11,24 +11,24 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
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);
|
super(CommandSender.class, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("!null,-> !null")
|
@Contract("!null,-> !null")
|
||||||
public static @Nullable MessageText of(@Nullable String message) {
|
public static @Nullable TextConfig of(@Nullable String message) {
|
||||||
if (message == null) return null;
|
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<>();
|
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));
|
return of(Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
+43
-18
@@ -3,21 +3,21 @@ package cc.carm.lib.mineconfiguration.bungee.source;
|
|||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
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.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.util.HashSet;
|
||||||
import java.nio.file.Files;
|
import java.util.List;
|
||||||
import java.nio.file.Path;
|
import java.util.Set;
|
||||||
|
|
||||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> implements CommentedYAML {
|
||||||
|
|
||||||
protected static final char SEPARATOR = '.';
|
protected static final char SEPARATOR = '.';
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
|||||||
protected Configuration configuration;
|
protected Configuration configuration;
|
||||||
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
||||||
|
|
||||||
protected BungeeYAMLComments comments = new BungeeYAMLComments();
|
protected ConfigurationComments comments = new ConfigurationComments();
|
||||||
|
|
||||||
public BungeeConfigProvider(@NotNull File file, @NotNull ConfigurationProvider loader) {
|
public BungeeConfigProvider(@NotNull File file, @NotNull ConfigurationProvider loader) {
|
||||||
super(file);
|
super(file);
|
||||||
@@ -52,22 +52,17 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ConfigurationComments getComments() {
|
public @NotNull ConfigurationComments getComments() {
|
||||||
return this.comments;
|
return this.comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws Exception {
|
public void save() throws Exception {
|
||||||
getLoader().save(configuration, file);
|
try {
|
||||||
if (getLoader() instanceof YamlConfiguration) {
|
CommentedYAMLWriter.writeWithComments(this, this.file);
|
||||||
StringWriter writer = new StringWriter();
|
} catch (Exception ex) {
|
||||||
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
getLoader().save(configuration, file);
|
||||||
String value = writer.toString(); // config contents
|
throw ex;
|
||||||
|
|
||||||
Path toUpdatePath = getFile().toPath();
|
|
||||||
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
|
||||||
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,4 +74,34 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
|||||||
public ConfigurationProvider getLoader() {
|
public ConfigurationProvider getLoader() {
|
||||||
return loader;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-115
@@ -1,115 +0,0 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
|
||||||
|
|
||||||
public class BungeeYAMLComments extends ConfigurationComments {
|
|
||||||
|
|
||||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
|
||||||
List<String> comments = getHeaderComment(path);
|
|
||||||
if (comments == null || comments.size() == 0) return null;
|
|
||||||
|
|
||||||
StringJoiner joiner = new StringJoiner("\n");
|
|
||||||
for (String comment : comments) {
|
|
||||||
if (comment.length() == 0) joiner.add(" ");
|
|
||||||
else joiner.add(indents + "# " + comment);
|
|
||||||
}
|
|
||||||
return joiner + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从一个文件读取配置并写入注释到某个写入器中。
|
|
||||||
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
|
||||||
*
|
|
||||||
* @param source 源配置文件
|
|
||||||
* @param writer 配置写入器
|
|
||||||
* @throws IOException 当写入发生错误时抛出
|
|
||||||
*/
|
|
||||||
public void writeComments(@NotNull Configuration source, @NotNull BufferedWriter writer) throws IOException {
|
|
||||||
ConfigurationProvider provider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
|
||||||
Configuration tmp = new Configuration();// 该对象用于临时记录配置内容
|
|
||||||
|
|
||||||
String configHeader = buildHeaderComments(null, "");
|
|
||||||
if (configHeader != null) writer.write(configHeader);
|
|
||||||
|
|
||||||
for (String fullKey : BungeeSectionWrapper.getAllKeys(source)) {
|
|
||||||
Object currentValue = source.get(fullKey);
|
|
||||||
|
|
||||||
String indents = getIndents(fullKey);
|
|
||||||
String headerComments = buildHeaderComments(fullKey, indents);
|
|
||||||
String inlineComment = getInlineComment(fullKey);
|
|
||||||
|
|
||||||
if (headerComments != null) writer.write(headerComments);
|
|
||||||
|
|
||||||
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
|
||||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
|
||||||
|
|
||||||
if (currentValue instanceof Configuration) {
|
|
||||||
Configuration section = (Configuration) currentValue;
|
|
||||||
writer.write(indents + trailingKey + ":");
|
|
||||||
if (inlineComment != null && inlineComment.length() > 0) {
|
|
||||||
writer.write(" # " + inlineComment);
|
|
||||||
}
|
|
||||||
if (!section.getKeys().isEmpty()) {
|
|
||||||
writer.write("\n");
|
|
||||||
} else {
|
|
||||||
writer.write(" {}\n");
|
|
||||||
if (indents.length() == 0) writer.write("\n");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp.set(trailingKey, currentValue);
|
|
||||||
StringWriter tmpStr = new StringWriter();
|
|
||||||
provider.save(tmp, tmpStr);
|
|
||||||
String yaml = tmpStr.toString();
|
|
||||||
tmpStr.close();
|
|
||||||
tmp.set(trailingKey, null);
|
|
||||||
|
|
||||||
yaml = yaml.substring(0, yaml.length() - 1);
|
|
||||||
|
|
||||||
if (inlineComment != null && inlineComment.length() > 0) {
|
|
||||||
if (yaml.contains("\n")) {
|
|
||||||
// section为多行内容,需要 InlineComment 加在首行末尾
|
|
||||||
String[] splitLine = yaml.split("\n", 2);
|
|
||||||
yaml = splitLine[0] + " # " + inlineComment + "\n" + splitLine[1];
|
|
||||||
} else {
|
|
||||||
// 其他情况下就直接加载后面就好。
|
|
||||||
yaml += " # " + inlineComment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.write(indents + yaml.replace("\n", "\n" + indents) + "\n");
|
|
||||||
if (indents.length() == 0) writer.write("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到一个键的缩进。
|
|
||||||
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
* @return 该键的缩进文本
|
|
||||||
*/
|
|
||||||
protected static String getIndents(@NotNull String key) {
|
|
||||||
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
|
||||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+5
-7
@@ -1,9 +1,9 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
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.BungeeConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
|
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 cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@@ -16,7 +16,7 @@ import java.util.List;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
|
public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSender> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <M> BungeeMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
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();
|
return asString().defaults(defaultMessage).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
|
||||||
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
@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
|
@Override
|
||||||
|
|||||||
+5
-8
@@ -1,10 +1,10 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
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.BungeeConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageListBuilder;
|
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.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.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -13,11 +13,10 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
|
public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, CommandSender> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <M> BungeeMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
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();
|
return asStrings().defaults(defaultMessages).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
|
||||||
@NotNull List<MessageText> messages, @NotNull String[] params,
|
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
@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
|
@Override
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ConfigTest {
|
|||||||
|
|
||||||
@HeaderComment("执行的指令列表")
|
@HeaderComment("执行的指令列表")
|
||||||
@InlineComment("建议以\"\"包裹")
|
@InlineComment("建议以\"\"包裹")
|
||||||
public static final ConfigValue<List<String>> COMMANDS = ConfiguredList.builder(String.class)
|
public static final ConfigValue<List<String>> COMMANDS = ConfiguredList.builderOf(String.class)
|
||||||
.fromString().defaults("alert Commands here!").build();
|
.fromString().defaults("alert Commands here!").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,14 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
<deps.easyconfifuration.version>3.4.0</deps.easyconfifuration.version>
|
<deps.easyconfifuration.version>3.6.0</deps.easyconfifuration.version>
|
||||||
<deps.easyplugin.version>1.5.2</deps.easyplugin.version>
|
<deps.easyplugin.version>1.5.4</deps.easyplugin.version>
|
||||||
|
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>2.4.0</version>
|
<version>2.6.2</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
@@ -108,7 +109,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>24.0.0</version>
|
<version>24.0.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>3.1.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -129,7 +130,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>3.1.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
@@ -149,7 +150,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
<version>2.5.3</version>
|
<version>3.0.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||||
<useReleaseProfile>false</useReleaseProfile>
|
<useReleaseProfile>false</useReleaseProfile>
|
||||||
@@ -160,7 +161,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.10.1</version>
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${project.jdk.version}</source>
|
<source>${project.jdk.version}</source>
|
||||||
<target>${project.jdk.version}</target>
|
<target>${project.jdk.version}</target>
|
||||||
@@ -177,7 +178,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
<version>3.3.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
|||||||
Reference in New Issue
Block a user