mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
105 Commits
1.1.0-SNAPSHOT
...
2.8.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 02f59b99f0 | |||
| e781d54348 | |||
| bbd2c9e5e7 | |||
| ccc8cc6b72 | |||
| 1612e49326 | |||
| 2754f12cd5 | |||
| c0f5d32ba0 | |||
| 6c355e0d89 | |||
| 6c7a5dd60a | |||
| 425d61834b | |||
| c9a272d052 | |||
| 327484cd53 | |||
| 99090929dd | |||
| 8437c4c904 | |||
| 21f7742d78 | |||
| 68e6280c94 | |||
| 9a8e6395bb | |||
| 7fa6fa1551 | |||
| 346ae4c494 | |||
| 2d8c1817a6 | |||
| f67d0fae8d | |||
| 8d723df7a6 | |||
| d4c7124d9e | |||
| 2804543419 | |||
| f826014c09 | |||
| 616d24d885 | |||
| 8d58583a1e | |||
| 4b594269bd | |||
| b629a7d96d | |||
| 455ab775ed | |||
| d5f1e8b230 | |||
| 11b910a273 | |||
| 40ec299c64 | |||
| 483fbc7c4d | |||
| 65d7a32108 | |||
| 6aa220924d | |||
| f4a55f216b | |||
| 34a51c42a5 | |||
| c50df3bc56 | |||
| 9a95e3d105 | |||
| 98ee47f676 | |||
| af614deae6 | |||
| cf80291e51 | |||
| 53ba56b0ad | |||
| da2023aad0 | |||
| 29526223e4 | |||
| e8044c112e | |||
| a552938858 | |||
| b61baed8bc | |||
| 0cd61842e5 | |||
| 4850514a8a | |||
| 1dca7a2274 | |||
| a02efbf29c | |||
| 352ef107f9 | |||
| 25f005ddfb | |||
| 26922f9225 | |||
| f0957c1b3e | |||
| 7d645f4386 | |||
| 08a56c7168 | |||
| f254383b79 |
@@ -0,0 +1,9 @@
|
||||
# MineConfiguration Javadoc
|
||||
|
||||
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/MineConfiguration) 。
|
||||
|
||||
## 如何实现?
|
||||
|
||||
若您也想通过 [Github Actions](https://docs.github.com/en/actions/learn-github-actions)
|
||||
自动部署项目的Javadoc到 [Github Pages](https://pages.github.com/) ,
|
||||
可以参考我的文章 [《自动部署Javadoc到Github Pages》](https://pages.carm.cc/doc/javadoc-in-github.html) 。
|
||||
@@ -12,7 +12,7 @@ on:
|
||||
|
||||
jobs:
|
||||
gh-deploy:
|
||||
name: "Publish Project (GitHub)"
|
||||
name: "Deploy Project (GitHub)"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -37,9 +37,8 @@ jobs:
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
central-deploy:
|
||||
name: "Deploy Project (Central Repository)"
|
||||
name: "Deploy Project (Central)"
|
||||
runs-on: ubuntu-latest
|
||||
if: '!contains( {{ env.GITHUB_REF }} , "SNAPSHOT" )'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: "Set up JDK"
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
name: "Publish Javadoc"
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
workflow_dispatch:
|
||||
release:
|
||||
# 创建release的时候触发
|
||||
types: [ published ]
|
||||
|
||||
|
||||
jobs:
|
||||
|
||||
javadoc-deploy:
|
||||
name: "Deploy Javadoc (Github Pages)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
|
||||
- name: "Generate Javadoc"
|
||||
run: mvn -B javadoc:aggregate --file pom.xml -DskipTests
|
||||
|
||||
- name: "Copy Javadoc"
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf target/site/apidocs/* docs/
|
||||
cp -vrf .doc/javadoc/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: "Generate Sitemap"
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||
path-to-root: docs
|
||||
|
||||
- name: Output stats
|
||||
run: |
|
||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
||||
ls -l docs
|
||||
|
||||
- name: Configure Git
|
||||
env:
|
||||
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
||||
run: |
|
||||
sudo timedatectl set-timezone "Asia/Shanghai"
|
||||
mkdir -p ~/.ssh/
|
||||
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||
git config --global user.name '${{ github.repository_owner }}'
|
||||
git config --global user.email '${{ github.repository_owner }}@users.noreply.github.com'
|
||||
|
||||
- name: Commit documentation changes
|
||||
run: |
|
||||
echo "Committing changes to git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git ..."
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
|
||||
- name: Javadoc Website Push
|
||||
run: |
|
||||
cd docs
|
||||
git push origin HEAD:gh-pages --force
|
||||
@@ -20,35 +20,36 @@ EasyConfiguration for MineCraft!
|
||||
|
||||
## 项目结构
|
||||
|
||||
### **MineConfiguration-CraftBukkit**
|
||||
### **MineConfiguration-Common** [`common`](common)
|
||||
|
||||
CraftBukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit** 或 **MineConfiguration-Spigot** 。
|
||||
全部版本的共用部分(均已被打包至下行包中),包括
|
||||
|
||||
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||
|
||||
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||
|
||||
### **MineConfiguration-Bukkit** [`platform/bukkit`](platform/bukkit)
|
||||
|
||||
适用于Bukkit的版本,同时支持其他以Bukkit为基础的服务端 *(如Spigot、Paper、CatServer)* 。
|
||||
|
||||
相较于基础版本,额外提供了以下功能:
|
||||
|
||||
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
||||
- `ConfiguredItem` (快捷读取简单的物品配置文件)
|
||||
- `ConfiguredSound` (快捷读取音效配置文件)
|
||||
- `ConfiguredItem` (快捷读\写\使用简单的物品配置文件)
|
||||
- `ConfiguredSound` (快捷读\写\使用音效配置文件)
|
||||
- `ConfiguredTitle` (快速读\写\使用标题文字配置文件)
|
||||
|
||||
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
||||
|
||||
### **MineConfiguration-Bukkit**
|
||||
### **MineConfiguration-Bungee** [`platform/bungee`](platform/bungee)
|
||||
|
||||
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
||||
|
||||
### **MineConfiguration-Spigot**
|
||||
|
||||
适用于 Spigot(1.18+) 的版本,适配了1.18与更新版本自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
||||
|
||||
### **MineConfiguration-Bungee**
|
||||
|
||||
适用于BungeeCord的版本,可用JSON与YAML格式,但**不支持配置文件注释**。
|
||||
|
||||
如需使用配置文件注释,建议使用 [EasyConfiguration-YAML](https://github.com/CarmJos/EasyConfiguration) 。
|
||||
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
||||
|
||||
## 开发
|
||||
|
||||
请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration) 的 [开发介绍](https://github.com/CarmJos/EasyConfiguration/tree/master/.documentation) 。
|
||||
其他功能请详见 [EasyConfiguration](https://github.com/CarmJos/EasyConfiguration)
|
||||
的 [开发介绍](https://github.com/CarmJos/EasyConfiguration/tree/master/.documentation) 。
|
||||
|
||||
### 依赖方式
|
||||
|
||||
|
||||
@@ -1,64 +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-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${easyconfiguration.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,33 +0,0 @@
|
||||
package cc.carm.lib.configuration;
|
||||
|
||||
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MineConfiguration {
|
||||
|
||||
public static BukkitConfigProvider from(File file, String source) {
|
||||
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
||||
try {
|
||||
provider.initializeFile(source);
|
||||
provider.initializeConfig();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(File file) {
|
||||
return from(file, file.getName());
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(String fileName) {
|
||||
return from(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(String fileName, String source) {
|
||||
return from(new File(fileName), source);
|
||||
}
|
||||
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
package cc.carm.lib.configuration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||
import cc.carm.lib.configuration.craft.source.CraftSectionWrapper;
|
||||
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 BukkitYAMLComments bukkitComments = 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 reload() throws Exception {
|
||||
configuration.load(getFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
configuration.save(getFile());
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
this.bukkitComments.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 void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
||||
this.bukkitComments.set(path, comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
||||
return this.bukkitComments.get(path);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package cc.carm.lib.configuration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
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.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static cc.carm.lib.configuration.craft.source.CraftConfigProvider.SEPARATOR;
|
||||
|
||||
public class BukkitYAMLComments {
|
||||
|
||||
Map<String, ConfigCommentInfo> comments = new HashMap<>();
|
||||
|
||||
protected Map<String, ConfigCommentInfo> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void set(@Nullable String path, @Nullable ConfigCommentInfo comments) {
|
||||
if (comments == null) {
|
||||
getComments().remove(path);
|
||||
} else {
|
||||
getComments().put(path, comments);
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull ConfigCommentInfo get(@Nullable String path) {
|
||||
return getComments().getOrDefault(path, ConfigCommentInfo.defaults());
|
||||
}
|
||||
|
||||
public @Nullable String buildComments(@NotNull String indents, @Nullable String path) {
|
||||
ConfigCommentInfo comments = get(path);
|
||||
if (!String.join("", comments.getComments()).isEmpty()) {
|
||||
String prefix = comments.startWrap() ? "\n" : "";
|
||||
String suffix = comments.endWrap() ? "\n" : "";
|
||||
StringJoiner joiner = new StringJoiner("\n", prefix, suffix);
|
||||
for (String comment : comments.getComments()) {
|
||||
if (comment.length() == 0) joiner.add(" ");
|
||||
else joiner.add(indents + "# " + comment);
|
||||
}
|
||||
return joiner + "\n";
|
||||
} else {
|
||||
return comments.startWrap() || comments.endWrap() ? "\n" : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从一个文件读取配置并写入注释到某个写入器中。
|
||||
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
||||
*
|
||||
* @param source 源配置文件
|
||||
* @param writer 配置写入器
|
||||
* @throws IOException 当写入发生错误时抛出
|
||||
*/
|
||||
public void writeComments(@NotNull YamlConfiguration source, @NotNull BufferedWriter writer) throws IOException {
|
||||
FileConfiguration temp = new YamlConfiguration(); // 该对象用于临时记录配置内容
|
||||
|
||||
for (String fullKey : source.getKeys(true)) {
|
||||
String indents = getIndents(fullKey);
|
||||
String comment = buildComments(indents, fullKey);
|
||||
if (comment != null) writer.write(comment);
|
||||
|
||||
Object currentValue = source.get(fullKey);
|
||||
|
||||
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
||||
|
||||
if (currentValue instanceof ConfigurationSection) {
|
||||
writer.write(indents + trailingKey + ":");
|
||||
if (!((ConfigurationSection) currentValue).getKeys(false).isEmpty()) {
|
||||
writer.write("\n");
|
||||
} else {
|
||||
writer.write(" {}\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
temp.set(trailingKey, currentValue);
|
||||
String yaml = temp.saveToString();
|
||||
yaml = yaml.substring(0, yaml.length() - 1).replace("\n", "\n" + indents);
|
||||
String toWrite = indents + yaml + "\n";
|
||||
temp.set(trailingKey, null);
|
||||
|
||||
writer.write(toWrite);
|
||||
}
|
||||
|
||||
String endComment = buildComments("", null);
|
||||
if (endComment != null) writer.write(endComment);
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到一个键的缩进。
|
||||
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
||||
*
|
||||
* @param key 键
|
||||
* @return 该键的缩进文本
|
||||
*/
|
||||
protected static String getIndents(String key) {
|
||||
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package cc.carm.lib.configuration.bungee;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
||||
|
||||
protected ConfigurationProvider loader;
|
||||
protected Configuration configuration;
|
||||
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
||||
|
||||
public BungeeConfigProvider(@NotNull File file, ConfigurationProvider loader) {
|
||||
super(file);
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public void initializeConfig() throws IOException {
|
||||
this.configuration = getLoader().load(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BungeeSectionWrapper getConfiguration() {
|
||||
return BungeeSectionWrapper.of(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() throws Exception {
|
||||
this.configuration = getLoader().load(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
getLoader().save(configuration, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
||||
// BungeeCord version doesn't support comments
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
||||
return null; // BungeeCord version doesn't support comments
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
||||
return this.initializer;
|
||||
}
|
||||
|
||||
public ConfigurationProvider getLoader() {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package cc.carm.lib.configuration.bungee;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BungeeSectionWrapper implements ConfigurationWrapper {
|
||||
|
||||
private final Configuration section;
|
||||
|
||||
private BungeeSectionWrapper(@NotNull Configuration section) {
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
@Contract("!null->!null")
|
||||
public static @Nullable BungeeSectionWrapper of(@Nullable Configuration section) {
|
||||
return section == null ? null : new BungeeSectionWrapper(section);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
return new LinkedHashSet<>(section.getKeys());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return section.getKeys().stream()
|
||||
.collect(Collectors.toMap(key -> key, section::get, (a, b) -> b, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
this.section.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return this.section.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return this.section.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return get(path) instanceof List<?>;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return this.section.getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSection(@NotNull String path) {
|
||||
return get(path) instanceof Configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
||||
return of(this.section.getSection(path));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.8.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
|
||||
<name>MineConfiguration-Common</name>
|
||||
<description>轻松(做)配置,全部版本的共用部分。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${deps.easyconfifuration.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-color</artifactId>
|
||||
<version>${deps.easyplugin.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.20-R0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public abstract class MessageConfigBuilder<R, T extends AbstractText<R>> {
|
||||
|
||||
protected final @NotNull Class<R> receiverClazz;
|
||||
protected final @NotNull Class<T> textClazz;
|
||||
|
||||
public MessageConfigBuilder(@NotNull Class<R> receiverClazz,
|
||||
@NotNull Class<T> textClazz) {
|
||||
this.receiverClazz = receiverClazz;
|
||||
this.textClazz = textClazz;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以单条消息为目标,构建一个消息配置。
|
||||
*
|
||||
* @param parser 消息解析器,负责将String转换为目标消息类型。
|
||||
* @param <M> 消息类型
|
||||
* @return 单条消息构建器
|
||||
*/
|
||||
public abstract <M> @NotNull MessageValueBuilder<M, R, T, ?> asValue(@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser);
|
||||
|
||||
/**
|
||||
* 以多行消息为目标,构建一个消息配置。
|
||||
*
|
||||
* @param parser 消息解析器
|
||||
* @param <M> 消息类型
|
||||
* @return 多行消息构建器
|
||||
*/
|
||||
public abstract <M> @NotNull MessageListBuilder<M, R, T, ?> asList(@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser);
|
||||
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
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 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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B extends MessageListBuilder<M, R, T, B>>
|
||||
extends CommonConfigBuilder<List<T>, B> {
|
||||
|
||||
protected final @NotNull Class<R> receiverClazz;
|
||||
|
||||
protected @NotNull String[] params;
|
||||
protected @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||
protected @NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction;
|
||||
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
public MessageListBuilder(@NotNull Class<R> receiverClazz,
|
||||
@NotNull Function<String, T> textBuilder,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser) {
|
||||
this.receiverClazz = receiverClazz;
|
||||
this.textBuilder = textBuilder;
|
||||
this.params = new String[0];
|
||||
this.messageParser = parser;
|
||||
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||
this.sendFunction = (sender, M) -> {
|
||||
};
|
||||
}
|
||||
|
||||
public B defaults(@NotNull String... messages) {
|
||||
return defaults(new ArrayList<>(Arrays.stream(messages).map(textBuilder).collect(Collectors.toList())));
|
||||
}
|
||||
|
||||
public B params(@NotNull String... params) {
|
||||
this.params = params;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public B params(@NotNull List<String> params) {
|
||||
this.params = params.toArray(new String[0]);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public B formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public B whenSend(@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction) {
|
||||
this.sendFunction = sendFunction;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
@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)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
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 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;
|
||||
|
||||
public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B extends MessageValueBuilder<M, R, T, B>>
|
||||
extends CommonConfigBuilder<T, B> {
|
||||
|
||||
|
||||
protected final @NotNull Class<R> receiverClazz;
|
||||
protected @NotNull String[] params;
|
||||
protected @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||
protected @NotNull BiConsumer<@NotNull R, @NotNull M> sendHandler;
|
||||
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
public MessageValueBuilder(@NotNull Class<R> receiverClazz,
|
||||
@NotNull Function<String, T> textBuilder,
|
||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser) {
|
||||
this.receiverClazz = receiverClazz;
|
||||
this.params = new String[0];
|
||||
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||
this.textBuilder = textBuilder;
|
||||
this.messageParser = parser;
|
||||
this.sendHandler = (receiver, M) -> {
|
||||
};
|
||||
}
|
||||
|
||||
public B defaults(@NotNull String message) {
|
||||
return defaults(this.textBuilder.apply(message));
|
||||
}
|
||||
|
||||
public B params(@NotNull String... params) {
|
||||
this.params = params;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public B params(@NotNull List<String> params) {
|
||||
this.params = params.toArray(new String[0]);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public B formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public B whenSend(@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction) {
|
||||
this.sendHandler = sendFunction;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
@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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package cc.carm.lib.mineconfiguration.common.data;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* @param <R> Receiver type
|
||||
*/
|
||||
public abstract class AbstractText<R> {
|
||||
|
||||
private final @NotNull Class<R> receiverClazz;
|
||||
protected @NotNull String message;
|
||||
|
||||
public AbstractText(@NotNull Class<R> receiverClazz, @NotNull String message) {
|
||||
this.receiverClazz = receiverClazz;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public @NotNull Class<R> getReceiverClazz() {
|
||||
return receiverClazz;
|
||||
}
|
||||
|
||||
public @NotNull String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
||||
return parse(parser, receiver, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public <M> @NotNull M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cc.carm.lib.mineconfiguration.common.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ParamsUtils {
|
||||
|
||||
/**
|
||||
* 默认的变量格式为 {@code %(变量名)}。
|
||||
*/
|
||||
public static Function<@NotNull String, @NotNull String> DEFAULT_PARAM_FORMATTER = (s) -> "%(" + s + ")";
|
||||
|
||||
public static String[] formatParams(@NotNull Function<String, String> formatter, @NotNull String[] params) {
|
||||
return Arrays.stream(params).map(formatter).toArray(String[]::new);
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildParams(@Nullable String[] params, @Nullable Object[] values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (params == null || params.length == 0) return map;
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
map.put(params[i], values.length > i ? values[i] : "?");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String setPlaceholders(@NotNull String messages, @NotNull Map<String, Object> placeholders) {
|
||||
if (messages.isEmpty()) return messages;
|
||||
|
||||
String parsed = messages;
|
||||
for (Map.Entry<String, Object> entry : placeholders.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
parsed = parsed.replace(entry.getKey(), value == null ? "" : value.toString());
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface BaseMessage<R, M> {
|
||||
|
||||
/**
|
||||
* 得到所有的接收者
|
||||
*
|
||||
* @return 全部可能的接收者
|
||||
*/
|
||||
@Unmodifiable
|
||||
@NotNull Iterable<R> getAllReceivers();
|
||||
|
||||
/**
|
||||
* 得到消息中的通过 {@link MessageValueBuilder#params(String...)}已定变量名(按定义顺序)
|
||||
*
|
||||
* @return 已定变量
|
||||
*/
|
||||
@NotNull String[] getParams();
|
||||
|
||||
/**
|
||||
* 向接收者发送消息的根方法。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param message 消息内容
|
||||
*/
|
||||
@ApiStatus.OverrideOnly
|
||||
void apply(@NotNull R receiver, @NotNull M message);
|
||||
|
||||
/**
|
||||
* 填入变量值,返回一个准备好待发送的消息。
|
||||
*
|
||||
* @param values 变量值
|
||||
* @return 准备好待发送的消息
|
||||
*/
|
||||
default @NotNull PreparedMessage<R, M> prepare(@NotNull Object... values) {
|
||||
return new PreparedMessage<>(this, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
@Nullable M parse(@Nullable R receiver, @NotNull Map<String, Object> placeholders);
|
||||
|
||||
/**
|
||||
* 为某位接收者解析此消息。
|
||||
*
|
||||
* @param receiver 接收者
|
||||
* @param values 已定变量的对应参数
|
||||
* @return 解析变量后的消息内容
|
||||
*/
|
||||
default @Nullable M parse(@Nullable R receiver, @Nullable Object... values) {
|
||||
return parse(receiver, ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
* @param values 已定变量的对应参数
|
||||
*/
|
||||
default void send(@Nullable R receiver, @Nullable Object... values) {
|
||||
send(receiver, ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 向某位接收者发送消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
if (receiver == null) return;
|
||||
M parsed = parse(receiver, placeholders);
|
||||
if (parsed == null) return;
|
||||
apply(receiver, parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向全部接收者(包括后台)发送不同参数的消息
|
||||
*
|
||||
* @param eachValues 每位接收者将收到已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToEach(@NotNull Function<@NotNull R, Object[]> eachValues) {
|
||||
sendToEach(null, eachValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向特定接收者发送不同参数的消息
|
||||
*
|
||||
* @param limiter 接收者限定器,为空则不限定接收者。
|
||||
* @param eachValues 每位接收者将收到已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToEach(@Nullable Predicate<R> limiter,
|
||||
@NotNull Function<@NotNull R, Object[]> eachValues) {
|
||||
Predicate<R> predicate = Optional.ofNullable(limiter).orElse(r -> true);
|
||||
for (R r : getAllReceivers()) {
|
||||
if (predicate.test(r)) {
|
||||
send(r, ParamsUtils.buildParams(getParams(), eachValues.apply(r)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param values 已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void sendToAll(@Nullable Object... values) {
|
||||
broadcast(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void sendToAll(@NotNull Map<String, Object> placeholders) {
|
||||
broadcast(placeholders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param values 已定变量的对应参数(按定义顺序)
|
||||
*/
|
||||
default void broadcast(@Nullable Object... values) {
|
||||
broadcast(ParamsUtils.buildParams(getParams(), values));
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播此消息(包括后台)
|
||||
*
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
default void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
getAllReceivers().forEach(r -> send(r, placeholders));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
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.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
||||
extends ConfiguredValue<T> implements BaseMessage<R, M> {
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||
protected final @NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction;
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
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(
|
||||
manifest, textClazz,
|
||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)),
|
||||
AbstractText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
this.sendFunction = sendFunction;
|
||||
this.textBuilder = textBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull R receiver, @NotNull M message) {
|
||||
sendFunction.accept(receiver, message);
|
||||
}
|
||||
|
||||
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(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) {
|
||||
this.set(value == null ? null : buildText(value));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
package cc.carm.lib.mineconfiguration.common.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
||||
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;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class ConfigMessageList<M, T extends AbstractText<R>, R>
|
||||
extends ConfiguredList<T> implements BaseMessage<R, List<M>> {
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||
protected final @NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction;
|
||||
|
||||
protected final @NotNull Function<String, T> textBuilder;
|
||||
|
||||
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(
|
||||
manifest, textClazz,
|
||||
ConfigDataFunction.castToString().andThen(textBuilder::apply),
|
||||
AbstractText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
this.sendFunction = sendFunction;
|
||||
this.textBuilder = textBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull R receiver, @NotNull List<M> message) {
|
||||
sendFunction.accept(receiver, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为某位接收者解析消息
|
||||
*
|
||||
* @param receiver 消息的接收者
|
||||
* @param placeholders 消息中的变量与对应参数
|
||||
*/
|
||||
@Override
|
||||
public @Nullable List<M> parse(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||
List<T> list = get();
|
||||
if (list.isEmpty()) return null;
|
||||
|
||||
List<String> messages = list.stream().map(T::getMessage).collect(Collectors.toList());
|
||||
if (String.join("", messages).isEmpty()) return null;
|
||||
|
||||
return list.stream().map(value -> value.parse(this.messageParser, receiver, placeholders))
|
||||
.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) {
|
||||
set(null);
|
||||
} else {
|
||||
set(buildText(values));
|
||||
}
|
||||
}
|
||||
|
||||
protected List<T> buildText(List<String> values) {
|
||||
return values.stream().map(textBuilder).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,57 +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-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${easyconfiguration.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.builder;
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.builder.item.ItemConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.builder.message.MessageConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder;
|
||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredItem;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CraftConfigBuilder extends ConfigBuilder {
|
||||
|
||||
public @NotNull SoundConfigBuilder createSound() {
|
||||
return new SoundConfigBuilder();
|
||||
}
|
||||
|
||||
public @NotNull ItemConfigBuilder createItem() {
|
||||
return new ItemConfigBuilder();
|
||||
}
|
||||
|
||||
public @NotNull MessageConfigBuilder createMessage() {
|
||||
return new MessageConfigBuilder();
|
||||
}
|
||||
|
||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
||||
return new SerializableBuilder<>(valueClass);
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredItem ofItem() {
|
||||
return createItem().build();
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredItem ofItem(@Nullable ItemConfig defaultItem) {
|
||||
return createItem().defaults(defaultItem).build();
|
||||
}
|
||||
|
||||
}
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.builder.item;
|
||||
|
||||
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredItem;
|
||||
import org.bukkit.Material;
|
||||
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;
|
||||
|
||||
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, ItemConfigBuilder> {
|
||||
|
||||
protected Material type;
|
||||
protected short data;
|
||||
protected String name;
|
||||
protected List<String> lore = new ArrayList<>();
|
||||
|
||||
public ItemConfigBuilder defaults(@NotNull Material type,
|
||||
@Nullable String name, @NotNull String... lore) {
|
||||
return defaults(type, (short) 0, name, Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaults(@NotNull Material type, short data,
|
||||
@Nullable String name, @NotNull String... lore) {
|
||||
return defaults(type, data, name, Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaults(@NotNull Material type, short data,
|
||||
@Nullable String name, @NotNull List<String> lore) {
|
||||
return defaultType(type).defaultDataID(data).defaultName(name).defaultLore(lore);
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultType(@NotNull Material type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultName(@Nullable String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultDataID(short dataID) {
|
||||
this.data = dataID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultLore(@NotNull String... lore) {
|
||||
return defaultLore(Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultLore(@NotNull List<String> lore) {
|
||||
this.lore = new ArrayList<>(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull ItemConfigBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected @Nullable ItemConfig buildDefault() {
|
||||
if (this.type == null) return null;
|
||||
else return new ItemConfig(type, data, name, lore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredItem build() {
|
||||
ItemConfig defaultItem = Optional.ofNullable(this.defaultValue).orElse(buildDefault());
|
||||
return new ConfiguredItem(this.provider, this.path, buildComments(), defaultItem);
|
||||
}
|
||||
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.craft.utils.ColorParser;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredMessage;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredMessageList;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class MessageConfigBuilder {
|
||||
|
||||
public <M> @NotNull MessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return new MessageValueBuilder<>(messageParser);
|
||||
}
|
||||
|
||||
public <M> @NotNull MessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return new MessageListBuilder<>(messageParser);
|
||||
}
|
||||
|
||||
public @NotNull MessageValueBuilder<String> asStringValue() {
|
||||
return asValue((sender, message) -> ColorParser.parseColor(message))
|
||||
.whenSend(CommandSender::sendMessage);
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredMessage<String> valueOfString() {
|
||||
return valueOfString("");
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredMessage<String> valueOfString(@NotNull String defaultMessage) {
|
||||
return asStringValue().content(defaultMessage).build();
|
||||
}
|
||||
|
||||
|
||||
public @NotNull MessageListBuilder<String> asStringList() {
|
||||
return asList((sender, message) -> ColorParser.parseColor(message))
|
||||
.whenSend((sender, messages) -> messages.forEach(sender::sendMessage));
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredMessageList<String> listOfString(@NotNull String... defaultMessages) {
|
||||
return asStringList().contents(defaultMessages).build();
|
||||
}
|
||||
|
||||
}
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredMessageList;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MessageListBuilder<M>
|
||||
extends CommonConfigBuilder<String, MessageListBuilder<M>> {
|
||||
|
||||
protected @NotNull List<String> messages;
|
||||
protected @NotNull String[] params;
|
||||
protected @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser;
|
||||
protected @NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction;
|
||||
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
|
||||
public MessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
this.messages = new ArrayList<>();
|
||||
this.params = new String[0];
|
||||
this.messageParser = parser;
|
||||
this.paramFormatter = MessageValueBuilder.DEFAULT_PARAM_FORMATTER;
|
||||
this.sendFunction = (sender, M) -> {
|
||||
};
|
||||
}
|
||||
|
||||
public MessageListBuilder<M> contents(@NotNull String... messages) {
|
||||
return contents(Arrays.asList(messages));
|
||||
}
|
||||
|
||||
public MessageListBuilder<M> contents(@NotNull List<String> messages) {
|
||||
this.messages = new ArrayList<>(messages);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageListBuilder<M> params(@NotNull String... params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageListBuilder<M> params(@NotNull List<String> params) {
|
||||
this.params = params.toArray(new String[0]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageListBuilder<M> formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageListBuilder<M> whenSend(@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
this.sendFunction = sendFunction;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull MessageListBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
this.provider, this.path, buildComments(),
|
||||
this.messages, buildParams(), this.messageParser, this.sendFunction
|
||||
);
|
||||
}
|
||||
|
||||
protected final String[] buildParams() {
|
||||
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
||||
}
|
||||
|
||||
}
|
||||
-79
@@ -1,79 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.builder.message;
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class MessageValueBuilder<M>
|
||||
extends CommonConfigBuilder<String, MessageValueBuilder<M>> {
|
||||
|
||||
public static Function<@NotNull String, @NotNull String> DEFAULT_PARAM_FORMATTER = (s) -> "%(" + s + ")";
|
||||
|
||||
protected @NotNull String message;
|
||||
protected @NotNull String[] params;
|
||||
protected @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser;
|
||||
protected @NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendHandler;
|
||||
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
|
||||
public MessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
this.message = "";
|
||||
this.params = new String[0];
|
||||
this.paramFormatter = DEFAULT_PARAM_FORMATTER;
|
||||
this.messageParser = parser;
|
||||
this.sendHandler = (sender, M) -> {
|
||||
};
|
||||
}
|
||||
|
||||
public MessageValueBuilder<M> content(@NotNull String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageValueBuilder<M> params(@NotNull String... params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageValueBuilder<M> params(@NotNull List<String> params) {
|
||||
this.params = params.toArray(new String[0]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageValueBuilder<M> formatParam(@NotNull Function<@NotNull String, @NotNull String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageValueBuilder<M> whenSend(@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
this.sendHandler = sendFunction;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull MessageValueBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
this.provider, this.path, buildComments(),
|
||||
this.message, buildParams(), this.messageParser, this.sendHandler
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
protected final String[] buildParams() {
|
||||
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
||||
}
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.builder.sound;
|
||||
|
||||
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredSound;
|
||||
import org.bukkit.Sound;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundConfigBuilder> {
|
||||
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume, float pitch) {
|
||||
return defaults(new SoundConfig(sound, volume, pitch));
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume) {
|
||||
return defaults(sound, volume, 1.0f);
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound) {
|
||||
return defaults(sound, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull SoundConfigBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSound build() {
|
||||
return new ConfiguredSound(this.provider, this.path, buildComments(), this.defaultValue);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.data;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemConfig {
|
||||
|
||||
protected @NotNull Material type;
|
||||
protected short data;
|
||||
protected @Nullable String name;
|
||||
protected @NotNull List<String> lore;
|
||||
|
||||
public ItemConfig(@NotNull Material type, short damage,
|
||||
@Nullable String name, @NotNull List<String> lore) {
|
||||
this.type = type;
|
||||
this.data = damage;
|
||||
this.name = name;
|
||||
this.lore = lore;
|
||||
}
|
||||
|
||||
public @NotNull Material getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public short getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public @Nullable String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public @NotNull List<String> getLore() {
|
||||
return lore;
|
||||
}
|
||||
|
||||
public final @NotNull ItemStack getItemStack() {
|
||||
return getItemStack(1);
|
||||
}
|
||||
|
||||
public @NotNull ItemStack getItemStack(int amount) {
|
||||
ItemStack item = new ItemStack(type, amount, data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
if (getName() != null) meta.setDisplayName(getName());
|
||||
if (!getLore().isEmpty()) meta.setLore(getLore());
|
||||
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);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
|
||||
String typeName = section.getString("name");
|
||||
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);
|
||||
else return new ItemConfig(
|
||||
type, section.getShort("data", (short) 0),
|
||||
section.getString("name"),
|
||||
parseStringList(section.getList("lore"))
|
||||
);
|
||||
}
|
||||
|
||||
private static List<String> parseStringList(@Nullable List<?> data) {
|
||||
if (data == null) return new ArrayList<>();
|
||||
else return data.stream()
|
||||
.map(o -> o instanceof String ? (String) o : o.toString())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.data;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MessageText {
|
||||
|
||||
@Contract("!null,-> !null")
|
||||
public static @Nullable MessageText of(@Nullable String message) {
|
||||
if (message == null) return null;
|
||||
else return new MessageText(message);
|
||||
}
|
||||
|
||||
public static @NotNull List<MessageText> of(@NotNull List<String> messages) {
|
||||
return messages.stream().map(MessageText::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static @NotNull List<MessageText> of(@NotNull String... messages) {
|
||||
return Arrays.stream(messages).map(MessageText::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected @NotNull String message;
|
||||
|
||||
public MessageText(@NotNull String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public @NotNull String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @NotNull M> parser,
|
||||
@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||
return parse(parser, sender, buildParams(params, values));
|
||||
}
|
||||
|
||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @NotNull M> parser,
|
||||
@Nullable CommandSender sender, @NotNull Map<String, Object> placeholders) {
|
||||
String message = getMessage();
|
||||
if (message.isEmpty()) return null; // No further processing
|
||||
else return parser.apply(sender, setPlaceholders(message, placeholders));
|
||||
}
|
||||
|
||||
protected static Map<String, Object> buildParams(@Nullable String[] params, @Nullable Object[] values) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (params == null || params.length == 0) return map;
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
map.put(params[i], values.length > i ? values[i] : "?");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
protected static String setPlaceholders(@NotNull String messages, @NotNull Map<String, Object> placeholders) {
|
||||
if (messages.isEmpty()) return messages;
|
||||
|
||||
String parsed = messages;
|
||||
for (Map.Entry<String, Object> entry : placeholders.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
parsed = parsed.replace(entry.getKey(), value == null ? "" : value.toString());
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ColorParser {
|
||||
|
||||
public static String parse(String text) {
|
||||
text = parseHexColor(text);
|
||||
return parseColor(text);
|
||||
}
|
||||
|
||||
public static String[] parse(String... texts) {
|
||||
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static List<String> parse(List<String> texts) {
|
||||
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static String parseColor(final String text) {
|
||||
return text.replaceAll("&", "§").replace("§§", "&");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse HEXColor code like &(#000000) to minecraft colored text.
|
||||
*
|
||||
* @param text the text to parse
|
||||
* @return color parsed
|
||||
*/
|
||||
public static String parseHexColor(String text) {
|
||||
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
||||
hexColor = hexColor.replace("&", "");
|
||||
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
|
||||
for (int i = 1; i < hexColor.length(); i++) {
|
||||
bukkitColorCode.append('§').append(hexColor.charAt(i));
|
||||
}
|
||||
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
|
||||
matcher.reset(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||
import cc.carm.lib.configuration.craft.builder.item.ItemConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider,
|
||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||
@Nullable ItemConfig defaultValue) {
|
||||
super(provider, sectionPath, comments, ItemConfig.class, defaultValue, getItemParser(), ItemConfig::serialize);
|
||||
}
|
||||
|
||||
public static ConfigValueParser<ConfigurationWrapper, ItemConfig> getItemParser() {
|
||||
return (s, d) -> ItemConfig.deserialize(s);
|
||||
}
|
||||
|
||||
}
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||
import cc.carm.lib.configuration.craft.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessage<M> extends ConfiguredValue<MessageText> {
|
||||
|
||||
@NotNull
|
||||
public static <M> MessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return CraftConfigValue.builder().createMessage().asValue(messageParser);
|
||||
}
|
||||
|
||||
public static MessageValueBuilder<String> fromString() {
|
||||
return CraftConfigValue.builder().createMessage().asStringValue();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString() {
|
||||
return CraftConfigValue.builder().createMessage().valueOfString();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||
return CraftConfigValue.builder().createMessage().valueOfString(defaultMessage);
|
||||
}
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
protected final @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser;
|
||||
protected final @NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction;
|
||||
|
||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
|
||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||
@NotNull String message, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||
super(provider, sectionPath, comments, MessageText.class, MessageText.of(message),
|
||||
ConfigValueParser.castToString().andThen((s, d) -> MessageText.of(s)),
|
||||
MessageText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
this.sendFunction = sendFunction;
|
||||
}
|
||||
|
||||
public @Nullable M parse(@Nullable CommandSender sender, @Nullable Object... values) {
|
||||
MessageText value = get();
|
||||
if (value == null) return null;
|
||||
else return value.parse(this.messageParser, sender, this.params, values);
|
||||
}
|
||||
|
||||
public @Nullable M parse(@Nullable CommandSender sender, @NotNull Map<String, Object> placeholders) {
|
||||
MessageText value = get();
|
||||
if (value == null) return null;
|
||||
else return value.parse(this.messageParser, sender, placeholders);
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender receiver, @Nullable Object... values) {
|
||||
if (receiver == null) return;
|
||||
M parsed = parse(receiver, values);
|
||||
if (parsed == null) return;
|
||||
sendFunction.accept(receiver, parsed);
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender receiver, @NotNull Map<String, Object> placeholders) {
|
||||
if (receiver == null) return;
|
||||
M parsed = parse(receiver, placeholders);
|
||||
if (parsed == null) return;
|
||||
sendFunction.accept(receiver, parsed);
|
||||
}
|
||||
|
||||
public void broadcast(@Nullable Object... values) {
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, values));
|
||||
send(Bukkit.getConsoleSender(), values);
|
||||
}
|
||||
|
||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||
send(Bukkit.getConsoleSender(), placeholders);
|
||||
}
|
||||
|
||||
public void set(@Nullable String value) {
|
||||
this.set(value == null ? null : new MessageText(value));
|
||||
}
|
||||
|
||||
}
|
||||
-111
@@ -1,111 +0,0 @@
|
||||
package cc.carm.lib.configuration.craft.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||
import cc.carm.lib.configuration.craft.builder.message.MessageListBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ConfiguredMessageList<M> extends ConfiguredList<MessageText> {
|
||||
|
||||
@NotNull
|
||||
public static <M> MessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return CraftConfigValue.builder().createMessage().asList(messageParser);
|
||||
}
|
||||
|
||||
public static MessageListBuilder<String> fromString() {
|
||||
return CraftConfigValue.builder().createMessage().asStringList();
|
||||
}
|
||||
|
||||
public static ConfiguredMessageList<String> ofString(@NotNull String... defaultMessages) {
|
||||
return CraftConfigValue.builder().createMessage().listOfString(defaultMessages);
|
||||
}
|
||||
|
||||
protected final @NotNull String[] params;
|
||||
protected final @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser;
|
||||
protected final @NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction;
|
||||
|
||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
|
||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||
@NotNull List<String> messages, @NotNull String[] params,
|
||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||
super(provider, sectionPath, comments, MessageText.class, MessageText.of(messages),
|
||||
ConfigDataFunction.castToString().andThen(MessageText::new), MessageText::getMessage
|
||||
);
|
||||
this.params = params;
|
||||
this.messageParser = messageParser;
|
||||
this.sendFunction = sendFunction;
|
||||
}
|
||||
|
||||
public @Nullable List<M> parse(@Nullable CommandSender sender, @Nullable Object... values) {
|
||||
List<MessageText> list = get();
|
||||
if (list.isEmpty()) return null;
|
||||
return list.stream().map(value -> value.parse(this.messageParser, sender, this.params, values))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public @Nullable List<M> parse(@Nullable CommandSender sender, @NotNull Map<String, Object> placeholders) {
|
||||
List<MessageText> list = get();
|
||||
if (list.isEmpty()) return null;
|
||||
return list.stream().map(value -> value.parse(this.messageParser, sender, placeholders))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender receiver, @Nullable Object... values) {
|
||||
if (receiver == null) return;
|
||||
List<M> parsed = parse(receiver, values);
|
||||
if (parsed == null) return;
|
||||
sendFunction.accept(receiver, parsed);
|
||||
}
|
||||
|
||||
public void send(@Nullable CommandSender receiver, @NotNull Map<String, Object> placeholders) {
|
||||
if (receiver == null) return;
|
||||
List<M> parsed = parse(receiver, placeholders);
|
||||
if (parsed == null) return;
|
||||
sendFunction.accept(receiver, parsed);
|
||||
}
|
||||
|
||||
public void broadcast(@Nullable Object... values) {
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, values));
|
||||
send(Bukkit.getConsoleSender(), values);
|
||||
}
|
||||
|
||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||
send(Bukkit.getConsoleSender(), placeholders);
|
||||
}
|
||||
|
||||
public void setNull() {
|
||||
set(null);
|
||||
}
|
||||
|
||||
public void setMessages(@NotNull String... values) {
|
||||
if (values.length == 0) {
|
||||
setNull();
|
||||
return;
|
||||
}
|
||||
set(MessageText.of(values));
|
||||
}
|
||||
|
||||
public void setMessages(@Nullable List<String> values) {
|
||||
if (values == null || values.isEmpty()) {
|
||||
setNull();
|
||||
return;
|
||||
}
|
||||
set(MessageText.of(values));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>2.8.3</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</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<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.5.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.13.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.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+8
-10
@@ -1,13 +1,12 @@
|
||||
package cc.carm.lib.configuration.craft;
|
||||
package cc.carm.lib.mineconfiguration.bukkit;
|
||||
|
||||
import cc.carm.lib.configuration.craft.builder.CraftConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||
import cc.carm.lib.configuration.craft.source.CraftSectionWrapper;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
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;
|
||||
|
||||
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||
|
||||
@@ -15,15 +14,14 @@ public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||
return new CraftConfigBuilder();
|
||||
}
|
||||
|
||||
public CraftConfigValue(@Nullable CraftConfigProvider provider,
|
||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
|
||||
super(provider, configPath, comments, 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() {
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
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 extends AbstractConfiguration<BukkitConfigProvider> {
|
||||
|
||||
public static BukkitConfigProvider from(File file, String source) {
|
||||
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
||||
try {
|
||||
provider.initializeFile(source);
|
||||
provider.initializeConfig();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(File file) {
|
||||
return from(file, file.getName());
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(String fileName) {
|
||||
return from(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(String fileName, String source) {
|
||||
return from(new File(fileName), source);
|
||||
}
|
||||
|
||||
public static BukkitConfigProvider from(Plugin plugin, String fileName) {
|
||||
return from(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package cc.carm.lib.configuration.craft.builder;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder;
|
||||
|
||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||
|
||||
public abstract class AbstractCraftBuilder<T, B extends AbstractCraftBuilder<T, B>>
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder;
|
||||
|
||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
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 org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftConfigBuilder extends ConfigBuilder {
|
||||
|
||||
public @NotNull SoundConfigBuilder createSound() {
|
||||
return new SoundConfigBuilder();
|
||||
}
|
||||
|
||||
public @NotNull ItemConfigBuilder createItem() {
|
||||
return new ItemConfigBuilder();
|
||||
}
|
||||
|
||||
public @NotNull CraftMessageBuilder createMessage() {
|
||||
return new CraftMessageBuilder();
|
||||
}
|
||||
|
||||
public @NotNull TitleConfigBuilder createTitle() {
|
||||
return new TitleConfigBuilder();
|
||||
}
|
||||
|
||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
||||
return new SerializableBuilder<>(valueClass);
|
||||
}
|
||||
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
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.value.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<ItemStack, ItemConfigBuilder> {
|
||||
|
||||
protected Material type;
|
||||
protected short data = 0;
|
||||
protected String name = null;
|
||||
protected List<String> lore = new ArrayList<>();
|
||||
|
||||
protected Map<Enchantment, Integer> enchants = new LinkedHashMap<>();
|
||||
protected Set<ItemFlag> flags = new LinkedHashSet<>();
|
||||
|
||||
protected @NotNull String[] params = new String[0];
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||
|
||||
public ItemConfigBuilder defaults(@NotNull Material type,
|
||||
@Nullable String name, @NotNull String... lore) {
|
||||
return defaults(type, (short) 0, name, Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaults(@NotNull Material type, short data,
|
||||
@Nullable String name, @NotNull String... lore) {
|
||||
return defaults(type, data, name, Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaults(@NotNull Material type, short data,
|
||||
@Nullable String name, @NotNull List<String> lore) {
|
||||
return defaultType(type).defaultDataID(data).defaultName(name).defaultLore(lore);
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultType(@NotNull Material type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultName(@Nullable String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultDataID(short dataID) {
|
||||
this.data = dataID;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultLore(@NotNull String... lore) {
|
||||
return defaultLore(Arrays.asList(lore));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultLore(@NotNull List<String> lore) {
|
||||
this.lore = new ArrayList<>(lore);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultEnchants(@NotNull Map<Enchantment, Integer> enchants) {
|
||||
this.enchants = new LinkedHashMap<>(enchants);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultEnchant(@NotNull Enchantment enchant, int level) {
|
||||
return defaultEnchants(Collections.singletonMap(enchant, level));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultFlags(@NotNull Set<ItemFlag> flags) {
|
||||
this.flags = new LinkedHashSet<>(flags);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemConfigBuilder defaultFlags(@NotNull ItemFlag... flags) {
|
||||
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
|
||||
}
|
||||
|
||||
public ItemConfigBuilder formatParam(@NotNull UnaryOperator<String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public ItemConfigBuilder params(@NotNull String... params) {
|
||||
this.params = params;
|
||||
return getThis();
|
||||
}
|
||||
|
||||
public ItemConfigBuilder params(@NotNull List<String> params) {
|
||||
this.params = params.toArray(new String[0]);
|
||||
return getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull ItemConfigBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected @Nullable ItemStack buildDefault() {
|
||||
if (this.type == null) return null;
|
||||
|
||||
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() {
|
||||
return new ConfiguredItem(
|
||||
new ValueManifest<>(
|
||||
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||
Optional.ofNullable(this.defaultValue).orElse(buildDefault())
|
||||
), buildParams()
|
||||
);
|
||||
}
|
||||
|
||||
protected final String[] buildParams() {
|
||||
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
||||
}
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||
|
||||
|
||||
public CraftMessageBuilder() {
|
||||
super(CommandSender.class, TextConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <M> CraftMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
return new CraftMessageValueBuilder<>(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <M> CraftMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
return new CraftMessageListBuilder<>(parser);
|
||||
}
|
||||
|
||||
public @NotNull
|
||||
CraftMessageValueBuilder<String> asStringValue() {
|
||||
return asValue(defaultParser()).whenSend(CommandSender::sendMessage);
|
||||
}
|
||||
|
||||
public @NotNull
|
||||
CraftMessageListBuilder<String> asStringList() {
|
||||
return asList(defaultParser()).whenSend((r, m) -> m.forEach(r::sendMessage));
|
||||
}
|
||||
|
||||
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
||||
return (receiver, message) -> TextParser.parseText(receiver, message, new HashMap<>());
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageListBuilder<M>
|
||||
extends MessageListBuilder<M, CommandSender, TextConfig, CraftMessageListBuilder<M>> {
|
||||
|
||||
public CraftMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, TextConfig::of, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull CraftMessageListBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
|
||||
import cc.carm.lib.mineconfiguration.common.builder.message.MessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class CraftMessageValueBuilder<M>
|
||||
extends MessageValueBuilder<M, CommandSender, TextConfig, CraftMessageValueBuilder<M>> {
|
||||
|
||||
public CraftMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, TextConfig::new, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull CraftMessageValueBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package cc.carm.lib.configuration.craft.builder.serializable;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.serializable;
|
||||
|
||||
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.configuration.craft.value.ConfiguredSerializable;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSerializable<T> build() {
|
||||
return new ConfiguredSerializable<>(this.provider, this.path, buildComments(), this.valueClass, this.defaultValue);
|
||||
return new ConfiguredSerializable<>(buildManifest(), valueClass);
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.builder.sound;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredSound;
|
||||
import org.bukkit.Sound;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundConfigBuilder> {
|
||||
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume, float pitch) {
|
||||
return defaults(new SoundConfig(sound.name(), sound, volume, pitch));
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume) {
|
||||
return defaults(sound, volume, 1.0f);
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound) {
|
||||
return defaults(sound, 1.0f);
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull String soundName, float volume, float pitch) {
|
||||
return defaults(new SoundConfig(soundName, volume, pitch));
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull String soundName, float volume) {
|
||||
return defaults(soundName, volume, 1.0f);
|
||||
}
|
||||
|
||||
public @NotNull SoundConfigBuilder defaults(@NotNull String soundName) {
|
||||
return defaults(soundName, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull SoundConfigBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredSound build() {
|
||||
return new ConfiguredSound(buildManifest());
|
||||
}
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
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.value.ConfiguredTitle;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
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> {
|
||||
|
||||
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 ConfiguredTitle.TitleConsumer sendConsumer;
|
||||
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||
|
||||
public TitleConfigBuilder() {
|
||||
this.sendConsumer = ConfiguredTitle.DEFAULT_TITLE_CONSUMER;
|
||||
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||
}
|
||||
|
||||
public @NotNull TitleConfigBuilder defaults(@Nullable String line1,
|
||||
@Nullable String line2) {
|
||||
return defaults(TitleConfig.of(line1, line2));
|
||||
}
|
||||
|
||||
public @NotNull TitleConfigBuilder whenSend(@NotNull ConfiguredTitle.TitleConsumer consumer) {
|
||||
this.sendConsumer = consumer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder params(String... params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder params(@NotNull List<String> params) {
|
||||
return params(params.toArray(new String[0]));
|
||||
}
|
||||
|
||||
public TitleConfigBuilder fadeIn(@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn) {
|
||||
this.fadeIn = fadeIn;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder stay(@Range(from = 0L, to = Integer.MAX_VALUE) int stay) {
|
||||
this.stay = stay;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder fadeOut(@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut) {
|
||||
this.fadeOut = fadeOut;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TitleConfigBuilder formatParam(UnaryOperator<String> paramFormatter) {
|
||||
this.paramFormatter = paramFormatter;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull TitleConfigBuilder getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredTitle build() {
|
||||
return new ConfiguredTitle(
|
||||
buildManifest(), ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
|
||||
);
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
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;
|
||||
|
||||
protected int customModelData = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
+34
-12
@@ -1,41 +1,61 @@
|
||||
package cc.carm.lib.configuration.craft.data;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SoundConfig {
|
||||
|
||||
protected @NotNull Sound type;
|
||||
protected @NotNull String typeName;
|
||||
protected @Nullable Sound type;
|
||||
protected float volume;
|
||||
protected float pitch;
|
||||
|
||||
public SoundConfig(@NotNull Sound type) {
|
||||
this(type, 1, 1);
|
||||
public SoundConfig(@NotNull String typeName) {
|
||||
this(typeName, 1, 1);
|
||||
}
|
||||
|
||||
public SoundConfig(@NotNull Sound type, float volume) {
|
||||
this(type, volume, 1);
|
||||
public SoundConfig(@NotNull String typeName, float volume) {
|
||||
this(typeName, volume, 1);
|
||||
}
|
||||
|
||||
public SoundConfig(@NotNull Sound type, float volume, float pitch) {
|
||||
public SoundConfig(@NotNull String typeName, float volume, float pitch) {
|
||||
this(typeName, Arrays.stream(Sound.values()).filter(s -> s.name().equalsIgnoreCase(typeName)).findFirst().orElse(null), volume, pitch);
|
||||
}
|
||||
|
||||
public SoundConfig(@NotNull String typeName, @Nullable Sound type, float volume, float pitch) {
|
||||
this.typeName = typeName;
|
||||
this.type = type;
|
||||
this.volume = volume;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void playTo(Player player) {
|
||||
if (type == null) return;
|
||||
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);
|
||||
}
|
||||
|
||||
public @NotNull Sound getType() {
|
||||
public @NotNull String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public @Nullable Sound getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -48,6 +68,7 @@ public class SoundConfig {
|
||||
}
|
||||
|
||||
public void setType(@NotNull Sound type) {
|
||||
this.typeName = type.name();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@@ -61,23 +82,24 @@ public class SoundConfig {
|
||||
|
||||
public @NotNull String serialize() {
|
||||
if (pitch != 1) {
|
||||
return type.name() + ":" + volume + ":" + pitch;
|
||||
return typeName + ":" + volume + ":" + pitch;
|
||||
} else if (volume != 1) {
|
||||
return type.name() + ":" + volume;
|
||||
return typeName + ":" + volume;
|
||||
} else {
|
||||
return type.name();
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("null -> null")
|
||||
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
||||
if (string == null) return null;
|
||||
if (string == null || string.isEmpty()) return null;
|
||||
|
||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||
if (args.length < 1) return null;
|
||||
|
||||
try {
|
||||
return new SoundConfig(
|
||||
args[0],
|
||||
Sound.valueOf(args[0]),
|
||||
(args.length >= 2) ? Float.parseFloat(args[1]) : 1,
|
||||
(args.length >= 3) ? Float.parseFloat(args[2]) : 1
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
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.stream.Collectors;
|
||||
|
||||
public class TextConfig extends AbstractText<CommandSender> {
|
||||
|
||||
public TextConfig(@NotNull String message) {
|
||||
super(CommandSender.class, message);
|
||||
}
|
||||
|
||||
@Contract("!null,-> !null")
|
||||
public static @Nullable TextConfig of(@Nullable String message) {
|
||||
if (message == null) return null;
|
||||
else return new TextConfig(message);
|
||||
}
|
||||
|
||||
public static @NotNull List<TextConfig> of(@Nullable List<String> messages) {
|
||||
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||
else return messages.stream().map(TextConfig::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static @NotNull List<TextConfig> of(@NotNull String... messages) {
|
||||
return of(Arrays.asList(messages));
|
||||
}
|
||||
|
||||
}
|
||||
+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);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package cc.carm.lib.configuration.craft.source;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||
@@ -26,7 +26,7 @@ public abstract class CraftConfigProvider extends FileConfigProvider<CraftSectio
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() throws Exception {
|
||||
protected void onReload() throws Exception {
|
||||
configuration.load(getFile());
|
||||
}
|
||||
|
||||
+18
-17
@@ -1,4 +1,4 @@
|
||||
package cc.carm.lib.configuration.craft.source;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -10,61 +10,62 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class CraftSectionWrapper implements ConfigurationWrapper {
|
||||
public class CraftSectionWrapper implements ConfigurationWrapper<ConfigurationSection> {
|
||||
|
||||
protected final ConfigurationSection section;
|
||||
protected final ConfigurationSection configuration;
|
||||
|
||||
protected CraftSectionWrapper(ConfigurationSection section) {
|
||||
this.section = section;
|
||||
protected CraftSectionWrapper(ConfigurationSection configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public ConfigurationSection getSourceSection() {
|
||||
return section;
|
||||
@Override
|
||||
public @NotNull ConfigurationSection getSource() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
return this.section.getKeys(deep);
|
||||
return this.configuration.getKeys(deep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return this.section.getValues(deep);
|
||||
return this.configuration.getValues(deep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
this.section.set(path, value);
|
||||
this.configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return this.section.contains(path);
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return this.section.get(path);
|
||||
return this.configuration.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return this.section.isList(path);
|
||||
return this.configuration.isList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return this.section.getList(path);
|
||||
return this.configuration.getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSection(@NotNull String path) {
|
||||
return this.section.isConfigurationSection(path);
|
||||
return this.configuration.isConfigurationSection(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
||||
return Optional.ofNullable(section.getConfigurationSection(path))
|
||||
public @Nullable CraftSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||
return Optional.ofNullable(configuration.getConfigurationSection(path))
|
||||
.map(CraftSectionWrapper::of).orElse(null);
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlaceholderAPIHelper {
|
||||
|
||||
public static String parseMessages(Player player, String message) {
|
||||
try {
|
||||
return PlaceholderAPI.setPlaceholders(player, message);
|
||||
} catch (Exception ignored) {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> parseMessages(Player player, List<String> messages) {
|
||||
try {
|
||||
return PlaceholderAPI.setPlaceholders(player, messages);
|
||||
} catch (Exception ignored) {
|
||||
return messages;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TextParser {
|
||||
|
||||
@Contract("_,!null,_->!null")
|
||||
public static @Nullable String parseText(@Nullable CommandSender sender, @Nullable String message, @NotNull Map<String, Object> placeholders) {
|
||||
if (message == null) return null;
|
||||
if (sender instanceof Player && hasPlaceholderAPI()) {
|
||||
message = PlaceholderAPIHelper.parseMessages((Player) sender, message);
|
||||
}
|
||||
return ColorParser.parse(ParamsUtils.setPlaceholders(message, placeholders));
|
||||
}
|
||||
|
||||
public static @NotNull List<String> parseList(@Nullable CommandSender sender, List<String> messages, @NotNull Map<String, Object> placeholders) {
|
||||
if (sender instanceof Player && hasPlaceholderAPI()) {
|
||||
messages = PlaceholderAPIHelper.parseMessages((Player) sender, messages);
|
||||
}
|
||||
return ColorParser.parse(messages.stream().map(s -> ParamsUtils.setPlaceholders(s, placeholders)).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public static boolean hasPlaceholderAPI() {
|
||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
|
||||
}
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||
import com.cryptomorin.xseries.XItemStack;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
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.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.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConfiguredItem extends ConfiguredSection<ItemStack> {
|
||||
|
||||
public static final @NotNull Pattern LORE_INSERT_PATTERN = Pattern.compile("^#(.*)#(\\{\\w+})?$");
|
||||
public static final @NotNull Pattern LORE_OFFSET_PATTERN = Pattern.compile("\\{(-?\\d+)(?:,(-?\\d+))?}");
|
||||
|
||||
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 @Nullable ItemStack get() {
|
||||
return Optional.ofNullable(super.get()).map(ItemStack::clone).orElse(null);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public @NotNull PreparedItem prepare(@NotNull Object... values) {
|
||||
return new PreparedItem(this, values);
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player) {
|
||||
return get(player, new HashMap<>());
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
|
||||
return get(player, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player,
|
||||
@NotNull Object[] values,
|
||||
@NotNull Map<String, List<String>> inserted) {
|
||||
return get(player, ParamsUtils.buildParams(params, values), inserted);
|
||||
}
|
||||
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player, @NotNull String[] params, @NotNull Object[] values) {
|
||||
return get(player, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player,
|
||||
@NotNull Map<String, Object> placeholders) {
|
||||
return get(player, placeholders, new HashMap<>());
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(@Nullable Player player,
|
||||
@NotNull Map<String, Object> placeholders,
|
||||
@NotNull Map<String, List<String>> inserted) {
|
||||
return get(item -> {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return;
|
||||
|
||||
List<String> lore = insertLore(meta.getLore(), inserted);
|
||||
if (!lore.isEmpty()) {
|
||||
meta.setLore(TextParser.parseList(player, lore, placeholders));
|
||||
}
|
||||
|
||||
String name = meta.getDisplayName();
|
||||
if (!name.isEmpty()) {
|
||||
meta.setDisplayName(TextParser.parseText(player, name, placeholders));
|
||||
}
|
||||
|
||||
item.setItemMeta(meta);
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
|
||||
return getOptional().map(item -> {
|
||||
modifier.accept(item);
|
||||
return item;
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
public static List<String> insertLore(List<String> original, Map<String, List<String>> inserted) {
|
||||
if (original == null) return Collections.emptyList();
|
||||
|
||||
List<String> finalLore = new ArrayList<>();
|
||||
for (String line : original) {
|
||||
if (line == null) continue;
|
||||
|
||||
Matcher matcher = LORE_INSERT_PATTERN.matcher(line);
|
||||
if (!matcher.matches()) {
|
||||
finalLore.add(line);
|
||||
} else {
|
||||
String path = matcher.group(1);
|
||||
String offset = matcher.group(2);
|
||||
finalLore.addAll(addLoreOffset(inserted.get(path), offset));
|
||||
}
|
||||
}
|
||||
|
||||
return finalLore;
|
||||
}
|
||||
|
||||
public static List<String> addLoreOffset(List<String> lore, String offsetSettings) {
|
||||
if (lore == null || lore.isEmpty()) return Collections.emptyList();
|
||||
if (offsetSettings == null) return lore;
|
||||
|
||||
Matcher offsetMatcher = LORE_OFFSET_PATTERN.matcher(offsetSettings);
|
||||
if (!offsetMatcher.matches()) return lore;
|
||||
|
||||
int upOffset = Optional.ofNullable(offsetMatcher.group(1)).map(Integer::parseInt).orElse(0);
|
||||
int downOffset = Optional.ofNullable(offsetMatcher.group(2)).map(Integer::parseInt).orElse(0);
|
||||
|
||||
return addLoreOffset(lore, upOffset, downOffset);
|
||||
}
|
||||
|
||||
public static List<String> addLoreOffset(List<String> lore, int upOffset, int downOffset) {
|
||||
if (lore == null || lore.isEmpty()) return Collections.emptyList();
|
||||
upOffset = Math.max(0, upOffset);
|
||||
downOffset = Math.max(0, downOffset);
|
||||
|
||||
ArrayList<String> finalLore = new ArrayList<>(lore);
|
||||
for (int i = 0; i < upOffset; i++) finalLore.add(0, " ");
|
||||
for (int i = 0; i < downOffset; i++) finalLore.add(finalLore.size(), " ");
|
||||
|
||||
return finalLore;
|
||||
}
|
||||
|
||||
public static class PreparedItem {
|
||||
|
||||
protected final @NotNull ConfiguredItem itemConfig;
|
||||
protected final @NotNull Map<String, List<String>> insertLore = new HashMap<>();
|
||||
|
||||
protected @NotNull Object[] values;
|
||||
|
||||
protected @NotNull BiConsumer<ItemStack, Player> itemModifier;
|
||||
protected @NotNull BiConsumer<ItemMeta, Player> metaModifier;
|
||||
|
||||
protected PreparedItem(@NotNull ConfiguredItem itemConfig, @NotNull Object[] values) {
|
||||
this.itemConfig = itemConfig;
|
||||
this.values = values;
|
||||
itemModifier = (item, player) -> {
|
||||
};
|
||||
metaModifier = (meta, player) -> {
|
||||
};
|
||||
}
|
||||
|
||||
public PreparedItem modifyMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
|
||||
this.metaModifier = this.metaModifier.andThen(modifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem modifyItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
|
||||
this.itemModifier = this.itemModifier.andThen(modifier);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(String path, List<String> content) {
|
||||
insertLore.put(path, content);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(String path, String... content) {
|
||||
return insertLore(path, Arrays.asList(content));
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(String path, ConfiguredList<String> content) {
|
||||
return insertLore(path, content.copy());
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(String path, ConfiguredMessage<String> content, Object... params) {
|
||||
return insertLore(path, content.parse(null, params));
|
||||
}
|
||||
|
||||
public PreparedItem insertLore(String path, ConfiguredMessageList<String> content, Object... params) {
|
||||
return insertLore(path, content.parse(null, params));
|
||||
}
|
||||
|
||||
public PreparedItem values(Object... values) {
|
||||
this.values = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PreparedItem amount(int amount) {
|
||||
return modifyItem((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 modifyMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
|
||||
}
|
||||
|
||||
public PreparedItem addItemFlags(ItemFlag... flags) {
|
||||
return modifyMeta((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 modifyItem((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 modifyItem((item, player) -> {
|
||||
if (!(item.getItemMeta() instanceof SkullMeta)) return;
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwningPlayer(owner);
|
||||
});
|
||||
}
|
||||
|
||||
public @Nullable ItemStack get(Player player) {
|
||||
return Optional.ofNullable(itemConfig.get(player, values, insertLore)).map(item -> {
|
||||
itemModifier.accept(item, player);
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
|
||||
metaModifier.accept(meta, player);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.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;
|
||||
|
||||
public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> CraftMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return CraftConfigValue.builder().createMessage().asValue(messageParser);
|
||||
}
|
||||
|
||||
public static CraftMessageValueBuilder<String> asString() {
|
||||
return CraftConfigValue.builder().createMessage().asStringValue();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString() {
|
||||
return asString().build();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||
return asString().defaults(defaultMessage).build();
|
||||
}
|
||||
|
||||
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(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
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
senders.addAll(Bukkit.getOnlinePlayers());
|
||||
return senders;
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, CommandSender> {
|
||||
|
||||
@NotNull
|
||||
public static <M> CraftMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||
return CraftConfigValue.builder().createMessage().asList(messageParser);
|
||||
}
|
||||
|
||||
public static CraftMessageListBuilder<String> asStrings() {
|
||||
return CraftConfigValue.builder().createMessage().asStringList();
|
||||
}
|
||||
|
||||
public static ConfiguredMessageList<String> ofStrings(@NotNull String... defaultMessages) {
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
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(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
senders.addAll(Bukkit.getOnlinePlayers());
|
||||
return senders;
|
||||
}
|
||||
}
|
||||
+6
-9
@@ -1,8 +1,7 @@
|
||||
package cc.carm.lib.configuration.craft.value;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -22,10 +21,8 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
||||
|
||||
protected final @NotNull Class<T> valueClass;
|
||||
|
||||
public ConfiguredSerializable(@Nullable CraftConfigProvider provider,
|
||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments,
|
||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
||||
super(provider, configPath, comments, 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);
|
||||
}
|
||||
+25
-12
@@ -1,16 +1,15 @@
|
||||
package cc.carm.lib.configuration.craft.value;
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
||||
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
||||
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.Optional;
|
||||
|
||||
@@ -32,10 +31,20 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
return CraftConfigValue.builder().createSound().defaults(sound, volume, pitch).build();
|
||||
}
|
||||
|
||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider,
|
||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
||||
@Nullable SoundConfig defaultValue) {
|
||||
super(provider, sectionPath, comments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
||||
public static @NotNull ConfiguredSound of(String soundName) {
|
||||
return CraftConfigValue.builder().createSound().defaults(soundName).build();
|
||||
}
|
||||
|
||||
public static @NotNull ConfiguredSound of(String soundName, float volume) {
|
||||
return CraftConfigValue.builder().createSound().defaults(soundName, volume).build();
|
||||
}
|
||||
|
||||
public static @NotNull ConfiguredSound of(String soundName, float volume, float pitch) {
|
||||
return CraftConfigValue.builder().createSound().defaults(soundName, volume, pitch).build();
|
||||
}
|
||||
|
||||
public ConfiguredSound(@NotNull ValueManifest<SoundConfig> manifest) {
|
||||
super(manifest, SoundConfig.class, getSoundParser(), SoundConfig::serialize);
|
||||
}
|
||||
|
||||
public void setSound(@NotNull Sound sound) {
|
||||
@@ -47,7 +56,7 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||
}
|
||||
|
||||
public void setSound(@NotNull Sound sound, float volume, float pitch) {
|
||||
set(new SoundConfig(sound, volume, pitch));
|
||||
set(new SoundConfig(sound.name(), sound, volume, pitch));
|
||||
}
|
||||
|
||||
public void playTo(@NotNull Player player) {
|
||||
@@ -58,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));
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||
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.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();
|
||||
}
|
||||
|
||||
public static ConfiguredTitle of(@Nullable String line1, @Nullable String line2) {
|
||||
return create().defaults(line1, line2).build();
|
||||
}
|
||||
|
||||
public static ConfiguredTitle of(@Nullable String line1, @Nullable String line2,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
return create().defaults(line1, line2).fadeIn(fadeIn).stay(stay).fadeOut(fadeOut).build();
|
||||
}
|
||||
|
||||
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(@NotNull ValueManifest<TitleConfig> manifest, @NotNull String[] params,
|
||||
@NotNull ConfiguredTitle.TitleConsumer sendConsumer,
|
||||
int fadeIn, int stay, int fadeOut) {
|
||||
super(manifest, TitleConfig.class, getTitleParser(), TitleConfig::serialize);
|
||||
this.sendConsumer = sendConsumer;
|
||||
this.params = params;
|
||||
this.fadeIn = fadeIn;
|
||||
this.stay = stay;
|
||||
this.fadeOut = fadeOut;
|
||||
}
|
||||
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE)
|
||||
public int getFadeInTicks() {
|
||||
return fadeIn;
|
||||
}
|
||||
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE)
|
||||
public int getStayTicks() {
|
||||
return stay;
|
||||
}
|
||||
|
||||
@Range(from = 0L, to = Integer.MAX_VALUE)
|
||||
public int getFadeOutTicks() {
|
||||
return fadeOut;
|
||||
}
|
||||
|
||||
public @NotNull ConfiguredTitle.TitleConsumer getSendConsumer() {
|
||||
return sendConsumer;
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player, Object... values) {
|
||||
send(player, this.params, values);
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player, @NotNull String[] params, @NotNull Object[] values) {
|
||||
send(player, ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
public void send(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||
TitleConfig config = get();
|
||||
if (config != null) {
|
||||
config.send(player, fadeIn, stay, fadeOut, placeholders, sendConsumer);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendToAll(Object... values) {
|
||||
sendToAll(this.params, values);
|
||||
}
|
||||
|
||||
public void sendToAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||
sendToAll(ParamsUtils.buildParams(params, values));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LoreOffsetTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void lore() {
|
||||
|
||||
System.out.println(ConfiguredItem.addLoreOffset(Arrays.asList("测试lore", "第二行"), "{1,-5}"));
|
||||
System.out.println(ConfiguredItem.addLoreOffset(Arrays.asList("测试lore", "第二行"), "{1,2}"));
|
||||
System.out.println(ConfiguredItem.addLoreOffset(Arrays.asList("测试lore", "第二行"), "{1,0}"));
|
||||
System.out.println(ConfiguredItem.addLoreOffset(Arrays.asList("测试lore", "第二行"), "{2}"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,22 +5,35 @@
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
<version>2.8.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-bungee</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>MineConfiguration-Bungee</name>
|
||||
<description>轻松(做)配置,适用于BungeeCord的版本,可用JSON与YAML格式。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${easyconfiguration.version}</version>
|
||||
<artifactId>mineconfiguration-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>yamlcommentwriter</artifactId>
|
||||
<version>${deps.yamlcommentwriter.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -44,18 +57,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||
|
||||
public static @NotNull BungeeConfigBuilder builder() {
|
||||
return new BungeeConfigBuilder();
|
||||
}
|
||||
|
||||
public BungeeConfigValue(@NotNull ValueManifest<T> manifest) {
|
||||
super(manifest);
|
||||
}
|
||||
|
||||
public BungeeConfigProvider getBukkitProvider() {
|
||||
ConfigurationProvider<?> provider = getProvider();
|
||||
if (provider instanceof BungeeConfigProvider) return (BungeeConfigProvider) getProvider();
|
||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
||||
}
|
||||
|
||||
public BungeeSectionWrapper getBukkitConfig() {
|
||||
return getBukkitProvider().getConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
+51
-3
@@ -1,14 +1,18 @@
|
||||
package cc.carm.lib.configuration;
|
||||
package cc.carm.lib.mineconfiguration.bungee;
|
||||
|
||||
import cc.carm.lib.configuration.bungee.BungeeConfigProvider;
|
||||
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);
|
||||
@@ -37,6 +41,14 @@ public class MineConfiguration {
|
||||
return from(new File(fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(Plugin plugin, String fileName) {
|
||||
return from(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(File file, String source) {
|
||||
return create(file, source, ConfigurationProvider.getProvider(YamlConfiguration.class));
|
||||
}
|
||||
@@ -53,6 +65,13 @@ public class MineConfiguration {
|
||||
return fromYAML(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(Plugin plugin, String fileName) {
|
||||
return fromYAML(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromYAML(Plugin plugin, String fileName, String source) {
|
||||
return fromYAML(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(File file, String source) {
|
||||
return create(file, source, ConfigurationProvider.getProvider(JsonConfiguration.class));
|
||||
@@ -70,5 +89,34 @@ public class MineConfiguration {
|
||||
return fromJSON(fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(Plugin plugin, String fileName) {
|
||||
return fromJSON(plugin, fileName, fileName);
|
||||
}
|
||||
|
||||
public static BungeeConfigProvider fromJSON(Plugin plugin, String fileName, String source) {
|
||||
return fromJSON(new File(plugin.getDataFolder(), fileName), source);
|
||||
}
|
||||
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin) {
|
||||
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin,
|
||||
@NotNull ConfigurationRoot configRoot,
|
||||
@NotNull ConfigurationRoot messageRoot) {
|
||||
this(plugin);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
public MineConfiguration(@NotNull Plugin plugin,
|
||||
@NotNull Class<? extends ConfigurationRoot> configRoot,
|
||||
@NotNull Class<? extends ConfigurationRoot> messageRoot) {
|
||||
this(plugin);
|
||||
initializeConfig(configRoot);
|
||||
initializeMessage(messageRoot);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||
|
||||
public abstract class AbstractBungeeBuilder<T, B extends AbstractBungeeBuilder<T, B>>
|
||||
extends AbstractConfigBuilder<T, B, BungeeConfigProvider> {
|
||||
|
||||
public AbstractBungeeBuilder() {
|
||||
super(BungeeConfigProvider.class);
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageBuilder;
|
||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BungeeConfigBuilder extends ConfigBuilder {
|
||||
|
||||
public @NotNull BungeeMessageBuilder createMessage() {
|
||||
return new BungeeMessageBuilder();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
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 net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class BungeeMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||
|
||||
|
||||
public BungeeMessageBuilder() {
|
||||
super(CommandSender.class, TextConfig.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <M> BungeeMessageValueBuilder<M> asValue(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
return new BungeeMessageValueBuilder<>(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <M> BungeeMessageListBuilder<M> asList(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
return new BungeeMessageListBuilder<>(parser);
|
||||
}
|
||||
|
||||
public @NotNull
|
||||
BungeeMessageValueBuilder<String> asStringValue() {
|
||||
return asValue(defaultParser()).whenSend(CommandSender::sendMessage);
|
||||
}
|
||||
|
||||
public @NotNull
|
||||
BungeeMessageListBuilder<String> asStringList() {
|
||||
return asList(defaultParser()).whenSend((r, m) -> m.forEach(r::sendMessage));
|
||||
}
|
||||
|
||||
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
||||
return (receiver, message) -> ColorParser.parse(message);
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
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;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
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 BungeeMessageListBuilder<M>
|
||||
extends MessageListBuilder<M, CommandSender, TextConfig, BungeeMessageListBuilder<M>> {
|
||||
|
||||
public BungeeMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, TextConfig::of, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull BungeeMessageListBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessageList<M> build() {
|
||||
return new ConfiguredMessageList<>(
|
||||
buildManifest(TextConfig.of(new ArrayList<>())),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendFunction
|
||||
);
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||
|
||||
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;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class BungeeMessageValueBuilder<M>
|
||||
extends MessageValueBuilder<M, CommandSender, TextConfig, BungeeMessageValueBuilder<M>> {
|
||||
|
||||
public BungeeMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
||||
super(CommandSender.class, TextConfig::new, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull BungeeMessageValueBuilder<M> getThis() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfiguredMessage<M> build() {
|
||||
return new ConfiguredMessage<>(
|
||||
buildManifest(TextConfig.of("")),
|
||||
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||
this.messageParser, this.sendHandler
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.data;
|
||||
|
||||
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
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.stream.Collectors;
|
||||
|
||||
public class TextConfig extends AbstractText<CommandSender> {
|
||||
|
||||
public TextConfig(@NotNull String message) {
|
||||
super(CommandSender.class, message);
|
||||
}
|
||||
|
||||
@Contract("!null,-> !null")
|
||||
public static @Nullable TextConfig of(@Nullable String message) {
|
||||
if (message == null) return null;
|
||||
else return new TextConfig(message);
|
||||
}
|
||||
|
||||
public static @NotNull List<TextConfig> of(@Nullable List<String> messages) {
|
||||
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
||||
else return messages.stream().map(TextConfig::of).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static @NotNull List<TextConfig> of(@NotNull String... messages) {
|
||||
return of(Arrays.asList(messages));
|
||||
}
|
||||
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> implements CommentedYAML {
|
||||
|
||||
protected static final char SEPARATOR = '.';
|
||||
|
||||
protected ConfigurationProvider loader;
|
||||
protected Configuration configuration;
|
||||
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
||||
|
||||
protected ConfigurationComments comments = new ConfigurationComments();
|
||||
|
||||
public BungeeConfigProvider(@NotNull File file, @NotNull ConfigurationProvider loader) {
|
||||
super(file);
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
public BungeeConfigProvider(@NotNull File file, @NotNull Class<? extends ConfigurationProvider> providerClass) {
|
||||
this(file, ConfigurationProvider.getProvider(providerClass));
|
||||
}
|
||||
|
||||
public void initializeConfig() throws IOException {
|
||||
this.configuration = getLoader().load(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BungeeSectionWrapper getConfiguration() {
|
||||
return BungeeSectionWrapper.of(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReload() throws Exception {
|
||||
this.configuration = getLoader().load(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigurationComments getComments() {
|
||||
return this.comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() throws Exception {
|
||||
try {
|
||||
CommentedYAMLWriter.writeWithComments(this, this.file);
|
||||
} catch (Exception ex) {
|
||||
getLoader().save(configuration, file);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
||||
return this.initializer;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
||||
|
||||
public class BungeeSectionWrapper implements ConfigurationWrapper<Configuration> {
|
||||
|
||||
private final Configuration configuration;
|
||||
|
||||
private BungeeSectionWrapper(@NotNull Configuration section) {
|
||||
this.configuration = section;
|
||||
}
|
||||
|
||||
@Contract("!null->!null")
|
||||
public static @Nullable BungeeSectionWrapper of(@Nullable Configuration section) {
|
||||
return section == null ? null : new BungeeSectionWrapper(section);
|
||||
}
|
||||
|
||||
protected static Set<String> getAllKeys(@NotNull Configuration config) {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
for (String key : config.getKeys()) {
|
||||
keys.add(key);
|
||||
Object value = config.get(key);
|
||||
if (value instanceof Configuration) {
|
||||
getAllKeys((Configuration) value).stream()
|
||||
.map(subKey -> key + SEPARATOR + subKey).forEach(keys::add);
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Configuration getSource() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Set<String> getKeys(boolean deep) {
|
||||
if (deep) {
|
||||
return new LinkedHashSet<>(getAllKeys(configuration));
|
||||
} else {
|
||||
return new LinkedHashSet<>(configuration.getKeys());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||
return getKeys(deep).stream()
|
||||
.collect(Collectors.toMap(key -> key, configuration::get, (a, b) -> b, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull String path, @Nullable Object value) {
|
||||
this.configuration.set(path, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull String path) {
|
||||
return this.configuration.contains(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Object get(@NotNull String path) {
|
||||
return this.configuration.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isList(@NotNull String path) {
|
||||
return get(path) instanceof List<?>;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<?> getList(@NotNull String path) {
|
||||
return this.configuration.getList(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigurationSection(@NotNull String path) {
|
||||
return get(path) instanceof Configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BungeeSectionWrapper getConfigurationSection(@NotNull String path) {
|
||||
return of(this.configuration.getSection(path));
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||
|
||||
import cc.carm.lib.configuration.core.value.ValueManifest;
|
||||
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
|
||||
import cc.carm.lib.mineconfiguration.bungee.data.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
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) {
|
||||
return BungeeConfigValue.builder().createMessage().asValue(messageParser);
|
||||
}
|
||||
|
||||
public static BungeeMessageValueBuilder<String> asString() {
|
||||
return BungeeConfigValue.builder().createMessage().asStringValue();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString() {
|
||||
return asString().build();
|
||||
}
|
||||
|
||||
public static ConfiguredMessage<String> ofString(@NotNull String defaultMessage) {
|
||||
return asString().defaults(defaultMessage).build();
|
||||
}
|
||||
|
||||
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(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(ProxyServer.getInstance().getConsole());
|
||||
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||
return senders;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
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.TextConfig;
|
||||
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
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) {
|
||||
return BungeeConfigValue.builder().createMessage().asList(messageParser);
|
||||
}
|
||||
|
||||
public static BungeeMessageListBuilder<String> asStrings() {
|
||||
return BungeeConfigValue.builder().createMessage().asStringList();
|
||||
}
|
||||
|
||||
public static ConfiguredMessageList<String> ofStrings(@NotNull String... defaultMessages) {
|
||||
return asStrings().defaults(defaultMessages).build();
|
||||
}
|
||||
|
||||
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(manifest, TextConfig.class, params, messageParser, sendFunction, TextConfig::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<CommandSender> getAllReceivers() {
|
||||
List<CommandSender> senders = new ArrayList<>();
|
||||
senders.add(ProxyServer.getInstance().getConsole());
|
||||
senders.addAll(ProxyServer.getInstance().getPlayers());
|
||||
return senders;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.configuration.core.annotation.HeaderComment;
|
||||
import cc.carm.lib.configuration.core.annotation.InlineComment;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.configuration.core.value.ConfigValue;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||
import cc.carm.lib.mineconfiguration.bungee.MineConfiguration;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
File file = new File("target/config.yml");
|
||||
ConfigurationProvider<?> config = MineConfiguration.from(file);
|
||||
config.initialize(Configuration.class);
|
||||
|
||||
try {
|
||||
System.out.println("--------------------------------------------");
|
||||
System.out.println(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8));
|
||||
System.out.println("--------------------------------------------");
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@HeaderComment({
|
||||
"MineConfiguration for BungeeCord",
|
||||
"测试实例配置文件", ""
|
||||
})
|
||||
public static class Configuration extends ConfigurationRoot {
|
||||
|
||||
@InlineComment("是否显示DEBUG消息")
|
||||
public static final ConfigValue<Boolean> DEBUG = ConfiguredValue.of(Boolean.class, false);
|
||||
|
||||
@HeaderComment("启动时执行的命令")
|
||||
public static final class START_UP {
|
||||
|
||||
@HeaderComment("延迟执行的时间(单位:秒)")
|
||||
public static final ConfigValue<Integer> DELAY = ConfiguredValue.of(Integer.class, 30);
|
||||
|
||||
@HeaderComment("循环执行的间隔(单位:秒)")
|
||||
public static final ConfigValue<Integer> PERIOD = ConfiguredValue.of(Integer.class, 10);
|
||||
|
||||
@HeaderComment("执行的指令列表")
|
||||
@InlineComment("建议以\"\"包裹")
|
||||
public static final ConfigValue<List<String>> COMMANDS = ConfiguredList.builderOf(String.class)
|
||||
.fromString().defaults("alert Commands here!").build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,26 +3,27 @@
|
||||
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<modules>
|
||||
<module>bungee</module>
|
||||
|
||||
<module>craftbukkit</module>
|
||||
<module>bukkit</module>
|
||||
<module>spigot</module>
|
||||
</modules>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<project.jdk.version>8</project.jdk.version>
|
||||
<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>
|
||||
|
||||
<easyconfiguration.version>2.3.0</easyconfiguration.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>1.1.0-SNAPSHOT</version>
|
||||
<version>2.8.3</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>common</module>
|
||||
<module>platform/bungee</module>
|
||||
<module>platform/bukkit</module>
|
||||
</modules>
|
||||
|
||||
<name>MineConfiguration</name>
|
||||
<description>EasyConfiguration for MineCraft.</description>
|
||||
@@ -39,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>
|
||||
@@ -47,8 +48,8 @@
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The MIT License</name>
|
||||
<url>https://opensource.org/licenses/MIT</url>
|
||||
<name>GNU LESSER GENERAL PUBLIC LICENSE</name>
|
||||
<url>https://www.gnu.org/licenses/lgpl-3.0.html</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
@@ -64,26 +65,30 @@
|
||||
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>nexus</id>
|
||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/*</url>
|
||||
<id>sonatype</id>
|
||||
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>minebench-repo</id>
|
||||
<url>https://repo.minebench.de/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>lumine</id>
|
||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
@@ -104,7 +109,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<version>24.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -117,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>
|
||||
@@ -125,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>
|
||||
@@ -145,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>
|
||||
@@ -153,6 +158,36 @@
|
||||
<goals>deploy</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>${project.jdk.version}</source>
|
||||
<target>${project.jdk.version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<compilerArgument>-parameters</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<pluginManagement>
|
||||
@@ -161,7 +196,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
<version>3.5.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
@@ -169,11 +204,13 @@
|
||||
<charset>UTF-8</charset>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
<locale>zh_CN</locale>
|
||||
|
||||
<includeDependencySources>true</includeDependencySources>
|
||||
<dependencySourceIncludes>
|
||||
<dependencySourceInclude>cc.carm.lib:*</dependencySourceInclude>
|
||||
</dependencySourceIncludes>
|
||||
<additionalOptions>
|
||||
<additionalOption>-Xdoclint:none</additionalOption>
|
||||
</additionalOptions>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@@ -185,42 +222,10 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<compilerArgument>-parameters</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.5.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -286,7 +291,7 @@
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
|
||||
</profiles>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mineconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
</properties>
|
||||
<artifactId>mineconfiguration-spigot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-core</artifactId>
|
||||
<version>${easyconfiguration.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>mineconfiguration-craftbukkit</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>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -1,33 +0,0 @@
|
||||
package cc.carm.lib.configuration;
|
||||
|
||||
import cc.carm.lib.configuration.spigot.source.SpigotConfigProvider;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
package cc.carm.lib.configuration.spigot.source;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SpigotConfigProvider extends CraftConfigProvider {
|
||||
|
||||
public SpigotConfigProvider(@NotNull File file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig() {
|
||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||
this.initializer = new ConfigInitializer<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo commentInfo) {
|
||||
if (path == null) {
|
||||
if (commentInfo == null) this.configuration.options().setFooter(null);
|
||||
else if (!String.join("", commentInfo.getComments()).isEmpty()) {
|
||||
this.configuration.options().setFooter(Arrays.asList(commentInfo.getComments()));
|
||||
}
|
||||
} else {
|
||||
if (commentInfo == null) this.configuration.setComments(path, null);
|
||||
else {
|
||||
List<String> comments = new ArrayList<>();
|
||||
|
||||
if (!String.join("", commentInfo.getComments()).isEmpty()) {
|
||||
if (commentInfo.startWrap()) comments.add("");
|
||||
comments.addAll(Arrays.asList(commentInfo.getComments()));
|
||||
if (commentInfo.endWrap()) comments.add("");
|
||||
} else if (commentInfo.startWrap() || commentInfo.endWrap()) {
|
||||
comments.add("");
|
||||
}
|
||||
|
||||
this.configuration.setComments(path, comments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user