mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d1639362b | |||
| ce205e10fe | |||
| 8e4e712936 | |||
| c3d9c65a86 | |||
| ebddeff78d | |||
| afcdc2c378 | |||
| 5905b25c73 | |||
| 31f51c9b96 | |||
| eb8f279e0b | |||
| e291c3a109 | |||
| 433f780608 | |||
| 385f6dd22f | |||
| 04168d4d12 | |||
| 143e0c2283 | |||
| 4b4f90ee38 | |||
| 97d24c7027 | |||
| d1b01ffed5 | |||
| 67931094e6 | |||
| 02f59b99f0 | |||
| e781d54348 | |||
| bbd2c9e5e7 | |||
| ccc8cc6b72 | |||
| 1612e49326 | |||
| 2754f12cd5 | |||
| c0f5d32ba0 | |||
| 6c355e0d89 | |||
| 6c7a5dd60a | |||
| 425d61834b | |||
| c9a272d052 | |||
| 327484cd53 | |||
| 99090929dd | |||
| 8437c4c904 | |||
| 21f7742d78 | |||
| 68e6280c94 | |||
| 9a8e6395bb |
@@ -30,7 +30,7 @@ jobs:
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf target/site/apidocs/* docs/
|
||||
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
|
||||
cp -vrf .doc/javadoc/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: "Generate Sitemap"
|
||||
id: sitemap
|
||||
|
||||
@@ -20,44 +20,35 @@ EasyConfiguration for MineCraft!
|
||||
|
||||
## 项目结构
|
||||
|
||||
### **MineConfiguration-Common**
|
||||
### **MineConfiguration-Common** [`common`](common)
|
||||
|
||||
全部版本的共用部分,包括
|
||||
全部版本的共用部分(均已被打包至下行包中),包括
|
||||
|
||||
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||
|
||||
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||
|
||||
### MineConfiguration-Bukkit
|
||||
### **MineConfiguration-Bukkit** [`platform/bukkit`](platform/bukkit)
|
||||
|
||||
#### MineConfiguration-Bukkit-Base
|
||||
|
||||
Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit-General** 或 **MineConfiguration-Bukkit-Native** 。
|
||||
适用于Bukkit的版本,同时支持其他以Bukkit为基础的服务端 *(如Spigot、Paper、CatServer)* 。
|
||||
|
||||
相较于基础版本,额外提供了以下功能:
|
||||
|
||||
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
||||
- `ConfiguredItem` (快捷读取简单的物品配置文件)
|
||||
- `ConfiguredSound` (快捷读取音效配置文件)
|
||||
- `ConfiguredItem` (快捷读\写\使用简单的物品配置文件)
|
||||
- `ConfiguredSound` (快捷读\写\使用音效配置文件)
|
||||
- `ConfiguredTitle` (快速读\写\使用标题文字配置文件)
|
||||
|
||||
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
||||
|
||||
#### **MineConfiguration-Bukkit** _(推荐)_
|
||||
|
||||
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
||||
|
||||
#### **MineConfiguration-Spigot**
|
||||
|
||||
适用于 Spigot(1.18+) 的版本,适配了1.18及以后版本Spigot原生自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
||||
|
||||
### **MineConfiguration-Bungee**
|
||||
### **MineConfiguration-Bungee** [`platform/bungee`](platform/bungee)
|
||||
|
||||
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
||||
|
||||
## 开发
|
||||
|
||||
请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
||||
其他功能请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
||||
的 [开发介绍](https://github.com/CarmJos/EasyConfiguration/tree/master/.documentation) 。
|
||||
|
||||
### 依赖方式
|
||||
@@ -113,7 +104,7 @@ Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bu
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-spigot</artifactId>
|
||||
|
||||
+16
-3
@@ -5,24 +5,37 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.5.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
|
||||
<name>MineConfiguration-Common</name>
|
||||
<description>轻松(做)配置,全部版本的共用部分。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${easyconfiguration.version}</version>
|
||||
<version>${deps.easyconfifuration.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-color</artifactId>
|
||||
<version>${deps.easyplugin.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
|
||||
+10
-1
@@ -1,16 +1,18 @@
|
||||
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -67,4 +69,11 @@ public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B exte
|
||||
@Override
|
||||
public abstract @NotNull ConfigMessageList<M, T, R> build();
|
||||
|
||||
protected @NotNull ValueManifest<List<T>> buildManifest(@NotNull List<T> emptyValue) {
|
||||
return new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(emptyValue)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,13 +1,15 @@
|
||||
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -64,4 +66,10 @@ public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B ext
|
||||
@Override
|
||||
public abstract @NotNull ConfigMessage<M, T, R> build();
|
||||
|
||||
protected @NotNull ValueManifest<T> buildManifest(@NotNull T emptyValue) {
|
||||
return new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(emptyValue)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,16 +28,14 @@ public abstract class AbstractText<R> {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
||||
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
||||
return parse(parser, receiver, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
String message = getMessage();
|
||||
if (message.isEmpty()) return null; // No further processing
|
||||
else return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
|
||||
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.common.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ColorParser {
|
||||
|
||||
public static Pattern HEX_PATTERN = Pattern.compile("&\\(&?#([0-9a-fA-F]{6})\\)");
|
||||
|
||||
public static String parse(String text) {
|
||||
return parseBaseColor(parseHexColor(text));
|
||||
}
|
||||
|
||||
public static String[] parse(String... texts) {
|
||||
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static List<String> parse(List<String> texts) {
|
||||
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static String parseBaseColor(final String text) {
|
||||
return text.replaceAll("&", "§").replace("§§", "&");
|
||||
}
|
||||
|
||||
public static String parseHexColor(String text) {
|
||||
Matcher matcher = HEX_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
text = matcher.replaceFirst(buildHexColor(matcher.group(1)).toLowerCase());
|
||||
matcher.reset(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static String buildHexColor(String hexCode) {
|
||||
return Arrays.stream(hexCode.split(""))
|
||||
.map(s -> '§' + s)
|
||||
.collect(Collectors.joining("", '§' + "x", ""));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface BaseMessage<R, M> {
|
||||
|
||||
/**
|
||||
* 得到所有的接收者
|
||||
*
|
||||
* @return 全部可能的接收者
|
||||
*/
|
||||
@Unmodifiable
|
||||
@NotNull Iterable<R> getAllReceivers();
|
||||
|
||||
/**
|
||||
* 得到消息中的通过 {@link MessageValueBuilder#params(String...)}已定变量名(按定义顺序)
|
||||
*
|
||||
* @return 已定变量
|
||||
*/
|
||||
@NotNull String[] getParams();
|
||||
|
||||
/**
|
||||
* 向接收者发送消息的根方法。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param message 消息内容
|
||||
*/
|
||||
@ApiStatus.OverrideOnly
|
||||
void apply(@NotNull R receiver, @NotNull M message);
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
@Nullable M parse(@Nullable R receiver, @NotNull Map<String, Object> placeholders);
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param values 已定变量的对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
default @Nullable M parse(@Nullable R receiver, @Nullable Object... values) {
|
||||
return parse(receiver, ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
* @param values 已定变量的对应参数
|
||||
*/
|
||||
default void send(@Nullable R receiver, @Nullable Object... values) {
|
||||
send(receiver, ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
if (receiver == null) return;
|
||||
M parsed = parse(receiver, placeholders);
|
||||
if (parsed == null) return;
|
||||
apply(receiver, parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向全部接收者(包括后台)发送不同参数的消息
|
||||
*
|
||||
* @param eachValues 每位接收者将收到已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToEach(@NotNull Function<@NotNull R, Object[]> eachValues) {
|
||||
sendToEach(null, eachValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向特定接收者发送不同参数的消息
|
||||
*
|
||||
* @param limiter 接收者限定器,为空则不限定接收者。
|
||||
* @param eachValues 每位接收者将收到已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToEach(@Nullable Predicate<R> limiter,
|
||||
@NotNull Function<@NotNull R, Object[]> eachValues) {
|
||||
Predicate<R> predicate = Optional.ofNullable(limiter).orElse(r -> true);
|
||||
for (R r : getAllReceivers()) {
|
||||
if (predicate.test(r)) {
|
||||
send(r, ParamsUtils.buildParams(getParams(), eachValues.apply(r)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param values 已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToAll(@Nullable Object... values) {
|
||||
broadcast(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void sendToAll(@NotNull Map<String, Object> placeholders) {
|
||||
broadcast(placeholders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param values 已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void broadcast(@Nullable Object... values) {
|
||||
broadcast(ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
getAllReceivers().forEach(r -> send(r, placeholders));
|
||||
}
|
||||
|
||||
}
|
||||
+22
-32
@@ -1,70 +1,59 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
extends ConfiguredValue<T> {
|
||||
extends ConfiguredValue<T> implements BaseMessage<R, M> {
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||
protected final @NotNull BiConsumer<@NotNull R, @NotNull M> messageConsumer;
|
||||
protected final @NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction;
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
public ConfigMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
||||
public ConfigMessage(@NotNull ValueManifest<T> manifest,
|
||||
@NotNull Class<T> textClazz, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull R, @NotNull M> messageConsumer,
|
||||
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
||||
@NotNull Function<String, T> textBuilder) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
|
||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
||||
super(
|
||||
manifest, textClazz,
|
||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)),
|
||||
AbstractText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
this.messageConsumer = messageConsumer;
|
||||
this.sendFunction = sendFunction;
|
||||
this.textBuilder = textBuilder;
|
||||
}
|
||||
|
||||
public @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
||||
return parse(sender, ParamsUtils.buildParams(params, values));
|
||||
@Override
|
||||
public String[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull R receiver, @NotNull M message) {
|
||||
sendFunction.accept(receiver, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||
T value = get();
|
||||
if (value == null || value.getMessage().isEmpty()) return null;
|
||||
else return value.parse(this.messageParser, sender, placeholders);
|
||||
}
|
||||
|
||||
public void send(@Nullable R receiver, @Nullable Object... values) {
|
||||
send(receiver, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
if (receiver == null) return;
|
||||
M parsed = parse(receiver, placeholders);
|
||||
if (parsed == null) return;
|
||||
messageConsumer.accept(receiver, parsed);
|
||||
}
|
||||
|
||||
public void broadcast(@Nullable Object... values) {
|
||||
broadcast(ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
||||
|
||||
public void set(@Nullable String value) {
|
||||
this.set(value == null ? null : buildText(value));
|
||||
}
|
||||
@@ -72,4 +61,5 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
protected T buildText(String value) {
|
||||
return textBuilder.apply(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+36
-29
@@ -1,10 +1,9 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -16,7 +15,8 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends ConfiguredList<T> {
|
||||
public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
|
||||
extends ConfiguredList<T> implements BaseMessage<R, List<M>> {
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||
@@ -24,16 +24,15 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
||||
public ConfigMessageList(@NotNull ValueManifest<List<T>> manifest,
|
||||
@NotNull Class<T> textClazz, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
||||
@NotNull Function<String, @NotNull T> textBuilder) {
|
||||
super(
|
||||
provider, sectionPath, headerComments, inlineComments, textClazz, messages,
|
||||
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
|
||||
manifest, textClazz,
|
||||
ConfigDataFunction.castToString().andThen(textBuilder::apply),
|
||||
AbstractText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
@@ -41,49 +40,57 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
||||
this.textBuilder = textBuilder;
|
||||
}
|
||||
|
||||
public @Nullable List<M> parse(@Nullable R sender, @Nullable Object... values) {
|
||||
return parse(sender, ParamsUtils.buildParams(params, values));
|
||||
@Override
|
||||
public String[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public @Nullable List<M> parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||
@Override
|
||||
public void apply(@NotNull R receiver, @NotNull List<M> message) {
|
||||
sendFunction.accept(receiver, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
@Override
|
||||
public @Nullable List<M> parse(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
List<T> list = get();
|
||||
if (list.isEmpty()) return null;
|
||||
|
||||
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
|
||||
if (String.join("", messages).isEmpty()) return null;
|
||||
|
||||
return list.stream().map(value -> value.parse(this.messageParser, sender, placeholders))
|
||||
return list.stream().map(value -> value.parse(this.messageParser, receiver, placeholders))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void send(@Nullable R receiver, @Nullable Object... values) {
|
||||
send(receiver, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
List<T> list = get();
|
||||
if (list.isEmpty()) return null;
|
||||
|
||||
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
if (receiver == null) return;
|
||||
List<M> parsed = parse(receiver, placeholders);
|
||||
if (parsed == null) return;
|
||||
sendFunction.accept(receiver, parsed);
|
||||
}
|
||||
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
|
||||
if (String.join("", messages).isEmpty()) return null;
|
||||
|
||||
public void broadcast(@Nullable Object... values) {
|
||||
broadcast(ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
String combined = String.join("\n", messages);
|
||||
T text = textBuilder.apply(combined);
|
||||
|
||||
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
||||
return text.parse(this.messageParser, receiver, placeholders);
|
||||
}
|
||||
|
||||
public void setMessages(@NotNull String... values) {
|
||||
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
||||
}
|
||||
|
||||
public void setMessages(@Nullable List<String> values) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
if (values == null) {
|
||||
set(null);
|
||||
} else {
|
||||
set(buildText(values));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected List<T> buildText(List<String> values) {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.0.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.0.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+25
-9
@@ -5,25 +5,32 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.5.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>base</module>
|
||||
<module>general</module>
|
||||
</modules>
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bukkit-Parent</name>
|
||||
<name>MineConfiguration-Bukkit</name>
|
||||
<description>轻松(做)配置,适用于Bukkit系服务端的版本。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
@@ -35,7 +42,7 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.1</version>
|
||||
<version>2.11.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -49,4 +56,13 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+4
-5
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.CraftConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
@@ -16,16 +17,14 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||
return new CraftConfigBuilder();
|
||||
}
|
||||
|
||||
public CraftConfigValue(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable T defaultValue) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
||||
public CraftConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||
super(manifest);
|
||||
}
|
||||
|
||||
public CraftConfigProvider getBukkitProvider() {
|
||||
ConfigurationProvider<?> provider = getProvider();
|
||||
if (provider instanceof CraftConfigProvider) return (CraftConfigProvider) getProvider();
|
||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
||||
else throw new IllegalStateException("Provider is not a CraftConfigProvider");
|
||||
}
|
||||
|
||||
public CraftSectionWrapper getBukkitConfig() {
|
||||
+1
@@ -38,4 +38,5 @@ public class MineConfiguration {
|
||||
public static BukkitConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
}
|
||||
+7
-2
@@ -1,5 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.item;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||
@@ -110,8 +111,12 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredItem build() {
|
||||
ItemConfig defaultItem = Optional.ofNullable(this.defaultValue).orElse(buildDefault());
|
||||
return new ConfiguredItem(this.provider, this.path, this.headerComments, this.inlineComment, defaultItem, buildParams());
|
||||
return new ConfiguredItem(
|
||||
new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(buildDefault())
|
||||
), buildParams()
|
||||
);
|
||||
}
|
||||
|
||||
protected final String[] buildParams() {
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||
@@ -8,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||
+1
-3
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageListBuilder<M>
|
||||
@@ -27,8 +26,7 @@ public class CraftMessageListBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of(new ArrayList<>())),
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
+1
-3
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageValueBuilder<M>
|
||||
@@ -26,8 +25,7 @@ public class CraftMessageValueBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of("")),
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
+1
-1
@@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSerializable<T> build() {
|
||||
return new ConfiguredSerializable<>(this.provider, this.path, this.headerComments, this.inlineComment, this.valueClass, this.defaultValue);
|
||||
return new ConfiguredSerializable<>(buildManifest(), valueClass);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundC
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSound build() {
|
||||
return new ConfiguredSound(this.provider, this.path, this.headerComments, this.inlineComment, this.defaultValue);
|
||||
return new ConfiguredSound(buildManifest());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -89,8 +89,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
||||
@Override
|
||||
public @NotNull ConfiguredTitle build() {
|
||||
return new ConfiguredTitle(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
this.defaultValue, ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
|
||||
);
|
||||
}
|
||||
+8
-2
@@ -1,8 +1,10 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@@ -126,7 +128,11 @@ public class ItemConfig {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
|
||||
return deserialize(CraftSectionWrapper.of(section));
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
|
||||
String typeName = section.getString("type");
|
||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||
|
||||
@@ -156,7 +162,7 @@ public class ItemConfig {
|
||||
return flags;
|
||||
}
|
||||
|
||||
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper section) {
|
||||
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper<?> section) {
|
||||
Map<Enchantment, Integer> enchantments = new LinkedHashMap<>();
|
||||
if (section == null) return enchantments;
|
||||
section.getKeys(false).forEach(key -> {
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class TitleConfig {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper section) {
|
||||
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
|
||||
return of(section.getString("line1"), section.getString("line2"));
|
||||
}
|
||||
|
||||
+5
-22
@@ -1,10 +1,10 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -12,13 +12,12 @@ import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
protected BukkitYAMLComments bukkitComments = new BukkitYAMLComments();
|
||||
protected @NotNull BukkitYAMLComments comments = new BukkitYAMLComments();
|
||||
|
||||
public BukkitConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
@@ -39,7 +38,7 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
configuration.save(getFile());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
this.bukkitComments.writeComments(configuration, new BufferedWriter(writer));
|
||||
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
||||
String value = writer.toString(); // config contents
|
||||
|
||||
Path toUpdatePath = getFile().toPath();
|
||||
@@ -49,24 +48,8 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||
this.bukkitComments.setHeaderComments(path, comments);
|
||||
public @Nullable ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
this.bukkitComments.setInlineComment(path, comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@Unmodifiable
|
||||
public List<String> getHeaderComment(@Nullable String path) {
|
||||
return this.bukkitComments.getHeaderComment(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return this.bukkitComments.getInlineComment(path);
|
||||
}
|
||||
}
|
||||
+4
-42
@@ -1,58 +1,20 @@
|
||||
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 org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitYAMLComments {
|
||||
|
||||
protected final @NotNull Map<String, List<String>> headerComments = new HashMap<>();
|
||||
protected final @NotNull Map<String, String> inlineComments = new HashMap<>();
|
||||
|
||||
protected @NotNull Map<String, List<String>> getHeaderComments() {
|
||||
return headerComments;
|
||||
}
|
||||
|
||||
protected @NotNull Map<String, String> getInlineComments() {
|
||||
return inlineComments;
|
||||
}
|
||||
|
||||
public void setHeaderComments(@Nullable String path, @Nullable List<String> comments) {
|
||||
|
||||
if (comments == null) {
|
||||
getHeaderComments().remove(path);
|
||||
} else {
|
||||
getHeaderComments().put(path, comments);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
if (comment == null) {
|
||||
getInlineComments().remove(path);
|
||||
} else {
|
||||
getInlineComments().put(path, comment);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Unmodifiable
|
||||
public List<String> getHeaderComment(@Nullable String path) {
|
||||
return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return getInlineComments().get(path);
|
||||
}
|
||||
public class BukkitYAMLComments extends ConfigurationComments {
|
||||
|
||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||
List<String> comments = getHeaderComment(path);
|
||||
+17
-16
@@ -10,61 +10,62 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class CraftSectionWrapper implements ConfigurationWrapper {
|
||||
public class CraftSectionWrapper implements ConfigurationWrapper<ConfigurationSection> {
|
||||
|
||||
protected final ConfigurationSection section;
|
||||
protected final ConfigurationSection configuration;
|
||||
|
||||
protected CraftSectionWrapper(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
protected CraftSectionWrapper(ConfigurationSection configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public ConfigurationSection getSourceSection() {
|
||||
return section;
|
||||
@Override
|
||||
public @NotNull ConfigurationSection getSource() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
return this.section.getKeys(deep);
|
||||
return this.configuration.getKeys(deep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return this.section.getValues(deep);
|
||||
return this.configuration.getValues(deep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
this.section.set(path, value);
|
||||
this.configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return this.section.contains(path);
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return this.section.get(path);
|
||||
return this.configuration.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return this.section.isList(path);
|
||||
return this.configuration.isList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return this.section.getList(path);
|
||||
return this.configuration.getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSection(@NotNull String path) {
|
||||
return this.section.isConfigurationSection(path);
|
||||
return this.configuration.isConfigurationSection(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
||||
return Optional.ofNullable(section.getConfigurationSection(path))
|
||||
public @Nullable CraftSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||
return Optional.ofNullable(configuration.getConfigurationSection(path))
|
||||
.map(CraftSectionWrapper::of).orElse(null);
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,11 +7,12 @@ 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(Player player, long fadeIn, long stay, long fadeOut, String line1, String line2) throws Exception {
|
||||
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) {
|
||||
@@ -35,7 +36,6 @@ public class ProtocolLibHelper {
|
||||
.write(1, Math.toIntExact(stay))
|
||||
.write(2, Math.toIntExact(fadeOut));
|
||||
pm.sendServerPacket(player, timePacket, false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ColorParser;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
+11
-11
@@ -1,20 +1,19 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
||||
@@ -33,14 +32,15 @@ public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
|
||||
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue, getItemParser(), ItemConfig::serialize);
|
||||
public ConfiguredItem(@NotNull ValueManifest<ItemConfig> manifest, @NotNull String[] params) {
|
||||
super(
|
||||
manifest, ItemConfig.class,
|
||||
getItemParser(), ItemConfig::serialize
|
||||
);
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public static ConfigValueParser<ConfigurationWrapper, ItemConfig> getItemParser() {
|
||||
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
|
||||
return (s, d) -> ItemConfig.deserialize(s);
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,17 +1,18 @@
|
||||
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.builder.message.CraftMessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@@ -34,19 +35,18 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
|
||||
return asString().defaults(defaultMessage).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull TextConfig defaultMessage, @NotNull String[] params,
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, defaultMessage, params, messageParser, sendFunction, TextConfig::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||
send(Bukkit.getConsoleSender(), placeholders);
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
senders.addAll(Bukkit.getOnlinePlayers());
|
||||
return senders;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
-11
@@ -1,17 +1,18 @@
|
||||
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.builder.message.CraftMessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@@ -30,17 +31,17 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, C
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull List<TextConfig> messages, @NotNull String[] params,
|
||||
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, messages, params, messageParser, sendFunction, TextConfig::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||
send(Bukkit.getConsoleSender(), placeholders);
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
senders.addAll(Bukkit.getOnlinePlayers());
|
||||
return senders;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-6
@@ -1,12 +1,11 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
||||
@@ -22,10 +21,8 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
||||
|
||||
protected final @NotNull Class<T> valueClass;
|
||||
|
||||
public ConfiguredSerializable(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
||||
public ConfiguredSerializable(@NotNull ValueManifest<T> manifest, @NotNull Class<T> valueClass) {
|
||||
super(manifest);
|
||||
this.valueClass = valueClass;
|
||||
}
|
||||
|
||||
+3
-7
@@ -1,7 +1,7 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||
@@ -9,9 +9,7 @@ import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
@@ -44,10 +42,8 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
return CraftConfigValue.builder().createSound().defaults(soundName, volume, pitch).build();
|
||||
}
|
||||
|
||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable SoundConfig defaultValue) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
||||
public ConfiguredSound(@NotNull ValueManifest<SoundConfig> manifest) {
|
||||
super(manifest, SoundConfig.class, getSoundParser(), SoundConfig::serialize);
|
||||
}
|
||||
|
||||
public void setSound(@NotNull Sound sound) {
|
||||
+25
-15
@@ -1,22 +1,24 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
|
||||
@@ -40,12 +42,10 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
protected final int stay;
|
||||
protected final int fadeOut;
|
||||
|
||||
public ConfiguredTitle(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable TitleConfig defaultValue, @NotNull String[] params,
|
||||
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
|
||||
@NotNull TitleSendConsumer sendConsumer,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, TitleConfig.class, defaultValue, getTitleParser(), TitleConfig::serialize);
|
||||
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
|
||||
this.sendConsumer = sendConsumer;
|
||||
this.params = params;
|
||||
this.fadeIn = fadeIn;
|
||||
@@ -87,23 +87,33 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAll(Object... values) {
|
||||
sendAll(this.params, values);
|
||||
public void sendToAll(Object... values) {
|
||||
sendToAll(this.params, values);
|
||||
}
|
||||
|
||||
public void sendAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||
sendAll(ParamsUtils.buildParams(params, values));
|
||||
public void sendToAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||
sendToAll(ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public void sendAll(@NotNull Map<String, Object> placeholders) {
|
||||
public void sendToAll(@NotNull Map<String, Object> placeholders) {
|
||||
TitleConfig config = get();
|
||||
if (config == null) return;
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> send(onlinePlayer, placeholders));
|
||||
}
|
||||
|
||||
public void sendToEach(@NotNull Function<@NotNull Player, Object[]> eachValues) {
|
||||
sendToEach(null, eachValues);
|
||||
}
|
||||
|
||||
public static ConfigValueParser<ConfigurationWrapper, TitleConfig> getTitleParser() {
|
||||
public void sendToEach(@Nullable Predicate<Player> limiter,
|
||||
@NotNull Function<@NotNull Player, Object[]> eachValues) {
|
||||
Predicate<Player> predicate = Optional.ofNullable(limiter).orElse(r -> true);
|
||||
Bukkit.getOnlinePlayers().stream().filter(predicate)
|
||||
.forEach(r -> send(r, ParamsUtils.buildParams(params, eachValues.apply(r))));
|
||||
}
|
||||
|
||||
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
|
||||
return (s, d) -> TitleConfig.deserialize(s);
|
||||
}
|
||||
}
|
||||
+7
-11
@@ -5,25 +5,28 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.5.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bungee</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bungee</name>
|
||||
|
||||
<description>轻松(做)配置,适用于BungeeCord的版本,可用JSON与YAML格式。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${easyconfiguration.version}</version>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -43,13 +46,6 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+5
-9
@@ -1,14 +1,12 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.BungeeConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeSectionWrapper;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||
|
||||
@@ -16,10 +14,8 @@ public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||
return new BungeeConfigBuilder();
|
||||
}
|
||||
|
||||
public BungeeConfigValue(@Nullable BungeeConfigProvider provider, @Nullable String configPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable T defaultValue) {
|
||||
super(provider, configPath, headerComments, inlineComments, defaultValue);
|
||||
public BungeeConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||
super(manifest);
|
||||
}
|
||||
|
||||
public BungeeConfigProvider getBukkitProvider() {
|
||||
|
||||
+5
-4
@@ -1,19 +1,20 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ColorParser;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||
|
||||
|
||||
public BungeeMessageBuilder() {
|
||||
super(CommandSender.class, MessageText.class);
|
||||
super(CommandSender.class, TextConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessageList;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
@@ -13,10 +14,10 @@ import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageListBuilder<M>
|
||||
extends MessageListBuilder<M, CommandSender, MessageText, BungeeMessageListBuilder<M>> {
|
||||
extends MessageListBuilder<M, CommandSender, TextConfig, BungeeMessageListBuilder<M>> {
|
||||
|
||||
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, MessageText::of, parser);
|
||||
super(CommandSender.class, TextConfig::of, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,8 +28,7 @@ public class BungeeMessageListBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
|
||||
+4
-6
@@ -1,6 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessage;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
@@ -8,14 +8,13 @@ import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageValueBuilder<M>
|
||||
extends MessageValueBuilder<M, CommandSender, MessageText, BungeeMessageValueBuilder<M>> {
|
||||
extends MessageValueBuilder<M, CommandSender, TextConfig, BungeeMessageValueBuilder<M>> {
|
||||
|
||||
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, MessageText::new, parser);
|
||||
super(CommandSender.class, TextConfig::new, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,8 +25,7 @@ public class BungeeMessageValueBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
|
||||
+7
-7
@@ -11,24 +11,24 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MessageText extends AbstractText<CommandSender> {
|
||||
public class TextConfig extends AbstractText<CommandSender> {
|
||||
|
||||
public MessageText(@NotNull String message) {
|
||||
public TextConfig(@NotNull String message) {
|
||||
super(CommandSender.class, message);
|
||||
}
|
||||
|
||||
@Contract("!null,-> !null")
|
||||
public static @Nullable MessageText of(@Nullable String message) {
|
||||
public static @Nullable TextConfig of(@Nullable String message) {
|
||||
if (message == null) return null;
|
||||
else return new MessageText(message);
|
||||
else return new TextConfig(message);
|
||||
}
|
||||
|
||||
public static @NotNull List<MessageText> of(@Nullable List<String> messages) {
|
||||
public static @NotNull List<TextConfig> of(@Nullable List<String> messages) {
|
||||
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
|
||||
else return messages.stream().map(TextConfig::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static @NotNull List<MessageText> of(@NotNull String... messages) {
|
||||
public static @NotNull List<TextConfig> of(@NotNull String... messages) {
|
||||
return of(Arrays.asList(messages));
|
||||
}
|
||||
|
||||
+6
-22
@@ -1,13 +1,13 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||
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 org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
@@ -16,7 +16,6 @@ import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
||||
|
||||
@@ -52,6 +51,11 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
||||
this.configuration = getLoader().load(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
getLoader().save(configuration, file);
|
||||
@@ -67,26 +71,6 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||
this.comments.setHeaderComments(path, comments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
this.comments.setInlineComment(path, comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
|
||||
return this.comments.getHeaderComment(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return this.comments.getInlineComment(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
||||
return this.initializer;
|
||||
|
||||
+17
-12
@@ -11,12 +11,12 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
||||
|
||||
public class BungeeSectionWrapper implements ConfigurationWrapper {
|
||||
public class BungeeSectionWrapper implements ConfigurationWrapper<Configuration> {
|
||||
|
||||
private final Configuration section;
|
||||
private final Configuration configuration;
|
||||
|
||||
private BungeeSectionWrapper(@NotNull Configuration section) {
|
||||
this.section = section;
|
||||
this.configuration = section;
|
||||
}
|
||||
|
||||
@Contract("!null->!null")
|
||||
@@ -37,34 +37,39 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Configuration getSource() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
if (deep) {
|
||||
return new LinkedHashSet<>(getAllKeys(section));
|
||||
return new LinkedHashSet<>(getAllKeys(configuration));
|
||||
} else {
|
||||
return new LinkedHashSet<>(section.getKeys());
|
||||
return new LinkedHashSet<>(configuration.getKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return getKeys(deep).stream()
|
||||
.collect(Collectors.toMap(key -> key, section::get, (a, b) -> b, LinkedHashMap::new));
|
||||
.collect(Collectors.toMap(key -> key, configuration::get, (a, b) -> b, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
this.section.set(path, value);
|
||||
this.configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return this.section.contains(path);
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return this.section.get(path);
|
||||
return this.configuration.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +79,7 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return this.section.getList(path);
|
||||
return this.configuration.getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +88,7 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
||||
return of(this.section.getSection(path));
|
||||
public @Nullable BungeeSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||
return of(this.configuration.getSection(path));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-42
@@ -1,60 +1,23 @@
|
||||
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 org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.*;
|
||||
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 {
|
||||
|
||||
protected final @NotNull Map<String, List<String>> headerComments = new HashMap<>();
|
||||
protected final @NotNull Map<String, String> inlineComments = new HashMap<>();
|
||||
|
||||
protected @NotNull Map<String, List<String>> getHeaderComments() {
|
||||
return headerComments;
|
||||
}
|
||||
|
||||
protected @NotNull Map<String, String> getInlineComments() {
|
||||
return inlineComments;
|
||||
}
|
||||
|
||||
public void setHeaderComments(@Nullable String path, @Nullable List<String> comments) {
|
||||
if (comments == null) {
|
||||
getHeaderComments().remove(path);
|
||||
} else {
|
||||
getHeaderComments().put(path, comments);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
if (comment == null) {
|
||||
getInlineComments().remove(path);
|
||||
} else {
|
||||
getInlineComments().put(path, comment);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Unmodifiable
|
||||
public List<String> getHeaderComment(@Nullable String path) {
|
||||
return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return getInlineComments().get(path);
|
||||
}
|
||||
public class BungeeYAMLComments extends ConfigurationComments {
|
||||
|
||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||
List<String> comments = getHeaderComment(path);
|
||||
@@ -144,7 +107,7 @@ public class BungeeYAMLComments {
|
||||
* @param key 键
|
||||
* @return 该键的缩进文本
|
||||
*/
|
||||
protected static String getIndents(String key) {
|
||||
protected static String getIndents(@NotNull String key) {
|
||||
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||
}
|
||||
|
||||
+12
-11
@@ -1,21 +1,22 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.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.configuration.core.source.ConfigurationProvider;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
|
||||
public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> BungeeMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
@@ -34,18 +35,18 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
|
||||
return asString().defaults(defaultMessage).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
||||
send(ProxyServer.getInstance().getConsole(), placeholders);
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(ProxyServer.getInstance().getConsole());
|
||||
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||
return senders;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-12
@@ -1,21 +1,22 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
|
||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> BungeeMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
@@ -30,17 +31,17 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull List<MessageText> messages, @NotNull String[] params,
|
||||
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
||||
send(ProxyServer.getInstance().getConsole(), placeholders);
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(ProxyServer.getInstance().getConsole());
|
||||
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||
return senders;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<artifactId>mineconfiguration-spigot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--PlaceholderAPI for general placeholder's support-->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.1</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>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.spigot;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.spigot.source.SpigotConfigProvider;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MineConfiguration {
|
||||
|
||||
public static SpigotConfigProvider from(File file, String source) {
|
||||
SpigotConfigProvider provider = new SpigotConfigProvider(file);
|
||||
try {
|
||||
provider.initializeFile(source);
|
||||
provider.initializeConfig();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static SpigotConfigProvider from(File file) {
|
||||
return from(file, file.getName());
|
||||
}
|
||||
|
||||
public static SpigotConfigProvider from(String fileName) {
|
||||
return from(fileName, fileName);
|
||||
}
|
||||
|
||||
public static SpigotConfigProvider from(String fileName, String source) {
|
||||
return from(new File(fileName), source);
|
||||
}
|
||||
|
||||
public static SpigotConfigProvider from(Plugin plugin, String fileName) {
|
||||
return from(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static SpigotConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.spigot.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotConfigProvider extends CraftConfigProvider {
|
||||
|
||||
public SpigotConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig() {
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||
if (path == null) {
|
||||
this.configuration.options().setHeader(comments);
|
||||
} else {
|
||||
this.configuration.setComments(path, comments);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||
if (comment == null) {
|
||||
this.configuration.setInlineComments(path, null);
|
||||
} else {
|
||||
this.configuration.setComments(path, Collections.singletonList(comment));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
|
||||
if (path == null) return Collections.unmodifiableList(this.configuration.options().getHeader());
|
||||
else return this.configuration.getComments(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getInlineComment(@NotNull String path) {
|
||||
return String.join(" ", this.configuration.getInlineComments(path));
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,18 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
|
||||
<easyconfiguration.version>3.1.0</easyconfiguration.version>
|
||||
<deps.easyconfifuration.version>3.5.0</deps.easyconfifuration.version>
|
||||
<deps.easyplugin.version>1.5.4</deps.easyplugin.version>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.5.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>common</module>
|
||||
|
||||
<module>platform/bungee</module>
|
||||
<module>platform/bukkit</module>
|
||||
<module>platform/spigot</module>
|
||||
</modules>
|
||||
|
||||
<name>MineConfiguration</name>
|
||||
@@ -39,7 +39,7 @@
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:CarmJos/Easy.MineConfiguration</connection>
|
||||
<connection>scm:git:git@github.com:CarmJos/MineConfiguration</connection>
|
||||
<developerConnection>scm:git:git@github.com:CarmJos/MineConfiguration.git</developerConnection>
|
||||
<url>https://github.com/CarmJos/MineConfiguration</url>
|
||||
<tag>HEAD</tag>
|
||||
@@ -65,9 +65,13 @@
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
@@ -76,13 +80,14 @@
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<id>lumine</id>
|
||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
@@ -103,7 +108,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<version>24.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -116,7 +121,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
@@ -155,7 +160,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>${project.jdk.version}</source>
|
||||
<target>${project.jdk.version}</target>
|
||||
@@ -167,7 +172,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -190,7 +195,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
@@ -219,7 +224,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.4.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
Reference in New Issue
Block a user