mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fa6fa1551 | |||
| 346ae4c494 | |||
| 2d8c1817a6 | |||
| f67d0fae8d | |||
| 8d723df7a6 | |||
| d4c7124d9e | |||
| 2804543419 | |||
| f826014c09 | |||
| 616d24d885 | |||
| 8d58583a1e | |||
| 4b594269bd | |||
| b629a7d96d | |||
| 455ab775ed | |||
| d5f1e8b230 | |||
| 11b910a273 | |||
| 40ec299c64 | |||
| 483fbc7c4d | |||
| 65d7a32108 | |||
| 6aa220924d | |||
| f4a55f216b | |||
| 34a51c42a5 | |||
| c50df3bc56 | |||
| 9a95e3d105 | |||
| 98ee47f676 |
@@ -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:
|
jobs:
|
||||||
gh-deploy:
|
gh-deploy:
|
||||||
name: "Publish Project (GitHub)"
|
name: "Deploy Project (GitHub)"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||||
|
|
||||||
central-deploy:
|
central-deploy:
|
||||||
name: "Deploy Project (Central Repository)"
|
name: "Deploy Project (Central)"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -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 .documentation/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
|
||||||
@@ -23,14 +23,17 @@ EasyConfiguration for MineCraft!
|
|||||||
### **MineConfiguration-Common**
|
### **MineConfiguration-Common**
|
||||||
|
|
||||||
全部版本的共用部分,包括
|
全部版本的共用部分,包括
|
||||||
|
|
||||||
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||||
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||||
|
|
||||||
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||||
|
|
||||||
### **MineConfiguration-CraftBukkit**
|
### MineConfiguration-Bukkit
|
||||||
|
|
||||||
CraftBukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit** 或 **MineConfiguration-Spigot** 。
|
#### MineConfiguration-Bukkit-Base
|
||||||
|
|
||||||
|
Bukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit-General** 或 **MineConfiguration-Bukkit-Native** 。
|
||||||
|
|
||||||
相较于基础版本,额外提供了以下功能:
|
相较于基础版本,额外提供了以下功能:
|
||||||
|
|
||||||
@@ -40,23 +43,22 @@ CraftBukkit系通用依赖,不包含实现部分,请使用 **MineConfigurati
|
|||||||
|
|
||||||
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
||||||
|
|
||||||
### **MineConfiguration-Bukkit**
|
#### **MineConfiguration-Bukkit** _(推荐)_
|
||||||
|
|
||||||
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
||||||
|
|
||||||
### **MineConfiguration-Spigot**
|
#### **MineConfiguration-Spigot**
|
||||||
|
|
||||||
适用于 Spigot(1.18+) 的版本,适配了1.18与更新版本自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
适用于 Spigot(1.18+) 的版本,适配了1.18及以后版本Spigot原生自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
||||||
|
|
||||||
### **MineConfiguration-Bungee**
|
### **MineConfiguration-Bungee**
|
||||||
|
|
||||||
适用于BungeeCord的版本,可用JSON与YAML格式,但**不支持配置文件注释**。
|
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
||||||
|
|
||||||
如需使用配置文件注释,建议使用 [EasyConfiguration-YAML](https://github.com/CarmJos/EasyConfiguration) 。
|
|
||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
|
|
||||||
请详见 [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,71 +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.2.2</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>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.clip</groupId>
|
|
||||||
<artifactId>placeholderapi</artifactId>
|
|
||||||
<version>2.11.1</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,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());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bungee.source;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+3
-23
@@ -5,12 +5,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.2</version>
|
<version>2.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>mineconfiguration-common</artifactId>
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
|
||||||
@@ -23,14 +23,6 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>de.themoep</groupId>
|
|
||||||
<artifactId>minedown</artifactId>
|
|
||||||
<version>1.7.1-SNAPSHOT</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-chat</artifactId>
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
@@ -43,18 +35,6 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
|||||||
+2
-8
@@ -1,19 +1,13 @@
|
|||||||
package cc.carm.lib.configuration.common.builder.message;
|
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public abstract class MessageConfigBuilder<R, T extends AbstractText<R>> {
|
public abstract class MessageConfigBuilder<R, T extends AbstractText<R>> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认的变量格式为 {@code %(变量名)}。
|
|
||||||
*/
|
|
||||||
public static Function<@NotNull String, @NotNull String> DEFAULT_PARAM_FORMATTER = (s) -> "%(" + s + ")";
|
|
||||||
|
|
||||||
protected final @NotNull Class<R> receiverClazz;
|
protected final @NotNull Class<R> receiverClazz;
|
||||||
protected final @NotNull Class<T> textClazz;
|
protected final @NotNull Class<T> textClazz;
|
||||||
|
|
||||||
+5
-10
@@ -1,8 +1,9 @@
|
|||||||
package cc.carm.lib.configuration.common.builder.message;
|
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||||
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import cc.carm.lib.configuration.common.value.ConfigMessageList;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -15,8 +16,6 @@ import java.util.function.BiFunction;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder.DEFAULT_PARAM_FORMATTER;
|
|
||||||
|
|
||||||
public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B extends MessageListBuilder<M, R, T, B>>
|
public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B extends MessageListBuilder<M, R, T, B>>
|
||||||
extends CommonConfigBuilder<List<T>, B> {
|
extends CommonConfigBuilder<List<T>, B> {
|
||||||
|
|
||||||
@@ -36,7 +35,7 @@ public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B exte
|
|||||||
this.textBuilder = textBuilder;
|
this.textBuilder = textBuilder;
|
||||||
this.params = new String[0];
|
this.params = new String[0];
|
||||||
this.messageParser = parser;
|
this.messageParser = parser;
|
||||||
this.paramFormatter = DEFAULT_PARAM_FORMATTER;
|
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||||
this.sendFunction = (sender, M) -> {
|
this.sendFunction = (sender, M) -> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -68,8 +67,4 @@ public abstract class MessageListBuilder<M, R, T extends AbstractText<R>, B exte
|
|||||||
@Override
|
@Override
|
||||||
public abstract @NotNull ConfigMessageList<M, T, R> build();
|
public abstract @NotNull ConfigMessageList<M, T, R> build();
|
||||||
|
|
||||||
protected final String[] buildParams() {
|
|
||||||
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-11
@@ -1,19 +1,17 @@
|
|||||||
package cc.carm.lib.configuration.common.builder.message;
|
package cc.carm.lib.mineconfiguration.common.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import cc.carm.lib.configuration.common.value.ConfigMessage;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||||
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.CommonConfigBuilder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder.DEFAULT_PARAM_FORMATTER;
|
|
||||||
|
|
||||||
public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B extends MessageValueBuilder<M, R, T, B>>
|
public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B extends MessageValueBuilder<M, R, T, B>>
|
||||||
extends CommonConfigBuilder<T, B> {
|
extends CommonConfigBuilder<T, B> {
|
||||||
|
|
||||||
@@ -32,7 +30,7 @@ public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B ext
|
|||||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser) {
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> parser) {
|
||||||
this.receiverClazz = receiverClazz;
|
this.receiverClazz = receiverClazz;
|
||||||
this.params = new String[0];
|
this.params = new String[0];
|
||||||
this.paramFormatter = DEFAULT_PARAM_FORMATTER;
|
this.paramFormatter = ParamsUtils.DEFAULT_PARAM_FORMATTER;
|
||||||
this.textBuilder = textBuilder;
|
this.textBuilder = textBuilder;
|
||||||
this.messageParser = parser;
|
this.messageParser = parser;
|
||||||
this.sendHandler = (receiver, M) -> {
|
this.sendHandler = (receiver, M) -> {
|
||||||
@@ -66,8 +64,4 @@ public abstract class MessageValueBuilder<M, R, T extends AbstractText<R>, B ext
|
|||||||
@Override
|
@Override
|
||||||
public abstract @NotNull ConfigMessage<M, T, R> build();
|
public abstract @NotNull ConfigMessage<M, T, R> build();
|
||||||
|
|
||||||
protected final String[] buildParams() {
|
|
||||||
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+4
-25
@@ -1,9 +1,9 @@
|
|||||||
package cc.carm.lib.configuration.common.data;
|
package cc.carm.lib.mineconfiguration.common.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -30,35 +30,14 @@ public abstract class AbstractText<R> {
|
|||||||
|
|
||||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||||
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
@Nullable R receiver, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
return parse(parser, receiver, buildParams(params, values));
|
return parse(parser, receiver, ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
public <M> @Nullable M parse(@NotNull BiFunction<@Nullable R, @NotNull String, @NotNull M> parser,
|
||||||
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
String message = getMessage();
|
String message = getMessage();
|
||||||
if (message.isEmpty()) return null; // No further processing
|
if (message.isEmpty()) return null; // No further processing
|
||||||
else return parser.apply(receiver, setPlaceholders(message, placeholders));
|
else return parser.apply(receiver, ParamsUtils.setPlaceholders(message, placeholders));
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
+12
-16
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.common.utils;
|
package cc.carm.lib.mineconfiguration.common.utils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -8,6 +8,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class ColorParser {
|
public class ColorParser {
|
||||||
|
|
||||||
|
public static Pattern HEX_PATTERN = Pattern.compile("&\\(&?#([0-9a-fA-F]{6})\\)");
|
||||||
|
|
||||||
public static String parse(String text) {
|
public static String parse(String text) {
|
||||||
return parseBaseColor(parseHexColor(text));
|
return parseBaseColor(parseHexColor(text));
|
||||||
}
|
}
|
||||||
@@ -24,25 +26,19 @@ public class ColorParser {
|
|||||||
return text.replaceAll("&", "§").replace("§§", "&");
|
return text.replaceAll("&", "§").replace("§§", "&");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse HEXColor code like <blockquote><pre>&(#000000)</pre></blockquote> to minecraft colored text.
|
|
||||||
*
|
|
||||||
* @param text the text to parse
|
|
||||||
* @return color parsed
|
|
||||||
*/
|
|
||||||
public static String parseHexColor(String text) {
|
public static String parseHexColor(String text) {
|
||||||
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
Matcher matcher = HEX_PATTERN.matcher(text);
|
||||||
Matcher matcher = pattern.matcher(text);
|
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
text = matcher.replaceFirst(buildHexColor(matcher.group(1)).toLowerCase());
|
||||||
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);
|
matcher.reset(text);
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String buildHexColor(String hexCode) {
|
||||||
|
return Arrays.stream(hexCode.split(""))
|
||||||
|
.map(s -> '§' + s)
|
||||||
|
.collect(Collectors.joining("", '§' + "x", ""));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+14
-13
@@ -1,13 +1,14 @@
|
|||||||
package cc.carm.lib.configuration.common.value;
|
package cc.carm.lib.mineconfiguration.common.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@@ -18,27 +19,27 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
|||||||
|
|
||||||
protected final @NotNull String[] params;
|
protected final @NotNull String[] params;
|
||||||
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
protected final @NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser;
|
||||||
protected final @NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction;
|
protected final @NotNull BiConsumer<@NotNull R, @NotNull M> messageConsumer;
|
||||||
|
|
||||||
protected final @NotNull Function<String, T> textBuilder;
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
public ConfigMessage(@Nullable ConfigurationProvider<?> provider,
|
public ConfigMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
@NotNull Class<T> textClazz, @NotNull T defaultMessage, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull R, @NotNull M> sendFunction,
|
@NotNull BiConsumer<@NotNull R, @NotNull M> messageConsumer,
|
||||||
@NotNull Function<String, T> textBuilder) {
|
@NotNull Function<String, T> textBuilder) {
|
||||||
super(provider, sectionPath, comments, textClazz, defaultMessage,
|
super(provider, sectionPath, headerComments, inlineComments, textClazz, defaultMessage,
|
||||||
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
ConfigValueParser.castToString().andThen((s, d) -> textBuilder.apply(s)), AbstractText::getMessage
|
||||||
);
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
this.messageParser = messageParser;
|
this.messageParser = messageParser;
|
||||||
this.sendFunction = sendFunction;
|
this.messageConsumer = messageConsumer;
|
||||||
this.textBuilder = textBuilder;
|
this.textBuilder = textBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
public @Nullable M parse(@Nullable R sender, @Nullable Object... values) {
|
||||||
return parse(sender, AbstractText.buildParams(params, values));
|
return parse(sender, ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
public @Nullable M parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||||
@@ -48,18 +49,18 @@ public abstract class ConfigMessage<M, T extends AbstractText<R>, R>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable R receiver, @Nullable Object... values) {
|
public void send(@Nullable R receiver, @Nullable Object... values) {
|
||||||
send(receiver, AbstractText.buildParams(params, values));
|
send(receiver, ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
if (receiver == null) return;
|
if (receiver == null) return;
|
||||||
M parsed = parse(receiver, placeholders);
|
M parsed = parse(receiver, placeholders);
|
||||||
if (parsed == null) return;
|
if (parsed == null) return;
|
||||||
sendFunction.accept(receiver, parsed);
|
messageConsumer.accept(receiver, parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(@Nullable Object... values) {
|
public void broadcast(@Nullable Object... values) {
|
||||||
broadcast(AbstractText.buildParams(params, values));
|
broadcast(ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
||||||
+9
-9
@@ -1,8 +1,8 @@
|
|||||||
package cc.carm.lib.configuration.common.value;
|
package cc.carm.lib.mineconfiguration.common.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
import cc.carm.lib.configuration.core.function.ConfigDataFunction;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -25,14 +25,14 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
protected final @NotNull Function<String, T> textBuilder;
|
protected final @NotNull Function<String, T> textBuilder;
|
||||||
|
|
||||||
@SuppressWarnings("NullableProblems")
|
@SuppressWarnings("NullableProblems")
|
||||||
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider,
|
public ConfigMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
@NotNull Class<T> textClazz, @NotNull List<T> messages, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable R, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
@NotNull BiConsumer<@NotNull R, @NotNull List<M>> sendFunction,
|
||||||
@NotNull Function<String, @NotNull T> textBuilder) {
|
@NotNull Function<String, @NotNull T> textBuilder) {
|
||||||
super(
|
super(
|
||||||
provider, sectionPath, comments, textClazz, messages,
|
provider, sectionPath, headerComments, inlineComments, textClazz, messages,
|
||||||
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
|
ConfigDataFunction.castToString().andThen(textBuilder::apply), AbstractText::getMessage
|
||||||
);
|
);
|
||||||
this.params = params;
|
this.params = params;
|
||||||
@@ -42,7 +42,7 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable List<M> parse(@Nullable R sender, @Nullable Object... values) {
|
public @Nullable List<M> parse(@Nullable R sender, @Nullable Object... values) {
|
||||||
return parse(sender, T.buildParams(params, values));
|
return parse(sender, ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable List<M> parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
public @Nullable List<M> parse(@Nullable R sender, @NotNull Map<String, Object> placeholders) {
|
||||||
@@ -57,7 +57,7 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable R receiver, @Nullable Object... values) {
|
public void send(@Nullable R receiver, @Nullable Object... values) {
|
||||||
send(receiver, T.buildParams(params, values));
|
send(receiver, ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
public void send(@Nullable R receiver, @NotNull Map<String, Object> placeholders) {
|
||||||
@@ -68,7 +68,7 @@ public abstract class ConfigMessageList<M, T extends AbstractText<R>, R> extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(@Nullable Object... values) {
|
public void broadcast(@Nullable Object... values) {
|
||||||
broadcast(T.buildParams(params, values));
|
broadcast(ParamsUtils.buildParams(params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
public abstract void broadcast(@NotNull Map<String, Object> placeholders);
|
||||||
@@ -1,71 +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.2.2</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>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>mineconfiguration-common</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>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.clip</groupId>
|
|
||||||
<artifactId>placeholderapi</artifactId>
|
|
||||||
<version>2.11.1</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>
|
|
||||||
-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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder.message;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.builder.message.MessageListBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
|
||||||
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.Optional;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
public class CraftMessageListBuilder<M>
|
|
||||||
extends MessageListBuilder<M, CommandSender, MessageText, CraftMessageListBuilder<M>> {
|
|
||||||
|
|
||||||
public CraftMessageListBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
|
||||||
super(CommandSender.class, MessageText::of, parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull CraftMessageListBuilder<M> getThis() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ConfiguredMessageList<M> build() {
|
|
||||||
return new ConfiguredMessageList<>(
|
|
||||||
this.provider, this.path, buildComments(),
|
|
||||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
|
||||||
buildParams(), this.messageParser, this.sendFunction
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder.message;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.builder.message.MessageValueBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
|
||||||
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.Optional;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
public class CraftMessageValueBuilder<M>
|
|
||||||
extends MessageValueBuilder<M, CommandSender, MessageText, CraftMessageValueBuilder<M>> {
|
|
||||||
|
|
||||||
public CraftMessageValueBuilder(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> parser) {
|
|
||||||
super(CommandSender.class, MessageText::new, parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull CraftMessageValueBuilder<M> getThis() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ConfiguredMessage<M> build() {
|
|
||||||
return new ConfiguredMessage<>(
|
|
||||||
this.provider, this.path, buildComments(),
|
|
||||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
|
||||||
buildParams(), this.messageParser, this.sendHandler
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-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,119 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.utils.ColorParser;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import cc.carm.lib.configuration.craft.utils.PAPIHelper;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.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) {
|
|
||||||
return getItemStack(null, amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ItemStack getItemStack(@Nullable Player player) {
|
|
||||||
return getItemStack(player, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount) {
|
|
||||||
ItemStack item = new ItemStack(type, amount, data);
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (meta == null) return item;
|
|
||||||
if (getName() != null) meta.setDisplayName(parseName(player, getName()));
|
|
||||||
if (!getLore().isEmpty()) meta.setLore(parseLore(player, 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("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);
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static @NotNull String parseName(@Nullable Player player, String message) {
|
|
||||||
if (player != null && hasPlaceholderAPI()) message = PAPIHelper.parseMessages(player, message);
|
|
||||||
return ColorParser.parse(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected static @NotNull List<String> parseLore(@Nullable Player player, List<String> messages) {
|
|
||||||
if (player != null && hasPlaceholderAPI()) messages = PAPIHelper.parseMessages(player, messages);
|
|
||||||
return ColorParser.parse(messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasPlaceholderAPI() {
|
|
||||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.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 MessageText extends AbstractText<CommandSender> {
|
|
||||||
|
|
||||||
public MessageText(@NotNull String message) {
|
|
||||||
super(CommandSender.class, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
@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(@Nullable List<String> messages) {
|
|
||||||
if (messages == null || messages.isEmpty()) return new ArrayList<>();
|
|
||||||
else return messages.stream().map(MessageText::of).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull List<MessageText> of(@NotNull String... messages) {
|
|
||||||
return of(Arrays.asList(messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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 <blockquote><pre>&(#000000)</pre></blockquote> 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,19 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.utils;
|
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PAPIHelper {
|
|
||||||
|
|
||||||
public static String parseMessages(Player player, String message) {
|
|
||||||
return PlaceholderAPI.setPlaceholders(player, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> parseMessages(Player player, List<String> messages) {
|
|
||||||
return PlaceholderAPI.setPlaceholders(player, messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+10
-8
@@ -1,23 +1,25 @@
|
|||||||
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.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.CraftConfigBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
public static @NotNull CraftConfigBuilder builder() {
|
public static @NotNull CraftConfigBuilder builder() {
|
||||||
return new CraftConfigBuilder();
|
return new CraftConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftConfigValue(@Nullable CraftConfigProvider provider,
|
public CraftConfigValue(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
super(provider, configPath, comments, defaultValue);
|
@Nullable T defaultValue) {
|
||||||
|
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftConfigProvider getBukkitProvider() {
|
public CraftConfigProvider getBukkitProvider() {
|
||||||
+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;
|
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||||
|
|
||||||
public abstract class AbstractCraftBuilder<T, B extends AbstractCraftBuilder<T, B>>
|
public abstract class AbstractCraftBuilder<T, B extends AbstractCraftBuilder<T, B>>
|
||||||
+12
-7
@@ -1,12 +1,13 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder;
|
package cc.carm.lib.mineconfiguration.bukkit.builder;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.item.ItemConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.message.CraftMessageBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.serializable.SerializableBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.value.ConfiguredItem;
|
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -25,6 +26,10 @@ public class CraftConfigBuilder extends ConfigBuilder {
|
|||||||
return new CraftMessageBuilder();
|
return new CraftMessageBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull TitleConfigBuilder createTitle() {
|
||||||
|
return new TitleConfigBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
||||||
return new SerializableBuilder<>(valueClass);
|
return new SerializableBuilder<>(valueClass);
|
||||||
}
|
}
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.builder.item;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ItemConfigBuilder extends AbstractCraftBuilder<ItemConfig, 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 Function<@NotNull String, @NotNull 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 ItemConfig buildDefault() {
|
||||||
|
if (this.type == null) return null;
|
||||||
|
else return new ItemConfig(type, data, name, lore, enchants, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredItem build() {
|
||||||
|
ItemConfig defaultItem = Optional.ofNullable(this.defaultValue).orElse(buildDefault());
|
||||||
|
return new ConfiguredItem(this.provider, this.path, this.headerComments, this.inlineComment, defaultItem, buildParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final String[] buildParams() {
|
||||||
|
return Arrays.stream(params).map(param -> paramFormatter.apply(param)).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+8
-19
@@ -1,22 +1,20 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder.message;
|
package cc.carm.lib.mineconfiguration.bukkit.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||||
import cc.carm.lib.configuration.common.utils.ColorParser;
|
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.utils.PAPIHelper;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, MessageText> {
|
public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, TextConfig> {
|
||||||
|
|
||||||
|
|
||||||
public CraftMessageBuilder() {
|
public CraftMessageBuilder() {
|
||||||
super(CommandSender.class, MessageText.class);
|
super(CommandSender.class, TextConfig.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,16 +38,7 @@ public class CraftMessageBuilder extends MessageConfigBuilder<CommandSender, Mes
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
protected static @NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable String> defaultParser() {
|
||||||
return (receiver, message) -> {
|
return (receiver, message) -> TextParser.parseText(receiver, message, new HashMap<>());
|
||||||
if (receiver instanceof Player && hasPlaceholderAPI()) {
|
|
||||||
message = PAPIHelper.parseMessages((Player) receiver, message);
|
|
||||||
}
|
|
||||||
return ColorParser.parse(message);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasPlaceholderAPI() {
|
|
||||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
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.Optional;
|
||||||
|
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<>(
|
||||||
|
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(TextConfig.of(new ArrayList<>())),
|
||||||
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
|
this.messageParser, this.sendFunction
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
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.Optional;
|
||||||
|
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<>(
|
||||||
|
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||||
|
Optional.ofNullable(this.defaultValue).orElse(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.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||||
import cc.carm.lib.configuration.craft.value.ConfiguredSerializable;
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredSerializable;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public class SerializableBuilder<T extends ConfigurationSerializable>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredSerializable<T> build() {
|
public @NotNull ConfiguredSerializable<T> build() {
|
||||||
return new ConfiguredSerializable<>(this.provider, this.path, buildComments(), this.valueClass, this.defaultValue);
|
return new ConfiguredSerializable<>(this.provider, this.path, this.headerComments, this.inlineComment, this.valueClass, this.defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+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(this.provider, this.path, this.headerComments, this.inlineComment, this.defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+97
@@ -0,0 +1,97 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.builder.title;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.AbstractCraftBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.ProtocolLibHelper;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class TitleConfigBuilder extends AbstractCraftBuilder<TitleConfig, TitleConfigBuilder> {
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
protected static @NotNull TitleSendConsumer DEFAULT_TITLE_CONSUMER = (player, fadeIn, stay, fadeOut, line1, line2) -> {
|
||||||
|
if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
|
||||||
|
try {
|
||||||
|
ProtocolLibHelper.sendTitle(player, fadeIn, stay, fadeOut, line1, line2);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
player.sendTitle(line1, line2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
protected @NotNull String[] params = new String[0];
|
||||||
|
|
||||||
|
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn = 10;
|
||||||
|
protected @Range(from = 0L, to = Integer.MAX_VALUE) int stay = 60;
|
||||||
|
protected @Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut = 10;
|
||||||
|
|
||||||
|
protected @NotNull TitleSendConsumer sendConsumer;
|
||||||
|
protected @NotNull Function<@NotNull String, @NotNull String> paramFormatter;
|
||||||
|
|
||||||
|
public TitleConfigBuilder() {
|
||||||
|
this.sendConsumer = TitleConfigBuilder.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 TitleSendConsumer 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(Function<String, String> paramFormatter) {
|
||||||
|
this.paramFormatter = paramFormatter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull TitleConfigBuilder getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredTitle build() {
|
||||||
|
return new ConfiguredTitle(
|
||||||
|
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||||
|
this.defaultValue, ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
|
this.sendConsumer, this.fadeIn, this.stay, this.fadeOut
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+172
@@ -0,0 +1,172 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ItemConfig {
|
||||||
|
|
||||||
|
protected @NotNull Material type;
|
||||||
|
protected short data;
|
||||||
|
protected @Nullable String name;
|
||||||
|
protected @NotNull List<String> lore;
|
||||||
|
|
||||||
|
protected @NotNull Map<Enchantment, Integer> enchants;
|
||||||
|
protected @NotNull Set<ItemFlag> flags;
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, @Nullable String name) {
|
||||||
|
this(type, name, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, @Nullable String name, @NotNull List<String> lore) {
|
||||||
|
this(type, (short) 0, name, lore);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, short damage,
|
||||||
|
@Nullable String name, @NotNull List<String> lore) {
|
||||||
|
this(type, damage, name, lore, Collections.emptyMap(), Collections.emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemConfig(@NotNull Material type, short damage,
|
||||||
|
@Nullable String name, @NotNull List<String> lore,
|
||||||
|
@NotNull Map<Enchantment, Integer> enchants,
|
||||||
|
@NotNull Set<ItemFlag> flags) {
|
||||||
|
this.type = type;
|
||||||
|
this.data = damage;
|
||||||
|
this.name = name;
|
||||||
|
this.lore = lore;
|
||||||
|
this.enchants = enchants;
|
||||||
|
this.flags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Material getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getName(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return Optional.ofNullable(getName())
|
||||||
|
.map(name -> TextParser.parseText(player, name, placeholders))
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> getLore() {
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable List<String> getLore(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (getLore().isEmpty()) return null;
|
||||||
|
else return TextParser.parseList(player, getLore(), placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final @NotNull ItemStack getItemStack() {
|
||||||
|
return getItemStack(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(int amount) {
|
||||||
|
return getItemStack(null, amount, new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player) {
|
||||||
|
return getItemStack(player, new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return getItemStack(player, 1, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ItemStack getItemStack(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
|
||||||
|
ItemStack item = new ItemStack(type, amount, data);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return item;
|
||||||
|
Optional.ofNullable(getName(player, placeholders)).ifPresent(meta::setDisplayName);
|
||||||
|
Optional.ofNullable(getLore(player, placeholders)).ifPresent(meta::setLore);
|
||||||
|
enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true));
|
||||||
|
flags.forEach(meta::addItemFlags);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("type", type.name());
|
||||||
|
if (this.data != 0) map.put("data", data);
|
||||||
|
if (name != null) map.put("name", name);
|
||||||
|
if (!lore.isEmpty()) map.put("lore", lore);
|
||||||
|
|
||||||
|
Map<String, Integer> enchantments = new LinkedHashMap<>();
|
||||||
|
enchants.forEach((enchant, level) -> {
|
||||||
|
if (level > 0) enchantments.put(enchant.getName(), level);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!enchantments.isEmpty()) {
|
||||||
|
map.put("enchants", enchantments);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flags.isEmpty()) {
|
||||||
|
map.put("flags", flags.stream().map(ItemFlag::name).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ItemConfig deserialize(@NotNull 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+27
-12
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@@ -7,27 +7,36 @@ import org.jetbrains.annotations.Contract;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class SoundConfig {
|
public class SoundConfig {
|
||||||
|
|
||||||
protected @NotNull Sound type;
|
protected @NotNull String typeName;
|
||||||
|
protected @Nullable Sound type;
|
||||||
protected float volume;
|
protected float volume;
|
||||||
protected float pitch;
|
protected float pitch;
|
||||||
|
|
||||||
public SoundConfig(@NotNull Sound type) {
|
public SoundConfig(@NotNull String typeName) {
|
||||||
this(type, 1, 1);
|
this(typeName, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundConfig(@NotNull Sound type, float volume) {
|
public SoundConfig(@NotNull String typeName, float volume) {
|
||||||
this(type, volume, 1);
|
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.type = type;
|
||||||
this.volume = volume;
|
this.volume = volume;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playTo(Player player) {
|
public void playTo(Player player) {
|
||||||
|
if (type == null) return;
|
||||||
player.playSound(player.getLocation(), type, volume, pitch);
|
player.playSound(player.getLocation(), type, volume, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +44,11 @@ public class SoundConfig {
|
|||||||
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Sound getType() {
|
public @NotNull String getTypeName() {
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Sound getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +61,7 @@ public class SoundConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(@NotNull Sound type) {
|
public void setType(@NotNull Sound type) {
|
||||||
|
this.typeName = type.name();
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,23 +75,24 @@ public class SoundConfig {
|
|||||||
|
|
||||||
public @NotNull String serialize() {
|
public @NotNull String serialize() {
|
||||||
if (pitch != 1) {
|
if (pitch != 1) {
|
||||||
return type.name() + ":" + volume + ":" + pitch;
|
return typeName + ":" + volume + ":" + pitch;
|
||||||
} else if (volume != 1) {
|
} else if (volume != 1) {
|
||||||
return type.name() + ":" + volume;
|
return typeName + ":" + volume;
|
||||||
} else {
|
} else {
|
||||||
return type.name();
|
return typeName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Contract("null -> null")
|
@Contract("null -> null")
|
||||||
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
||||||
if (string == null) return null;
|
if (string == null || string.isEmpty()) return null;
|
||||||
|
|
||||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||||
if (args.length < 1) return null;
|
if (args.length < 1) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new SoundConfig(
|
return new SoundConfig(
|
||||||
|
args[0],
|
||||||
Sound.valueOf(args[0]),
|
Sound.valueOf(args[0]),
|
||||||
(args.length >= 2) ? Float.parseFloat(args[1]) : 1,
|
(args.length >= 2) ? Float.parseFloat(args[1]) : 1,
|
||||||
(args.length >= 3) ? Float.parseFloat(args[2]) : 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.TextParser;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class TitleConfig {
|
||||||
|
|
||||||
|
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2) {
|
||||||
|
return of(
|
||||||
|
Optional.ofNullable(line1).map(TextConfig::of).orElse(null),
|
||||||
|
Optional.ofNullable(line2).map(TextConfig::of).orElse(null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull TitleConfig of(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||||
|
return new TitleConfig(line1, line2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @Nullable TextConfig line1;
|
||||||
|
protected @Nullable TextConfig line2;
|
||||||
|
|
||||||
|
protected TitleConfig(@Nullable TextConfig line1, @Nullable TextConfig line2) {
|
||||||
|
this.line1 = line1;
|
||||||
|
this.line2 = line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Player player,
|
||||||
|
@Range(from = 0L, to = Long.MAX_VALUE) int fadeIn,
|
||||||
|
@Range(from = 0L, to = Long.MAX_VALUE) int stay,
|
||||||
|
@Range(from = 0L, to = Long.MAX_VALUE) int fadeOut,
|
||||||
|
@NotNull Map<String, Object> placeholders,
|
||||||
|
@Nullable TitleSendConsumer sendConsumer) {
|
||||||
|
if (this.line1 == null && this.line2 == null) return;
|
||||||
|
if (sendConsumer == null) return;
|
||||||
|
sendConsumer.send(
|
||||||
|
player, fadeIn, stay, fadeOut,
|
||||||
|
parseLine(this.line1, player, placeholders),
|
||||||
|
parseLine(this.line2, player, placeholders)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @NotNull String parseLine(@Nullable TextConfig text,
|
||||||
|
@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (text == null) return "";
|
||||||
|
else return TextParser.parseText(player, text.getMessage(), placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
if (this.line1 != null) map.put("line1", this.line1.getMessage());
|
||||||
|
if (this.line2 != null) map.put("line2", this.line2.getMessage());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull TitleConfig deserialize(@NotNull ConfigurationWrapper section) {
|
||||||
|
return of(section.getString("line1"), section.getString("line2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.function;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TitleSendConsumer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向目标玩家发送标题文字
|
||||||
|
*
|
||||||
|
* @param player 目标玩家
|
||||||
|
* @param fadeIn 淡入时间 (ticks)
|
||||||
|
* @param stay 保留时间 (ticks)
|
||||||
|
* @param fadeOut 淡出时间 (ticks)
|
||||||
|
* @param line1 第一行文字
|
||||||
|
* @param line2 第二行文字
|
||||||
|
*/
|
||||||
|
void send(@NotNull Player player,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||||
|
@NotNull String line1, @NotNull String line2);
|
||||||
|
|
||||||
|
}
|
||||||
+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.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||||
@@ -26,7 +26,7 @@ public abstract class CraftConfigProvider extends FileConfigProvider<CraftSectio
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() throws Exception {
|
protected void onReload() throws Exception {
|
||||||
configuration.load(getFile());
|
configuration.load(getFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
+1
-1
@@ -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 cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ProtocolLibHelper {
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public static void sendTitle(Player player, long fadeIn, long stay, long fadeOut, String line1, String line2) throws Exception {
|
||||||
|
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
|
||||||
|
|
||||||
|
if (line1 != null) {
|
||||||
|
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
|
||||||
|
packet.getTitleActions().write(0, EnumWrappers.TitleAction.TITLE);
|
||||||
|
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line1));
|
||||||
|
pm.sendServerPacket(player, packet, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line2 != null) {
|
||||||
|
PacketContainer packet = pm.createPacket(PacketType.Play.Server.TITLE);
|
||||||
|
packet.getTitleActions().write(0, EnumWrappers.TitleAction.SUBTITLE);
|
||||||
|
packet.getChatComponents().write(0, WrappedChatComponent.fromText(line2));
|
||||||
|
pm.sendServerPacket(player, packet, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketContainer timePacket = pm.createPacket(PacketType.Play.Server.TITLE);
|
||||||
|
timePacket.getTitleActions().write(0, EnumWrappers.TitleAction.TIMES);
|
||||||
|
timePacket.getIntegers()
|
||||||
|
.write(0, Math.toIntExact(fadeIn))
|
||||||
|
.write(1, Math.toIntExact(stay))
|
||||||
|
.write(2, Math.toIntExact(fadeOut));
|
||||||
|
pm.sendServerPacket(player, timePacket, false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.common.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.item.ItemConfigBuilder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ConfiguredItem extends ConfiguredSection<ItemConfig> {
|
||||||
|
|
||||||
|
public static ItemConfigBuilder create() {
|
||||||
|
return CraftConfigValue.builder().createItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredItem of() {
|
||||||
|
return CraftConfigValue.builder().ofItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredItem of(@Nullable ItemConfig defaultItem) {
|
||||||
|
return CraftConfigValue.builder().ofItem(defaultItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
|
public ConfiguredItem(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
|
@Nullable ItemConfig defaultValue, @NotNull String[] params) {
|
||||||
|
super(provider, sectionPath, headerComments, inlineComments, ItemConfig.class, defaultValue, getItemParser(), ItemConfig::serialize);
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigValueParser<ConfigurationWrapper, ItemConfig> getItemParser() {
|
||||||
|
return (s, d) -> ItemConfig.deserialize(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String[] getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack getItem(@Nullable Player player) {
|
||||||
|
return getItem(player, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack getItem(@Nullable Player player, int amount) {
|
||||||
|
return getItem(player, amount, new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Object... values) {
|
||||||
|
return getItem(player, amount, ParamsUtils.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull String[] params, @NotNull Object[] values) {
|
||||||
|
return getItem(player, amount, ParamsUtils.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack getItem(@Nullable Player player, int amount, @NotNull Map<String, Object> placeholders) {
|
||||||
|
return getOptional().map(item -> item.getItemStack(player, amount, placeholders)).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+12
-12
@@ -1,21 +1,21 @@
|
|||||||
package cc.carm.lib.configuration.craft.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.value.ConfigMessage;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.message.CraftMessageValueBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandSender> {
|
public class ConfiguredMessage<M> extends ConfigMessage<M, TextConfig, CommandSender> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <M> CraftMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
public static <M> CraftMessageValueBuilder<@Nullable M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||||
@@ -34,15 +34,15 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
|
|||||||
return asString().defaults(defaultMessage).build();
|
return asString().defaults(defaultMessage).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
|
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
@NotNull TextConfig defaultMessage, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||||
super(provider, sectionPath, comments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, defaultMessage, params, messageParser, sendFunction, TextConfig::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, placeholders));
|
||||||
send(Bukkit.getConsoleSender(), placeholders);
|
send(Bukkit.getConsoleSender(), placeholders);
|
||||||
+10
-11
@@ -1,11 +1,10 @@
|
|||||||
package cc.carm.lib.configuration.craft.value;
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.value.ConfigMessageList;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
import cc.carm.lib.mineconfiguration.bukkit.data.TextConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder;
|
||||||
import cc.carm.lib.configuration.craft.builder.message.CraftMessageListBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.MessageText;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -16,7 +15,7 @@ import java.util.Map;
|
|||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText, CommandSender> {
|
public class ConfiguredMessageList<M> extends ConfigMessageList<M, TextConfig, CommandSender> {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <M> CraftMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
public static <M> CraftMessageListBuilder<M> create(@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser) {
|
||||||
@@ -31,12 +30,12 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
|
|||||||
return asStrings().defaults(defaultMessages).build();
|
return asStrings().defaults(defaultMessages).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
|
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull List<MessageText> messages, @NotNull String[] params,
|
@NotNull List<TextConfig> messages, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||||
super(provider, sectionPath, comments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
super(provider, sectionPath, headerComments, inlineComments, TextConfig.class, messages, params, messageParser, sendFunction, TextConfig::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
+7
-7
@@ -1,12 +1,12 @@
|
|||||||
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.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
||||||
@@ -22,10 +22,10 @@ public class ConfiguredSerializable<T extends ConfigurationSerializable> extends
|
|||||||
|
|
||||||
protected final @NotNull Class<T> valueClass;
|
protected final @NotNull Class<T> valueClass;
|
||||||
|
|
||||||
public ConfiguredSerializable(@Nullable CraftConfigProvider provider,
|
public ConfiguredSerializable(@Nullable CraftConfigProvider provider, @Nullable String sectionPath,
|
||||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
||||||
super(provider, configPath, comments, defaultValue);
|
super(provider, sectionPath, headerComments, inlineComments, defaultValue);
|
||||||
this.valueClass = valueClass;
|
this.valueClass = valueClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
+21
-9
@@ -1,17 +1,17 @@
|
|||||||
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.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.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
||||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bukkit.builder.sound.SoundConfigBuilder;
|
||||||
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||||
@@ -32,10 +32,22 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
|||||||
return CraftConfigValue.builder().createSound().defaults(sound, volume, pitch).build();
|
return CraftConfigValue.builder().createSound().defaults(sound, volume, pitch).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider,
|
public static @NotNull ConfiguredSound of(String soundName) {
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
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(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@Nullable SoundConfig defaultValue) {
|
@Nullable SoundConfig defaultValue) {
|
||||||
super(provider, sectionPath, comments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
super(provider, sectionPath, headerComments, inlineComments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSound(@NotNull Sound sound) {
|
public void setSound(@NotNull Sound sound) {
|
||||||
@@ -47,7 +59,7 @@ public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSound(@NotNull Sound sound, float volume, float pitch) {
|
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) {
|
public void playTo(@NotNull Player player) {
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.CraftConfigValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.utils.ParamsUtils;
|
||||||
|
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
|
import cc.carm.lib.configuration.core.value.type.ConfiguredSection;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.function.TitleSendConsumer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ConfiguredTitle extends ConfiguredSection<TitleConfig> {
|
||||||
|
|
||||||
|
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 TitleSendConsumer sendConsumer;
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
|
protected final int fadeIn;
|
||||||
|
protected final int stay;
|
||||||
|
protected final int fadeOut;
|
||||||
|
|
||||||
|
public ConfiguredTitle(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
|
@Nullable TitleConfig defaultValue, @NotNull String[] params,
|
||||||
|
@NotNull TitleSendConsumer sendConsumer,
|
||||||
|
int fadeIn, int stay, int fadeOut) {
|
||||||
|
super(provider, sectionPath, headerComments, inlineComments, TitleConfig.class, defaultValue, 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 TitleSendConsumer 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 sendAll(Object... values) {
|
||||||
|
sendAll(this.params, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||||
|
sendAll(ParamsUtils.buildParams(params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAll(@NotNull Map<String, Object> placeholders) {
|
||||||
|
TitleConfig config = get();
|
||||||
|
if (config == null) return;
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> send(onlinePlayer, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static ConfigValueParser<ConfigurationWrapper, TitleConfig> getTitleParser() {
|
||||||
|
return (s, d) -> TitleConfig.deserialize(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+10
-2
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.lib.configuration;
|
package cc.carm.lib.mineconfiguration.bukkit;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigProvider;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -30,4 +31,11 @@ public class MineConfiguration {
|
|||||||
return from(new File(fileName), 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+18
-14
@@ -1,12 +1,10 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.source;
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
import cc.carm.lib.configuration.core.source.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.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -14,6 +12,7 @@ import java.io.StringWriter;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
public class BukkitConfigProvider extends CraftConfigProvider {
|
||||||
|
|
||||||
@@ -35,11 +34,6 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
|||||||
return CraftSectionWrapper.of(this.configuration);
|
return CraftSectionWrapper.of(this.configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() throws Exception {
|
|
||||||
configuration.load(getFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws Exception {
|
public void save() throws Exception {
|
||||||
configuration.save(getFile());
|
configuration.save(getFile());
|
||||||
@@ -55,14 +49,24 @@ public class BukkitConfigProvider extends CraftConfigProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||||
this.bukkitComments.set(path, comment);
|
this.bukkitComments.setHeaderComments(path, comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||||
return this.bukkitComments.get(path);
|
this.bukkitComments.setInlineComment(path, comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
@Unmodifiable
|
||||||
|
public List<String> getHeaderComment(@Nullable String path) {
|
||||||
|
return this.bukkitComments.getHeaderComment(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String getInlineComment(@NotNull String path) {
|
||||||
|
return this.bukkitComments.getInlineComment(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+146
@@ -0,0 +1,146 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class BukkitYAMLComments {
|
||||||
|
|
||||||
|
protected final @NotNull Map<String, List<String>> headerComments = new HashMap<>();
|
||||||
|
protected final @NotNull Map<String, String> inlineComments = new HashMap<>();
|
||||||
|
|
||||||
|
protected @NotNull Map<String, List<String>> getHeaderComments() {
|
||||||
|
return headerComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @NotNull Map<String, String> getInlineComments() {
|
||||||
|
return inlineComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderComments(@Nullable String path, @Nullable List<String> comments) {
|
||||||
|
|
||||||
|
if (comments == null) {
|
||||||
|
getHeaderComments().remove(path);
|
||||||
|
} else {
|
||||||
|
getHeaderComments().put(path, comments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||||
|
if (comment == null) {
|
||||||
|
getInlineComments().remove(path);
|
||||||
|
} else {
|
||||||
|
getInlineComments().put(path, comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Unmodifiable
|
||||||
|
public List<String> getHeaderComment(@Nullable String path) {
|
||||||
|
return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getInlineComment(@NotNull String path) {
|
||||||
|
return getInlineComments().get(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||||
|
List<String> comments = getHeaderComment(path);
|
||||||
|
if (comments == null || comments.size() == 0) return null;
|
||||||
|
|
||||||
|
StringJoiner joiner = new StringJoiner("\n");
|
||||||
|
for (String comment : comments) {
|
||||||
|
if (comment.length() == 0) joiner.add(" ");
|
||||||
|
else joiner.add(indents + "# " + comment);
|
||||||
|
}
|
||||||
|
return joiner + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从一个文件读取配置并写入注释到某个写入器中。
|
||||||
|
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
||||||
|
*
|
||||||
|
* @param source 源配置文件
|
||||||
|
* @param writer 配置写入器
|
||||||
|
* @throws IOException 当写入发生错误时抛出
|
||||||
|
*/
|
||||||
|
public void writeComments(@NotNull YamlConfiguration source, @NotNull BufferedWriter writer) throws IOException {
|
||||||
|
FileConfiguration temp = new YamlConfiguration(); // 该对象用于临时记录配置内容
|
||||||
|
|
||||||
|
String configHeader = buildHeaderComments(null, "");
|
||||||
|
if (configHeader != null) writer.write(configHeader);
|
||||||
|
|
||||||
|
for (String fullKey : source.getKeys(true)) {
|
||||||
|
Object currentValue = source.get(fullKey);
|
||||||
|
|
||||||
|
String indents = getIndents(fullKey);
|
||||||
|
String headerComments = buildHeaderComments(fullKey, indents);
|
||||||
|
String inlineComment = getInlineComment(fullKey);
|
||||||
|
|
||||||
|
if (headerComments != null) writer.write(headerComments);
|
||||||
|
|
||||||
|
String[] splitFullKey = fullKey.split("[" + CraftConfigProvider.SEPARATOR + "]");
|
||||||
|
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
||||||
|
|
||||||
|
if (currentValue instanceof ConfigurationSection) {
|
||||||
|
ConfigurationSection section = (ConfigurationSection) currentValue;
|
||||||
|
writer.write(indents + trailingKey + ":");
|
||||||
|
if (inlineComment != null && inlineComment.length() > 0) {
|
||||||
|
writer.write(" # " + inlineComment);
|
||||||
|
}
|
||||||
|
if (!section.getKeys(false).isEmpty()) {
|
||||||
|
writer.write("\n");
|
||||||
|
} else {
|
||||||
|
writer.write(" {}\n");
|
||||||
|
if (indents.length() == 0) writer.write("\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp.set(trailingKey, currentValue);
|
||||||
|
String yaml = temp.saveToString();
|
||||||
|
temp.set(trailingKey, null);
|
||||||
|
|
||||||
|
yaml = yaml.substring(0, yaml.length() - 1);
|
||||||
|
|
||||||
|
if (inlineComment != null && inlineComment.length() > 0) {
|
||||||
|
if (yaml.contains("\n")) {
|
||||||
|
// section为多行内容,需要 InlineComment 加在首行末尾
|
||||||
|
String[] splitLine = yaml.split("\n", 2);
|
||||||
|
yaml = splitLine[0] + " # " + inlineComment + "\n" + splitLine[1];
|
||||||
|
} else {
|
||||||
|
// 其他情况下就直接加载后面就好。
|
||||||
|
yaml += " # " + inlineComment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write(indents + yaml.replace("\n", "\n" + indents) + "\n");
|
||||||
|
if (indents.length() == 0) writer.write("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到一个键的缩进。
|
||||||
|
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @return 该键的缩进文本
|
||||||
|
*/
|
||||||
|
protected static String getIndents(String key) {
|
||||||
|
String[] splitKey = key.split("[" + BukkitConfigProvider.SEPARATOR + "]");
|
||||||
|
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?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.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-bukkit-parent</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>base</module>
|
||||||
|
<module>general</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Bukkit-Parent</name>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--PlaceholderAPI for general placeholder's support-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--ProtocolLib for general packet's function support-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.8.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -5,16 +5,19 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.2</version>
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>mineconfiguration-bungee</artifactId>
|
<artifactId>mineconfiguration-bungee</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Bungee</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -51,18 +54,6 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
+10
-8
@@ -1,23 +1,25 @@
|
|||||||
package cc.carm.lib.configuration.bungee;
|
package cc.carm.lib.mineconfiguration.bungee;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.builder.BungeeConfigBuilder;
|
import cc.carm.lib.mineconfiguration.bungee.builder.BungeeConfigBuilder;
|
||||||
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||||
import cc.carm.lib.configuration.bungee.source.BungeeSectionWrapper;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeSectionWrapper;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
public abstract class BungeeConfigValue<T> extends CachedConfigValue<T> {
|
||||||
|
|
||||||
public static @NotNull BungeeConfigBuilder builder() {
|
public static @NotNull BungeeConfigBuilder builder() {
|
||||||
return new BungeeConfigBuilder();
|
return new BungeeConfigBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BungeeConfigValue(@Nullable BungeeConfigProvider provider,
|
public BungeeConfigValue(@Nullable BungeeConfigProvider provider, @Nullable String configPath,
|
||||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
super(provider, configPath, comments, defaultValue);
|
@Nullable T defaultValue) {
|
||||||
|
super(provider, configPath, headerComments, inlineComments, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BungeeConfigProvider getBukkitProvider() {
|
public BungeeConfigProvider getBukkitProvider() {
|
||||||
+25
-2
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.lib.configuration;
|
package cc.carm.lib.mineconfiguration.bungee;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.JsonConfiguration;
|
import net.md_5.bungee.config.JsonConfiguration;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
@@ -37,6 +38,14 @@ public class MineConfiguration {
|
|||||||
return from(new File(fileName), source);
|
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) {
|
public static BungeeConfigProvider fromYAML(File file, String source) {
|
||||||
return create(file, source, ConfigurationProvider.getProvider(YamlConfiguration.class));
|
return create(file, source, ConfigurationProvider.getProvider(YamlConfiguration.class));
|
||||||
}
|
}
|
||||||
@@ -53,6 +62,13 @@ public class MineConfiguration {
|
|||||||
return fromYAML(fileName, fileName);
|
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) {
|
public static BungeeConfigProvider fromJSON(File file, String source) {
|
||||||
return create(file, source, ConfigurationProvider.getProvider(JsonConfiguration.class));
|
return create(file, source, ConfigurationProvider.getProvider(JsonConfiguration.class));
|
||||||
@@ -70,5 +86,12 @@ public class MineConfiguration {
|
|||||||
return fromJSON(fileName, fileName);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.configuration.bungee.builder;
|
package cc.carm.lib.mineconfiguration.bungee.builder;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.source.BungeeConfigProvider;
|
import cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider;
|
||||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
||||||
|
|
||||||
public abstract class AbstractBungeeBuilder<T, B extends AbstractBungeeBuilder<T, B>>
|
public abstract class AbstractBungeeBuilder<T, B extends AbstractBungeeBuilder<T, B>>
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.configuration.bungee.builder;
|
package cc.carm.lib.mineconfiguration.bungee.builder;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageBuilder;
|
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageBuilder;
|
||||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
package cc.carm.lib.configuration.bungee.builder.message;
|
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.configuration.common.builder.message.MessageConfigBuilder;
|
import cc.carm.lib.mineconfiguration.common.builder.message.MessageConfigBuilder;
|
||||||
import cc.carm.lib.configuration.common.utils.ColorParser;
|
import cc.carm.lib.mineconfiguration.common.utils.ColorParser;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
+8
-6
@@ -1,8 +1,9 @@
|
|||||||
package cc.carm.lib.configuration.bungee.builder.message;
|
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.configuration.bungee.value.ConfiguredMessageList;
|
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessageList;
|
||||||
import cc.carm.lib.configuration.common.builder.message.MessageListBuilder;
|
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 net.md_5.bungee.api.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -26,9 +27,10 @@ public class BungeeMessageListBuilder<M>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredMessageList<M> build() {
|
public @NotNull ConfiguredMessageList<M> build() {
|
||||||
return new ConfiguredMessageList<>(
|
return new ConfiguredMessageList<>(
|
||||||
this.provider, this.path, buildComments(),
|
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
Optional.ofNullable(this.defaultValue).orElse(MessageText.of(new ArrayList<>())),
|
||||||
buildParams(), this.messageParser, this.sendFunction
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
|
this.messageParser, this.sendFunction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-6
@@ -1,8 +1,9 @@
|
|||||||
package cc.carm.lib.configuration.bungee.builder.message;
|
package cc.carm.lib.mineconfiguration.bungee.builder.message;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.configuration.bungee.value.ConfiguredMessage;
|
import cc.carm.lib.mineconfiguration.bungee.value.ConfiguredMessage;
|
||||||
import cc.carm.lib.configuration.common.builder.message.MessageValueBuilder;
|
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 net.md_5.bungee.api.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -25,9 +26,10 @@ public class BungeeMessageValueBuilder<M>
|
|||||||
@Override
|
@Override
|
||||||
public @NotNull ConfiguredMessage<M> build() {
|
public @NotNull ConfiguredMessage<M> build() {
|
||||||
return new ConfiguredMessage<>(
|
return new ConfiguredMessage<>(
|
||||||
this.provider, this.path, buildComments(),
|
this.provider, this.path, this.headerComments, this.inlineComment,
|
||||||
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
Optional.ofNullable(this.defaultValue).orElse(MessageText.of("")),
|
||||||
buildParams(), this.messageParser, this.sendHandler
|
ParamsUtils.formatParams(this.paramFormatter, this.params),
|
||||||
|
this.messageParser, this.sendHandler
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.configuration.bungee.data;
|
package cc.carm.lib.mineconfiguration.bungee.data;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.common.data.AbstractText;
|
import cc.carm.lib.mineconfiguration.common.data.AbstractText;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
||||||
|
|
||||||
|
protected static final char SEPARATOR = '.';
|
||||||
|
|
||||||
|
protected ConfigurationProvider loader;
|
||||||
|
protected Configuration configuration;
|
||||||
|
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
||||||
|
|
||||||
|
protected BungeeYAMLComments comments = new BungeeYAMLComments();
|
||||||
|
|
||||||
|
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 void save() throws Exception {
|
||||||
|
getLoader().save(configuration, file);
|
||||||
|
if (getLoader() instanceof YamlConfiguration) {
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
this.comments.writeComments(configuration, new BufferedWriter(writer));
|
||||||
|
String value = writer.toString(); // config contents
|
||||||
|
|
||||||
|
Path toUpdatePath = getFile().toPath();
|
||||||
|
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
||||||
|
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||||
|
this.comments.setHeaderComments(path, comments);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||||
|
this.comments.setInlineComment(path, comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
|
||||||
|
return this.comments.getHeaderComment(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String getInlineComment(@NotNull String path) {
|
||||||
|
return this.comments.getInlineComment(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
||||||
|
return this.initializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationProvider getLoader() {
|
||||||
|
return loader;
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
-2
@@ -1,4 +1,4 @@
|
|||||||
package cc.carm.lib.configuration.bungee.source;
|
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
@@ -9,6 +9,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
||||||
|
|
||||||
public class BungeeSectionWrapper implements ConfigurationWrapper {
|
public class BungeeSectionWrapper implements ConfigurationWrapper {
|
||||||
|
|
||||||
private final Configuration section;
|
private final Configuration section;
|
||||||
@@ -22,14 +24,31 @@ public class BungeeSectionWrapper implements ConfigurationWrapper {
|
|||||||
return section == null ? null : new BungeeSectionWrapper(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
|
@Override
|
||||||
public @NotNull Set<String> getKeys(boolean deep) {
|
public @NotNull Set<String> getKeys(boolean deep) {
|
||||||
|
if (deep) {
|
||||||
|
return new LinkedHashSet<>(getAllKeys(section));
|
||||||
|
} else {
|
||||||
return new LinkedHashSet<>(section.getKeys());
|
return new LinkedHashSet<>(section.getKeys());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
public @NotNull Map<String, Object> getValues(boolean deep) {
|
||||||
return section.getKeys().stream()
|
return getKeys(deep).stream()
|
||||||
.collect(Collectors.toMap(key -> key, section::get, (a, b) -> b, LinkedHashMap::new));
|
.collect(Collectors.toMap(key -> key, section::get, (a, b) -> b, LinkedHashMap::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bungee.source;
|
||||||
|
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import static cc.carm.lib.mineconfiguration.bungee.source.BungeeConfigProvider.SEPARATOR;
|
||||||
|
|
||||||
|
public class BungeeYAMLComments {
|
||||||
|
|
||||||
|
protected final @NotNull Map<String, List<String>> headerComments = new HashMap<>();
|
||||||
|
protected final @NotNull Map<String, String> inlineComments = new HashMap<>();
|
||||||
|
|
||||||
|
protected @NotNull Map<String, List<String>> getHeaderComments() {
|
||||||
|
return headerComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @NotNull Map<String, String> getInlineComments() {
|
||||||
|
return inlineComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeaderComments(@Nullable String path, @Nullable List<String> comments) {
|
||||||
|
if (comments == null) {
|
||||||
|
getHeaderComments().remove(path);
|
||||||
|
} else {
|
||||||
|
getHeaderComments().put(path, comments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||||
|
if (comment == null) {
|
||||||
|
getInlineComments().remove(path);
|
||||||
|
} else {
|
||||||
|
getInlineComments().put(path, comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Unmodifiable
|
||||||
|
public List<String> getHeaderComment(@Nullable String path) {
|
||||||
|
return Optional.ofNullable(getHeaderComments().get(path)).map(Collections::unmodifiableList).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getInlineComment(@NotNull String path) {
|
||||||
|
return getInlineComments().get(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String buildHeaderComments(@Nullable String path, @NotNull String indents) {
|
||||||
|
List<String> comments = getHeaderComment(path);
|
||||||
|
if (comments == null || comments.size() == 0) return null;
|
||||||
|
|
||||||
|
StringJoiner joiner = new StringJoiner("\n");
|
||||||
|
for (String comment : comments) {
|
||||||
|
if (comment.length() == 0) joiner.add(" ");
|
||||||
|
else joiner.add(indents + "# " + comment);
|
||||||
|
}
|
||||||
|
return joiner + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从一个文件读取配置并写入注释到某个写入器中。
|
||||||
|
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
||||||
|
*
|
||||||
|
* @param source 源配置文件
|
||||||
|
* @param writer 配置写入器
|
||||||
|
* @throws IOException 当写入发生错误时抛出
|
||||||
|
*/
|
||||||
|
public void writeComments(@NotNull Configuration source, @NotNull BufferedWriter writer) throws IOException {
|
||||||
|
ConfigurationProvider provider = ConfigurationProvider.getProvider(YamlConfiguration.class);
|
||||||
|
Configuration tmp = new Configuration();// 该对象用于临时记录配置内容
|
||||||
|
|
||||||
|
String configHeader = buildHeaderComments(null, "");
|
||||||
|
if (configHeader != null) writer.write(configHeader);
|
||||||
|
|
||||||
|
for (String fullKey : BungeeSectionWrapper.getAllKeys(source)) {
|
||||||
|
Object currentValue = source.get(fullKey);
|
||||||
|
|
||||||
|
String indents = getIndents(fullKey);
|
||||||
|
String headerComments = buildHeaderComments(fullKey, indents);
|
||||||
|
String inlineComment = getInlineComment(fullKey);
|
||||||
|
|
||||||
|
if (headerComments != null) writer.write(headerComments);
|
||||||
|
|
||||||
|
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
||||||
|
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
||||||
|
|
||||||
|
if (currentValue instanceof Configuration) {
|
||||||
|
Configuration section = (Configuration) currentValue;
|
||||||
|
writer.write(indents + trailingKey + ":");
|
||||||
|
if (inlineComment != null && inlineComment.length() > 0) {
|
||||||
|
writer.write(" # " + inlineComment);
|
||||||
|
}
|
||||||
|
if (!section.getKeys().isEmpty()) {
|
||||||
|
writer.write("\n");
|
||||||
|
} else {
|
||||||
|
writer.write(" {}\n");
|
||||||
|
if (indents.length() == 0) writer.write("\n");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp.set(trailingKey, currentValue);
|
||||||
|
StringWriter tmpStr = new StringWriter();
|
||||||
|
provider.save(tmp, tmpStr);
|
||||||
|
String yaml = tmpStr.toString();
|
||||||
|
tmpStr.close();
|
||||||
|
tmp.set(trailingKey, null);
|
||||||
|
|
||||||
|
yaml = yaml.substring(0, yaml.length() - 1);
|
||||||
|
|
||||||
|
if (inlineComment != null && inlineComment.length() > 0) {
|
||||||
|
if (yaml.contains("\n")) {
|
||||||
|
// section为多行内容,需要 InlineComment 加在首行末尾
|
||||||
|
String[] splitLine = yaml.split("\n", 2);
|
||||||
|
yaml = splitLine[0] + " # " + inlineComment + "\n" + splitLine[1];
|
||||||
|
} else {
|
||||||
|
// 其他情况下就直接加载后面就好。
|
||||||
|
yaml += " # " + inlineComment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write(indents + yaml.replace("\n", "\n" + indents) + "\n");
|
||||||
|
if (indents.length() == 0) writer.write("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到一个键的缩进。
|
||||||
|
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @return 该键的缩进文本
|
||||||
|
*/
|
||||||
|
protected static String getIndents(String key) {
|
||||||
|
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
||||||
|
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+10
-10
@@ -1,16 +1,16 @@
|
|||||||
package cc.carm.lib.configuration.bungee.value;
|
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.BungeeConfigValue;
|
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||||
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageValueBuilder;
|
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageValueBuilder;
|
||||||
import cc.carm.lib.configuration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.configuration.common.value.ConfigMessage;
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessage;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@@ -34,15 +34,15 @@ public class ConfiguredMessage<M> extends ConfigMessage<M, MessageText, CommandS
|
|||||||
return asString().defaults(defaultMessage).build();
|
return asString().defaults(defaultMessage).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider,
|
public ConfiguredMessage(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
@NotNull MessageText defaultMessage, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull M> sendFunction) {
|
||||||
super(provider, sectionPath, comments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, defaultMessage, params, messageParser, sendFunction, MessageText::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
ProxyServer.getInstance().getPlayers().forEach(pl -> send(pl, placeholders));
|
||||||
send(ProxyServer.getInstance().getConsole(), placeholders);
|
send(ProxyServer.getInstance().getConsole(), placeholders);
|
||||||
+8
-9
@@ -1,10 +1,9 @@
|
|||||||
package cc.carm.lib.configuration.bungee.value;
|
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.BungeeConfigValue;
|
import cc.carm.lib.mineconfiguration.bungee.BungeeConfigValue;
|
||||||
import cc.carm.lib.configuration.bungee.builder.message.BungeeMessageListBuilder;
|
import cc.carm.lib.mineconfiguration.bungee.builder.message.BungeeMessageListBuilder;
|
||||||
import cc.carm.lib.configuration.bungee.data.MessageText;
|
import cc.carm.lib.mineconfiguration.bungee.data.MessageText;
|
||||||
import cc.carm.lib.configuration.common.value.ConfigMessageList;
|
import cc.carm.lib.mineconfiguration.common.value.ConfigMessageList;
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@@ -31,12 +30,12 @@ public class ConfiguredMessageList<M> extends ConfigMessageList<M, MessageText,
|
|||||||
return asStrings().defaults(defaultMessages).build();
|
return asStrings().defaults(defaultMessages).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider,
|
public ConfiguredMessageList(@Nullable ConfigurationProvider<?> provider, @Nullable String sectionPath,
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
@Nullable List<String> headerComments, @Nullable String inlineComments,
|
||||||
@NotNull List<MessageText> messages, @NotNull String[] params,
|
@NotNull List<MessageText> messages, @NotNull String[] params,
|
||||||
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> messageParser,
|
||||||
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
@NotNull BiConsumer<@NotNull CommandSender, @NotNull List<M>> sendFunction) {
|
||||||
super(provider, sectionPath, comments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
super(provider, sectionPath, headerComments, inlineComments, MessageText.class, messages, params, messageParser, sendFunction, MessageText::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
public void broadcast(@NotNull Map<String, Object> placeholders) {
|
||||||
@@ -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.builder(String.class)
|
||||||
|
.fromString().defaults("alert Commands here!").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,15 +3,17 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.2</version>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>mineconfiguration-spigot</artifactId>
|
<artifactId>mineconfiguration-spigot</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
@@ -19,14 +21,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
<artifactId>mineconfiguration-bukkit-base</artifactId>
|
||||||
<version>${easyconfiguration.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -38,6 +33,8 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<!--PlaceholderAPI for general placeholder's support-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
@@ -45,22 +42,18 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--ProtocolLib for general packet's function support-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.8.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
+11
-2
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.lib.configuration;
|
package cc.carm.lib.mineconfiguration.spigot;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.spigot.source.SpigotConfigProvider;
|
import cc.carm.lib.mineconfiguration.spigot.source.SpigotConfigProvider;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -30,4 +31,12 @@ public class MineConfiguration {
|
|||||||
return from(new File(fileName), source);
|
return from(new File(fileName), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SpigotConfigProvider from(Plugin plugin, String fileName) {
|
||||||
|
return from(plugin, fileName, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpigotConfigProvider from(Plugin plugin, String fileName, String source) {
|
||||||
|
return from(new File(plugin.getDataFolder(), fileName), source);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.spigot.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.core.ConfigInitializer;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.source.CraftConfigProvider;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SpigotConfigProvider extends CraftConfigProvider {
|
||||||
|
|
||||||
|
public SpigotConfigProvider(@NotNull File file) {
|
||||||
|
super(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeConfig() {
|
||||||
|
this.configuration = YamlConfiguration.loadConfiguration(file);
|
||||||
|
this.initializer = new ConfigInitializer<>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHeaderComment(@Nullable String path, @Nullable List<String> comments) {
|
||||||
|
if (path == null) {
|
||||||
|
this.configuration.options().setHeader(comments);
|
||||||
|
} else {
|
||||||
|
this.configuration.setComments(path, comments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInlineComment(@NotNull String path, @Nullable String comment) {
|
||||||
|
if (comment == null) {
|
||||||
|
this.configuration.setInlineComments(path, null);
|
||||||
|
} else {
|
||||||
|
this.configuration.setComments(path, Collections.singletonList(comment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable @Unmodifiable List<String> getHeaderComment(@Nullable String path) {
|
||||||
|
if (path == null) return Collections.unmodifiableList(this.configuration.options().getHeader());
|
||||||
|
else return this.configuration.getComments(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String getInlineComment(@NotNull String path) {
|
||||||
|
return String.join(" ", this.configuration.getInlineComments(path));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,27 +3,26 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<modules>
|
|
||||||
<module>bungee</module>
|
|
||||||
|
|
||||||
<module>craftbukkit</module>
|
|
||||||
<module>bukkit</module>
|
|
||||||
<module>spigot</module>
|
|
||||||
<module>common</module>
|
|
||||||
</modules>
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<project.jdk.version>8</project.jdk.version>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
<easyconfiguration.version>2.3.0</easyconfiguration.version>
|
<easyconfiguration.version>3.1.0</easyconfiguration.version>
|
||||||
</properties>
|
</properties>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>1.2.2</version>
|
<version>2.0.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>common</module>
|
||||||
|
|
||||||
|
<module>platform/bungee</module>
|
||||||
|
<module>platform/bukkit</module>
|
||||||
|
<module>platform/spigot</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
<name>MineConfiguration</name>
|
<name>MineConfiguration</name>
|
||||||
<description>EasyConfiguration for MineCraft.</description>
|
<description>EasyConfiguration for MineCraft.</description>
|
||||||
@@ -48,8 +47,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>The MIT License</name>
|
<name>GNU LESSER GENERAL PUBLIC LICENSE</name>
|
||||||
<url>https://opensource.org/licenses/MIT</url>
|
<url>https://www.gnu.org/licenses/lgpl-3.0.html</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -86,12 +85,6 @@
|
|||||||
<url>https://repo1.maven.org/maven2/</url>
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>github</id>
|
|
||||||
<name>GitHub Packages</name>
|
|
||||||
<url>https://maven.pkg.github.com/CarmJos/*</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
@@ -159,6 +152,36 @@
|
|||||||
<goals>deploy</goals>
|
<goals>deploy</goals>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.10.1</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.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>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
@@ -175,7 +198,6 @@
|
|||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
<docencoding>UTF-8</docencoding>
|
<docencoding>UTF-8</docencoding>
|
||||||
<locale>zh_CN</locale>
|
<locale>zh_CN</locale>
|
||||||
|
|
||||||
<includeDependencySources>true</includeDependencySources>
|
<includeDependencySources>true</includeDependencySources>
|
||||||
<dependencySourceIncludes>
|
<dependencySourceIncludes>
|
||||||
<dependencySourceInclude>cc.carm.lib:*</dependencySourceInclude>
|
<dependencySourceInclude>cc.carm.lib:*</dependencySourceInclude>
|
||||||
@@ -194,38 +216,6 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
@@ -295,7 +285,7 @@
|
|||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
-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