mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47d7b17082 | |||
| 0663f3d117 | |||
| 1947ba1899 | |||
| 2e4de9880f | |||
| 398bc773d6 | |||
| 1396c6bd6e | |||
| 2959c00795 | |||
| 09537975e4 | |||
| 02625b5c0c | |||
| bb9e24dd96 | |||
| 5bdc5908ef | |||
| dde304625e | |||
| 24ef0b6dcd | |||
| a1d6cf1258 | |||
| 0f7fc39f87 | |||
| 92ecb55a95 | |||
| bfd1624e85 | |||
| 01d3c245a9 | |||
| 8721c6085f | |||
| eca4d47b8f | |||
| 3750ac7d58 | |||
| d3bdc4ad60 | |||
| 6bb6fb1b95 | |||
| dd2499512c | |||
| 3aa0542f01 | |||
| 4d9d5f5d84 | |||
| 2b31ee1318 | |||
| 9d6212e5ea | |||
| 8f3d574446 | |||
| 437e1d6d61 | |||
| a04b7c9c06 | |||
| 74e88a126c | |||
| 79a65a94bc | |||
| 6ba08f7a67 | |||
| 166b9fa0a8 | |||
| 6257cdd114 | |||
| c28ee7d57b | |||
| 3d1639362b | |||
| ce205e10fe | |||
| 8e4e712936 | |||
| c3d9c65a86 | |||
| ebddeff78d | |||
| afcdc2c378 | |||
| 5905b25c73 | |||
| 31f51c9b96 | |||
| eb8f279e0b | |||
| e291c3a109 | |||
| 433f780608 | |||
| 385f6dd22f | |||
| 04168d4d12 | |||
| 143e0c2283 | |||
| 4b4f90ee38 | |||
| 97d24c7027 | |||
| d1b01ffed5 | |||
| 67931094e6 |
@@ -22,7 +22,7 @@ jobs:
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
# cache: maven # Say 4uck u to github cache services.
|
||||
server-id: github
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
# cache: maven # Say 4uck u to github cache services.
|
||||
server-id: ossrh
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_PASSWORD
|
||||
|
||||
@@ -20,44 +20,35 @@ EasyConfiguration for MineCraft!
|
||||
|
||||
## 项目结构
|
||||
|
||||
### **MineConfiguration-Common**
|
||||
### **MineConfiguration-Common** [`common`](common)
|
||||
|
||||
全部版本的共用部分,包括
|
||||
全部版本的共用部分(均已被打包至下行包中),包括
|
||||
|
||||
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||
|
||||
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||
|
||||
### MineConfiguration-Bukkit
|
||||
### **MineConfiguration-Bukkit** [`platform/bukkit`](platform/bukkit)
|
||||
|
||||
#### MineConfiguration-Bukkit-Base
|
||||
|
||||
Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit-General** 或 **MineConfiguration-Bukkit-Native** 。
|
||||
适用于Bukkit的版本,同时支持其他以Bukkit为基础的服务端 *(如Spigot、Paper、CatServer)* 。
|
||||
|
||||
相较于基础版本,额外提供了以下功能:
|
||||
|
||||
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
||||
- `ConfiguredItem` (快捷读取简单的物品配置文件)
|
||||
- `ConfiguredSound` (快捷读取音效配置文件)
|
||||
- `ConfiguredItem` (快捷读\写\使用简单的物品配置文件)
|
||||
- `ConfiguredSound` (快捷读\写\使用音效配置文件)
|
||||
- `ConfiguredTitle` (快速读\写\使用标题文字配置文件)
|
||||
|
||||
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
||||
|
||||
#### **MineConfiguration-Bukkit** _(推荐)_
|
||||
|
||||
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
||||
|
||||
#### **MineConfiguration-Spigot**
|
||||
|
||||
适用于 Spigot(1.18+) 的版本,适配了1.18及以后版本Spigot原生自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
||||
|
||||
### **MineConfiguration-Bungee**
|
||||
### **MineConfiguration-Bungee** [`platform/bungee`](platform/bungee)
|
||||
|
||||
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
||||
|
||||
## 开发
|
||||
|
||||
请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
||||
其他功能请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
||||
的 [开发介绍](https://github.com/CarmJos/EasyConfiguration/tree/master/.documentation) 。
|
||||
|
||||
### 依赖方式
|
||||
@@ -113,7 +104,7 @@ Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bu
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-spigot</artifactId>
|
||||
|
||||
+14
-2
@@ -5,15 +5,20 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.8.6</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
|
||||
<name>MineConfiguration-Common</name>
|
||||
<description>轻松(做)配置,全部版本的共用部分。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
@@ -23,11 +28,18 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-color</artifactId>
|
||||
<version>${deps.easyplugin.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.16-R0.4</version>
|
||||
<version>1.20-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package cc.carm.lib.mineconfiguration.common;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class AbstractConfiguration<P extends ConfigurationProvider<?>> {
|
||||
|
||||
private final P configProvider;
|
||||
private final P messageProvider;
|
||||
|
||||
protected AbstractConfiguration(@NotNull P configProvider, @NotNull P messageProvider) {
|
||||
this.configProvider = configProvider;
|
||||
this.messageProvider = messageProvider;
|
||||
}
|
||||
|
||||
public void initializeConfig(@NotNull ConfigurationRoot configRoot) {
|
||||
this.configProvider.initialize(configRoot);
|
||||
}
|
||||
|
||||
public void initializeMessage(@NotNull ConfigurationRoot messageRoot) {
|
||||
this.messageProvider.initialize(messageRoot);
|
||||
}
|
||||
|
||||
public void initializeConfig(@NotNull Class<? extends ConfigurationRoot> configRoot) {
|
||||
this.configProvider.initialize(configRoot);
|
||||
}
|
||||
|
||||
public void initializeMessage(@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||
this.messageProvider.initialize(messageRoot);
|
||||
}
|
||||
|
||||
public P getConfigProvider() {
|
||||
return configProvider;
|
||||
}
|
||||
|
||||
public P getMessageProvider() {
|
||||
return messageProvider;
|
||||
}
|
||||
|
||||
public void reload() throws Exception {
|
||||
getConfigProvider().reload();
|
||||
getMessageProvider().reload();
|
||||
}
|
||||
|
||||
public void save() throws Exception {
|
||||
getConfigProvider().save();
|
||||
getMessageProvider().save();
|
||||
}
|
||||
|
||||
}
|
||||
+10
-1
@@ -1,16 +1,18 @@
|
||||
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -67,4 +69,11 @@ public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B exte
|
||||
@Override
|
||||
public abstract @NotNull ConfigMessageList<M, T, R> build();
|
||||
|
||||
protected @NotNull ValueManifest<List<T>> buildManifest(@NotNull List<T> emptyValue) {
|
||||
return new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(emptyValue)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,13 +1,15 @@
|
||||
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -64,4 +66,10 @@ public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B ext
|
||||
@Override
|
||||
public abstract @NotNull ConfigMessage<M, T, R> build();
|
||||
|
||||
protected @NotNull ValueManifest<T> buildManifest(@NotNull T emptyValue) {
|
||||
return new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(emptyValue)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.common.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* 颜色解析器,来自EasyPlugin项目。
|
||||
* <br> 普通颜色 格式 {@code &+颜色代码 },如 {@literal &c} 、{@literal &a}
|
||||
* <br> RGB颜色(版本需要≥1.14) 格式 {@code &(#XXXXXX) },如 {@literal &(#aaaaaa)}
|
||||
* <br> 渐变RBG颜色(版本需要≥1.14) 格式 {@code &<#XXXXXX>FOOBAR&<#XXXXXX> }
|
||||
* <p> 注意:当使用渐变RGB颜色时,普通颜色代码与RGB颜色代码将失效。
|
||||
*
|
||||
* @author CarmJos
|
||||
* @since 1.4.18
|
||||
*/
|
||||
public class ColorParser {
|
||||
|
||||
public static final Pattern HEX_PATTERN = Pattern.compile("&\\(&?#([\\da-fA-F]{6})\\)");
|
||||
public static final Pattern GRADIENT_PATTERN = Pattern.compile("&<&?#([\\da-fA-F]{6})>");
|
||||
public static final Pattern COLOR_PATTERN = Pattern.compile("([&§][0-9a-fA-FrRxX])+"); // 会影响颜色的代码
|
||||
public static final Pattern FORMAT_PATTERN = Pattern.compile("([&§][0-9a-fA-Fk-oK-OrRxX])+"); // MC可用的格式化代码
|
||||
|
||||
/**
|
||||
* 清除一条消息中的全部颜色代码 (包括RGB颜色代码与渐变颜色代码)
|
||||
*
|
||||
* @param text 源消息内容
|
||||
* @return 清理颜色后的消息
|
||||
*/
|
||||
public static @NotNull String clear(@NotNull String text) {
|
||||
text = HEX_PATTERN.matcher(text).replaceAll("");
|
||||
text = GRADIENT_PATTERN.matcher(text).replaceAll("");
|
||||
text = COLOR_PATTERN.matcher(text).replaceAll("");
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对一条消息进行颜色解析,包括普通颜色代码、RGB颜色代码与RBG渐变代码。
|
||||
*
|
||||
* @param text 源消息内容
|
||||
* @return 解析后的消息
|
||||
*/
|
||||
public static @NotNull String parse(@NotNull String text) {
|
||||
return parseBaseColor(parseGradientColor(parseHexColor(text)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 对多条消息进行颜色解析,包括普通颜色代码、RGB颜色代码与RBG渐变代码。
|
||||
*
|
||||
* @param texts 源消息内容
|
||||
* @return 解析后的消息
|
||||
*/
|
||||
public static @NotNull String[] parse(@NotNull String... texts) {
|
||||
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对多条消息进行颜色解析,包括普通颜色代码、RGB颜色代码与RBG渐变代码。
|
||||
*
|
||||
* @param texts 源消息内容
|
||||
* @return 解析后的消息
|
||||
*/
|
||||
public static @NotNull List<String> parse(@NotNull Collection<String> texts) {
|
||||
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析消息中的基本颜色代码格式 {@code &+颜色代码 },如 {@literal &c} 、{@literal &a}
|
||||
*
|
||||
* @param text 消息内容
|
||||
* @return RGB处理后的消息
|
||||
* @see net.md_5.bungee.api.ChatColor
|
||||
*/
|
||||
public static String parseBaseColor(final String text) {
|
||||
return text.replaceAll("&", "§").replace("§§", "&");
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析消息中的RGB颜色代码(版本需要≥1.14) 格式 {@code &(#XXXXXX) },如 {@literal &(#aaaaaa)}
|
||||
*
|
||||
* @param text 消息内容
|
||||
* @return RGB处理后的消息
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对一条消息进行RGB渐变处理(版本需要≥1.14),格式 {@code &<#XXXXXX>FOOBAR&<#XXXXXX> }。
|
||||
*
|
||||
* @param text 消息内容
|
||||
* @return RGB渐变处理后的消息
|
||||
*/
|
||||
public static @NotNull String parseGradientColor(@NotNull String text) {
|
||||
List<String> colors = new ArrayList<>();
|
||||
|
||||
Matcher matcher = ColorParser.GRADIENT_PATTERN.matcher(text);
|
||||
while (matcher.find()) colors.add(matcher.group(1));
|
||||
|
||||
if (colors.isEmpty()) return text; // 无渐变颜色,直接跳出
|
||||
|
||||
String[] parts = ColorParser.GRADIENT_PATTERN.split(text);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String startHex = i - 1 >= 0 && colors.size() > i - 1 ? colors.get(i - 1) : null; // 本条消息的起始颜色
|
||||
String endHex = colors.size() > i ? colors.get(i) : null; // 本条消息的结束颜色
|
||||
builder.append(gradientText(parts[i], startHex, endHex));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static @NotNull String gradientText(@NotNull String text,
|
||||
@Nullable Color startColor, @Nullable Color endColor) {
|
||||
Objects.requireNonNull(text, "Text to be gradient should not be null!");
|
||||
if (startColor == null || endColor == null || text.isEmpty()) {
|
||||
// 起始颜色有任一为空,则不进行渐变上色。
|
||||
// 若有起始颜色,则代表其跟在某个渐变之后,应当添加"&r"阻断前面的渐变。
|
||||
return (startColor != null ? "&r" : "") + text;
|
||||
}
|
||||
|
||||
// 用于记录消息中特殊格式的位置
|
||||
// 在渐变中,允许使用格式字符与颜色字符来改变其中某个字的颜色/格式,以支持更多形式内容。
|
||||
LinkedHashMap<Integer, String> extraFormats = new LinkedHashMap<>();
|
||||
Matcher matcher = ColorParser.FORMAT_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
extraFormats.put(matcher.start(), matcher.group());
|
||||
text = matcher.replaceFirst("");
|
||||
matcher.reset(text);
|
||||
}
|
||||
|
||||
if (text.length() == 1) {
|
||||
// 当只有一个实际字符时,无需进行渐变计算,直接返回 中间颜色+起始格式(如果有)+消息 即可。
|
||||
return colorText(text, extraFormats.get(0), buildHexColor(mediumHex(startColor, endColor)));
|
||||
}
|
||||
|
||||
String[] characters = text.split("");
|
||||
int step = characters.length; // 变换次数
|
||||
|
||||
// 决定每种颜色变换的方向
|
||||
int rDirection = startColor.getRed() < endColor.getRed() ? 1 : -1;
|
||||
int gDirection = startColor.getGreen() < endColor.getGreen() ? 1 : -1;
|
||||
int bDirection = startColor.getBlue() < endColor.getBlue() ? 1 : -1;
|
||||
|
||||
// 决定每种颜色每次变换的度
|
||||
int rStep = Math.abs(startColor.getRed() - endColor.getRed()) / (step - 1);
|
||||
int gStep = Math.abs(startColor.getGreen() - endColor.getGreen()) / (step - 1);
|
||||
int bStep = Math.abs(startColor.getBlue() - endColor.getBlue()) / (step - 1);
|
||||
|
||||
String[] hexes = IntStream.range(0, step).mapToObj(i -> colorToHex(
|
||||
startColor.getRed() + rStep * i * rDirection,
|
||||
startColor.getGreen() + gStep * i * gDirection,
|
||||
startColor.getBlue() + bStep * i * bDirection
|
||||
)).toArray(String[]::new);
|
||||
|
||||
return IntStream.range(0, characters.length)
|
||||
.mapToObj(i -> colorText(characters[i], extraFormats.get(i), buildHexColor(hexes[i])))
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
|
||||
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
|
||||
return gradientText(text,
|
||||
startHex == null ? null : Color.decode("0x" + startHex),
|
||||
endHex == null ? null : Color.decode("0x" + endHex)
|
||||
);
|
||||
}
|
||||
|
||||
private static String mediumHex(@NotNull Color start, @NotNull Color end) {
|
||||
return colorToHex(
|
||||
Math.abs(start.getRed() - end.getRed()) / 2,
|
||||
Math.abs(start.getGreen() - end.getGreen()) / 2,
|
||||
Math.abs(start.getBlue() - end.getBlue()) / 2
|
||||
);
|
||||
}
|
||||
|
||||
private static String colorText(String message, @Nullable String format, @Nullable String color) {
|
||||
if (format != null && COLOR_PATTERN.matcher(format).find()) {
|
||||
// format中存在影响颜色的内容,则当前消息的颜色会被覆盖。
|
||||
// 为了减少最终消息的长度,故直接返回键入的FORMAT和对应消息的内容。
|
||||
return format + message;
|
||||
}
|
||||
return (color == null ? "" : color) + (format == null ? "" : parseBaseColor(format)) + message;
|
||||
}
|
||||
|
||||
protected static String colorToHex(Color color) {
|
||||
return colorToHex(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
protected static String colorToHex(int r, int g, int b) {
|
||||
// 将R、G、B转换为16进制(若非2位则补0)输出
|
||||
return String.format("%02X%02X%02X", r, g, b);
|
||||
}
|
||||
|
||||
protected static String buildHexColor(String hexCode) {
|
||||
return Arrays.stream(hexCode.split("")).map(s -> '§' + s)
|
||||
.collect(Collectors.joining("", '§' + "x", ""));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,23 +39,33 @@ public interface BaseMessage<R, M> {
|
||||
void apply(@NotNull R receiver, @NotNull M message);
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
* 填入变量值,返回一个准备好待发送的消息。
|
||||
*
|
||||
* @param sender 接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
* @param values 变量值
|
||||
* @return 准备好待发送的消息
|
||||
*/
|
||||
@Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders);
|
||||
default @NotNull PreparedMessage<R, M> prepare(@NotNull Object... values) {
|
||||
return new PreparedMessage<>(this, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param sender 接收者
|
||||
* @param values 已定变量的对应参数
|
||||
* @param receiver 接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
default @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
||||
return parse(sender, ParamsUtils.buildParams(getParams(), values));
|
||||
@Nullable M parse(@Nullable R receiver, @NotNull Map<String, Object> placeholders);
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param values 已定变量的对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
default @Nullable M parse(@Nullable R receiver, @Nullable Object... values) {
|
||||
return parse(receiver, ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +116,26 @@ public interface BaseMessage<R, M> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param values 已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToAll(@Nullable Object... values) {
|
||||
broadcast(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void sendToAll(@NotNull Map<String, Object> placeholders) {
|
||||
broadcast(placeholders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
|
||||
+44
-11
@@ -1,13 +1,13 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -22,15 +22,15 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
public ConfigMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
||||
public ConfigMessage(@NotNull ValueManifest<T> manifest,
|
||||
@NotNull Class<T> textClazz, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
||||
@NotNull Function<String, T> textBuilder) {
|
||||
super(
|
||||
provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
|
||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
||||
manifest, textClazz,
|
||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)),
|
||||
AbstractText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
@@ -48,11 +48,20 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
sendFunction.accept(receiver, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||
protected <N> @Nullable N parseTo(@Nullable R sender, @NotNull Map<String, Object> placeholders,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable N> parser) {
|
||||
T value = get();
|
||||
if (value == null || value.getMessage().isEmpty()) return null;
|
||||
else return value.parse(this.messageParser, sender, placeholders);
|
||||
else return value.parse(parser, sender, placeholders);
|
||||
}
|
||||
|
||||
public @Nullable String parseString(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||
return parseTo(sender, placeholders, (r, s) -> s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||
return parseTo(sender, placeholders, this.messageParser);
|
||||
}
|
||||
|
||||
public void set(@Nullable String value) {
|
||||
@@ -62,5 +71,29 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
protected T buildText(String value) {
|
||||
return textBuilder.apply(value);
|
||||
}
|
||||
|
||||
|
||||
public abstract class PreparedMessage<P, N> {
|
||||
|
||||
protected final @NotNull Object[] values;
|
||||
|
||||
protected PreparedMessage(@NotNull Object[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public Object[] getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public abstract void to(P receiver);
|
||||
|
||||
public void to(Collection<P> receivers) {
|
||||
receivers.forEach(this::to);
|
||||
}
|
||||
|
||||
public N get(P receiver) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-7
@@ -1,9 +1,10 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,15 +25,15 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
||||
public ConfigMessageList(@NotNull ValueManifest<List<T>> manifest,
|
||||
@NotNull Class<T> textClazz, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
||||
@NotNull Function<String, @NotNull T> textBuilder) {
|
||||
super(
|
||||
provider, sectionPath, headerComments, inlineComments, textClazz, messages,
|
||||
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
|
||||
manifest, textClazz,
|
||||
ConfigDataFunction.castToString().andThen(textBuilder::apply),
|
||||
AbstractText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
@@ -68,12 +69,33 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Object... values) {
|
||||
return parseToLine(receiver, "\n", ParamsUtils.buildParams(this.params, values));
|
||||
}
|
||||
|
||||
public @Nullable M parseToLine(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
return parseToLine(receiver, "\n", placeholders);
|
||||
}
|
||||
|
||||
public @Nullable M parseToLine(@Nullable R receiver, @NotNull String delimiter, @NotNull Map<String, Object> placeholders) {
|
||||
List<T> list = get();
|
||||
if (list.isEmpty()) return null;
|
||||
|
||||
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
|
||||
if (String.join("", messages).isEmpty()) return null;
|
||||
|
||||
String combined = String.join(delimiter, messages);
|
||||
T text = textBuilder.apply(combined);
|
||||
|
||||
return text.parse(this.messageParser, receiver, placeholders);
|
||||
}
|
||||
|
||||
public void setMessages(@NotNull String... values) {
|
||||
setMessages(values.length == 0 ? null : Arrays.asList(values));
|
||||
}
|
||||
|
||||
public void setMessages(@Nullable List<String> values) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
if (values == null) {
|
||||
set(null);
|
||||
} else {
|
||||
set(buildText(values));
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PreparedMessage<R, M> {
|
||||
|
||||
protected final @NotNull BaseMessage<R, M> message;
|
||||
protected final @NotNull Object[] values;
|
||||
|
||||
protected PreparedMessage(@NotNull BaseMessage<R, M> message, @NotNull Object[] values) {
|
||||
this.message = message;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
public @Nullable M parse(@Nullable R receiver) {
|
||||
return message.parse(receiver, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
*/
|
||||
public void to(@Nullable R receiver) {
|
||||
message.send(receiver, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receivers 消息的接收者们
|
||||
*/
|
||||
public void to(@NotNull Iterable<R> receivers) {
|
||||
receivers.forEach(this::to);
|
||||
}
|
||||
|
||||
public void toAll() {
|
||||
to(message.getAllReceivers());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.2.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
-178
@@ -1,178 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemConfig {
|
||||
|
||||
protected @NotNull Material type;
|
||||
protected short data;
|
||||
protected @Nullable String name;
|
||||
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,
|
||||
@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.data = damage;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
this.enchants = enchants;
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public @NotNull Material getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public short getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public @Nullable String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @Nullable String getName(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
return Optional.ofNullable(getName())
|
||||
.map(name -> TextParser.parseText(player, name, placeholders))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public @NotNull List<String> getLore() {
|
||||
return lore;
|
||||
}
|
||||
|
||||
public @Nullable List<String> getLore(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
if (getLore().isEmpty()) return null;
|
||||
else return TextParser.parseList(player, getLore(), placeholders);
|
||||
}
|
||||
|
||||
public final @NotNull ItemStack getItemStack() {
|
||||
return getItemStack(1);
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(int amount) {
|
||||
return getItemStack(null, amount, new HashMap<>());
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(@Nullable Player player) {
|
||||
return getItemStack(player, new HashMap<>());
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||
return getItemStack(player, 1, placeholders);
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
|
||||
ItemStack item = new ItemStack(type, amount, data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
Optional.ofNullable(getName(player, placeholders)).ifPresent(meta::setDisplayName);
|
||||
Optional.ofNullable(getLore(player, placeholders)).ifPresent(meta::setLore);
|
||||
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
|
||||
flags.forEach(meta::addItemFlags);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("type", type.name());
|
||||
if (this.data != 0) map.put("data", data);
|
||||
if (name != null) map.put("name", name);
|
||||
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;
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationSection section) throws Exception {
|
||||
return deserialize(CraftSectionWrapper.of(section));
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper<?> section) throws Exception {
|
||||
String typeName = section.getString("type");
|
||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
||||
|
||||
Material type = Material.matchMaterial(typeName);
|
||||
if (type == null) throw new Exception("Invalid material name: " + typeName);
|
||||
|
||||
short data = section.getShort("data", (short) 0);
|
||||
String name = section.getString("name");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TitleConfig {
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2) {
|
||||
return of(
|
||||
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
|
||||
Optional.ofNullable(line2).map(TextConfig::of).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||
return new TitleConfig(line1, line2);
|
||||
}
|
||||
|
||||
protected @Nullable TextConfig line1;
|
||||
protected @Nullable TextConfig line2;
|
||||
|
||||
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||
this.line1 = line1;
|
||||
this.line2 = line2;
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Long.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Long.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Long.MAX_VALUE) int fadeOut,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@Nullable TitleSendConsumer sendConsumer) {
|
||||
if (this.line1 == null && this.line2 == null) return;
|
||||
if (sendConsumer == null) return;
|
||||
sendConsumer.send(
|
||||
player, fadeIn, stay, fadeOut,
|
||||
parseLine(this.line1, player, placeholders),
|
||||
parseLine(this.line2, player, placeholders)
|
||||
);
|
||||
}
|
||||
|
||||
protected @NotNull String parseLine(@Nullable TextConfig text,
|
||||
@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||
if (text == null) return "";
|
||||
else return TextParser.parseText(player, text.getMessage(), placeholders);
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
if (this.line1 != null) map.put("line1", this.line1.getMessage());
|
||||
if (this.line2 != null) map.put("line2", this.line2.getMessage());
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
|
||||
return of(section.getString("line1"), section.getString("line2"));
|
||||
}
|
||||
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.function;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TitleSendConsumer {
|
||||
|
||||
/**
|
||||
* 向目标玩家发送标题文字
|
||||
*
|
||||
* @param player 目标玩家
|
||||
* @param fadeIn 淡入时间 (ticks)
|
||||
* @param stay 保留时间 (ticks)
|
||||
* @param fadeOut 淡出时间 (ticks)
|
||||
* @param line1 第一行文字
|
||||
* @param line2 第二行文字
|
||||
*/
|
||||
void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||
@NotNull String line1, @NotNull String line2);
|
||||
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ProtocolLibHelper {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void sendTitle(@NotNull Player player, long fadeIn, long stay, long fadeOut, String line1, String line2) throws Exception {
|
||||
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
if (line1 != null) {
|
||||
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
|
||||
packet.getTitleActions().write(0, EnumWrappers.TitleAction.TITLE);
|
||||
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line1));
|
||||
pm.sendServerPacket(player, packet, false);
|
||||
}
|
||||
|
||||
if (line2 != null) {
|
||||
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
|
||||
packet.getTitleActions().write(0, EnumWrappers.TitleAction.SUBTITLE);
|
||||
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line2));
|
||||
pm.sendServerPacket(player, packet, false);
|
||||
}
|
||||
|
||||
PacketContainer timePacket = pm.createPacket(PacketType.Play.Server.TITLE);
|
||||
timePacket.getTitleActions().write(0, EnumWrappers.TitleAction.TIMES);
|
||||
timePacket.getIntegers()
|
||||
.write(0, Math.toIntExact(fadeIn))
|
||||
.write(1, Math.toIntExact(stay))
|
||||
.write(2, Math.toIntExact(fadeOut));
|
||||
pm.sendServerPacket(player, timePacket, false);
|
||||
}
|
||||
|
||||
}
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
||||
|
||||
public static ItemConfigBuilder create() {
|
||||
return CraftConfigValue.builder().createItem();
|
||||
}
|
||||
|
||||
public static ConfiguredItem of() {
|
||||
return CraftConfigValue.builder().ofItem();
|
||||
}
|
||||
|
||||
public static ConfiguredItem of(@Nullable ItemConfig defaultItem) {
|
||||
return CraftConfigValue.builder().ofItem(defaultItem);
|
||||
}
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
|
||||
public ConfiguredItem(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
|
||||
super(
|
||||
provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue,
|
||||
getItemParser(), ItemConfig::serialize
|
||||
);
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public static ConfigValueParser<ConfigurationWrapper<?>, ItemConfig> getItemParser() {
|
||||
return (s, d) -> ItemConfig.deserialize(s);
|
||||
}
|
||||
|
||||
public @NotNull String[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public @Nullable ItemStack getItem(@Nullable Player player) {
|
||||
return getItem(player, 1);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount) {
|
||||
return getItem(player, amount, new HashMap<>());
|
||||
}
|
||||
|
||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Object... values) {
|
||||
return getItem(player, amount, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull String[] params, @NotNull Object[] values) {
|
||||
return getItem(player, amount, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
|
||||
return getOptional().map(item -> item.getItemStack(player, amount, placeholders)).orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +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.2.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bukkit</name>
|
||||
|
||||
<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>
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
protected @NotNull BukkitYAMLComments comments = new BukkitYAMLComments();
|
||||
|
||||
public BukkitConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
public void initializeConfig() {
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CraftSectionWrapper getConfiguration() {
|
||||
return CraftSectionWrapper.of(this.configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
configuration.save(getFile());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
||||
String value = writer.toString(); // config contents
|
||||
|
||||
Path toUpdatePath = getFile().toPath();
|
||||
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
||||
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
}
|
||||
-108
@@ -1,108 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitYAMLComments extends ConfigurationComments {
|
||||
|
||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||
List<String> comments = getHeaderComment(path);
|
||||
if (comments == null || comments.size() == 0) return null;
|
||||
|
||||
StringJoiner joiner = new StringJoiner("\n");
|
||||
for (String comment : comments) {
|
||||
if (comment.length() == 0) joiner.add(" ");
|
||||
else joiner.add(indents + "# " + comment);
|
||||
}
|
||||
return joiner + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* 从一个文件读取配置并写入注释到某个写入器中。
|
||||
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
||||
*
|
||||
* @param source 源配置文件
|
||||
* @param writer 配置写入器
|
||||
* @throws IOException 当写入发生错误时抛出
|
||||
*/
|
||||
public void writeComments(@NotNull YamlConfiguration source, @NotNull BufferedWriter writer) throws IOException {
|
||||
FileConfiguration temp = new YamlConfiguration(); // 该对象用于临时记录配置内容
|
||||
|
||||
String configHeader = buildHeaderComments(null, "");
|
||||
if (configHeader != null) writer.write(configHeader);
|
||||
|
||||
for (String fullKey : source.getKeys(true)) {
|
||||
Object currentValue = source.get(fullKey);
|
||||
|
||||
String indents = getIndents(fullKey);
|
||||
String headerComments = buildHeaderComments(fullKey, indents);
|
||||
String inlineComment = getInlineComment(fullKey);
|
||||
|
||||
if (headerComments != null) writer.write(headerComments);
|
||||
|
||||
String[] splitFullKey = fullKey.split("[" + CraftConfigProvider.SEPARATOR + "]");
|
||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
||||
|
||||
if (currentValue instanceof ConfigurationSection) {
|
||||
ConfigurationSection section = (ConfigurationSection) currentValue;
|
||||
writer.write(indents + trailingKey + ":");
|
||||
if (inlineComment != null && inlineComment.length() > 0) {
|
||||
writer.write(" # " + inlineComment);
|
||||
}
|
||||
if (!section.getKeys(false).isEmpty()) {
|
||||
writer.write("\n");
|
||||
} else {
|
||||
writer.write(" {}\n");
|
||||
if (indents.length() == 0) writer.write("\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
temp.set(trailingKey, currentValue);
|
||||
String yaml = temp.saveToString();
|
||||
temp.set(trailingKey, null);
|
||||
|
||||
yaml = yaml.substring(0, yaml.length() - 1);
|
||||
|
||||
if (inlineComment != null && inlineComment.length() > 0) {
|
||||
if (yaml.contains("\n")) {
|
||||
// section为多行内容,需要 InlineComment 加在首行末尾
|
||||
String[] splitLine = yaml.split("\n", 2);
|
||||
yaml = splitLine[0] + " # " + inlineComment + "\n" + splitLine[1];
|
||||
} else {
|
||||
// 其他情况下就直接加载后面就好。
|
||||
yaml += " # " + inlineComment;
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(indents + yaml.replace("\n", "\n" + indents) + "\n");
|
||||
if (indents.length() == 0) writer.write("\n");
|
||||
}
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到一个键的缩进。
|
||||
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
||||
*
|
||||
* @param key 键
|
||||
* @return 该键的缩进文本
|
||||
*/
|
||||
protected static String getIndents(String key) {
|
||||
String[] splitKey = key.split("[" + BukkitConfigProvider.SEPARATOR + "]");
|
||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||
}
|
||||
|
||||
}
|
||||
+39
-18
@@ -5,30 +5,50 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.8.6</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>base</module>
|
||||
<module>general</module>
|
||||
</modules>
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bukkit-Parent</name>
|
||||
<name>MineConfiguration-Bukkit</name>
|
||||
<description>轻松(做)配置,适用于Bukkit系服务端的版本。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>yamlcommentwriter</artifactId>
|
||||
<version>${deps.yamlcommentwriter.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>XSeries</artifactId>
|
||||
<version>9.6.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -36,18 +56,19 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.2</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>
|
||||
<version>2.11.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+4
-8
@@ -1,14 +1,12 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.CraftConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||
|
||||
@@ -16,16 +14,14 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||
return new CraftConfigBuilder();
|
||||
}
|
||||
|
||||
public CraftConfigValue(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable T defaultValue) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
||||
protected CraftConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||
super(manifest);
|
||||
}
|
||||
|
||||
public CraftConfigProvider getBukkitProvider() {
|
||||
ConfigurationProvider<?> provider = getProvider();
|
||||
if (provider instanceof CraftConfigProvider) return (CraftConfigProvider) getProvider();
|
||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
||||
else throw new IllegalStateException("Provider is not a CraftConfigProvider");
|
||||
}
|
||||
|
||||
public CraftSectionWrapper getBukkitConfig() {
|
||||
+26
-1
@@ -1,12 +1,16 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MineConfiguration {
|
||||
public class MineConfiguration extends AbstractConfiguration<BukkitConfigProvider> {
|
||||
|
||||
public static BukkitConfigProvider from(File file, String source) {
|
||||
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
||||
@@ -38,4 +42,25 @@ public class MineConfiguration {
|
||||
public static BukkitConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull JavaPlugin plugin) {
|
||||
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||
@NotNull ConfigurationRoot configRoot,
|
||||
@NotNull ConfigurationRoot messageRoot) {
|
||||
this(plugin);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
||||
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||
this(plugin);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
}
|
||||
-11
@@ -6,11 +6,8 @@ import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.serializable.SerializableBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CraftConfigBuilder extends ConfigBuilder {
|
||||
|
||||
@@ -34,12 +31,4 @@ public class CraftConfigBuilder extends ConfigBuilder {
|
||||
return new SerializableBuilder<>(valueClass);
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredItem ofItem() {
|
||||
return createItem().build();
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredItem ofItem(@Nullable ItemConfig defaultItem) {
|
||||
return createItem().defaults(defaultItem).build();
|
||||
}
|
||||
|
||||
}
|
||||
+26
-8
@@ -1,19 +1,22 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.item;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.ConfiguredItem;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> {
|
||||
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemStack, ItemConfigBuilder> {
|
||||
|
||||
protected Material type;
|
||||
protected short data = 0;
|
||||
@@ -83,7 +86,7 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
||||
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||
public ItemConfigBuilder formatParam(@NotNull UnaryOperator<String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return getThis();
|
||||
}
|
||||
@@ -103,15 +106,30 @@ public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConf
|
||||
return this;
|
||||
}
|
||||
|
||||
protected @Nullable ItemConfig buildDefault() {
|
||||
protected @Nullable ItemStack buildDefault() {
|
||||
if (this.type == null) return null;
|
||||
else return new ItemConfig(type, data, name, lore, enchants, flags);
|
||||
|
||||
ItemStack item = new ItemStack(type, 1, data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
|
||||
Optional.ofNullable(this.name).ifPresent(meta::setDisplayName);
|
||||
Optional.ofNullable(this.lore).ifPresent(meta::setLore);
|
||||
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
|
||||
flags.forEach(meta::addItemFlags);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredItem build() {
|
||||
ItemConfig defaultItem = Optional.ofNullable(this.defaultValue).orElse(buildDefault());
|
||||
return new ConfiguredItem(this.provider, this.path, this.headerComments, this.inlineComment, defaultItem, buildParams());
|
||||
return new ConfiguredItem(
|
||||
new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(buildDefault())
|
||||
), buildParams()
|
||||
);
|
||||
}
|
||||
|
||||
protected final String[] buildParams() {
|
||||
+1
-3
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageListBuilder<M>
|
||||
@@ -27,8 +26,7 @@ public class CraftMessageListBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of(new ArrayList<>())),
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
+1
-3
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageValueBuilder<M>
|
||||
@@ -26,8 +25,7 @@ public class CraftMessageValueBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of("")),
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
+1
-1
@@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSerializable<T> build() {
|
||||
return new ConfiguredSerializable<>(this.provider, this.path, this.headerComments, this.inlineComment, this.valueClass, this.defaultValue);
|
||||
return new ConfiguredSerializable<>(buildManifest(), valueClass);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundC
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSound build() {
|
||||
return new ConfiguredSound(this.provider, this.path, this.headerComments, this.inlineComment, this.defaultValue);
|
||||
return new ConfiguredSound(buildManifest());
|
||||
}
|
||||
|
||||
}
|
||||
+6
-21
@@ -2,43 +2,29 @@ package cc.carm.lib.mineconfiguration.bukkit.builder.title;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.ProtocolLibHelper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = (player, fadeIn, stay, fadeOut, line1, line2) -> {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||
try {
|
||||
ProtocolLibHelper.sendTitle(player, fadeIn, stay, fadeOut, line1, line2);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
} else {
|
||||
player.sendTitle(line1, line2);
|
||||
}
|
||||
};
|
||||
|
||||
protected @NotNull String[] params = new String[0];
|
||||
|
||||
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn = 10;
|
||||
protected @Range(from = 0L, to = Integer.MAX_VALUE) int stay = 60;
|
||||
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut = 10;
|
||||
|
||||
protected @NotNull TitleSendConsumer sendConsumer;
|
||||
protected @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
|
||||
public TitleConfigBuilder() {
|
||||
this.sendConsumer = TitleConfigBuilder.DEFAULT_TITLE_CONSUMER;
|
||||
this.sendConsumer = ConfiguredTitle.DEFAULT_TITLE_CONSUMER;
|
||||
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||
}
|
||||
|
||||
@@ -47,7 +33,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
||||
return defaults(TitleConfig.of(line1, line2));
|
||||
}
|
||||
|
||||
public @NotNull TitleConfigBuilder whenSend(@NotNull TitleSendConsumer consumer) {
|
||||
public @NotNull TitleConfigBuilder whenSend(@NotNull ConfiguredTitle.TitleConsumer consumer) {
|
||||
this.sendConsumer = consumer;
|
||||
return this;
|
||||
}
|
||||
@@ -76,7 +62,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder formatParam(Function<String, String> paramFormatter) {
|
||||
public TitleConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return this;
|
||||
}
|
||||
@@ -89,8 +75,7 @@ public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleC
|
||||
@Override
|
||||
public @NotNull ConfiguredTitle build() {
|
||||
return new ConfiguredTitle(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
this.defaultValue, ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
|
||||
);
|
||||
}
|
||||
+7
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@@ -40,6 +41,12 @@ public class SoundConfig {
|
||||
player.playSound(player.getLocation(), type, volume, pitch);
|
||||
}
|
||||
|
||||
public void playAt(Location location) {
|
||||
if (type == null) return;
|
||||
if (location.getWorld() == null) return;
|
||||
location.getWorld().playSound(location, type, volume, pitch);
|
||||
}
|
||||
|
||||
public void playToAll() {
|
||||
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TitleConfig {
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2) {
|
||||
return of(
|
||||
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
|
||||
Optional.ofNullable(line2).map(TextConfig::of).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||
return new TitleConfig(line1, line2);
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
return of(
|
||||
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
|
||||
Optional.ofNullable(line2).map(TextConfig::of).orElse(null),
|
||||
fadeIn, stay, fadeOut
|
||||
);
|
||||
}
|
||||
|
||||
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
return new TitleConfig(line1, line2, fadeIn, stay, fadeOut);
|
||||
}
|
||||
|
||||
protected @Nullable TextConfig line1;
|
||||
protected @Nullable TextConfig line2;
|
||||
|
||||
protected final int fadeIn;
|
||||
protected final int stay;
|
||||
protected final int fadeOut;
|
||||
|
||||
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||
this(line1, line2, -1, -1, -1);
|
||||
}
|
||||
|
||||
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2, int fadeIn, int stay, int fadeOut) {
|
||||
this.line1 = line1;
|
||||
this.line2 = line2;
|
||||
this.fadeIn = fadeIn;
|
||||
this.stay = stay;
|
||||
this.fadeOut = fadeOut;
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||
send(
|
||||
player,
|
||||
this.fadeIn < 0 ? 10 : this.fadeIn,
|
||||
this.stay < 0 ? 60 : this.stay,
|
||||
this.fadeOut < 0 ? 10 : this.fadeOut,
|
||||
placeholders,
|
||||
sendConsumer
|
||||
);
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||
if (this.line1 == null && this.line2 == null) return;
|
||||
if (sendConsumer == null) return;
|
||||
sendConsumer.send(
|
||||
player, fadeIn, stay, fadeOut,
|
||||
parseLine(this.line1, player, placeholders),
|
||||
parseLine(this.line2, player, placeholders)
|
||||
);
|
||||
}
|
||||
|
||||
protected @NotNull String parseLine(@Nullable TextConfig text,
|
||||
@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||
if (text == null) return "";
|
||||
else return TextParser.parseText(player, text.getMessage(), placeholders);
|
||||
}
|
||||
|
||||
public @NotNull Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
if (this.line1 != null) map.put("line1", this.line1.getMessage());
|
||||
if (this.line2 != null) map.put("line2", this.line2.getMessage());
|
||||
if (this.fadeIn > 0) map.put("fadeIn", this.fadeIn);
|
||||
if (this.stay > 0) map.put("stay", this.stay);
|
||||
if (this.fadeOut > 0) map.put("fadeOut", this.fadeOut);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @Nullable TitleConfig deserialize(@NotNull ConfigurationWrapper<?> section) {
|
||||
String line1 = section.getString("line1");
|
||||
String line2 = section.getString("line2");
|
||||
if (line1 == null && line2 == null) return null;
|
||||
|
||||
return of(
|
||||
line1, line2,
|
||||
section.getInt("fadeIn", -1),
|
||||
section.getInt("stay", -1),
|
||||
section.getInt("fadeOut", -1)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import cc.carm.lib.yamlcommentupdater.CommentedYAML;
|
||||
import cc.carm.lib.yamlcommentupdater.CommentedYAMLWriter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BukkitConfigProvider extends CraftConfigProvider implements CommentedYAML {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
protected @NotNull ConfigurationComments comments = new ConfigurationComments();
|
||||
|
||||
public BukkitConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
public void initializeConfig() {
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CraftSectionWrapper getConfiguration() {
|
||||
return CraftSectionWrapper.of(this.configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
try {
|
||||
CommentedYAMLWriter.writeWithComments(this, this.file);
|
||||
} catch (Exception ex) {
|
||||
configuration.save(file);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeValue(@NotNull String key, @NotNull Object value) {
|
||||
FileConfiguration temp = new YamlConfiguration();
|
||||
temp.set(key, value);
|
||||
return temp.saveToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(@Nullable String sectionKey, boolean deep) {
|
||||
if (sectionKey == null) return configuration.getKeys(deep);
|
||||
|
||||
ConfigurationSection section = configuration.getConfigurationSection(sectionKey);
|
||||
if (section == null) return null;
|
||||
|
||||
return section.getKeys(deep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object getValue(@NotNull String key) {
|
||||
return configuration.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> getHeaderComments(@Nullable String key) {
|
||||
return comments.getHeaderComment(key);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ColorParser;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
+15
-5
@@ -1,18 +1,22 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import com.cryptomorin.xseries.messages.ActionBar;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@@ -35,12 +39,18 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSe
|
||||
return asString().defaults(defaultMessage).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull TextConfig defaultMessage, @NotNull String[] params,
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, defaultMessage, params, messageParser, sendFunction, TextConfig::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
public void sendActionBar(Player player, String... values) {
|
||||
sendActionBar(player, ParamsUtils.buildParams(this.params, values));
|
||||
}
|
||||
|
||||
public void sendActionBar(Player player, Map<String, Object> placeholders) {
|
||||
ActionBar.sendActionBar(player, parseString(player, placeholders));
|
||||
}
|
||||
|
||||
@Override
|
||||
+3
-5
@@ -1,6 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
@@ -31,12 +31,10 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, C
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull List<TextConfig> messages, @NotNull String[] params,
|
||||
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, messages, params, messageParser, sendFunction, TextConfig::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
+4
-7
@@ -1,12 +1,11 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
||||
@@ -22,10 +21,8 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
||||
|
||||
protected final @NotNull Class<T> valueClass;
|
||||
|
||||
public ConfiguredSerializable(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
||||
public ConfiguredSerializable(@NotNull ValueManifest<T> manifest, @NotNull Class<T> valueClass) {
|
||||
super(manifest);
|
||||
this.valueClass = valueClass;
|
||||
}
|
||||
|
||||
@@ -38,7 +35,7 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
||||
} catch (Exception e) {
|
||||
// 出现了解析错误,提示并返回默认值。
|
||||
e.printStackTrace();
|
||||
return useDefault();
|
||||
return getDefaultValue();
|
||||
}
|
||||
} else return Optional.ofNullable(getCachedValue()).orElse(defaultValue);
|
||||
}
|
||||
+8
-7
@@ -1,17 +1,16 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
@@ -44,10 +43,8 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
return CraftConfigValue.builder().createSound().defaults(soundName, volume, pitch).build();
|
||||
}
|
||||
|
||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable SoundConfig defaultValue) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
||||
public ConfiguredSound(@NotNull ValueManifest<SoundConfig> manifest) {
|
||||
super(manifest, SoundConfig.class, getSoundParser(), SoundConfig::serialize);
|
||||
}
|
||||
|
||||
public void setSound(@NotNull Sound sound) {
|
||||
@@ -70,6 +67,10 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
Optional.ofNullable(get()).ifPresent(SoundConfig::playToAll);
|
||||
}
|
||||
|
||||
public void playAt(Location location) {
|
||||
Optional.ofNullable(get()).ifPresent(s -> s.playAt(location));
|
||||
}
|
||||
|
||||
public static ConfigValueParser<Object, SoundConfig> getSoundParser() {
|
||||
return ConfigValueParser.castToString().andThen((s, d) -> SoundConfig.deserialize(s));
|
||||
}
|
||||
+49
-15
@@ -1,25 +1,29 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import com.cryptomorin.xseries.messages.Titles;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
|
||||
public static final @NotNull ConfiguredTitle.TitleConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
|
||||
|
||||
public static TitleConfigBuilder create() {
|
||||
return CraftConfigValue.builder().createTitle();
|
||||
}
|
||||
@@ -33,19 +37,17 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
return create().defaults(line1, line2).fadeIn(fadeIn).stay(stay).fadeOut(fadeOut).build();
|
||||
}
|
||||
|
||||
protected final @NotNull TitleSendConsumer sendConsumer;
|
||||
protected final @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
|
||||
protected final @NotNull String[] params;
|
||||
|
||||
protected final int fadeIn;
|
||||
protected final int stay;
|
||||
protected final int fadeOut;
|
||||
|
||||
public ConfiguredTitle(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable TitleConfig defaultValue, @NotNull String[] params,
|
||||
@NotNull TitleSendConsumer sendConsumer,
|
||||
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
|
||||
@NotNull ConfiguredTitle.TitleConsumer sendConsumer,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, TitleConfig.class, defaultValue, getTitleParser(), TitleConfig::serialize);
|
||||
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
|
||||
this.sendConsumer = sendConsumer;
|
||||
this.params = params;
|
||||
this.fadeIn = fadeIn;
|
||||
@@ -68,7 +70,7 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
return fadeOut;
|
||||
}
|
||||
|
||||
public @NotNull TitleSendConsumer getSendConsumer() {
|
||||
public @NotNull ConfiguredTitle.TitleConsumer getSendConsumer() {
|
||||
return sendConsumer;
|
||||
}
|
||||
|
||||
@@ -87,23 +89,55 @@ public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAll(Object... values) {
|
||||
sendAll(this.params, values);
|
||||
public void sendToAll(Object... values) {
|
||||
sendToAll(this.params, values);
|
||||
}
|
||||
|
||||
public void sendAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||
sendAll(ParamsUtils.buildParams(params, values));
|
||||
public void sendToAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||
sendToAll(ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public void sendAll(@NotNull Map<String, Object> placeholders) {
|
||||
public void sendToAll(@NotNull Map<String, Object> placeholders) {
|
||||
TitleConfig config = get();
|
||||
if (config == null) return;
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> send(onlinePlayer, placeholders));
|
||||
}
|
||||
|
||||
public void sendToEach(@NotNull Function<@NotNull Player, Object[]> eachValues) {
|
||||
sendToEach(null, eachValues);
|
||||
}
|
||||
|
||||
public void sendToEach(@Nullable Predicate<Player> limiter,
|
||||
@NotNull Function<@NotNull Player, Object[]> eachValues) {
|
||||
Predicate<Player> predicate = Optional.ofNullable(limiter).orElse(r -> true);
|
||||
Bukkit.getOnlinePlayers().stream().filter(predicate)
|
||||
.forEach(r -> send(r, ParamsUtils.buildParams(params, eachValues.apply(r))));
|
||||
}
|
||||
|
||||
public static ConfigValueParser<ConfigurationWrapper<?>, TitleConfig> getTitleParser() {
|
||||
return (s, d) -> TitleConfig.deserialize(s);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TitleConsumer {
|
||||
|
||||
/**
|
||||
* 向目标玩家发送标题文字
|
||||
*
|
||||
* @param player 目标玩家
|
||||
* @param fadeIn 淡入时间 (ticks)
|
||||
* @param stay 保留时间 (ticks)
|
||||
* @param fadeOut 淡出时间 (ticks)
|
||||
* @param line1 第一行文字
|
||||
* @param line2 第二行文字
|
||||
*/
|
||||
void send(@NotNull Player player,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||
@NotNull String line1, @NotNull String line2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
import com.cryptomorin.xseries.XItemStack;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ConfiguredItem extends ConfiguredSection<ItemStack> {
|
||||
|
||||
|
||||
public static ItemConfigBuilder create() {
|
||||
return new ItemConfigBuilder();
|
||||
}
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
|
||||
public ConfiguredItem(@NotNull ValueManifest<ItemStack> manifest, @NotNull String[] params) {
|
||||
super(
|
||||
manifest, ItemStack.class,
|
||||
(data, v) -> XItemStack.deserialize((ConfigurationSection) data.getSource()),
|
||||
XItemStack::serialize
|
||||
);
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
public @NotNull String[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<@Nullable ItemStack> getOptional() {
|
||||
return Optional.ofNullable(super.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ItemStack get() {
|
||||
return getOptional().map(ItemStack::clone).orElse(null);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
|
||||
return getOptional().map(item -> {
|
||||
modifier.accept(item);
|
||||
return item;
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
public @NotNull PreparedItem prepare(@NotNull Object... values) {
|
||||
return PreparedItem.of(player -> get()).params(params).values(values);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player) {
|
||||
return get(player, new HashMap<>());
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
|
||||
return prepare(values).get(player);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
|
||||
return prepare().params(params).values(values).get(player);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player,
|
||||
@NotNull Map<String, Object> placeholders) {
|
||||
return prepare().placeholders(placeholders).get(player);
|
||||
}
|
||||
|
||||
|
||||
public void modifyItem(Consumer<ItemStack> modifier) {
|
||||
ItemStack item = get();
|
||||
if (item == null) return;
|
||||
modifier.accept(item);
|
||||
set(item);
|
||||
}
|
||||
|
||||
public void modifyMeta(Consumer<ItemMeta> modifier) {
|
||||
modifyItem(item -> {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
modifier.accept(meta);
|
||||
item.setItemMeta(meta);
|
||||
});
|
||||
}
|
||||
|
||||
public void setName(@Nullable String name) {
|
||||
modifyMeta(meta -> meta.setDisplayName(name));
|
||||
}
|
||||
|
||||
public void setLore(@Nullable List<String> lore) {
|
||||
modifyMeta(meta -> meta.setLore(lore));
|
||||
}
|
||||
|
||||
public void setLore(String... lore) {
|
||||
if (lore.length == 0) setLore((List<String>) null);
|
||||
else setLore(Arrays.asList(lore));
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoreContent {
|
||||
|
||||
public static LoreContent of(@NotNull List<String> content) {
|
||||
return of(content, false);
|
||||
}
|
||||
|
||||
public static LoreContent of(@NotNull List<String> content, boolean original) {
|
||||
return new LoreContent(content, original);
|
||||
}
|
||||
|
||||
protected final @NotNull List<String> content;
|
||||
protected final boolean original;
|
||||
|
||||
public LoreContent(@NotNull List<String> content, boolean original) {
|
||||
this.content = content;
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
|
||||
public @NotNull List<String> getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public boolean isOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PreparedItem {
|
||||
|
||||
public static final @NotNull Pattern LORE_INSERT_PATTERN = Pattern.compile("^(?:\\{(.*)})?#(.*)#(?:\\{(-?\\d+)(?:,(-?\\d+))?})?$");
|
||||
|
||||
public static PreparedItem of(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||
return new PreparedItem(itemProvider);
|
||||
}
|
||||
|
||||
public static PreparedItem of(@Nullable ItemStack item) {
|
||||
return of(player -> item);
|
||||
}
|
||||
|
||||
protected final @NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider;
|
||||
|
||||
protected @NotNull Map<String, Object> placeholders = new HashMap<>();
|
||||
protected @NotNull String[] params;
|
||||
protected @NotNull Object[] values;
|
||||
|
||||
protected final @NotNull Map<String, LoreContent> insertLore = new HashMap<>();
|
||||
|
||||
protected @NotNull BiConsumer<ItemStack, Player> itemModifier;
|
||||
protected @NotNull BiConsumer<ItemMeta, Player> metaModifier;
|
||||
|
||||
protected PreparedItem(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||
this.itemProvider = itemProvider;
|
||||
this.params = new String[0];
|
||||
this.values = new Object[0];
|
||||
itemModifier = (item, player) -> {
|
||||
};
|
||||
metaModifier = (meta, player) -> {
|
||||
};
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Player player) {
|
||||
@Nullable ItemStack item = itemProvider.apply(player);
|
||||
if (item == null) return null;
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
|
||||
|
||||
Map<String, Object> finalPlaceholders = buildPlaceholders();
|
||||
|
||||
String name = meta.getDisplayName();
|
||||
if (!name.isEmpty()) {
|
||||
meta.setDisplayName(TextParser.parseText(player, name, finalPlaceholders));
|
||||
}
|
||||
|
||||
List<String> parsedLore = parseLore(player, meta.getLore(), insertLore, finalPlaceholders);
|
||||
if (!parsedLore.isEmpty()) {
|
||||
meta.setLore(parsedLore);
|
||||
}
|
||||
|
||||
metaModifier.accept(meta, player);
|
||||
item.setItemMeta(meta);
|
||||
itemModifier.accept(item, player);
|
||||
return item;
|
||||
}
|
||||
|
||||
public PreparedItem handleMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
|
||||
this.metaModifier = this.metaModifier.andThen(modifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem handleItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
|
||||
this.itemModifier = this.itemModifier.andThen(modifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem params(String[] params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem values(Object... values) {
|
||||
this.values = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem placeholders(@NotNull Map<String, Object> placeholders) {
|
||||
this.placeholders = placeholders;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem placeholders(@NotNull Consumer<Map<String, Object>> consumer) {
|
||||
Map<String, Object> placeholders = new HashMap<>();
|
||||
consumer.accept(placeholders);
|
||||
return placeholders(placeholders);
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path, @NotNull LoreContent content) {
|
||||
insertLore.put(path, content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path, @NotNull List<String> content) {
|
||||
return insertLore(path, content, false);
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path, @NotNull List<String> content, boolean original) {
|
||||
return insertLore(path, LoreContent.of(content, original));
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path, @NotNull String... content) {
|
||||
return insertLore(path, Arrays.asList(content));
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path, @NotNull ConfiguredList<String> content) {
|
||||
return insertLore(path, content.copy());
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path,
|
||||
@NotNull ConfiguredMessage<String> content, @NotNull Object... params) {
|
||||
String c = content.parse(null, params);
|
||||
if (c == null) return this;
|
||||
return insertLore(path, c);
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(@NotNull String path,
|
||||
@NotNull ConfiguredMessageList<String> content, @NotNull Object... params) {
|
||||
List<String> c = content.parse(null, params);
|
||||
if (c == null || c.isEmpty()) return this;
|
||||
return insertLore(path, c);
|
||||
}
|
||||
|
||||
public PreparedItem amount(int amount) {
|
||||
return handleItem((item, player) -> item.setAmount(amount));
|
||||
}
|
||||
|
||||
public PreparedItem addEnchantment(Enchantment e) {
|
||||
return addEnchantment(e, 1);
|
||||
}
|
||||
|
||||
public PreparedItem addEnchantment(Enchantment e, int level) {
|
||||
return addEnchantment(e, level, true);
|
||||
}
|
||||
|
||||
public PreparedItem addEnchantment(Enchantment e, int level, boolean ignoreLevelRestriction) {
|
||||
return handleMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
|
||||
}
|
||||
|
||||
public PreparedItem addItemFlags(ItemFlag... flags) {
|
||||
return handleMeta((meta, player) -> meta.addItemFlags(flags));
|
||||
}
|
||||
|
||||
public PreparedItem glow() {
|
||||
return addItemFlags(ItemFlag.HIDE_ENCHANTS).addEnchantment(Enchantment.DURABILITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param owner 玩家名
|
||||
* @return this
|
||||
* @deprecated Use {@link #setSkullOwner(OfflinePlayer)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public PreparedItem setSkullOwner(String owner) {
|
||||
return handleItem((item, player) -> {
|
||||
if (!(item.getItemMeta() instanceof SkullMeta)) return;
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(owner);
|
||||
});
|
||||
}
|
||||
|
||||
public PreparedItem setSkullOwner(UUID owner) {
|
||||
return setSkullOwner(Bukkit.getOfflinePlayer(owner));
|
||||
}
|
||||
|
||||
public PreparedItem setSkullOwner(OfflinePlayer owner) {
|
||||
return handleItem((item, player) -> {
|
||||
if (!(item.getItemMeta() instanceof SkullMeta)) return;
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwningPlayer(owner);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected Map<String, Object> buildPlaceholders() {
|
||||
Map<String, Object> finalPlaceholders = new HashMap<>();
|
||||
finalPlaceholders.putAll(ParamsUtils.buildParams(params, values));
|
||||
finalPlaceholders.putAll(this.placeholders);
|
||||
return finalPlaceholders;
|
||||
}
|
||||
|
||||
public static List<String> parseLore(@Nullable Player player, @Nullable List<String> lore,
|
||||
@NotNull Map<String, LoreContent> insertedLore,
|
||||
@NotNull Map<String, Object> placeholders) {
|
||||
List<String> parsedLore = new ArrayList<>();
|
||||
if (lore == null || lore.isEmpty()) return parsedLore;
|
||||
|
||||
for (String line : lore) {
|
||||
Matcher matcher = PreparedItem.LORE_INSERT_PATTERN.matcher(line);
|
||||
if (!matcher.matches()) {
|
||||
parsedLore.add(TextParser.parseText(player, line, placeholders));
|
||||
continue;
|
||||
}
|
||||
|
||||
String path = matcher.group(2);
|
||||
LoreContent content = insertedLore.get(path);
|
||||
if (content == null) continue;
|
||||
|
||||
String prefix = Optional.ofNullable(matcher.group(1))
|
||||
.map(s -> TextParser.parseText(player, s, placeholders))
|
||||
.orElse("");
|
||||
int offset1 = Optional.ofNullable(matcher.group(3))
|
||||
.map(Integer::parseInt).orElse(0);
|
||||
Integer offset2 = Optional.ofNullable(matcher.group(4))
|
||||
.map(Integer::parseInt).orElse(null);
|
||||
|
||||
List<String> inserted = parseLoreLine(
|
||||
player, content, placeholders, prefix,
|
||||
offset2 == null ? 0 : offset1, offset2 == null ? offset1 : offset2
|
||||
);
|
||||
|
||||
if (content.isOriginal()) {
|
||||
parsedLore.addAll(inserted);
|
||||
} else {
|
||||
parsedLore.addAll(TextParser.parseList(player, inserted, placeholders));
|
||||
}
|
||||
}
|
||||
return parsedLore;
|
||||
}
|
||||
|
||||
public static List<String> parseLoreLine(@Nullable Player player, @NotNull LoreContent content,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@NotNull String parsedPrefix, int upOffset, int downOffset) {
|
||||
if (content.getContent().isEmpty()) return Collections.emptyList();
|
||||
|
||||
upOffset = Math.max(0, upOffset);
|
||||
downOffset = Math.max(0, downOffset);
|
||||
|
||||
List<String> finalLore = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < upOffset; i++) finalLore.add(" ");
|
||||
if (content.isOriginal()) {
|
||||
content.getContent().stream().map(s -> parsedPrefix + s).forEach(finalLore::add);
|
||||
} else {
|
||||
content.getContent().stream().map(s -> parsedPrefix + TextParser.parseText(player, s, placeholders))
|
||||
.forEach(finalLore::add);
|
||||
}
|
||||
for (int i = 0; i < downOffset; i++) finalLore.add(" ");
|
||||
|
||||
return finalLore;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.LoreContent;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class LoreInsertTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void insert() {
|
||||
List<String> original = Arrays.asList(
|
||||
"测试lore的第一行",
|
||||
"测试lore的第二行",
|
||||
"#click-lore#{1,2}",
|
||||
"测试lore的倒数第二行",
|
||||
"{--> }#click-lore#{2}",
|
||||
"测试lore的倒数第一行"
|
||||
);
|
||||
|
||||
List<String> replace = Arrays.asList("> 插入的点击行1", "> 插入的点击行2");
|
||||
Map<String, LoreContent> inserted = new HashMap<>();
|
||||
inserted.put("click-lore", LoreContent.of(replace));
|
||||
PreparedItem.parseLore(null, original, inserted, new HashMap<>()).forEach(System.out::println);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parse() {
|
||||
System.out.println(parse("{LOVE}#click-lore#{1,0}"));
|
||||
System.out.println(parse("#click-lore#{1,2}"));
|
||||
System.out.println(parse("#click-lore#{1}"));
|
||||
System.out.println(parse("#click-lore#{我}"));
|
||||
}
|
||||
|
||||
public static String parse(String line) {
|
||||
Matcher matcher = PreparedItem.LORE_INSERT_PATTERN.matcher(line);
|
||||
if (!matcher.matches()) {
|
||||
return "Failed -> [" + line + "]";
|
||||
} else {
|
||||
String prefix = matcher.group(1);
|
||||
String path = matcher.group(2);
|
||||
|
||||
String offset1 = matcher.group(3);
|
||||
String offset2 = matcher.group(4);
|
||||
return "Prefix -> [" + prefix + "] Path -> [" + path + "] Offset-> [" + offset1 + "/" + offset2 + "]";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
-2
@@ -5,19 +5,22 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.8.6</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bungee</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bungee</name>
|
||||
|
||||
<description>轻松(做)配置,适用于BungeeCord的版本,可用JSON与YAML格式。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
@@ -27,6 +30,13 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>yamlcommentwriter</artifactId>
|
||||
<version>${deps.yamlcommentwriter.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
|
||||
+5
-9
@@ -1,14 +1,12 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.BungeeConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeSectionWrapper;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||
|
||||
@@ -16,10 +14,8 @@ public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||
return new BungeeConfigBuilder();
|
||||
}
|
||||
|
||||
public BungeeConfigValue(@Nullable BungeeConfigProvider provider, @Nullable String configPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@Nullable T defaultValue) {
|
||||
super(provider, configPath, headerComments, inlineComments, defaultValue);
|
||||
public BungeeConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||
super(manifest);
|
||||
}
|
||||
|
||||
public BungeeConfigProvider getBukkitProvider() {
|
||||
|
||||
+26
-1
@@ -1,15 +1,18 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.JsonConfiguration;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MineConfiguration {
|
||||
public class MineConfiguration extends AbstractConfiguration<BungeeConfigProvider> {
|
||||
|
||||
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
|
||||
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
|
||||
@@ -94,4 +97,26 @@ public class MineConfiguration {
|
||||
return fromJSON(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin) {
|
||||
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin,
|
||||
@NotNull ConfigurationRoot configRoot,
|
||||
@NotNull ConfigurationRoot messageRoot) {
|
||||
this(plugin);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin,
|
||||
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
||||
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||
this(plugin);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ColorParser;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -10,11 +10,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||
|
||||
|
||||
public BungeeMessageBuilder() {
|
||||
super(CommandSender.class, MessageText.class);
|
||||
super(CommandSender.class, TextConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-5
@@ -1,6 +1,7 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessageList;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
@@ -13,10 +14,10 @@ import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageListBuilder<M>
|
||||
extends MessageListBuilder<M, CommandSender, MessageText, BungeeMessageListBuilder<M>> {
|
||||
extends MessageListBuilder<M, CommandSender, TextConfig, BungeeMessageListBuilder<M>> {
|
||||
|
||||
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, MessageText::of, parser);
|
||||
super(CommandSender.class, TextConfig::of, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,8 +28,7 @@ public class BungeeMessageListBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
|
||||
+4
-6
@@ -1,6 +1,6 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessage;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
@@ -8,14 +8,13 @@ import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageValueBuilder<M>
|
||||
extends MessageValueBuilder<M, CommandSender, MessageText, BungeeMessageValueBuilder<M>> {
|
||||
extends MessageValueBuilder<M, CommandSender, TextConfig, BungeeMessageValueBuilder<M>> {
|
||||
|
||||
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, MessageText::new, parser);
|
||||
super(CommandSender.class, TextConfig::new, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,8 +25,7 @@ public class BungeeMessageValueBuilder<M>
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
|
||||
+7
-7
@@ -11,24 +11,24 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MessageText extends AbstractText<CommandSender> {
|
||||
public class TextConfig extends AbstractText<CommandSender> {
|
||||
|
||||
public MessageText(@NotNull String message) {
|
||||
public TextConfig(@NotNull String message) {
|
||||
super(CommandSender.class, message);
|
||||
}
|
||||
|
||||
@Contract("!null,-> !null")
|
||||
public static @Nullable MessageText of(@Nullable String message) {
|
||||
public static @Nullable TextConfig of(@Nullable String message) {
|
||||
if (message == null) return null;
|
||||
else return new MessageText(message);
|
||||
else return new TextConfig(message);
|
||||
}
|
||||
|
||||
public static @NotNull List<MessageText> of(@Nullable List<String> messages) {
|
||||
public static @NotNull List<TextConfig> of(@Nullable List<String> messages) {
|
||||
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
|
||||
else return messages.stream().map(TextConfig::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static @NotNull List<MessageText> of(@NotNull String... messages) {
|
||||
public static @NotNull List<TextConfig> of(@NotNull String... messages) {
|
||||
return of(Arrays.asList(messages));
|
||||
}
|
||||
|
||||
+43
-18
@@ -3,21 +3,21 @@ package cc.carm.lib.mineconfiguration.bungee.source;
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||
import cc.carm.lib.yamlcommentupdater.CommentedYAML;
|
||||
import cc.carm.lib.yamlcommentupdater.CommentedYAMLWriter;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> implements CommentedYAML {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
@@ -25,7 +25,7 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
||||
protected Configuration configuration;
|
||||
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
||||
|
||||
protected BungeeYAMLComments comments = new BungeeYAMLComments();
|
||||
protected ConfigurationComments comments = new ConfigurationComments();
|
||||
|
||||
public BungeeConfigProvider(@NotNull File file, @NotNull ConfigurationProvider loader) {
|
||||
super(file);
|
||||
@@ -52,22 +52,17 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationComments getComments() {
|
||||
public @NotNull ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
getLoader().save(configuration, file);
|
||||
if (getLoader() instanceof YamlConfiguration) {
|
||||
StringWriter writer = new StringWriter();
|
||||
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
||||
String value = writer.toString(); // config contents
|
||||
|
||||
Path toUpdatePath = getFile().toPath();
|
||||
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
||||
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
try {
|
||||
CommentedYAMLWriter.writeWithComments(this, this.file);
|
||||
} catch (Exception ex) {
|
||||
getLoader().save(configuration, file);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,4 +74,34 @@ public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrappe
|
||||
public ConfigurationProvider getLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeValue(@NotNull String key, @NotNull Object value) {
|
||||
Configuration tmp = new Configuration();// 该对象用于临时记录配置内容
|
||||
tmp.set(key, value);
|
||||
StringWriter tmpStr = new StringWriter();
|
||||
loader.save(tmp, tmpStr);
|
||||
return tmpStr.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys(@Nullable String sectionKey, boolean deep) {
|
||||
if (sectionKey == null) return BungeeSectionWrapper.getAllKeys(this.configuration);
|
||||
|
||||
Configuration section = configuration.getSection(sectionKey);
|
||||
if (section == null) return null;
|
||||
|
||||
return new HashSet<>(section.getKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object getValue(@NotNull String key) {
|
||||
return configuration.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> getHeaderComments(@Nullable String key) {
|
||||
return comments.getHeaderComment(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-115
@@ -1,115 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
||||
|
||||
public class BungeeYAMLComments extends ConfigurationComments {
|
||||
|
||||
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||
List<String> comments = getHeaderComment(path);
|
||||
if (comments == null || comments.size() == 0) return null;
|
||||
|
||||
StringJoiner joiner = new StringJoiner("\n");
|
||||
for (String comment : comments) {
|
||||
if (comment.length() == 0) joiner.add(" ");
|
||||
else joiner.add(indents + "# " + comment);
|
||||
}
|
||||
return joiner + "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* 从一个文件读取配置并写入注释到某个写入器中。
|
||||
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
||||
*
|
||||
* @param source 源配置文件
|
||||
* @param writer 配置写入器
|
||||
* @throws IOException 当写入发生错误时抛出
|
||||
*/
|
||||
public void writeComments(@NotNull Configuration source, @NotNull BufferedWriter writer) throws IOException {
|
||||
ConfigurationProvider provider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||
Configuration tmp = new Configuration();// 该对象用于临时记录配置内容
|
||||
|
||||
String configHeader = buildHeaderComments(null, "");
|
||||
if (configHeader != null) writer.write(configHeader);
|
||||
|
||||
for (String fullKey : BungeeSectionWrapper.getAllKeys(source)) {
|
||||
Object currentValue = source.get(fullKey);
|
||||
|
||||
String indents = getIndents(fullKey);
|
||||
String headerComments = buildHeaderComments(fullKey, indents);
|
||||
String inlineComment = getInlineComment(fullKey);
|
||||
|
||||
if (headerComments != null) writer.write(headerComments);
|
||||
|
||||
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
||||
|
||||
if (currentValue instanceof Configuration) {
|
||||
Configuration section = (Configuration) currentValue;
|
||||
writer.write(indents + trailingKey + ":");
|
||||
if (inlineComment != null && inlineComment.length() > 0) {
|
||||
writer.write(" # " + inlineComment);
|
||||
}
|
||||
if (!section.getKeys().isEmpty()) {
|
||||
writer.write("\n");
|
||||
} else {
|
||||
writer.write(" {}\n");
|
||||
if (indents.length() == 0) writer.write("\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
tmp.set(trailingKey, currentValue);
|
||||
StringWriter tmpStr = new StringWriter();
|
||||
provider.save(tmp, tmpStr);
|
||||
String yaml = tmpStr.toString();
|
||||
tmpStr.close();
|
||||
tmp.set(trailingKey, null);
|
||||
|
||||
yaml = yaml.substring(0, yaml.length() - 1);
|
||||
|
||||
if (inlineComment != null && inlineComment.length() > 0) {
|
||||
if (yaml.contains("\n")) {
|
||||
// section为多行内容,需要 InlineComment 加在首行末尾
|
||||
String[] splitLine = yaml.split("\n", 2);
|
||||
yaml = splitLine[0] + " # " + inlineComment + "\n" + splitLine[1];
|
||||
} else {
|
||||
// 其他情况下就直接加载后面就好。
|
||||
yaml += " # " + inlineComment;
|
||||
}
|
||||
}
|
||||
|
||||
writer.write(indents + yaml.replace("\n", "\n" + indents) + "\n");
|
||||
if (indents.length() == 0) writer.write("\n");
|
||||
}
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到一个键的缩进。
|
||||
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
||||
*
|
||||
* @param key 键
|
||||
* @return 该键的缩进文本
|
||||
*/
|
||||
protected static String getIndents(@NotNull String key) {
|
||||
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||
}
|
||||
|
||||
}
|
||||
+5
-7
@@ -1,9 +1,9 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
|
||||
public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> BungeeMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
@@ -35,12 +35,10 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
|
||||
return asString().defaults(defaultMessage).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
||||
public ConfiguredMessage(@NotNull ValueManifest<TextConfig> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-8
@@ -1,10 +1,10 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -13,11 +13,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
|
||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> BungeeMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
@@ -32,12 +31,10 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||
@NotNull List<MessageText> messages, @NotNull String[] params,
|
||||
public ConfiguredMessageList(@NotNull ValueManifest<List<TextConfig>> manifest, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
||||
super(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ConfigTest {
|
||||
|
||||
@HeaderComment("执行的指令列表")
|
||||
@InlineComment("建议以\"\"包裹")
|
||||
public static final ConfigValue<List<String>> COMMANDS = ConfiguredList.builder(String.class)
|
||||
public static final ConfigValue<List<String>> COMMANDS = ConfiguredList.builderOf(String.class)
|
||||
.fromString().defaults("alert Commands here!").build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +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.2.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<artifactId>mineconfiguration-spigot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Spigot</name>
|
||||
|
||||
<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.2</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);
|
||||
}
|
||||
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.spigot.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
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 java.io.File;
|
||||
|
||||
public class SpigotConfigProvider extends CraftConfigProvider {
|
||||
|
||||
public SpigotConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
protected SpigotYAMLComments comments = null;
|
||||
|
||||
@Override
|
||||
public void initializeConfig() {
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.comments = new SpigotYAMLComments(configuration);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package cc.carm.lib.mineconfiguration.spigot.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationComments;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotYAMLComments extends ConfigurationComments {
|
||||
|
||||
protected final YamlConfiguration configuration;
|
||||
|
||||
public SpigotYAMLComments(YamlConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderComments(@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,19 +10,19 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
|
||||
<deps.easyconfifuration.version>3.3.1</deps.easyconfifuration.version>
|
||||
<deps.easyconfifuration.version>3.8.0</deps.easyconfifuration.version>
|
||||
<deps.easyplugin.version>1.5.8</deps.easyplugin.version>
|
||||
<deps.yamlcommentwriter.version>1.0.1</deps.yamlcommentwriter.version>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<version>2.8.6</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>common</module>
|
||||
|
||||
<module>platform/bungee</module>
|
||||
<module>platform/bukkit</module>
|
||||
<module>platform/spigot</module>
|
||||
</modules>
|
||||
|
||||
<name>MineConfiguration</name>
|
||||
@@ -40,7 +40,7 @@
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:CarmJos/Easy.MineConfiguration</connection>
|
||||
<connection>scm:git:git@github.com:CarmJos/MineConfiguration</connection>
|
||||
<developerConnection>scm:git:git@github.com:CarmJos/MineConfiguration.git</developerConnection>
|
||||
<url>https://github.com/CarmJos/MineConfiguration</url>
|
||||
<tag>HEAD</tag>
|
||||
@@ -109,7 +109,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.1.0</version>
|
||||
<version>24.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<version>3.1.2</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
@@ -130,7 +130,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
@@ -150,7 +150,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<version>3.0.1</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
@@ -161,7 +161,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>${project.jdk.version}</source>
|
||||
<target>${project.jdk.version}</target>
|
||||
@@ -178,7 +178,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -196,7 +196,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
@@ -225,7 +225,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
|
||||
Reference in New Issue
Block a user