mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 7fa6fa1551 | |||
| 346ae4c494 | |||
| 2d8c1817a6 | |||
| f67d0fae8d | |||
| 8d723df7a6 | |||
| d4c7124d9e |
@@ -30,7 +30,7 @@ jobs:
|
|||||||
rm -rf docs
|
rm -rf docs
|
||||||
mkdir -vp docs
|
mkdir -vp docs
|
||||||
cp -vrf target/site/apidocs/* 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"
|
- name: "Generate Sitemap"
|
||||||
id: sitemap
|
id: sitemap
|
||||||
|
|||||||
@@ -20,44 +20,35 @@ EasyConfiguration for MineCraft!
|
|||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
### **MineConfiguration-Common**
|
### **MineConfiguration-Common** [`common`](common)
|
||||||
|
|
||||||
全部版本的共用部分,包括
|
全部版本的共用部分(均已被打包至下行包中),包括
|
||||||
|
|
||||||
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||||
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||||
|
|
||||||
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||||
|
|
||||||
### MineConfiguration-Bukkit
|
### **MineConfiguration-Bukkit** [`platform/bukkit`](platform/bukkit)
|
||||||
|
|
||||||
#### MineConfiguration-Bukkit-Base
|
适用于Bukkit的版本,同时支持其他以Bukkit为基础的服务端 *(如Spigot、Paper、CatServer)* 。
|
||||||
|
|
||||||
Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit-General** 或 **MineConfiguration-Bukkit-Native** 。
|
|
||||||
|
|
||||||
相较于基础版本,额外提供了以下功能:
|
相较于基础版本,额外提供了以下功能:
|
||||||
|
|
||||||
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
||||||
- `ConfiguredItem` (快捷读取简单的物品配置文件)
|
- `ConfiguredItem` (快捷读\写\使用简单的物品配置文件)
|
||||||
- `ConfiguredSound` (快捷读取音效配置文件)
|
- `ConfiguredSound` (快捷读\写\使用音效配置文件)
|
||||||
|
- `ConfiguredTitle` (快速读\写\使用标题文字配置文件)
|
||||||
|
|
||||||
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
||||||
|
|
||||||
#### **MineConfiguration-Bukkit** _(推荐)_
|
### **MineConfiguration-Bungee** [`platform/bungee`](platform/bungee)
|
||||||
|
|
||||||
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
|
||||||
|
|
||||||
#### **MineConfiguration-Spigot**
|
|
||||||
|
|
||||||
适用于 Spigot(1.18+) 的版本,适配了1.18及以后版本Spigot原生自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
|
||||||
|
|
||||||
### **MineConfiguration-Bungee**
|
|
||||||
|
|
||||||
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
|
|
||||||
请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
其他功能请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
||||||
的 [开发介绍](https://github.com/CarmJos/EasyConfiguration/tree/master/.documentation) 。
|
的 [开发介绍](https://github.com/CarmJos/EasyConfiguration/tree/master/.documentation) 。
|
||||||
|
|
||||||
### 依赖方式
|
### 依赖方式
|
||||||
@@ -113,7 +104,7 @@ Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bu
|
|||||||
<version>[LATEST RELEASE]</version>
|
<version>[LATEST RELEASE]</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-spigot</artifactId>
|
<artifactId>mineconfiguration-spigot</artifactId>
|
||||||
|
|||||||
+16
-3
@@ -5,24 +5,37 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.0.0</version>
|
<version>2.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
<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>
|
</properties>
|
||||||
<artifactId>mineconfiguration-common</artifactId>
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Common</name>
|
||||||
|
<description>轻松(做)配置,全部版本的共用部分。</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
<artifactId>easyconfiguration-core</artifactId>
|
||||||
<version>${easyconfiguration.version}</version>
|
<version>${deps.easyconfifuration.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-color</artifactId>
|
||||||
|
<version>${deps.easyplugin.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-chat</artifactId>
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
|||||||
@@ -28,16 +28,14 @@ public abstract class AbstractText<R> {
|
|||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||||
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
return parse(parser, receiver, ParamsUtils.buildParams(params, values));
|
return parse(parser, receiver, ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||||
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
String message = getMessage();
|
return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
|
||||||
if (message.isEmpty()) return null; // No further processing
|
|
||||||
else 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 sender 接收者
|
||||||
|
* @param placeholders 消息中的变量与对应参数
|
||||||
|
* @return 解析变量后的消息内容
|
||||||
|
*/
|
||||||
|
@Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为某位接收者解析此消息。
|
||||||
|
*
|
||||||
|
* @param sender 接收者
|
||||||
|
* @param values 已定变量的对应参数
|
||||||
|
* @return 解析变量后的消息内容
|
||||||
|
*/
|
||||||
|
default @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
||||||
|
return parse(sender, 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+17
-26
@@ -1,10 +1,9 @@
|
|||||||
package cc.carm.lib.mineconfiguration.common.value;
|
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.function.ConfigValueParser;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -15,11 +14,11 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
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 String[] params;
|
||||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
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;
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
@@ -27,44 +26,35 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
|||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull R, @NotNull M> messageConsumer,
|
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
||||||
@NotNull Function<String, T> textBuilder) {
|
@NotNull Function<String, T> textBuilder) {
|
||||||
super(provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
|
super(
|
||||||
|
provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
|
||||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
||||||
);
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.messageParser = messageParser;
|
this.messageParser = messageParser;
|
||||||
this.messageConsumer = messageConsumer;
|
this.sendFunction = sendFunction;
|
||||||
this.textBuilder = textBuilder;
|
this.textBuilder = textBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
@Override
|
||||||
return parse(sender, ParamsUtils.buildParams(params, values));
|
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) {
|
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||||
T value = get();
|
T value = get();
|
||||||
if (value == null || value.getMessage().isEmpty()) return null;
|
if (value == null || value.getMessage().isEmpty()) return null;
|
||||||
else return value.parse(this.messageParser, sender, placeholders);
|
else return value.parse(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) {
|
public void set(@Nullable String value) {
|
||||||
this.set(value == null ? null : buildText(value));
|
this.set(value == null ? null : buildText(value));
|
||||||
}
|
}
|
||||||
@@ -72,4 +62,5 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
|||||||
protected T buildText(String value) {
|
protected T buildText(String value) {
|
||||||
return textBuilder.apply(value);
|
return textBuilder.apply(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-26
@@ -1,10 +1,9 @@
|
|||||||
package cc.carm.lib.mineconfiguration.common.value;
|
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.function.ConfigDataFunction;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -16,7 +15,8 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
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 String[] params;
|
||||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||||
@@ -24,7 +24,6 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
|
|
||||||
protected final @NotNull Function<String, T> textBuilder;
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
@SuppressWarnings("NullableProblems")
|
|
||||||
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
||||||
@@ -41,38 +40,34 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
this.textBuilder = textBuilder;
|
this.textBuilder = textBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable List<M> parse(@Nullable R sender, @Nullable Object... values) {
|
@Override
|
||||||
return parse(sender, ParamsUtils.buildParams(params, values));
|
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();
|
List<T> list = get();
|
||||||
if (list.isEmpty()) return null;
|
if (list.isEmpty()) return null;
|
||||||
|
|
||||||
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
|
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
|
||||||
if (String.join("", messages).isEmpty()) return null;
|
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());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
List<M> parsed = parse(receiver, placeholders);
|
|
||||||
if (parsed == null) return;
|
|
||||||
sendFunction.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 setMessages(@NotNull String... values) {
|
public void setMessages(@NotNull String... values) {
|
||||||
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
||||||
}
|
}
|
||||||
@@ -83,7 +78,6 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
} else {
|
} else {
|
||||||
set(buildText(values));
|
set(buildText(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<T> buildText(List<String> 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.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>
|
|
||||||
</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.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>
|
|
||||||
</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>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.0.0</version>
|
<version>2.4.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
<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>
|
</properties>
|
||||||
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>jar</packaging>
|
||||||
<modules>
|
|
||||||
<module>base</module>
|
|
||||||
<module>general</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
<name>MineConfiguration-Bukkit-Parent</name>
|
<name>MineConfiguration-Bukkit</name>
|
||||||
|
<description>轻松(做)配置,适用于Bukkit系服务端的版本。</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
@@ -35,7 +42,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.1</version>
|
<version>2.11.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -49,4 +56,13 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+1
-1
@@ -25,7 +25,7 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
|||||||
public CraftConfigProvider getBukkitProvider() {
|
public CraftConfigProvider getBukkitProvider() {
|
||||||
ConfigurationProvider<?> provider = getProvider();
|
ConfigurationProvider<?> provider = getProvider();
|
||||||
if (provider instanceof CraftConfigProvider) return (CraftConfigProvider) 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() {
|
public CraftSectionWrapper getBukkitConfig() {
|
||||||
+1
@@ -38,4 +38,5 @@ public class MineConfiguration {
|
|||||||
public static BukkitConfigProvider from(Plugin plugin, String fileName, String source) {
|
public static BukkitConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+25
-5
@@ -5,13 +5,12 @@ import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
|||||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> {
|
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> {
|
||||||
@@ -21,6 +20,9 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
protected String name = null;
|
protected String name = null;
|
||||||
protected List<String> lore = new ArrayList<>();
|
protected List<String> lore = new ArrayList<>();
|
||||||
|
|
||||||
|
protected Map<Enchantment, Integer> enchants = new LinkedHashMap<>();
|
||||||
|
protected Set<ItemFlag> flags = new LinkedHashSet<>();
|
||||||
|
|
||||||
protected @NotNull String[] params = new String[0];
|
protected @NotNull String[] params = new String[0];
|
||||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||||
|
|
||||||
@@ -63,6 +65,24 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ItemConfigBuilder defaultEnchants(@NotNull Map<Enchantment, Integer> enchants) {
|
||||||
|
this.enchants = new LinkedHashMap<>(enchants);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfigBuilder defaultEnchant(@NotNull Enchantment enchant, int level) {
|
||||||
|
return defaultEnchants(Collections.singletonMap(enchant, level));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfigBuilder defaultFlags(@NotNull Set<ItemFlag> flags) {
|
||||||
|
this.flags = new LinkedHashSet<>(flags);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfigBuilder defaultFlags(@NotNull ItemFlag... flags) {
|
||||||
|
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
|
||||||
|
}
|
||||||
|
|
||||||
public ItemConfigBuilder formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
public ItemConfigBuilder formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||||
this.paramFormatter = paramFormatter;
|
this.paramFormatter = paramFormatter;
|
||||||
return getThis();
|
return getThis();
|
||||||
@@ -85,7 +105,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
|||||||
|
|
||||||
protected @Nullable ItemConfig buildDefault() {
|
protected @Nullable ItemConfig buildDefault() {
|
||||||
if (this.type == null) return null;
|
if (this.type == null) return null;
|
||||||
else return new ItemConfig(type, data, name, lore);
|
else return new ItemConfig(type, data, name, lore, enchants, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
+79
-6
@@ -1,15 +1,20 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
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 cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ItemConfig {
|
public class ItemConfig {
|
||||||
|
|
||||||
@@ -18,12 +23,32 @@ public class ItemConfig {
|
|||||||
protected @Nullable String name;
|
protected @Nullable String name;
|
||||||
protected @NotNull List<String> lore;
|
protected @NotNull List<String> lore;
|
||||||
|
|
||||||
|
protected @NotNull Map<Enchantment, Integer> enchants;
|
||||||
|
protected @NotNull Set<ItemFlag> flags;
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, @Nullable String name) {
|
||||||
|
this(type, name, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, @Nullable String name, @NotNull List<String> lore) {
|
||||||
|
this(type, (short) 0, name, lore);
|
||||||
|
}
|
||||||
|
|
||||||
public ItemConfig(@NotNull Material type, short damage,
|
public ItemConfig(@NotNull Material type, short damage,
|
||||||
@Nullable String name, @NotNull List<String> lore) {
|
@Nullable String name, @NotNull List<String> lore) {
|
||||||
|
this(type, damage, name, lore, Collections.emptyMap(), Collections.emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, short damage,
|
||||||
|
@Nullable String name, @NotNull List<String> lore,
|
||||||
|
@NotNull Map<Enchantment, Integer> enchants,
|
||||||
|
@NotNull Set<ItemFlag> flags) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.data = damage;
|
this.data = damage;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
|
this.enchants = enchants;
|
||||||
|
this.flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Material getType() {
|
public @NotNull Material getType() {
|
||||||
@@ -75,6 +100,8 @@ public class ItemConfig {
|
|||||||
if (meta == null) return item;
|
if (meta == null) return item;
|
||||||
Optional.ofNullable(getName(player, placeholders)).ifPresent(meta::setDisplayName);
|
Optional.ofNullable(getName(player, placeholders)).ifPresent(meta::setDisplayName);
|
||||||
Optional.ofNullable(getLore(player, placeholders)).ifPresent(meta::setLore);
|
Optional.ofNullable(getLore(player, placeholders)).ifPresent(meta::setLore);
|
||||||
|
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
|
||||||
|
flags.forEach(meta::addItemFlags);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
@@ -86,20 +113,66 @@ public class ItemConfig {
|
|||||||
if (name != null) map.put("name", name);
|
if (name != null) map.put("name", name);
|
||||||
if (!lore.isEmpty()) map.put("lore", lore);
|
if (!lore.isEmpty()) map.put("lore", lore);
|
||||||
|
|
||||||
|
Map<String, Integer> enchantments = new LinkedHashMap<>();
|
||||||
|
enchants.forEach((enchant, level) -> {
|
||||||
|
if (level > 0) enchantments.put(enchant.getName(), level);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!enchantments.isEmpty()) {
|
||||||
|
map.put("enchants", enchantments);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flags.isEmpty()) {
|
||||||
|
map.put("flags", flags.stream().map(ItemFlag::name).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
return map;
|
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");
|
String typeName = section.getString("type");
|
||||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||||
|
|
||||||
Material type = Material.matchMaterial(typeName);
|
Material type = Material.matchMaterial(typeName);
|
||||||
if (type == null) throw new Exception("Invalid material name: " + typeName);
|
if (type == null) throw new Exception("Invalid material name: " + typeName);
|
||||||
else return new ItemConfig(
|
|
||||||
type, section.getShort("data", (short) 0),
|
short data = section.getShort("data", (short) 0);
|
||||||
section.getString("name"),
|
String name = section.getString("name");
|
||||||
section.getStringList("lore")
|
List<String> lore = section.getStringList("lore");
|
||||||
);
|
|
||||||
|
Map<Enchantment, Integer> enchantments = readEnchantments(section.getConfigurationSection("enchants"));
|
||||||
|
Set<ItemFlag> flags = readFlags(section.getStringList("flags"));
|
||||||
|
|
||||||
|
return new ItemConfig(type, data, name, lore, enchantments, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemFlag parseFlag(String flagName) {
|
||||||
|
return Arrays.stream(ItemFlag.values()).filter(flag -> flag.name().equalsIgnoreCase(flagName)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Set<ItemFlag> readFlags(List<String> flagConfig) {
|
||||||
|
Set<ItemFlag> flags = new LinkedHashSet<>();
|
||||||
|
for (String flagName : flagConfig) {
|
||||||
|
ItemFlag flag = parseFlag(flagName);
|
||||||
|
if (flag != null) flags.add(flag);
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Enchantment, Integer> readEnchantments(ConfigurationWrapper<?> section) {
|
||||||
|
Map<Enchantment, Integer> enchantments = new LinkedHashMap<>();
|
||||||
|
if (section == null) return enchantments;
|
||||||
|
section.getKeys(false).forEach(key -> {
|
||||||
|
Enchantment enchantment = Enchantment.getByName(key);
|
||||||
|
int level = section.getInt(key, 0);
|
||||||
|
if (enchantment != null && level > 0) {
|
||||||
|
enchantments.put(enchantment, level);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return enchantments;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -85,7 +85,7 @@ public class SoundConfig {
|
|||||||
|
|
||||||
@Contract("null -> null")
|
@Contract("null -> null")
|
||||||
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
||||||
if (string == null) return null;
|
if (string == null || string.isEmpty()) return null;
|
||||||
|
|
||||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||||
if (args.length < 1) return null;
|
if (args.length < 1) return null;
|
||||||
+1
-1
@@ -61,7 +61,7 @@ public class TitleConfig {
|
|||||||
return map;
|
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"));
|
return of(section.getString("line1"), section.getString("line2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
+5
-22
@@ -1,10 +1,10 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Unmodifiable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -12,13 +12,12 @@ import java.io.StringWriter;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
public class BukkitConfigProvider extends CraftConfigProvider {
|
||||||
|
|
||||||
protected static final char SEPARATOR = '.';
|
protected static final char SEPARATOR = '.';
|
||||||
|
|
||||||
protected BukkitYAMLComments bukkitComments = new BukkitYAMLComments();
|
protected @NotNull BukkitYAMLComments comments = new BukkitYAMLComments();
|
||||||
|
|
||||||
public BukkitConfigProvider(@NotNull File file) {
|
public BukkitConfigProvider(@NotNull File file) {
|
||||||
super(file);
|
super(file);
|
||||||
@@ -39,7 +38,7 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
|||||||
configuration.save(getFile());
|
configuration.save(getFile());
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
this.bukkitComments.writeComments(configuration, new BufferedWriter(writer));
|
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
||||||
String value = writer.toString(); // config contents
|
String value = writer.toString(); // config contents
|
||||||
|
|
||||||
Path toUpdatePath = getFile().toPath();
|
Path toUpdatePath = getFile().toPath();
|
||||||
@@ -49,24 +48,8 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
public @Nullable ConfigurationComments getComments() {
|
||||||
this.bukkitComments.setHeaderComments(path, comments);
|
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;
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Unmodifiable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.StringJoiner;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class BukkitYAMLComments {
|
public class BukkitYAMLComments extends ConfigurationComments {
|
||||||
|
|
||||||
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 @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||||
List<String> comments = getHeaderComment(path);
|
List<String> comments = getHeaderComment(path);
|
||||||
+17
-16
@@ -10,61 +10,62 @@ import java.util.Map;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
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) {
|
protected CraftSectionWrapper(ConfigurationSection configuration) {
|
||||||
this.section = section;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationSection getSourceSection() {
|
@Override
|
||||||
return section;
|
public @NotNull ConfigurationSection getSource() {
|
||||||
|
return this.configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Set<String> getKeys(boolean deep) {
|
public @NotNull Set<String> getKeys(boolean deep) {
|
||||||
return this.section.getKeys(deep);
|
return this.configuration.getKeys(deep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||||
return this.section.getValues(deep);
|
return this.configuration.getValues(deep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(@NotNull String path, @Nullable Object value) {
|
public void set(@NotNull String path, @Nullable Object value) {
|
||||||
this.section.set(path, value);
|
this.configuration.set(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(@NotNull String path) {
|
public boolean contains(@NotNull String path) {
|
||||||
return this.section.contains(path);
|
return this.configuration.contains(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Object get(@NotNull String path) {
|
public @Nullable Object get(@NotNull String path) {
|
||||||
return this.section.get(path);
|
return this.configuration.get(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isList(@NotNull String path) {
|
public boolean isList(@NotNull String path) {
|
||||||
return this.section.isList(path);
|
return this.configuration.isList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<?> getList(@NotNull String path) {
|
public @Nullable List<?> getList(@NotNull String path) {
|
||||||
return this.section.getList(path);
|
return this.configuration.getList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConfigurationSection(@NotNull String path) {
|
public boolean isConfigurationSection(@NotNull String path) {
|
||||||
return this.section.isConfigurationSection(path);
|
return this.configuration.isConfigurationSection(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
public @Nullable CraftSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||||
return Optional.ofNullable(section.getConfigurationSection(path))
|
return Optional.ofNullable(configuration.getConfigurationSection(path))
|
||||||
.map(CraftSectionWrapper::of).orElse(null);
|
.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.EnumWrappers;
|
||||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ProtocolLibHelper {
|
public class ProtocolLibHelper {
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@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();
|
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
|
||||||
|
|
||||||
if (line1 != null) {
|
if (line1 != null) {
|
||||||
@@ -35,7 +36,6 @@ public class ProtocolLibHelper {
|
|||||||
.write(1, Math.toIntExact(stay))
|
.write(1, Math.toIntExact(stay))
|
||||||
.write(2, Math.toIntExact(fadeOut));
|
.write(2, Math.toIntExact(fadeOut));
|
||||||
pm.sendServerPacket(player, timePacket, false);
|
pm.sendServerPacket(player, timePacket, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
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 cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
+10
-7
@@ -1,13 +1,13 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
|
||||||
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.function.ConfigValueParser;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -33,14 +33,17 @@ public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
|||||||
|
|
||||||
protected final @NotNull String[] params;
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
public ConfiguredItem(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
|
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
|
||||||
super(provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue, getItemParser(), ItemConfig::serialize);
|
super(
|
||||||
|
provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue,
|
||||||
|
getItemParser(), ItemConfig::serialize
|
||||||
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigValueParser<ConfigurationWrapper, ItemConfig> getItemParser() {
|
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
|
||||||
return (s, d) -> ItemConfig.deserialize(s);
|
return (s, d) -> ItemConfig.deserialize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
+9
-7
@@ -1,17 +1,18 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
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.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -43,10 +44,11 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
List<CommandSender> senders = new ArrayList<>();
|
||||||
send(Bukkit.getConsoleSender(), placeholders);
|
senders.add(Bukkit.getConsoleSender());
|
||||||
|
senders.addAll(Bukkit.getOnlinePlayers());
|
||||||
|
return senders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+10
-7
@@ -1,17 +1,18 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -38,9 +39,11 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, C
|
|||||||
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, messages, params, messageParser, sendFunction, TextConfig::of);
|
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, messages, params, messageParser, sendFunction, TextConfig::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
@Override
|
||||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||||
send(Bukkit.getConsoleSender(), placeholders);
|
List<CommandSender> senders = new ArrayList<>();
|
||||||
|
senders.add(Bukkit.getConsoleSender());
|
||||||
|
senders.addAll(Bukkit.getOnlinePlayers());
|
||||||
|
return senders;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+9
-9
@@ -1,14 +1,14 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
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.function.ConfigValueParser;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
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.bukkit.function.TitleSendConsumer;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -87,15 +87,15 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAll(Object... values) {
|
public void sendToAll(Object... values) {
|
||||||
sendAll(this.params, values);
|
sendToAll(this.params, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAll(@NotNull String[] params, @NotNull Object[] values) {
|
public void sendToAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||||
sendAll(ParamsUtils.buildParams(params, 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();
|
TitleConfig config = get();
|
||||||
if (config == null) return;
|
if (config == null) return;
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ConfigValueParser<ConfigurationWrapper, TitleConfig> getTitleParser() {
|
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
|
||||||
return (s, d) -> TitleConfig.deserialize(s);
|
return (s, d) -> TitleConfig.deserialize(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+7
-11
@@ -5,25 +5,28 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>2.0.0</version>
|
<version>2.4.0</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
<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>
|
</properties>
|
||||||
<artifactId>mineconfiguration-bungee</artifactId>
|
<artifactId>mineconfiguration-bungee</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>MineConfiguration-Bungee</name>
|
<name>MineConfiguration-Bungee</name>
|
||||||
|
<description>轻松(做)配置,适用于BungeeCord的版本,可用JSON与YAML格式。</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
<version>${easyconfiguration.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -43,13 +46,6 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>mineconfiguration-common</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+2
-1
@@ -1,14 +1,15 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
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 net.md_5.bungee.api.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+6
-22
@@ -1,13 +1,13 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.source;
|
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Unmodifiable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -16,7 +16,6 @@ import java.io.StringWriter;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
||||||
|
|
||||||
@@ -52,6 +51,11 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
|||||||
this.configuration = getLoader().load(file);
|
this.configuration = getLoader().load(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigurationComments getComments() {
|
||||||
|
return this.comments;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws Exception {
|
public void save() throws Exception {
|
||||||
getLoader().save(configuration, file);
|
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
|
@Override
|
||||||
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
||||||
return this.initializer;
|
return this.initializer;
|
||||||
|
|||||||
+17
-12
@@ -11,12 +11,12 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
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) {
|
private BungeeSectionWrapper(@NotNull Configuration section) {
|
||||||
this.section = section;
|
this.configuration = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("!null->!null")
|
@Contract("!null->!null")
|
||||||
@@ -37,34 +37,39 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
|||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Configuration getSource() {
|
||||||
|
return this.configuration;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Set<String> getKeys(boolean deep) {
|
public @NotNull Set<String> getKeys(boolean deep) {
|
||||||
if (deep) {
|
if (deep) {
|
||||||
return new LinkedHashSet<>(getAllKeys(section));
|
return new LinkedHashSet<>(getAllKeys(configuration));
|
||||||
} else {
|
} else {
|
||||||
return new LinkedHashSet<>(section.getKeys());
|
return new LinkedHashSet<>(configuration.getKeys());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||||
return getKeys(deep).stream()
|
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
|
@Override
|
||||||
public void set(@NotNull String path, @Nullable Object value) {
|
public void set(@NotNull String path, @Nullable Object value) {
|
||||||
this.section.set(path, value);
|
this.configuration.set(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(@NotNull String path) {
|
public boolean contains(@NotNull String path) {
|
||||||
return this.section.contains(path);
|
return this.configuration.contains(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Object get(@NotNull String path) {
|
public @Nullable Object get(@NotNull String path) {
|
||||||
return this.section.get(path);
|
return this.configuration.get(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,7 +79,7 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<?> getList(@NotNull String path) {
|
public @Nullable List<?> getList(@NotNull String path) {
|
||||||
return this.section.getList(path);
|
return this.configuration.getList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,7 +88,7 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
public @Nullable BungeeSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||||
return of(this.section.getSection(path));
|
return of(this.configuration.getSection(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-42
@@ -1,60 +1,23 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.source;
|
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.Configuration;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.Unmodifiable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
import java.util.StringJoiner;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
||||||
|
|
||||||
public class BungeeYAMLComments {
|
public class BungeeYAMLComments extends ConfigurationComments {
|
||||||
|
|
||||||
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 @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||||
List<String> comments = getHeaderComment(path);
|
List<String> comments = getHeaderComment(path);
|
||||||
@@ -144,7 +107,7 @@ public class BungeeYAMLComments {
|
|||||||
* @param key 键
|
* @param key 键
|
||||||
* @return 该键的缩进文本
|
* @return 该键的缩进文本
|
||||||
*/
|
*/
|
||||||
protected static String getIndents(String key) {
|
protected static String getIndents(@NotNull String key) {
|
||||||
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
||||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-5
@@ -1,17 +1,18 @@
|
|||||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
|
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
|
||||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
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.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -43,9 +44,11 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||||
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
List<CommandSender> senders = new ArrayList<>();
|
||||||
send(ProxyServer.getInstance().getConsole(), placeholders);
|
senders.add(ProxyServer.getInstance().getConsole());
|
||||||
|
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||||
|
return senders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -10,6 +10,8 @@ import net.md_5.bungee.api.ProxyServer;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@@ -38,9 +40,11 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
|
|||||||
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
@Override
|
||||||
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||||
send(ProxyServer.getInstance().getConsole(), placeholders);
|
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.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>
|
|
||||||
</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>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
<easyconfiguration.version>3.1.0</easyconfiguration.version>
|
<deps.easyconfifuration.version>3.4.0</deps.easyconfifuration.version>
|
||||||
|
<deps.easyplugin.version>1.5.2</deps.easyplugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.4.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>common</module>
|
<module>common</module>
|
||||||
|
|
||||||
<module>platform/bungee</module>
|
<module>platform/bungee</module>
|
||||||
<module>platform/bukkit</module>
|
<module>platform/bukkit</module>
|
||||||
<module>platform/spigot</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>MineConfiguration</name>
|
<name>MineConfiguration</name>
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<scm>
|
<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>
|
<developerConnection>scm:git:git@github.com:CarmJos/MineConfiguration.git</developerConnection>
|
||||||
<url>https://github.com/CarmJos/MineConfiguration</url>
|
<url>https://github.com/CarmJos/MineConfiguration</url>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
@@ -65,9 +65,13 @@
|
|||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>carm-repo</id>
|
<id>central</id>
|
||||||
<name>Carm's Repo</name>
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
@@ -76,13 +80,14 @@
|
|||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>nexus</id>
|
<id>lumine</id>
|
||||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>carm-repo</id>
|
||||||
<url>https://repo1.maven.org/maven2/</url>
|
<name>Carm's Repo</name>
|
||||||
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
@@ -103,7 +108,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>23.0.0</version>
|
<version>24.0.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -167,7 +172,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.3.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@@ -190,7 +195,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.5.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
@@ -219,7 +224,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.4.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
|||||||
Reference in New Issue
Block a user