mirror of
https://github.com/CarmJos/MineConfiguration.git
synced 2026-06-05 06:51:49 +08:00
Compare commits
284 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d4d4bf0fe | |||
| 6944210ed4 | |||
| c159be5bd1 | |||
| 0b1866e59e | |||
| a3bcf78ff1 | |||
| f4b7dd99c8 | |||
| 8828421632 | |||
| b253658bd9 | |||
| 17ba07b2a8 | |||
| 7da7704065 | |||
| 7aa9f02c87 | |||
| 136e16ed59 | |||
| 4e5405304c | |||
| 4c309fd7e1 | |||
| 9e9c49032f | |||
| 0a4191666e | |||
| 043c6166fc | |||
| 2e4021a13e | |||
| 4b69661562 | |||
| d81a2ecf99 | |||
| a5d564c40c | |||
| 30e1e440ef | |||
| e28501e63a | |||
| b7f9add038 | |||
| d4b06fe7e6 | |||
| 2b68387e7b | |||
| 804639d6a0 | |||
| ee47be4842 | |||
| 63eabb955c | |||
| 35b4726c82 | |||
| ca47d2b3a8 | |||
| 75279de348 | |||
| 3cb0eac566 | |||
| 60aa5ccb1f | |||
| 19286850fa | |||
| 6e755ee48e | |||
| f0f4de7d93 | |||
| c0045a8ab0 | |||
| 2c2adeadad | |||
| 30bb6c18ee | |||
| eb5d7351f1 | |||
| 5a58277722 | |||
| dda8bc5e7a | |||
| 5d956cd6f6 | |||
| 366aa372d9 | |||
| 2a9c7d4ec5 | |||
| 390552efed | |||
| 6eafb82ce5 | |||
| 1ee6474c0e | |||
| b26d3ae52c | |||
| 8d972612e4 | |||
| 76d22520b9 | |||
| d8f5615f2d | |||
| ac279f71c0 | |||
| 0c1026f37e | |||
| 112e34e1b4 | |||
| ce4ceaef73 | |||
| 10ad1c8fcd | |||
| abdbd88946 | |||
| 517b661a13 | |||
| 4ddd2a3454 | |||
| 50f7eb31bb | |||
| e44e74a512 | |||
| 051049eee2 | |||
| c4010bb642 | |||
| 420eb93366 | |||
| b346fc7600 | |||
| f354258593 | |||
| e859722a85 | |||
| adf26baf59 | |||
| 3d814baa8f | |||
| c5c93d836f | |||
| 7820b14344 | |||
| 3a1ad7f9ce | |||
| adbc393ee9 | |||
| 2b5b62c979 | |||
| bb84f593e4 | |||
| 96804f83ba | |||
| a7b1c06c8f | |||
| 180ccc5046 | |||
| bab34b840f | |||
| bba135e911 | |||
| 87799d2c70 | |||
| b601b4433d | |||
| 5ffb734f22 | |||
| d697a268b4 | |||
| bcd6a9c0d0 | |||
| 6b6710fe8f | |||
| 44d3fb16cf | |||
| ffd18557e1 | |||
| 249ca790e4 | |||
| 4b6ff606b2 | |||
| 7795f66744 | |||
| ded6c53924 | |||
| 154f536768 | |||
| a46dbfae3d | |||
| 2291375276 | |||
| 9d835fd83d | |||
| 1999d9a9f9 | |||
| 11051cdf34 | |||
| 9b015a4427 | |||
| 204f3b012b | |||
| 4c3ee212c8 | |||
| cf3b65a413 | |||
| d2d45fb7aa | |||
| 127183ec47 | |||
| afe3e5199b | |||
| 8fa807053d | |||
| 9200f4f220 | |||
| 0a60497be8 | |||
| 1a8979d18c | |||
| 9c08be7660 | |||
| 6bbf32515d | |||
| 3538ae557b | |||
| cd4394ed68 | |||
| 2a28415e48 | |||
| 191702c5ef | |||
| ea39874d6c | |||
| feccc6f284 | |||
| d76685c7c1 | |||
| 524e3849e8 | |||
| 919ec4eefd | |||
| 1a198abf9f | |||
| c4b7eed949 | |||
| 56183172a4 | |||
| 0b4ade5370 | |||
| 59d97bf40d | |||
| 9093bb8a6d | |||
| dde394559c | |||
| b1e2bcb4c9 | |||
| a9bcf7ffc9 | |||
| 1f9af2c22c | |||
| 653a3f761c | |||
| 05a9dccbaa | |||
| e6ab328ac4 | |||
| 91f65cc08b | |||
| 7d4d716724 | |||
| 7ecfff5bc4 | |||
| 1cebe8daca | |||
| 49df2ca24e | |||
| 6e1803fb75 | |||
| 480f015a2f | |||
| bf5c6a2fce | |||
| f86229037d | |||
| 38292052f5 | |||
| b737e4dda2 | |||
| 058da094cd | |||
| 020adeb030 | |||
| 3183e1025d | |||
| 3c57b97fb1 | |||
| c77253508c | |||
| 56ee1ec991 | |||
| 706db18ffe | |||
| 46bfbe063e | |||
| c3d993311e | |||
| 67d1fd67fc | |||
| 357b6054a4 | |||
| c150d607e9 | |||
| dbcaff5c93 | |||
| e0d5f9229b | |||
| caf92ef565 | |||
| 77547cdc80 | |||
| 5d55ddbce9 | |||
| c73032266d | |||
| a6b6d46be6 | |||
| 47d7b17082 | |||
| 0663f3d117 | |||
| 1947ba1899 | |||
| 2e4de9880f | |||
| 398bc773d6 | |||
| 1396c6bd6e | |||
| 2959c00795 | |||
| 09537975e4 | |||
| 02625b5c0c | |||
| bb9e24dd96 | |||
| 5bdc5908ef | |||
| dde304625e | |||
| 24ef0b6dcd | |||
| a1d6cf1258 | |||
| 0f7fc39f87 | |||
| 92ecb55a95 | |||
| bfd1624e85 | |||
| 01d3c245a9 | |||
| 8721c6085f | |||
| eca4d47b8f | |||
| 3750ac7d58 | |||
| d3bdc4ad60 | |||
| 6bb6fb1b95 | |||
| dd2499512c | |||
| 3aa0542f01 | |||
| 4d9d5f5d84 | |||
| 2b31ee1318 | |||
| 9d6212e5ea | |||
| 8f3d574446 | |||
| 437e1d6d61 | |||
| a04b7c9c06 | |||
| 74e88a126c | |||
| 79a65a94bc | |||
| 6ba08f7a67 | |||
| 166b9fa0a8 | |||
| 6257cdd114 | |||
| c28ee7d57b | |||
| 3d1639362b | |||
| ce205e10fe | |||
| 8e4e712936 | |||
| c3d9c65a86 | |||
| ebddeff78d | |||
| afcdc2c378 | |||
| 5905b25c73 | |||
| 31f51c9b96 | |||
| eb8f279e0b | |||
| e291c3a109 | |||
| 433f780608 | |||
| 385f6dd22f | |||
| 04168d4d12 | |||
| 143e0c2283 | |||
| 4b4f90ee38 | |||
| 97d24c7027 | |||
| d1b01ffed5 | |||
| 67931094e6 | |||
| 02f59b99f0 | |||
| e781d54348 | |||
| bbd2c9e5e7 | |||
| ccc8cc6b72 | |||
| 1612e49326 | |||
| 2754f12cd5 | |||
| c0f5d32ba0 | |||
| 6c355e0d89 | |||
| 6c7a5dd60a | |||
| 425d61834b | |||
| c9a272d052 | |||
| 327484cd53 | |||
| 99090929dd | |||
| 8437c4c904 | |||
| 21f7742d78 | |||
| 68e6280c94 | |||
| 9a8e6395bb | |||
| 7fa6fa1551 | |||
| 346ae4c494 | |||
| 2d8c1817a6 | |||
| f67d0fae8d | |||
| 8d723df7a6 | |||
| d4c7124d9e | |||
| 2804543419 | |||
| f826014c09 | |||
| 616d24d885 | |||
| 8d58583a1e | |||
| 4b594269bd | |||
| b629a7d96d | |||
| 455ab775ed | |||
| d5f1e8b230 | |||
| 11b910a273 | |||
| 40ec299c64 | |||
| 483fbc7c4d | |||
| 65d7a32108 | |||
| 6aa220924d | |||
| f4a55f216b | |||
| 34a51c42a5 | |||
| c50df3bc56 | |||
| 9a95e3d105 | |||
| 98ee47f676 | |||
| af614deae6 | |||
| cf80291e51 | |||
| 53ba56b0ad | |||
| da2023aad0 | |||
| 29526223e4 | |||
| e8044c112e | |||
| a552938858 | |||
| b61baed8bc | |||
| 0cd61842e5 | |||
| 4850514a8a | |||
| 1dca7a2274 | |||
| a02efbf29c | |||
| 352ef107f9 | |||
| 25f005ddfb | |||
| 26922f9225 | |||
| f0957c1b3e | |||
| 7d645f4386 | |||
| 08a56c7168 | |||
| f254383b79 | |||
| be3b7fffad | |||
| d567bfb4af | |||
| 1c0883534f | |||
| f632fafee4 |
@@ -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) 。
|
||||||
@@ -29,11 +29,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
# Checkout the repository to the GitHub Actions runner
|
# Checkout the repository to the GitHub Actions runner
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
|
||||||
- name: Run Codacy Analysis CLI
|
- name: Run Codacy Analysis CLI
|
||||||
uses: codacy/codacy-analysis-cli-action@d840f886c4bd4edc059706d09c6a1586111c540b
|
uses: codacy/codacy-analysis-cli-action@30783d03e758713bb5ed7b79292cfb14b9dd9a4a
|
||||||
with:
|
with:
|
||||||
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
|
# Check https://github.com/codacy/codacy-analysis-cli#project-token to get your project token from your Codacy repository
|
||||||
# You can also omit the token and run the tools that support default configurations
|
# You can also omit the token and run the tools that support default configurations
|
||||||
@@ -49,6 +49,6 @@ jobs:
|
|||||||
|
|
||||||
# Upload the SARIF file generated in the previous step
|
# Upload the SARIF file generated in the previous step
|
||||||
- name: Upload SARIF results file
|
- name: Upload SARIF results file
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v4
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -53,7 +53,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v4
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -67,4 +67,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v4
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v6
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '17'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
cache: maven
|
cache: maven
|
||||||
server-id: github
|
server-id: github
|
||||||
@@ -41,21 +41,21 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v6
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '17'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
cache: maven
|
cache: maven
|
||||||
server-id: ossrh
|
server-id: central
|
||||||
server-username: MAVEN_USERNAME
|
server-username: MAVEN_USERNAME
|
||||||
server-password: MAVEN_PASSWORD
|
server-password: MAVEN_PASSWORD
|
||||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||||
|
|
||||||
- name: "Central Deploy"
|
- name: "Central Deploy"
|
||||||
run: mvn -B -Possrh deploy --file pom.xml -DskipTests
|
run: mvn -B -Pcentral deploy --file pom.xml -DskipTests
|
||||||
env:
|
env:
|
||||||
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
|
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
|
||||||
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASS }}
|
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASS }}
|
||||||
|
|||||||
@@ -15,18 +15,26 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v6
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '17'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
server-id: github
|
||||||
|
server-username: MAVEN_USERNAME
|
||||||
|
server-password: MAVEN_TOKEN
|
||||||
- name: "Package"
|
- name: "Package"
|
||||||
run: mvn -B package --file pom.xml -Dgpg.skip
|
run: mvn -B package --file pom.xml -Dgpg.skip
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||||
- name: "Target Stage"
|
- name: "Target Stage"
|
||||||
run: mkdir staging && cp */target/*.jar staging
|
run: mkdir staging && cp */target/*.jar staging
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Artifact
|
name: Artifact
|
||||||
path: staging
|
path: staging
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
[](https://opensource.org/licenses/MIT)
|
[](https://opensource.org/licenses/MIT)
|
||||||
[](https://github.com/CarmJos/MineConfiguration/actions/workflows/maven.yml)
|
[](https://github.com/CarmJos/MineConfiguration/actions/workflows/maven.yml)
|
||||||

|

|
||||||

|
|
||||||
|
|
||||||
EasyConfiguration for MineCraft!
|
EasyConfiguration for MineCraft!
|
||||||
|
|
||||||
@@ -20,35 +19,36 @@ EasyConfiguration for MineCraft!
|
|||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
### **MineConfiguration-CraftBukkit**
|
### **MineConfiguration-Common** [`common`](common)
|
||||||
|
|
||||||
CraftBukkit系通用依赖,不包含实现部分,请使用 **MineConfiguration-Bukkit** 或 **MineConfiguration-Spigot** 。
|
全部版本的共用部分(均已被打包至下行包中),包括
|
||||||
|
|
||||||
|
- `ConfigMessage` (实现类为 `ConfiguredMessage<M>`)
|
||||||
|
- `ConfigMessageList` (实现类为 `ConfiguredMessageList<M>`)
|
||||||
|
|
||||||
|
如要使用,请访问对应实现类的builder() 方法来快速创建。
|
||||||
|
|
||||||
|
### **MineConfiguration-Bukkit** [`platform/bukkit`](platform/bukkit)
|
||||||
|
|
||||||
|
适用于Bukkit的版本,同时支持其他以Bukkit为基础的服务端 *(如Spigot、Paper、CatServer)* 。
|
||||||
|
|
||||||
相较于基础版本,额外提供了以下功能:
|
相较于基础版本,额外提供了以下功能:
|
||||||
|
|
||||||
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
- `ConfiguredSerializable<T extends ConfigurationSerializable>`
|
||||||
- `ConfiguredItem` (快捷读取简单的物品配置文件)
|
- `ConfiguredItem` (快捷读\写\使用简单的物品配置文件)
|
||||||
- `ConfiguredSound` (快捷读取音效配置文件)
|
- `ConfiguredSound` (快捷读\写\使用音效配置文件)
|
||||||
|
- `ConfiguredTitle` (快速读\写\使用标题文字配置文件)
|
||||||
|
|
||||||
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
以上类型可以通过 `CraftConfigValue.builder()` 来创建,部分类型提供了 `of(...);` 方法来快速创建。
|
||||||
|
|
||||||
### **MineConfiguration-Bukkit**
|
### **MineConfiguration-Bungee** [`platform/bungee`](platform/bungee)
|
||||||
|
|
||||||
适用于Bukkit的版本,包含以Bukkit为基础的其他服务端 *(如Spigot、Paper、CatServer)* 。
|
适用于BungeeCord的版本,可用JSON与YAML格式。其中JSON格式**不支持配置文件注释**。
|
||||||
|
|
||||||
### **MineConfiguration-Spigot**
|
|
||||||
|
|
||||||
适用于 Spigot(1.18+) 的版本,适配了1.18与更新版本自带的配置文件注释功能,随Spigot更新而优化,安全稳定。
|
|
||||||
|
|
||||||
### **MineConfiguration-Bungee**
|
|
||||||
|
|
||||||
适用于BungeeCord的版本,可用JSON与YAML格式,但**不支持配置文件注释**。
|
|
||||||
|
|
||||||
如需使用配置文件注释,建议使用 [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,64 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
|
||||||
<version>${easyconfiguration.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>bukkit</artifactId>
|
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package cc.carm.lib.configuration;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bukkit.source.BukkitConfigProvider;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class MineConfiguration {
|
|
||||||
|
|
||||||
public static BukkitConfigProvider from(File file, String source) {
|
|
||||||
BukkitConfigProvider provider = new BukkitConfigProvider(file);
|
|
||||||
try {
|
|
||||||
provider.initializeFile(source);
|
|
||||||
provider.initializeConfig();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitConfigProvider from(File file) {
|
|
||||||
return from(file, file.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitConfigProvider from(String fileName) {
|
|
||||||
return from(fileName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BukkitConfigProvider from(String fileName, String source) {
|
|
||||||
return from(new File(fileName), source);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-68
@@ -1,68 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftSectionWrapper;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public class BukkitConfigProvider extends CraftConfigProvider {
|
|
||||||
|
|
||||||
protected static final char SEPARATOR = '.';
|
|
||||||
|
|
||||||
protected BukkitYAMLComments bukkitComments = new BukkitYAMLComments();
|
|
||||||
|
|
||||||
public BukkitConfigProvider(@NotNull File file) {
|
|
||||||
super(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initializeConfig() {
|
|
||||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
|
||||||
this.initializer = new ConfigInitializer<>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull CraftSectionWrapper getConfiguration() {
|
|
||||||
return CraftSectionWrapper.of(this.configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() throws Exception {
|
|
||||||
configuration.load(getFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() throws Exception {
|
|
||||||
configuration.save(getFile());
|
|
||||||
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
this.bukkitComments.writeComments(configuration, new BufferedWriter(writer));
|
|
||||||
String value = writer.toString(); // config contents
|
|
||||||
|
|
||||||
Path toUpdatePath = getFile().toPath();
|
|
||||||
if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) {
|
|
||||||
Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
|
||||||
this.bukkitComments.set(path, comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
|
||||||
return this.bukkitComments.get(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bukkit.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import static cc.carm.lib.configuration.craft.source.CraftConfigProvider.SEPARATOR;
|
|
||||||
|
|
||||||
public class BukkitYAMLComments {
|
|
||||||
|
|
||||||
Map<String, ConfigCommentInfo> comments = new HashMap<>();
|
|
||||||
|
|
||||||
protected Map<String, ConfigCommentInfo> getComments() {
|
|
||||||
return comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(@Nullable String path, @Nullable ConfigCommentInfo comments) {
|
|
||||||
if (comments == null) {
|
|
||||||
getComments().remove(path);
|
|
||||||
} else {
|
|
||||||
getComments().put(path, comments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ConfigCommentInfo get(@Nullable String path) {
|
|
||||||
return getComments().getOrDefault(path, ConfigCommentInfo.defaults());
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable String buildComments(@NotNull String indents, @Nullable String path) {
|
|
||||||
ConfigCommentInfo comments = get(path);
|
|
||||||
if (!String.join("", comments.getComments()).isEmpty()) {
|
|
||||||
String prefix = comments.startWrap() ? "\n" : "";
|
|
||||||
String suffix = comments.endWrap() ? "\n" : "";
|
|
||||||
StringJoiner joiner = new StringJoiner("\n", prefix, suffix);
|
|
||||||
for (String comment : comments.getComments()) {
|
|
||||||
if (comment.length() == 0) joiner.add(" ");
|
|
||||||
else joiner.add(indents + "# " + comment);
|
|
||||||
}
|
|
||||||
return joiner + "\n";
|
|
||||||
} else {
|
|
||||||
return comments.startWrap() || comments.endWrap() ? "\n" : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从一个文件读取配置并写入注释到某个写入器中。
|
|
||||||
* 该方法的部分源代码借鉴自 tchristofferson/ConfigUpdater 项目。
|
|
||||||
*
|
|
||||||
* @param source 源配置文件
|
|
||||||
* @param writer 配置写入器
|
|
||||||
* @throws IOException 当写入发生错误时抛出
|
|
||||||
*/
|
|
||||||
public void writeComments(@NotNull YamlConfiguration source, @NotNull BufferedWriter writer) throws IOException {
|
|
||||||
FileConfiguration temp = new YamlConfiguration(); // 该对象用于临时记录配置内容
|
|
||||||
|
|
||||||
for (String fullKey : source.getKeys(true)) {
|
|
||||||
String indents = getIndents(fullKey);
|
|
||||||
String comment = buildComments(indents, fullKey);
|
|
||||||
if (comment != null) writer.write(comment);
|
|
||||||
|
|
||||||
Object currentValue = source.get(fullKey);
|
|
||||||
|
|
||||||
String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
|
|
||||||
String trailingKey = splitFullKey[splitFullKey.length - 1];
|
|
||||||
|
|
||||||
if (currentValue instanceof ConfigurationSection) {
|
|
||||||
writer.write(indents + trailingKey + ":");
|
|
||||||
if (!((ConfigurationSection) currentValue).getKeys(false).isEmpty()) {
|
|
||||||
writer.write("\n");
|
|
||||||
} else {
|
|
||||||
writer.write(" {}\n");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp.set(trailingKey, currentValue);
|
|
||||||
String yaml = temp.saveToString();
|
|
||||||
yaml = yaml.substring(0, yaml.length() - 1).replace("\n", "\n" + indents);
|
|
||||||
String toWrite = indents + yaml + "\n";
|
|
||||||
temp.set(trailingKey, null);
|
|
||||||
|
|
||||||
writer.write(toWrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
String endComment = buildComments("", null);
|
|
||||||
if (endComment != null) writer.write(endComment);
|
|
||||||
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到一个键的缩进。
|
|
||||||
* 该方法的源代码来自 tchristofferson/ConfigUpdater 项目。
|
|
||||||
*
|
|
||||||
* @param key 键
|
|
||||||
* @return 该键的缩进文本
|
|
||||||
*/
|
|
||||||
protected static String getIndents(String key) {
|
|
||||||
String[] splitKey = key.split("[" + SEPARATOR + "]");
|
|
||||||
return IntStream.range(1, splitKey.length).mapToObj(i -> " ").collect(Collectors.joining());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
package cc.carm.lib.configuration;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.bungee.BungeeConfigProvider;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.JsonConfiguration;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class MineConfiguration {
|
|
||||||
|
|
||||||
protected static BungeeConfigProvider create(File file, String source, ConfigurationProvider loader) {
|
|
||||||
BungeeConfigProvider provider = new BungeeConfigProvider(file, loader);
|
|
||||||
try {
|
|
||||||
provider.initializeFile(source);
|
|
||||||
provider.initializeConfig();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider from(File file, String source) {
|
|
||||||
return fromYAML(file, source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider from(File file) {
|
|
||||||
return from(file, file.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider from(String fileName) {
|
|
||||||
return from(fileName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider from(String fileName, String source) {
|
|
||||||
return from(new File(fileName), source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromYAML(File file, String source) {
|
|
||||||
return create(file, source, ConfigurationProvider.getProvider(YamlConfiguration.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromYAML(String fileName, String source) {
|
|
||||||
return fromYAML(new File(fileName), source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromYAML(File file) {
|
|
||||||
return fromYAML(file, file.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromYAML(String fileName) {
|
|
||||||
return fromYAML(fileName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromJSON(File file, String source) {
|
|
||||||
return create(file, source, ConfigurationProvider.getProvider(JsonConfiguration.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromJSON(String fileName, String source) {
|
|
||||||
return fromJSON(new File(fileName), source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromJSON(File file) {
|
|
||||||
return fromJSON(file, file.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BungeeConfigProvider fromJSON(String fileName) {
|
|
||||||
return fromJSON(fileName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bungee;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class BungeeConfigProvider extends FileConfigProvider<BungeeSectionWrapper> {
|
|
||||||
|
|
||||||
protected ConfigurationProvider loader;
|
|
||||||
protected Configuration configuration;
|
|
||||||
protected ConfigInitializer<BungeeConfigProvider> initializer;
|
|
||||||
|
|
||||||
public BungeeConfigProvider(@NotNull File file, ConfigurationProvider loader) {
|
|
||||||
super(file);
|
|
||||||
this.loader = loader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initializeConfig() throws IOException {
|
|
||||||
this.configuration = getLoader().load(file);
|
|
||||||
this.initializer = new ConfigInitializer<>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull BungeeSectionWrapper getConfiguration() {
|
|
||||||
return BungeeSectionWrapper.of(configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() throws Exception {
|
|
||||||
this.configuration = getLoader().load(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() throws Exception {
|
|
||||||
getLoader().save(configuration, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo comment) {
|
|
||||||
// BungeeCord version doesn't support comments
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
|
||||||
return null; // BungeeCord version doesn't support comments
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ConfigInitializer<BungeeConfigProvider> getInitializer() {
|
|
||||||
return this.initializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigurationProvider getLoader() {
|
|
||||||
return loader;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.bungee;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class BungeeSectionWrapper implements ConfigurationWrapper {
|
|
||||||
|
|
||||||
private final Configuration section;
|
|
||||||
|
|
||||||
private BungeeSectionWrapper(@NotNull Configuration section) {
|
|
||||||
this.section = section;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Contract("!null->!null")
|
|
||||||
public static @Nullable BungeeSectionWrapper of(@Nullable Configuration section) {
|
|
||||||
return section == null ? null : new BungeeSectionWrapper(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Set<String> getKeys(boolean deep) {
|
|
||||||
return new LinkedHashSet<>(section.getKeys());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
|
||||||
return section.getKeys().stream()
|
|
||||||
.collect(Collectors.toMap(key -> key, section::get, (a, b) -> b, LinkedHashMap::new));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(@NotNull String path, @Nullable Object value) {
|
|
||||||
this.section.set(path, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(@NotNull String path) {
|
|
||||||
return this.section.contains(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Object get(@NotNull String path) {
|
|
||||||
return this.section.get(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isList(@NotNull String path) {
|
|
||||||
return get(path) instanceof List<?>;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<?> getList(@NotNull String path) {
|
|
||||||
return this.section.getList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConfigurationSection(@NotNull String path) {
|
|
||||||
return get(path) instanceof Configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
|
||||||
return of(this.section.getSection(path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?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>3.1.4</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Common</name>
|
||||||
|
<description>轻松(做)配置,全部版本的共用部分。</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>configured-core</artifactId>
|
||||||
|
<version>${deps.configured.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>configured-feature-commentable</artifactId>
|
||||||
|
<version>${deps.configured.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>configured-feature-file</artifactId>
|
||||||
|
<version>${deps.configured.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>configured-feature-text</artifactId>
|
||||||
|
<version>${deps.configured.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-color</artifactId>
|
||||||
|
<version>${deps.easyplugin.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
<version>1.21-R0.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.common;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.Configuration;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class AbstractConfiguration<HOLDER extends ConfigurationHolder<?>> {
|
||||||
|
|
||||||
|
private final HOLDER config;
|
||||||
|
private final HOLDER message;
|
||||||
|
|
||||||
|
protected AbstractConfiguration(@NotNull HOLDER config, @NotNull HOLDER message) {
|
||||||
|
this.config = config;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeConfig(@NotNull Configuration configRoot) {
|
||||||
|
this.config.initialize(configRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeMessage(@NotNull Configuration messageRoot) {
|
||||||
|
this.message.initialize(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeConfig(@NotNull Class<? extends Configuration> configRoot) {
|
||||||
|
this.config.initialize(configRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeMessage(@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
|
this.message.initialize(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HOLDER getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HOLDER getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload() throws Exception {
|
||||||
|
getConfig().reload();
|
||||||
|
getMessage().reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() throws Exception {
|
||||||
|
getConfig().save();
|
||||||
|
getMessage().save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
|
||||||
<version>${easyconfiguration.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.bukkit</groupId>
|
|
||||||
<artifactId>bukkit</artifactId>
|
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.craft.builder.CraftConfigBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftSectionWrapper;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.configuration.core.value.impl.CachedConfigValue;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public abstract class CraftConfigValue<T> extends CachedConfigValue<T> {
|
|
||||||
|
|
||||||
public static @NotNull CraftConfigBuilder builder() {
|
|
||||||
return new CraftConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CraftConfigValue(@Nullable CraftConfigProvider provider,
|
|
||||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments, @Nullable T defaultValue) {
|
|
||||||
super(provider, configPath, comments, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CraftConfigProvider getBukkitProvider() {
|
|
||||||
ConfigurationProvider<?> provider = getProvider();
|
|
||||||
if (provider instanceof CraftConfigProvider) return (CraftConfigProvider) getProvider();
|
|
||||||
else throw new IllegalStateException("Provider is not a SpigotConfigProvider");
|
|
||||||
}
|
|
||||||
|
|
||||||
public CraftSectionWrapper getBukkitConfig() {
|
|
||||||
return getBukkitProvider().getConfiguration();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
|
||||||
import cc.carm.lib.configuration.core.builder.AbstractConfigBuilder;
|
|
||||||
|
|
||||||
public abstract class AbstractCraftBuilder<T, B extends AbstractCraftBuilder<T, B>>
|
|
||||||
extends AbstractConfigBuilder<T, B, CraftConfigProvider> {
|
|
||||||
|
|
||||||
public AbstractCraftBuilder() {
|
|
||||||
super(CraftConfigProvider.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.builder.ConfigBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.builder.item.ItemConfigBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.builder.serializable.SerializableBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.ItemConfig;
|
|
||||||
import cc.carm.lib.configuration.craft.value.ConfiguredItem;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class CraftConfigBuilder extends ConfigBuilder {
|
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder createSound() {
|
|
||||||
return new SoundConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ItemConfigBuilder createItem() {
|
|
||||||
return new ItemConfigBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public <V extends ConfigurationSerializable> @NotNull SerializableBuilder<V> ofSerializable(@NotNull Class<V> valueClass) {
|
|
||||||
return new SerializableBuilder<>(valueClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ConfiguredItem ofItem() {
|
|
||||||
return createItem().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ConfiguredItem ofItem(@Nullable ItemConfig defaultItem) {
|
|
||||||
return createItem().defaults(defaultItem).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-73
@@ -1,73 +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 defaults(new ItemConfig(type, data, name, lore));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemConfigBuilder defaultType(@NotNull Material type) {
|
|
||||||
this.type = type;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemConfigBuilder defaultName(@NotNull String name) {
|
|
||||||
this.name = name;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemConfigBuilder defaultDataID(short dataID) {
|
|
||||||
this.data = dataID;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemConfigBuilder defaultLore(@NotNull String... lore) {
|
|
||||||
this.lore = new ArrayList<>(Arrays.asList(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder.serializable;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.value.ConfiguredSerializable;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class SerializableBuilder<T extends ConfigurationSerializable>
|
|
||||||
extends AbstractCraftBuilder<T, SerializableBuilder<T>> {
|
|
||||||
|
|
||||||
protected final @NotNull Class<T> valueClass;
|
|
||||||
|
|
||||||
public SerializableBuilder(@NotNull Class<T> valueClass) {
|
|
||||||
this.valueClass = valueClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull SerializableBuilder<T> getThis() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ConfiguredSerializable<T> build() {
|
|
||||||
return new ConfiguredSerializable<>(this.provider, this.path, buildComments(), this.valueClass, this.defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
-34
@@ -1,34 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.builder.sound;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.craft.builder.AbstractCraftBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
|
||||||
import cc.carm.lib.configuration.craft.value.ConfiguredSound;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class SoundConfigBuilder extends AbstractCraftBuilder<SoundConfig, SoundConfigBuilder> {
|
|
||||||
|
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume, float pitch) {
|
|
||||||
return defaults(new SoundConfig(sound, volume, pitch));
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound, float volume) {
|
|
||||||
return defaults(sound, volume, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull SoundConfigBuilder defaults(@NotNull Sound sound) {
|
|
||||||
return defaults(sound, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected @NotNull SoundConfigBuilder getThis() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ConfiguredSound build() {
|
|
||||||
return new ConfiguredSound(this.provider, this.path, buildComments(), this.defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ItemConfig {
|
|
||||||
|
|
||||||
@NotNull Material type;
|
|
||||||
short data;
|
|
||||||
@Nullable String name;
|
|
||||||
@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 @NotNull ItemStack getItemStack() {
|
|
||||||
return getItemStack(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ItemStack getItemStack(int amount) {
|
|
||||||
ItemStack item = new ItemStack(type, amount, data);
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (meta == null) return item;
|
|
||||||
if (getName() != null) meta.setDisplayName(getName());
|
|
||||||
if (!getLore().isEmpty()) meta.setLore(getLore());
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public @NotNull Map<String, Object> serialize() {
|
|
||||||
Map<String, Object> map = new LinkedHashMap<>();
|
|
||||||
map.put("type", type.name());
|
|
||||||
if (this.data != 0) map.put("data", data);
|
|
||||||
if (name != null) map.put("name", name);
|
|
||||||
if (!lore.isEmpty()) map.put("lore", lore);
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull ItemConfig deserialize(@NotNull ConfigurationWrapper section) throws Exception {
|
|
||||||
String typeName = section.getString("name");
|
|
||||||
if (typeName == null) throw new NullPointerException("Item type name is null");
|
|
||||||
|
|
||||||
Material type = Material.matchMaterial(typeName);
|
|
||||||
if (type == null) throw new Exception("Invalid material name: " + typeName);
|
|
||||||
else return new ItemConfig(
|
|
||||||
type, section.getShort("data", (short) 0),
|
|
||||||
section.getString("name"),
|
|
||||||
parseStringList(section.getList("lore"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<String> parseStringList(@Nullable List<?> data) {
|
|
||||||
if (data == null) return new ArrayList<>();
|
|
||||||
else return data.stream()
|
|
||||||
.map(o -> o instanceof String ? (String) o : o.toString())
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.data;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.Contract;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class SoundConfig {
|
|
||||||
|
|
||||||
protected @NotNull Sound type;
|
|
||||||
protected float volume;
|
|
||||||
protected float pitch;
|
|
||||||
|
|
||||||
public SoundConfig(@NotNull Sound type) {
|
|
||||||
this(type, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundConfig(@NotNull Sound type, float volume) {
|
|
||||||
this(type, volume, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundConfig(@NotNull Sound type, float volume, float pitch) {
|
|
||||||
this.type = type;
|
|
||||||
this.volume = volume;
|
|
||||||
this.pitch = pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playTo(Player player) {
|
|
||||||
player.playSound(player.getLocation(), type, volume, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playToAll() {
|
|
||||||
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull Sound getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPitch() {
|
|
||||||
return pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getVolume() {
|
|
||||||
return volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(@NotNull Sound type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVolume(float volume) {
|
|
||||||
this.volume = volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPitch(float pitch) {
|
|
||||||
this.pitch = pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull String serialize() {
|
|
||||||
if (pitch != 1) {
|
|
||||||
return type.name() + ":" + volume + ":" + pitch;
|
|
||||||
} else if (volume != 1) {
|
|
||||||
return type.name() + ":" + volume;
|
|
||||||
} else {
|
|
||||||
return type.name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Contract("null -> null")
|
|
||||||
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
|
||||||
if (string == null) return null;
|
|
||||||
|
|
||||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
|
||||||
if (args.length < 1) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return new SoundConfig(
|
|
||||||
Sound.valueOf(args[0]),
|
|
||||||
(args.length >= 2) ? Float.parseFloat(args[1]) : 1,
|
|
||||||
(args.length >= 3) ? Float.parseFloat(args[2]) : 1
|
|
||||||
);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
throw new Exception("Sound " + string + " wasn't configured correctly.", exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-43
@@ -1,43 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
|
||||||
import cc.carm.lib.configuration.core.source.impl.FileConfigProvider;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public abstract class CraftConfigProvider extends FileConfigProvider<CraftSectionWrapper> {
|
|
||||||
|
|
||||||
public static final char SEPARATOR = '.';
|
|
||||||
|
|
||||||
protected ConfigInitializer<? extends CraftConfigProvider> initializer;
|
|
||||||
protected YamlConfiguration configuration;
|
|
||||||
|
|
||||||
public CraftConfigProvider(@NotNull File file) {
|
|
||||||
super(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void initializeConfig();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull CraftSectionWrapper getConfiguration() {
|
|
||||||
return CraftSectionWrapper.of(this.configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void reload() throws Exception {
|
|
||||||
configuration.load(getFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save() throws Exception {
|
|
||||||
configuration.save(getFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull ConfigInitializer<? extends CraftConfigProvider> getInitializer() {
|
|
||||||
return this.initializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-74
@@ -1,74 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class CraftSectionWrapper implements ConfigurationWrapper {
|
|
||||||
|
|
||||||
protected final ConfigurationSection section;
|
|
||||||
|
|
||||||
protected CraftSectionWrapper(ConfigurationSection section) {
|
|
||||||
this.section = section;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigurationSection getSourceSection() {
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Set<String> getKeys(boolean deep) {
|
|
||||||
return this.section.getKeys(deep);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Map<String, Object> getValues(boolean deep) {
|
|
||||||
return this.section.getValues(deep);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(@NotNull String path, @Nullable Object value) {
|
|
||||||
this.section.set(path, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(@NotNull String path) {
|
|
||||||
return this.section.contains(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Object get(@NotNull String path) {
|
|
||||||
return this.section.get(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isList(@NotNull String path) {
|
|
||||||
return this.section.isList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable List<?> getList(@NotNull String path) {
|
|
||||||
return this.section.getList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConfigurationSection(@NotNull String path) {
|
|
||||||
return this.section.isConfigurationSection(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ConfigurationWrapper getConfigurationSection(@NotNull String path) {
|
|
||||||
return Optional.ofNullable(section.getConfigurationSection(path))
|
|
||||||
.map(CraftSectionWrapper::of).orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CraftSectionWrapper of(ConfigurationSection section) {
|
|
||||||
return new CraftSectionWrapper(section);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-53
@@ -1,53 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.value;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class ConfiguredSerializable<T extends ConfigurationSerializable> extends CraftConfigValue<T> {
|
|
||||||
|
|
||||||
public static <V extends ConfigurationSerializable> ConfiguredSerializable<V> of(@NotNull Class<V> valueClass) {
|
|
||||||
return of(valueClass, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <V extends ConfigurationSerializable> ConfiguredSerializable<V> of(@NotNull Class<V> valueClass,
|
|
||||||
@Nullable V defaultValue) {
|
|
||||||
return builder().ofSerializable(valueClass).defaults(defaultValue).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final @NotNull Class<T> valueClass;
|
|
||||||
|
|
||||||
public ConfiguredSerializable(@Nullable CraftConfigProvider provider,
|
|
||||||
@Nullable String configPath, @Nullable ConfigCommentInfo comments,
|
|
||||||
@NotNull Class<T> valueClass, @Nullable T defaultValue) {
|
|
||||||
super(provider, configPath, comments, defaultValue);
|
|
||||||
this.valueClass = valueClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable T get() {
|
|
||||||
if (isExpired()) { // 已过时的数据,需要重新解析一次。
|
|
||||||
try {
|
|
||||||
// 若未出现错误,则直接更新缓存并返回。
|
|
||||||
return updateCache(getBukkitConfig().get(getConfigPath(), getDefaultValue(), valueClass));
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 出现了解析错误,提示并返回默认值。
|
|
||||||
e.printStackTrace();
|
|
||||||
return useDefault();
|
|
||||||
}
|
|
||||||
} else return Optional.ofNullable(getCachedValue()).orElse(defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(@Nullable T value) {
|
|
||||||
updateCache(value);
|
|
||||||
setValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.craft.value;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.function.ConfigValueParser;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
|
||||||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
|
|
||||||
import cc.carm.lib.configuration.craft.CraftConfigValue;
|
|
||||||
import cc.carm.lib.configuration.craft.builder.sound.SoundConfigBuilder;
|
|
||||||
import cc.carm.lib.configuration.craft.data.SoundConfig;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
|
||||||
|
|
||||||
public static @NotNull SoundConfigBuilder create() {
|
|
||||||
return CraftConfigValue.builder().createSound();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull ConfiguredSound of(Sound sound) {
|
|
||||||
return CraftConfigValue.builder().createSound().defaults(sound).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull ConfiguredSound of(Sound sound, float volume) {
|
|
||||||
return CraftConfigValue.builder().createSound().defaults(sound, volume).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static @NotNull ConfiguredSound of(Sound sound, float volume, float pitch) {
|
|
||||||
return CraftConfigValue.builder().createSound().defaults(sound, volume, pitch).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfiguredSound(@Nullable ConfigurationProvider<?> provider,
|
|
||||||
@Nullable String sectionPath, @Nullable ConfigCommentInfo comments,
|
|
||||||
@Nullable SoundConfig defaultValue) {
|
|
||||||
super(provider, sectionPath, comments, SoundConfig.class, defaultValue, getSoundParser(), SoundConfig::serialize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSound(@NotNull Sound sound) {
|
|
||||||
setSound(sound, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSound(@NotNull Sound sound, float volume) {
|
|
||||||
setSound(sound, volume, 1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSound(@NotNull Sound sound, float volume, float pitch) {
|
|
||||||
set(new SoundConfig(sound, volume, pitch));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playTo(@NotNull Player player) {
|
|
||||||
Optional.ofNullable(get()).ifPresent(c -> c.playTo(player));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void playToAll() {
|
|
||||||
Optional.ofNullable(get()).ifPresent(SoundConfig::playToAll);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigValueParser<Object, SoundConfig> getSoundParser() {
|
|
||||||
return ConfigValueParser.castToString().andThen((s, d) -> SoundConfig.deserialize(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
<?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>3.1.4</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
|
<deps.adventure.version>4.26.1</deps.adventure.version>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-velocity</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Adventure</name>
|
||||||
|
<description>轻松(做)配置,适用于基于Adventure的平台(如Velocity、Paper),可用JSON与YAML格式。</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>configured-yaml</artifactId>
|
||||||
|
<version>${deps.configured.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-api</artifactId>
|
||||||
|
<version>${deps.adventure.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-serializer-legacy</artifactId>
|
||||||
|
<version>${deps.adventure.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-serializer-plain</artifactId>
|
||||||
|
<version>${deps.adventure.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>${deps.adventure.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>
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.adventure;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.Configuration;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.source.yaml.YAMLConfigFactory;
|
||||||
|
import cc.carm.lib.configuration.source.yaml.YAMLSource;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MineConfiguration extends AbstractConfiguration<ConfigurationHolder<YAMLSource>> {
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull File pluginDataFolder) {
|
||||||
|
super(
|
||||||
|
YAMLConfigFactory.from(pluginDataFolder, "config.yml").build(),
|
||||||
|
YAMLConfigFactory.from(pluginDataFolder, "messages.yml").build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||||
|
@NotNull Configuration configRoot,
|
||||||
|
@NotNull Configuration messageRoot) {
|
||||||
|
this(pluginDataFolder);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||||
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
|
this(pluginDataFolder);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.adventure.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.text.ConfiguredText;
|
||||||
|
import cc.carm.lib.configuration.value.text.data.TextContents;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessage extends ConfiguredText<Component, Audience> {
|
||||||
|
|
||||||
|
public static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||||
|
|
||||||
|
public static AtomicReference<ComponentSerializer<?, ?, String>> SERIALIZER = new AtomicReference<>(LEGACY_SERIALIZER);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
|
||||||
|
public static ConfiguredMessage.Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage ofString(@NotNull String... messages) {
|
||||||
|
return create().defaults(messages).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessage(@NotNull ValueManifest<TextContents, TextContents> manifest,
|
||||||
|
@NotNull BiFunction<Audience, String, String> parser,
|
||||||
|
@NotNull BiFunction<Audience, String, Component> compiler,
|
||||||
|
@NotNull BiConsumer<Audience, List<Component>> dispatcher,
|
||||||
|
@NotNull String[] params) {
|
||||||
|
super(manifest, parser, compiler, dispatcher, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionBar(Audience audience, Object... values) {
|
||||||
|
Component content = prepare(values).parseLine(audience, (sender, message) -> Component.text(message));
|
||||||
|
if (content != null) audience.sendActionBar(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends ConfiguredText.Builder<Component, Audience, Builder> {
|
||||||
|
|
||||||
|
public Builder() {
|
||||||
|
super();
|
||||||
|
this.parser = (receiver, message) -> ColorParser.parse(message);
|
||||||
|
this.compiler = (receiver, message) -> SERIALIZER.get().deserialize(message);
|
||||||
|
this.dispatcher = (receiver, message) -> message.forEach(receiver::sendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage build() {
|
||||||
|
return new ConfiguredMessage(buildManifest(), this.parser, this.compiler, this.dispatcher, this.params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage.Builder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?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>3.1.4</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Bukkit</name>
|
||||||
|
<description>EasyConfiguration for Bukkit.</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>yamlcommentwriter</artifactId>
|
||||||
|
<version>${deps.yamlcommentwriter.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
|
<artifactId>XSeries</artifactId>
|
||||||
|
<version>13.6.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bukkit</groupId>
|
||||||
|
<artifactId>bukkit</artifactId>
|
||||||
|
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
<version>1.21-R0.4</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--PlaceholderAPI for general placeholder's support-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.Configuration;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitConfigFactory;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.source.BukkitSource;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MineConfiguration extends AbstractConfiguration<ConfigurationHolder<BukkitSource>> {
|
||||||
|
|
||||||
|
public static ConfigurationHolder<BukkitSource> from(@NotNull File file,
|
||||||
|
@Nullable String source) {
|
||||||
|
return BukkitConfigFactory.from(file).resourcePath(source).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigurationHolder<BukkitSource> from(@NotNull Plugin plugin,
|
||||||
|
@NotNull String fileName) {
|
||||||
|
return from(plugin, fileName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigurationHolder<BukkitSource> from(@NotNull Plugin plugin,
|
||||||
|
@NotNull String fileName, @Nullable String resource) {
|
||||||
|
return from(new File(plugin.getDataFolder(), fileName), resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull JavaPlugin plugin) {
|
||||||
|
super(from(plugin, "config.yml"), from(plugin, "messages.yml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||||
|
@NotNull Configuration configRoot,
|
||||||
|
@NotNull Configuration messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull JavaPlugin plugin,
|
||||||
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
|
this(plugin);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.NotifyCache;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.NotifyType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class NotifyConfig {
|
||||||
|
|
||||||
|
public static @Nullable NotifyConfig deserialize(@NotNull String config) {
|
||||||
|
return Optional.ofNullable(NotifyCache.deserialize(config)).map(NotifyConfig::of).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull NotifyConfig of(@NotNull NotifyCache<?, ?> cache) {
|
||||||
|
return new NotifyConfig(cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable NotifyConfig of(@NotNull String key, @Nullable String param, @Nullable String content) {
|
||||||
|
return Optional.ofNullable(NotifyCache.of(key, param, content)).map(NotifyConfig::of).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyConfig of(@NotNull T type, @Nullable String param, @Nullable String content) {
|
||||||
|
return of(type, type.parseMeta(param, content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyConfig of(@NotNull T type, @Nullable M meta) {
|
||||||
|
return of(NotifyCache.of(type, meta));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull NotifyCache<?, ?> cache;
|
||||||
|
|
||||||
|
|
||||||
|
public NotifyConfig(@NotNull NotifyCache<?, ?> cache) {
|
||||||
|
this.cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull NotifyCache<?, ?> getCache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
getCache().execute(player, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serialize() {
|
||||||
|
return getCache().serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+121
@@ -0,0 +1,121 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class SoundConfig {
|
||||||
|
|
||||||
|
protected @NotNull String typeName;
|
||||||
|
protected @Nullable Sound type;
|
||||||
|
protected float volume;
|
||||||
|
protected float pitch;
|
||||||
|
|
||||||
|
public SoundConfig(@NotNull String typeName) {
|
||||||
|
this(typeName, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoundConfig(@NotNull String typeName, float volume) {
|
||||||
|
this(typeName, volume, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoundConfig(@NotNull String typeName, float volume, float pitch) {
|
||||||
|
this(typeName, Arrays.stream(Sound.values()).filter(s -> s.name().equalsIgnoreCase(typeName)).findFirst().orElse(null), volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoundConfig(@NotNull String typeName, @Nullable Sound type, float volume, float pitch) {
|
||||||
|
this.typeName = typeName;
|
||||||
|
this.type = type;
|
||||||
|
this.volume = volume;
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playTo(@NotNull Player player) {
|
||||||
|
playTo(player, player.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playTo(@NotNull Player player, @NotNull Location location) {
|
||||||
|
if (type == null) return;
|
||||||
|
player.playSound(location, type, volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playAt(@NotNull Location location) {
|
||||||
|
if (type == null) return;
|
||||||
|
if (location.getWorld() == null) return;
|
||||||
|
location.getWorld().playSound(location, type, volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playToAll() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(this::playTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playToAll(@NotNull Location location) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> playTo(player, location));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getTypeName() {
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Sound getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPitch() {
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getVolume() {
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(@NotNull Sound type) {
|
||||||
|
this.typeName = type.name();
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVolume(float volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPitch(float pitch) {
|
||||||
|
this.pitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String serialize() {
|
||||||
|
if (pitch != 1) {
|
||||||
|
return typeName + ":" + volume + ":" + pitch;
|
||||||
|
} else if (volume != 1) {
|
||||||
|
return typeName + ":" + volume;
|
||||||
|
} else {
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("null -> null")
|
||||||
|
public static @Nullable SoundConfig deserialize(@Nullable String string) throws Exception {
|
||||||
|
if (string == null || string.isEmpty()) return null;
|
||||||
|
|
||||||
|
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||||
|
if (args.length < 1) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return new SoundConfig(
|
||||||
|
args[0],
|
||||||
|
Sound.valueOf(args[0]),
|
||||||
|
(args.length >= 2) ? Float.parseFloat(args[1]) : 1,
|
||||||
|
(args.length >= 3) ? Float.parseFloat(args[2]) : 1
|
||||||
|
);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new Exception("Sound " + string + " wasn't configured correctly.", exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+147
@@ -0,0 +1,147 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.data;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||||
|
import cc.carm.lib.configuration.value.text.PreparedText;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.MessageUtils;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TitleConfig {
|
||||||
|
|
||||||
|
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2) {
|
||||||
|
return new TitleConfig(line1, line2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull TitleConfig of(@Nullable String line1, @Nullable String line2,
|
||||||
|
int fadeIn, int stay, int fadeOut) {
|
||||||
|
return new TitleConfig(line1, line2, fadeIn, stay, fadeOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @Nullable String line1;
|
||||||
|
protected @Nullable String line2;
|
||||||
|
|
||||||
|
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 TitleConfig(@Nullable String line1, @Nullable String line2) {
|
||||||
|
this.line1 = line1;
|
||||||
|
this.line2 = line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TitleConfig(@Nullable String line1, @Nullable String line2, int fadeIn, int stay, int fadeOut) {
|
||||||
|
this.line1 = line1;
|
||||||
|
this.line2 = line2;
|
||||||
|
this.fadeIn = fadeIn;
|
||||||
|
this.stay = stay;
|
||||||
|
this.fadeOut = fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int stay() {
|
||||||
|
return stay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stay(int stay) {
|
||||||
|
this.stay = stay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String line1() {
|
||||||
|
return line1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void line1(@Nullable String line1) {
|
||||||
|
this.line1 = line1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String line2() {
|
||||||
|
return line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void line2(@Nullable String line2) {
|
||||||
|
this.line2 = line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int fadeIn() {
|
||||||
|
return fadeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fadeIn(int fadeIn) {
|
||||||
|
this.fadeIn = fadeIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int fadeOut() {
|
||||||
|
return fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fadeOut(int fadeOut) {
|
||||||
|
this.fadeOut = fadeOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStandardTime() {
|
||||||
|
return this.fadeIn == 10 && this.stay == 60 && this.fadeOut == 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Player player,
|
||||||
|
@NotNull Map<String, Object> placeholders,
|
||||||
|
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||||
|
send(
|
||||||
|
player,
|
||||||
|
this.fadeIn < 0 ? 10 : this.fadeIn,
|
||||||
|
this.stay < 0 ? 60 : this.stay,
|
||||||
|
this.fadeOut < 0 ? 10 : this.fadeOut,
|
||||||
|
placeholders,
|
||||||
|
sendConsumer
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Player player,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||||
|
@NotNull Map<String, Object> placeholders,
|
||||||
|
@Nullable ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||||
|
if (this.line1 == null && this.line2 == null) return;
|
||||||
|
if (sendConsumer == null) return;
|
||||||
|
sendConsumer.send(
|
||||||
|
player, fadeIn, stay, fadeOut,
|
||||||
|
parseLine(player, this.line1, placeholders),
|
||||||
|
parseLine(player, this.line2, placeholders)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @NotNull String parseLine(@NotNull Player player, @Nullable String text,
|
||||||
|
@NotNull Map<String, Object> placeholders) {
|
||||||
|
return text == null ? "" : MessageUtils.parseMessage(player, PreparedText.setPlaceholders(text, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, Object> serialize() {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
if (this.line1 != null) map.put("line1", this.line1);
|
||||||
|
if (this.line2 != null) map.put("line2", this.line2);
|
||||||
|
if (this.fadeIn > 0 && this.fadeIn != 10) map.put("fadeIn", this.fadeIn);
|
||||||
|
if (this.stay > 0 && this.stay != 60) map.put("stay", this.stay);
|
||||||
|
if (this.fadeOut > 0 && this.fadeOut != 10) map.put("fadeOut", this.fadeOut);
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable TitleConfig deserialize(@NotNull ConfigureSection section) {
|
||||||
|
String line1 = section.getString("line1");
|
||||||
|
String line2 = section.getString("line2");
|
||||||
|
if (line1 == null && line2 == null) return null;
|
||||||
|
|
||||||
|
return of(
|
||||||
|
line1, line2,
|
||||||
|
section.getInt("fadeIn", -1),
|
||||||
|
section.getInt("stay", -1),
|
||||||
|
section.getInt("fadeOut", -1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.commentable.Commentable;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.source.file.FileConfigFactory;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class BukkitConfigFactory extends FileConfigFactory<BukkitSource, ConfigurationHolder<BukkitSource>, BukkitConfigFactory> {
|
||||||
|
|
||||||
|
public static BukkitConfigFactory from(@NotNull String path) {
|
||||||
|
return new BukkitConfigFactory(new File(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitConfigFactory from(@NotNull File file) {
|
||||||
|
return new BukkitConfigFactory(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitConfigFactory from(@NotNull File parent, @NotNull String configName) {
|
||||||
|
return new BukkitConfigFactory(new File(parent, configName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitConfigFactory from(@NotNull Plugin plugin, @NotNull String configName) {
|
||||||
|
return from(plugin.getDataFolder(), configName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BukkitConfigFactory(@NotNull File file) {
|
||||||
|
super(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BukkitConfigFactory self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfigurationHolder<BukkitSource> build() {
|
||||||
|
|
||||||
|
File configFile = this.file;
|
||||||
|
String sourcePath = this.resourcePath;
|
||||||
|
|
||||||
|
Commentable.registerMeta(this.initializer); // Register commentable meta types
|
||||||
|
|
||||||
|
return new ConfigurationHolder<BukkitSource>(this.adapters, this.options, this.metadata, this.initializer) {
|
||||||
|
final @NotNull BukkitSource source = new BukkitSource(this, configFile, sourcePath);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull BukkitSource config() {
|
||||||
|
return this.source;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+135
@@ -0,0 +1,135 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.UnmodifiableView;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class BukkitSection implements ConfigureSection {
|
||||||
|
|
||||||
|
protected final @NotNull BukkitSource source;
|
||||||
|
protected final @Nullable BukkitSection parent;
|
||||||
|
protected final @NotNull String path;
|
||||||
|
protected final @NotNull ConfigurationSection data;
|
||||||
|
|
||||||
|
public BukkitSection(@NotNull BukkitSource source, @Nullable BukkitSection parent,
|
||||||
|
@NotNull String path, @NotNull ConfigurationSection data) {
|
||||||
|
this.source = source;
|
||||||
|
this.parent = parent;
|
||||||
|
this.path = path;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull BukkitSource source() {
|
||||||
|
return this.source;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable BukkitSection parent() {
|
||||||
|
return this.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String path() {
|
||||||
|
return this.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ConfigurationSection data() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Set<String> getKeys(boolean deep) {
|
||||||
|
return data().getKeys(deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull @UnmodifiableView Map<String, Object> getValues(boolean deep) {
|
||||||
|
|
||||||
|
Map<String, Object> original = data().getValues(deep);
|
||||||
|
// wrap all ConfigurationSection
|
||||||
|
for (Map.Entry<String, Object> entry : original.entrySet()) {
|
||||||
|
if (entry.getValue() instanceof ConfigurationSection) {
|
||||||
|
original.put(entry.getKey(), createSection(entry.getKey(), (ConfigurationSection) entry.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.unmodifiableMap(original);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> toMap(ConfigurationSection section) {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
for (String key : section.getKeys(false)) {
|
||||||
|
Object value = section.get(key);
|
||||||
|
if (value instanceof ConfigurationSection) {
|
||||||
|
map.put(key, toMap((ConfigurationSection) value));
|
||||||
|
} else if (value instanceof BukkitSection) {
|
||||||
|
map.put(key, toMap(((BukkitSection) value).data()));
|
||||||
|
} else if (value instanceof List<?>) {
|
||||||
|
List<Object> list = new ArrayList<>();
|
||||||
|
for (Object o : (List<?>) value) {
|
||||||
|
if (o instanceof ConfigurationSection) {
|
||||||
|
list.add(toMap((ConfigurationSection) o));
|
||||||
|
} else if (o instanceof BukkitSection) {
|
||||||
|
list.add(toMap(((BukkitSection) o).data()));
|
||||||
|
} else {
|
||||||
|
list.add(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.put(key, list);
|
||||||
|
} else {
|
||||||
|
map.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull @UnmodifiableView Map<String, Object> asMap() {
|
||||||
|
return toMap(data());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(@NotNull String path, @Nullable Object value) {
|
||||||
|
if (value instanceof BukkitSection) { // unwrap
|
||||||
|
value = ((BukkitSection) value).data();
|
||||||
|
}
|
||||||
|
data().set(path, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove(@NotNull String path) {
|
||||||
|
data().set(path, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ConfigureSection getSection(@NotNull String path) {
|
||||||
|
Object value = get(path);
|
||||||
|
if (value instanceof ConfigureSection) {
|
||||||
|
return (ConfigureSection) value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull BukkitSection createSection(@NotNull String path, @NotNull ConfigurationSection section) {
|
||||||
|
return new BukkitSection(source(), this, path, section);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull BukkitSection createSection(@NotNull String path, @NotNull Map<?, ?> data) {
|
||||||
|
return createSection(path, data().createSection(path, data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Object get(@NotNull String path) {
|
||||||
|
Object value = data().get(path);
|
||||||
|
if (value instanceof ConfigurationSection) { // wrap
|
||||||
|
return createSection(path, (ConfigurationSection) value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+109
@@ -0,0 +1,109 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.source;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.commentable.Commentable;
|
||||||
|
import cc.carm.lib.configuration.commentable.CommentableOptions;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.source.file.FileConfigSource;
|
||||||
|
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||||
|
import cc.carm.lib.yamlcommentupdater.CommentedSection;
|
||||||
|
import cc.carm.lib.yamlcommentupdater.CommentedYAMLWriter;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class BukkitSource extends FileConfigSource<BukkitSection, YamlConfiguration, BukkitSource>
|
||||||
|
implements CommentedSection {
|
||||||
|
|
||||||
|
protected @Nullable BukkitSection rootSection;
|
||||||
|
|
||||||
|
public BukkitSource(@NotNull ConfigurationHolder<? extends BukkitSource> holder,
|
||||||
|
@NotNull File file, @Nullable String resourcePath) {
|
||||||
|
super(holder, System.currentTimeMillis(), file, resourcePath);
|
||||||
|
initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
try {
|
||||||
|
initializeFile();
|
||||||
|
onReload();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull BukkitSource self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull YamlConfiguration original() {
|
||||||
|
return (YamlConfiguration) section().data(); // #data() of Root Section always returns YamlConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull BukkitSection section() {
|
||||||
|
return Objects.requireNonNull(rootSection, "Root section has not been initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() throws Exception {
|
||||||
|
CommentedYAMLWriter writer = new CommentedYAMLWriter(
|
||||||
|
String.valueOf(this.pathSeparator()), 2,
|
||||||
|
holder.options().get(CommentableOptions.COMMENT_EMPTY_VALUE)
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
fileWriter(w -> w.write(writer.saveToString(this)));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
fileWriter(w -> w.write(original().saveToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onReload() throws Exception {
|
||||||
|
YamlConfiguration configuration = fileReader(YamlConfiguration::loadConfiguration);
|
||||||
|
this.rootSection = new BukkitSection(this, null, "", configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String serializeValue(@NotNull String key, @NotNull Object value) {
|
||||||
|
FileConfiguration temp = new YamlConfiguration();
|
||||||
|
temp.set(key, value);
|
||||||
|
return temp.saveToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Set<String> getKeys(@Nullable String sectionKey, boolean deep) {
|
||||||
|
if (sectionKey == null) return section().getKeys(deep);
|
||||||
|
ConfigureSection sub = section().getSection(sectionKey);
|
||||||
|
if (sub == null) return null;
|
||||||
|
return sub.getKeys(deep);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Object getValue(@NotNull String key) {
|
||||||
|
return get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String getInlineComment(@NotNull String key) {
|
||||||
|
return Commentable.getInlineComment(holder(), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> getHeaderComments(@Nullable String key) {
|
||||||
|
return Commentable.getHeaderComments(holder(), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable List<String> getFooterComments(@Nullable String key) {
|
||||||
|
return Commentable.getFooterComments(holder(), key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class MessageUtils {
|
||||||
|
|
||||||
|
private MessageUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Contract("_,!null->!null")
|
||||||
|
public static @Nullable String parseMessage(@Nullable CommandSender sender, @Nullable String message) {
|
||||||
|
if (message == null) return null;
|
||||||
|
if (sender instanceof Player && hasPlaceholderAPI()) {
|
||||||
|
message = PlaceholderAPIHelper.parseMessages((Player) sender, message);
|
||||||
|
}
|
||||||
|
return ColorParser.parse(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> parseMessage(@Nullable CommandSender sender, @NotNull List<String> messages) {
|
||||||
|
if (sender instanceof Player && hasPlaceholderAPI()) {
|
||||||
|
messages = PlaceholderAPIHelper.parseMessages((Player) sender, messages);
|
||||||
|
}
|
||||||
|
return ColorParser.parse(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPlaceholderAPI() {
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.utils;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PlaceholderAPIHelper {
|
||||||
|
|
||||||
|
private 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.text.ConfiguredText;
|
||||||
|
import cc.carm.lib.configuration.value.text.data.TextContents;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.MessageUtils;
|
||||||
|
import com.cryptomorin.xseries.messages.ActionBar;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessage<M> extends ConfiguredText<M, CommandSender> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <M> ConfiguredMessage.Builder<M> create(
|
||||||
|
@NotNull BiFunction<@Nullable CommandSender, @NotNull String, @Nullable M> compiler
|
||||||
|
) {
|
||||||
|
return new Builder<M>().compiler(compiler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder<String> asString() {
|
||||||
|
return create((sender, message) -> message)
|
||||||
|
.parser(MessageUtils::parseMessage)
|
||||||
|
.dispatcher((sender, message) -> message.forEach(sender::sendMessage));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString() {
|
||||||
|
return asString().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage<String> ofString(@NotNull String... messages) {
|
||||||
|
return asString().defaults(messages).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessage(@NotNull ValueManifest<TextContents, TextContents> manifest,
|
||||||
|
@NotNull BiFunction<CommandSender, String, String> parser,
|
||||||
|
@NotNull BiFunction<CommandSender, String, M> compiler,
|
||||||
|
@NotNull BiConsumer<CommandSender, List<M>> dispatcher,
|
||||||
|
@NotNull String[] params) {
|
||||||
|
super(manifest, parser, compiler, dispatcher, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendActionBar(@NotNull Player player, Object... values) {
|
||||||
|
ActionBar.sendActionBar(player, (String) prepare(values).parseLine(player, (sender, message) -> message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print(Object... values) {
|
||||||
|
prepare(values).to(Bukkit.getConsoleSender());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder<M> extends ConfiguredText.Builder<M, CommandSender, Builder<M>> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage<M> build() {
|
||||||
|
return new ConfiguredMessage<>(buildManifest(), this.parser, this.compiler, this.dispatcher, this.params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage.Builder<M> self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+135
@@ -0,0 +1,135 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueAdapter;
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueType;
|
||||||
|
import cc.carm.lib.configuration.builder.AbstractConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class ConfiguredSound extends ConfiguredValue<SoundConfig> {
|
||||||
|
|
||||||
|
public static @NotNull Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ConfiguredSound of(Sound sound) {
|
||||||
|
return create().defaults(sound).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ConfiguredSound of(Sound sound, float volume) {
|
||||||
|
return create().defaults(sound, volume).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ConfiguredSound of(Sound sound, float volume, float pitch) {
|
||||||
|
return create().defaults(sound, volume, pitch).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ConfiguredSound of(String soundName) {
|
||||||
|
return create().defaults(soundName).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ConfiguredSound of(String soundName, float volume) {
|
||||||
|
return create().defaults(soundName, volume).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ConfiguredSound of(String soundName, float volume, float pitch) {
|
||||||
|
return create().defaults(soundName, volume, pitch).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static final ValueType<SoundConfig> SOUND_TYPE = ValueType.of(SoundConfig.class);
|
||||||
|
public static final ValueAdapter<SoundConfig> SOUND_ADAPTER = new ValueAdapter<>(SOUND_TYPE,
|
||||||
|
(holder, type, value) -> value.serialize(),
|
||||||
|
(holder, type, value) -> {
|
||||||
|
String conf = holder.deserialize(String.class, value);
|
||||||
|
return SoundConfig.deserialize(conf);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
public ConfiguredSound(@NotNull ValueManifest<SoundConfig, SoundConfig> manifest, @NotNull ValueAdapter<SoundConfig> adapter) {
|
||||||
|
super(manifest, adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@NotNull Sound sound) {
|
||||||
|
set(sound, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@NotNull Sound sound, float volume) {
|
||||||
|
set(sound, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@NotNull Sound sound, float volume, float pitch) {
|
||||||
|
set(new SoundConfig(sound.name(), sound, volume, pitch));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playTo(@NotNull Player player) {
|
||||||
|
Optional.ofNullable(get()).ifPresent(c -> c.playTo(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playToAll() {
|
||||||
|
Optional.ofNullable(get()).ifPresent(SoundConfig::playToAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playAt(Location location) {
|
||||||
|
Optional.ofNullable(get()).ifPresent(s -> s.playAt(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends AbstractConfigBuilder<SoundConfig, SoundConfig, ConfiguredSound, ConfigurationHolder<?>, Builder> {
|
||||||
|
|
||||||
|
protected @NotNull ValueAdapter<SoundConfig> adapter = SOUND_ADAPTER;
|
||||||
|
|
||||||
|
protected Builder() {
|
||||||
|
super(ConfigurationHolder.class, SOUND_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder adapter(@NotNull ValueAdapter<SoundConfig> adapter) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@NotNull Sound sound, float volume, float pitch) {
|
||||||
|
return defaults(new SoundConfig(sound.name(), sound, volume, pitch));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@NotNull Sound sound, float volume) {
|
||||||
|
return defaults(sound, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@NotNull Sound sound) {
|
||||||
|
return defaults(sound, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@NotNull String soundName, float volume, float pitch) {
|
||||||
|
return defaults(new SoundConfig(soundName, volume, pitch));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@NotNull String soundName, float volume) {
|
||||||
|
return defaults(soundName, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@NotNull String soundName) {
|
||||||
|
return defaults(soundName, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull Builder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredSound build() {
|
||||||
|
return new ConfiguredSound(buildManifest(), this.adapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+226
@@ -0,0 +1,226 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueAdapter;
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueType;
|
||||||
|
import cc.carm.lib.configuration.builder.AbstractConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||||
|
import cc.carm.lib.configuration.value.text.function.TextParser;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import com.cryptomorin.xseries.messages.Titles;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
public class ConfiguredTitle extends ConfiguredValue<TitleConfig> {
|
||||||
|
|
||||||
|
public static final @NotNull ConfiguredTitle.TitleConsumer DEFAULT_TITLE_CONSUMER = Titles::sendTitle;
|
||||||
|
|
||||||
|
public static Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ValueType<TitleConfig> TITLE_TYPE = ValueType.of(TitleConfig.class);
|
||||||
|
public static final ValueAdapter<TitleConfig> TITLE_ADAPTER = new ValueAdapter<>(TITLE_TYPE,
|
||||||
|
(holder, type, value) -> value.serialize(),
|
||||||
|
(holder, type, value) -> {
|
||||||
|
ConfigureSection section = holder.deserialize(ConfigureSection.class, value);
|
||||||
|
return TitleConfig.deserialize(section);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
protected final @NotNull ConfiguredTitle.TitleConsumer sendConsumer;
|
||||||
|
|
||||||
|
protected final @NotNull UnaryOperator<String> paramBuilder;
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
|
public ConfiguredTitle(@NotNull ValueManifest<TitleConfig, TitleConfig> manifest, ValueAdapter<TitleConfig> adapter,
|
||||||
|
@NotNull UnaryOperator<String> paramBuilder, @NotNull String[] params,
|
||||||
|
@NotNull ConfiguredTitle.TitleConsumer sendConsumer) {
|
||||||
|
super(manifest, adapter);
|
||||||
|
this.paramBuilder = paramBuilder;
|
||||||
|
this.sendConsumer = sendConsumer;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(Consumer<TitleConfig> handler) {
|
||||||
|
TitleConfig conf = get();
|
||||||
|
handler.accept(conf);
|
||||||
|
set(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLine1(@Nullable String line1) {
|
||||||
|
set(conf -> conf.line1(line1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLine2(@Nullable String line2) {
|
||||||
|
set(conf -> conf.line2(line2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFadeIn(int fadeIn) {
|
||||||
|
set(conf -> conf.fadeIn(fadeIn));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStay(int stay) {
|
||||||
|
set(conf -> conf.stay(stay));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFadeOut(int fadeOut) {
|
||||||
|
set(conf -> conf.fadeOut(fadeOut));
|
||||||
|
}
|
||||||
|
|
||||||
|
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, TextParser.buildParams(paramBuilder, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
TitleConfig config = get();
|
||||||
|
if (config != null) config.send(player, placeholders, sendConsumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(Object... values) {
|
||||||
|
sendToAll(this.params, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@NotNull String[] params, @NotNull Object[] values) {
|
||||||
|
sendToAll(TextParser.buildParams(paramBuilder, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@NotNull Map<String, Object> placeholders) {
|
||||||
|
TitleConfig config = get();
|
||||||
|
if (config == null) return;
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().forEach(onlinePlayer -> send(onlinePlayer, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToEach(@NotNull Function<@NotNull Player, Object[]> eachValues) {
|
||||||
|
sendToEach(null, eachValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToEach(@Nullable Predicate<Player> limiter,
|
||||||
|
@NotNull Function<@NotNull Player, Object[]> eachValues) {
|
||||||
|
Predicate<Player> predicate = Optional.ofNullable(limiter).orElse(r -> true);
|
||||||
|
Bukkit.getOnlinePlayers().stream().filter(predicate)
|
||||||
|
.forEach(r -> send(r, eachValues.apply(r)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TitleConsumer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向目标玩家发送标题文字
|
||||||
|
*
|
||||||
|
* @param player 目标玩家
|
||||||
|
* @param fadeIn 淡入时间 (ticks)
|
||||||
|
* @param stay 保留时间 (ticks)
|
||||||
|
* @param fadeOut 淡出时间 (ticks)
|
||||||
|
* @param line1 第一行文字
|
||||||
|
* @param line2 第二行文字
|
||||||
|
*/
|
||||||
|
void send(@NotNull Player player,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int stay,
|
||||||
|
@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut,
|
||||||
|
@NotNull String line1, @NotNull String line2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends AbstractConfigBuilder<TitleConfig, TitleConfig, ConfiguredTitle, ConfigurationHolder<?>, Builder> {
|
||||||
|
|
||||||
|
protected @NotNull ValueAdapter<TitleConfig> adapter = TITLE_ADAPTER;
|
||||||
|
protected @NotNull TitleConfig title = TitleConfig.of(null, null);
|
||||||
|
protected @NotNull String[] params = new String[0];
|
||||||
|
|
||||||
|
protected @NotNull ConfiguredTitle.TitleConsumer sendConsumer = DEFAULT_TITLE_CONSUMER;
|
||||||
|
protected @NotNull UnaryOperator<String> paramFormatter = s -> "%(" + s + ")";
|
||||||
|
|
||||||
|
protected Builder() {
|
||||||
|
super(ConfigurationHolder.class, TITLE_TYPE);
|
||||||
|
defaults(() -> this.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder adapter(@NotNull ValueAdapter<TitleConfig> adapter) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(Consumer<TitleConfig> handler) {
|
||||||
|
handler.accept(this.title);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder defaults(@Nullable String line1, @Nullable String line2) {
|
||||||
|
return line1(line1).line2(line2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder line1(@Nullable String line1) {
|
||||||
|
return defaults(t -> t.line1(line1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder line2(@Nullable String line2) {
|
||||||
|
return defaults(t -> t.line2(line2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder fadeIn(@Range(from = 0L, to = Integer.MAX_VALUE) int fadeIn) {
|
||||||
|
return defaults(t -> t.fadeIn(fadeIn));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder stay(@Range(from = 0L, to = Integer.MAX_VALUE) int stay) {
|
||||||
|
return defaults(t -> t.stay(stay));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder fadeOut(@Range(from = 0L, to = Integer.MAX_VALUE) int fadeOut) {
|
||||||
|
return defaults(t -> t.fadeOut(fadeOut));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder params(String... params) {
|
||||||
|
this.params = params;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder params(@NotNull List<String> params) {
|
||||||
|
return params(params.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Builder whenSend(@NotNull ConfiguredTitle.TitleConsumer consumer) {
|
||||||
|
this.sendConsumer = consumer;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull Builder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredTitle build() {
|
||||||
|
return new ConfiguredTitle(buildManifest(), this.adapter, this.paramFormatter, this.params, this.sendConsumer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+216
@@ -0,0 +1,216 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueAdapter;
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueType;
|
||||||
|
import cc.carm.lib.configuration.builder.AbstractConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.source.section.ConfigureSection;
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import com.cryptomorin.xseries.XItemStack;
|
||||||
|
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.function.BiFunction;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class ConfiguredItem extends ConfiguredValue<ItemStack> {
|
||||||
|
|
||||||
|
public static Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final @NotNull ValueType<ItemStack> ITEM_TYPE = ValueType.of(ItemStack.class);
|
||||||
|
public static final ValueAdapter<ItemStack> ITEM_ADAPTER = new ValueAdapter<>(ITEM_TYPE,
|
||||||
|
(holder, type, value) -> XItemStack.serialize(value),
|
||||||
|
(holder, type, value) -> {
|
||||||
|
ConfigureSection section = (ConfigureSection) value;
|
||||||
|
return XItemStack.deserialize(section.asMap());
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
protected final @NotNull BiFunction<Player, String, String> parser;
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
|
public ConfiguredItem(@NotNull ValueManifest<ItemStack, ItemStack> manifest, ValueAdapter<ItemStack> adapter,
|
||||||
|
@NotNull BiFunction<Player, String, String> parser, @NotNull String[] params) {
|
||||||
|
super(manifest, adapter);
|
||||||
|
this.parser = parser;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<@Nullable ItemStack> optional() {
|
||||||
|
return Optional.ofNullable(super.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable ItemStack get() {
|
||||||
|
return optional().map(ItemStack::clone).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(Consumer<ItemStack> modifier) {
|
||||||
|
return optional().map(item -> {
|
||||||
|
modifier.accept(item);
|
||||||
|
return item;
|
||||||
|
}).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player) {
|
||||||
|
return get(player, new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player, @NotNull Object... values) {
|
||||||
|
return prepare(values).get(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player,
|
||||||
|
@NotNull Map<String, Object> placeholders) {
|
||||||
|
return prepare().placeholders(placeholders).get(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Map<Integer, ItemStack> give(@NotNull Player player, @NotNull Object... values) {
|
||||||
|
return prepare(values).give(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull PreparedItem prepare(@NotNull Object... values) {
|
||||||
|
return PreparedItem.of(player -> get()).parser(parser).params(params).placeholders(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void modifyItem(Consumer<ItemStack> modifier) {
|
||||||
|
ItemStack item = get();
|
||||||
|
if (item == null) return;
|
||||||
|
modifier.accept(item);
|
||||||
|
set(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void modifyMeta(Consumer<ItemMeta> modifier) {
|
||||||
|
modifyItem(item -> {
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
modifier.accept(meta);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(@Nullable String name) {
|
||||||
|
modifyMeta(meta -> meta.setDisplayName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLore(@Nullable List<String> lore) {
|
||||||
|
modifyMeta(meta -> meta.setLore(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLore(String... lore) {
|
||||||
|
if (lore.length == 0) setLore((List<String>) null);
|
||||||
|
else setLore(Arrays.asList(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class Builder extends AbstractConfigBuilder<ItemStack, ItemStack, ConfiguredItem, ConfigurationHolder<?>, Builder> {
|
||||||
|
|
||||||
|
protected @Nullable ItemStack item = null;
|
||||||
|
protected @NotNull String[] params = new String[0];
|
||||||
|
protected @NotNull BiFunction<Player, String, String> parser = (player, message) -> ColorParser.parse(message);
|
||||||
|
|
||||||
|
public Builder() {
|
||||||
|
super(ConfigurationHolder.class, ITEM_TYPE);
|
||||||
|
defaults(() -> item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Builder defaults(@Nullable ItemStack item) {
|
||||||
|
this.item = item;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaults(@NotNull Material type) {
|
||||||
|
return defaults(new ItemStack(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaults(Consumer<ItemStack> consumer) {
|
||||||
|
if (this.item == null) return self();
|
||||||
|
consumer.accept(this.item);
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultMeta(Consumer<ItemMeta> consumer) {
|
||||||
|
return defaults(stack -> {
|
||||||
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
consumer.accept(meta);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultType(@NotNull Material type) {
|
||||||
|
return defaults(new ItemStack(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultName(@Nullable String name) {
|
||||||
|
return defaultMeta(meta -> meta.setDisplayName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public Builder defaultDataID(short dataID) {
|
||||||
|
return defaults(stack -> stack.setDurability(dataID));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultLore(@NotNull String... lore) {
|
||||||
|
return defaultLore(Arrays.asList(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultLore(@NotNull List<String> lore) {
|
||||||
|
return defaultMeta(meta -> meta.setLore(lore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultEnchants(@NotNull Map<Enchantment, Integer> enchants) {
|
||||||
|
return defaultMeta(meta -> enchants.forEach((enchant, level) -> meta.addEnchant(enchant, level, true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultEnchant(@NotNull Enchantment enchant, int level) {
|
||||||
|
return defaultEnchants(Collections.singletonMap(enchant, level));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultFlags(@NotNull Set<ItemFlag> flags) {
|
||||||
|
return defaultMeta(meta -> flags.forEach(meta::addItemFlags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder defaultFlags(@NotNull ItemFlag... flags) {
|
||||||
|
return defaultFlags(new LinkedHashSet<>(Arrays.asList(flags)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder parser(@NotNull BiFunction<Player, String, String> parser) {
|
||||||
|
this.parser = parser;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder params(@NotNull String... params) {
|
||||||
|
this.params = params;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder params(@NotNull List<String> params) {
|
||||||
|
this.params = params.toArray(new String[0]);
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull Builder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredItem build() {
|
||||||
|
return new ConfiguredItem(buildManifest(), ITEM_ADAPTER, parser, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+138
@@ -0,0 +1,138 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.value.text.data.TextContents;
|
||||||
|
import cc.carm.lib.configuration.value.text.function.ContentHandler;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public abstract class ItemModifier<S extends ItemModifier<S, R>, R>
|
||||||
|
extends ContentHandler<Player, S> {
|
||||||
|
|
||||||
|
protected final @NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider;
|
||||||
|
|
||||||
|
protected @NotNull BiConsumer<ItemStack, Player> itemConsumer;
|
||||||
|
protected @NotNull BiConsumer<ItemMeta, Player> metaConsumer;
|
||||||
|
|
||||||
|
protected ItemModifier(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||||
|
super();
|
||||||
|
this.itemProvider = itemProvider;
|
||||||
|
this.itemConsumer = (item, player) -> {
|
||||||
|
};
|
||||||
|
this.metaConsumer = (meta, player) -> {
|
||||||
|
};
|
||||||
|
this.lineSeparator = " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract @Nullable R get(Player player);
|
||||||
|
|
||||||
|
public void applyTo(@Nullable ItemStack item, @Nullable Player player) {
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return;
|
||||||
|
|
||||||
|
String name = meta.getDisplayName();
|
||||||
|
if (!name.isEmpty()) {
|
||||||
|
meta.setDisplayName(parse(player, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> parsedLore = parseLore(player, meta.getLore());
|
||||||
|
if (!parsedLore.isEmpty()) {
|
||||||
|
meta.setLore(parsedLore);
|
||||||
|
}
|
||||||
|
|
||||||
|
metaConsumer.accept(meta, player);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
itemConsumer.accept(item, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S handleMeta(@NotNull BiConsumer<ItemMeta, Player> modifier) {
|
||||||
|
this.metaConsumer = this.metaConsumer.andThen(modifier);
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S handleItem(@NotNull BiConsumer<ItemStack, Player> modifier) {
|
||||||
|
this.itemConsumer = this.itemConsumer.andThen(modifier);
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public S insert(@NotNull String key, @NotNull ConfiguredMessage<?> message,
|
||||||
|
@NotNull Object... values) {
|
||||||
|
return insert(key, receiver -> message.parse(receiver, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S amount(int amount) {
|
||||||
|
return handleItem((item, player) -> item.setAmount(amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addEnchantment(Enchantment e) {
|
||||||
|
return addEnchantment(e, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addEnchantment(Enchantment e, int level) {
|
||||||
|
return addEnchantment(e, level, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addEnchantment(Enchantment e, int level, boolean ignoreLevelRestriction) {
|
||||||
|
return handleMeta((meta, player) -> meta.addEnchant(e, level, ignoreLevelRestriction));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S addItemFlags(ItemFlag... flags) {
|
||||||
|
return handleMeta((meta, player) -> meta.addItemFlags(flags));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S glow() {
|
||||||
|
return addItemFlags(ItemFlag.HIDE_ENCHANTS).addEnchantment(Enchantment.DURABILITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner 玩家名
|
||||||
|
* @return this
|
||||||
|
* @deprecated Use {@link #setSkullOwner(OfflinePlayer)} instead.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public S setSkullOwner(String owner) {
|
||||||
|
return handleMeta((meta, player) -> {
|
||||||
|
if (!(meta instanceof SkullMeta)) return;
|
||||||
|
SkullMeta skullMeta = (SkullMeta) meta;
|
||||||
|
skullMeta.setOwner(owner);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public S setSkullOwner(UUID owner) {
|
||||||
|
return setSkullOwner(Bukkit.getOfflinePlayer(owner));
|
||||||
|
}
|
||||||
|
|
||||||
|
public S setSkullOwner(OfflinePlayer owner) {
|
||||||
|
return handleMeta((meta, player) -> {
|
||||||
|
if (!(meta instanceof SkullMeta)) return;
|
||||||
|
SkullMeta skullMeta = (SkullMeta) meta;
|
||||||
|
skullMeta.setOwningPlayer(owner);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> parseLore(@Nullable Player player, @Nullable List<String> current) {
|
||||||
|
if (current == null || current.isEmpty()) return new ArrayList<>();
|
||||||
|
List<String> parsed = new ArrayList<>();
|
||||||
|
handle(TextContents.of(current, new HashMap<>()), player, parsed::add);
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.item;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class PreparedItem extends ItemModifier<PreparedItem, ItemStack> {
|
||||||
|
|
||||||
|
public static PreparedItem of(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||||
|
return new PreparedItem(itemProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PreparedItem of(@Nullable ItemStack item) {
|
||||||
|
return of(player -> item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreparedItem(@NotNull Function<@NotNull Player, @Nullable ItemStack> itemProvider) {
|
||||||
|
super(itemProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ItemStack get(@Nullable Player player) {
|
||||||
|
@Nullable ItemStack item = itemProvider.apply(player);
|
||||||
|
if (item == null) return null;
|
||||||
|
|
||||||
|
applyTo(item, player);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Map<Integer, ItemStack> give(Player player) {
|
||||||
|
@Nullable ItemStack item = get(player);
|
||||||
|
if (item == null) return null;
|
||||||
|
return player.getInventory().addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean giveOrDrop(Player player) {
|
||||||
|
@Nullable Map<Integer, ItemStack> left = give(player);
|
||||||
|
if (left == null) return false;
|
||||||
|
left.values().forEach(item -> player.getWorld().dropItem(player.getLocation(), item));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PreparedItem self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
+164
@@ -0,0 +1,164 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueAdapter;
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueType;
|
||||||
|
import cc.carm.lib.configuration.builder.AbstractConfigBuilder;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.standard.ConfiguredList;
|
||||||
|
import cc.carm.lib.configuration.value.text.function.TextParser;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.NotifyType;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Range;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
public class ConfiguredNotify extends ConfiguredList<NotifyConfig> {
|
||||||
|
|
||||||
|
public static NotifyBuilder create() {
|
||||||
|
return new NotifyBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ValueType<NotifyConfig> NOTIFY_TYPE = ValueType.of(NotifyConfig.class);
|
||||||
|
public static final ValueAdapter<NotifyConfig> NOTIFY_ADAPTER = new ValueAdapter<>(NOTIFY_TYPE,
|
||||||
|
(holder, type, value) -> value.serialize(),
|
||||||
|
(holder, type, value) -> {
|
||||||
|
String conf = holder.deserialize(String.class, value);
|
||||||
|
return NotifyConfig.deserialize(conf);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
protected final @NotNull UnaryOperator<String> paramBuilder;
|
||||||
|
protected final @NotNull String[] params;
|
||||||
|
|
||||||
|
public ConfiguredNotify(@NotNull ValueManifest<List<NotifyConfig>, NotifyConfig> manifest,
|
||||||
|
@NotNull ValueAdapter<NotifyConfig> adapter,
|
||||||
|
@NotNull UnaryOperator<String> paramBuilder, @NotNull String[] params) {
|
||||||
|
super(manifest, ArrayList::new, adapter);
|
||||||
|
this.paramBuilder = paramBuilder;
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull PreparedNotify prepare(@NotNull Object... values) {
|
||||||
|
return new PreparedNotify(getNotNull(), TextParser.buildParams(paramBuilder, this.params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Player player, @NotNull Object... values) {
|
||||||
|
prepare(values).to(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@NotNull Iterable<? extends Player> players, @NotNull Object... values) {
|
||||||
|
prepare(values).to(players);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAll(@NotNull Object... values) {
|
||||||
|
prepare(values).toAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class NotifyBuilder extends AbstractConfigBuilder<List<NotifyConfig>, NotifyConfig, ConfiguredNotify, ConfigurationHolder<?>, NotifyBuilder> {
|
||||||
|
|
||||||
|
protected final @NotNull List<NotifyConfig> notifications = new ArrayList<>();
|
||||||
|
|
||||||
|
protected @NotNull String[] params = new String[0];
|
||||||
|
protected @NotNull ValueAdapter<NotifyConfig> adapter = NOTIFY_ADAPTER;
|
||||||
|
protected @NotNull UnaryOperator<String> paramFormatter = s -> "%(" + s + ")";
|
||||||
|
|
||||||
|
protected NotifyBuilder() {
|
||||||
|
super(ConfigurationHolder.class, new ValueType<List<NotifyConfig>>() {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull ConfiguredNotify.NotifyBuilder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredNotify build() {
|
||||||
|
return new ConfiguredNotify(buildManifest(), this.adapter, this.paramFormatter, this.params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder adapter(@NotNull ValueAdapter<NotifyConfig> adapter) {
|
||||||
|
this.adapter = adapter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultMessages(@NotNull String... messages) {
|
||||||
|
return defaultMessages(Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultMessages(@NotNull List<String> messages) {
|
||||||
|
for (String message : messages) {
|
||||||
|
notifications.add(NotifyConfig.of(NotifyType.Standard.MESSAGE, message));
|
||||||
|
}
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultActionBar(@NotNull String message) {
|
||||||
|
notifications.add(NotifyConfig.of(NotifyType.Standard.ACTIONBAR, message));
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultSound(@NotNull Sound sound, float volume, float pitch) {
|
||||||
|
return defaultSound(sound.name(), volume, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultSound(@NotNull Sound sound, float volume) {
|
||||||
|
return defaultSound(sound, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultSound(@NotNull Sound sound) {
|
||||||
|
return defaultSound(sound, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultSound(@NotNull String soundName, float volume, float pitch) {
|
||||||
|
notifications.add(NotifyConfig.of(NotifyType.Standard.SOUND, new SoundConfig(soundName, volume, pitch)));
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultSound(@NotNull String soundName, float volume) {
|
||||||
|
return defaultSound(soundName, volume, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultSound(@NotNull String soundName) {
|
||||||
|
return defaultSound(soundName, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultTitle(@Nullable String line1, @Nullable String line2,
|
||||||
|
@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) {
|
||||||
|
notifications.add(NotifyConfig.of(NotifyType.Standard.TITLE, TitleConfig.of(line1, line2, fadeIn, stay, fadeOut)));
|
||||||
|
return defaults(this.notifications);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder defaultTitle(@Nullable String line1, @Nullable String line2) {
|
||||||
|
return defaultTitle(line1, line2, 10, 60, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder params(String... params) {
|
||||||
|
this.params = params;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder params(@NotNull List<String> params) {
|
||||||
|
return params(params.toArray(new String[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotifyBuilder formatParam(UnaryOperator<String> paramFormatter) {
|
||||||
|
this.paramFormatter = paramFormatter;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.NotifyConfig;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PreparedNotify {
|
||||||
|
|
||||||
|
protected final @NotNull List<NotifyConfig> notifications;
|
||||||
|
protected final @NotNull Map<String, Object> placeholders;
|
||||||
|
|
||||||
|
protected PreparedNotify(@NotNull List<NotifyConfig> notifications, @NotNull Map<String, Object> placeholders) {
|
||||||
|
this.notifications = notifications;
|
||||||
|
this.placeholders = placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向某位接收者发送消息
|
||||||
|
*
|
||||||
|
* @param receiver 消息的接收者
|
||||||
|
*/
|
||||||
|
public void to(@NotNull Player receiver) {
|
||||||
|
notifications.forEach(config -> config.execute(receiver, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向某位接收者发送消息
|
||||||
|
*
|
||||||
|
* @param receivers 消息的接收者们
|
||||||
|
*/
|
||||||
|
public void to(@NotNull Iterable<? extends Player> receivers) {
|
||||||
|
receivers.forEach(this::to);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toAll() {
|
||||||
|
to(Bukkit.getOnlinePlayers());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class NotifyCache<T extends NotifyType<M>, M> {
|
||||||
|
|
||||||
|
// Notify config format: [TYPE(@PARAM)] CONTENTS...
|
||||||
|
public static final @NotNull Pattern CONFIG_FORMAT = Pattern.compile("\\[(?<type>[^@\\]]+)(@(?<param>[^]]+))?] (?<content>.*)");
|
||||||
|
|
||||||
|
public static @Nullable NotifyCache<?, ?> deserialize(@NotNull String config) {
|
||||||
|
// parse config with config_format
|
||||||
|
Matcher matcher = CONFIG_FORMAT.matcher(config.trim());
|
||||||
|
if (!matcher.matches()) return of("MESSAGE", null, config);
|
||||||
|
return of(matcher.group("type"), matcher.group("param"), matcher.group("content"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable NotifyCache<?, ?> of(@NotNull String key, @Nullable String param, @Nullable String content) {
|
||||||
|
NotifyType<?> type = NotifyType.get(key);
|
||||||
|
if (type == null) return null;
|
||||||
|
return NotifyCache.of(type, param, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyCache<T, M> of(@NotNull T type, @Nullable String param, @Nullable String content) {
|
||||||
|
return new NotifyCache<>(type, type.parseMeta(param, content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends NotifyType<M>, M> NotifyCache<T, M> of(@NotNull T type, @Nullable M meta) {
|
||||||
|
return new NotifyCache<>(type, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull T type;
|
||||||
|
protected final @Nullable M meta;
|
||||||
|
|
||||||
|
public NotifyCache(@NotNull T type, @Nullable M meta) {
|
||||||
|
this.type = type;
|
||||||
|
this.meta = meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull T getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable M getMeta() {
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(@NotNull Player player, @NotNull Map<String, Object> placeholders) {
|
||||||
|
type.execute(player, meta, placeholders);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String serialize() {
|
||||||
|
return type.serializeConfig(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.value.text.function.TextParser;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.utils.MessageUtils;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.standard.SoundNotify;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.standard.StringNotify;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.standard.TitleNotify;
|
||||||
|
import com.cryptomorin.xseries.messages.ActionBar;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public abstract class NotifyType<M> {
|
||||||
|
|
||||||
|
public interface Standard {
|
||||||
|
|
||||||
|
StringNotify MESSAGE = StringNotify.of("MESSAGE", Player::sendMessage, content -> Optional.ofNullable(content).orElse(" "));
|
||||||
|
StringNotify MSG = StringNotify.of("MSG", Player::sendMessage);
|
||||||
|
StringNotify ACTIONBAR = StringNotify.of("ACTIONBAR", ActionBar::sendActionBar);
|
||||||
|
TitleNotify TITLE = new TitleNotify("TITLE");
|
||||||
|
SoundNotify SOUND = new SoundNotify("SOUND");
|
||||||
|
|
||||||
|
static NotifyType<?>[] values() {
|
||||||
|
return new NotifyType<?>[]{MESSAGE, MSG, ACTIONBAR, TITLE, SOUND};
|
||||||
|
}
|
||||||
|
|
||||||
|
static NotifyType<?> valueOf(String name) {
|
||||||
|
return Arrays.stream(values()).filter(type -> type.key.equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Set<NotifyType<?>> TYPES = new HashSet<>(Arrays.asList(Standard.values()));
|
||||||
|
|
||||||
|
public static NotifyType<?> get(@NotNull String key) {
|
||||||
|
return TYPES.stream().filter(type -> type.key.equalsIgnoreCase(key)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final @NotNull String key;
|
||||||
|
protected final @NotNull Class<M> metaClass;
|
||||||
|
|
||||||
|
protected NotifyType(@NotNull String key, @NotNull Class<M> metaClass) {
|
||||||
|
this.key = key;
|
||||||
|
this.metaClass = metaClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Class<M> getMetaClass() {
|
||||||
|
return metaClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse metadata from string.
|
||||||
|
* <br> e.g. "[TYPE-KEY@PARAM] CONTENTS..."
|
||||||
|
*
|
||||||
|
* @param param The param of the notify config.
|
||||||
|
* @param content The content of the notify config.
|
||||||
|
* @return The parsed metadata.
|
||||||
|
*/
|
||||||
|
public abstract @Nullable M parseMeta(@Nullable String param, @Nullable String content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the metadata to singleton string to storage on configs.
|
||||||
|
*
|
||||||
|
* @param meta The parsed metadata.
|
||||||
|
* @return The serialized string.
|
||||||
|
*/
|
||||||
|
public abstract @NotNull String serializeConfig(@Nullable M meta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the notify content to specific player.
|
||||||
|
*
|
||||||
|
* @param player The player who receive the notification.
|
||||||
|
* @param meta The parsed metadata.
|
||||||
|
*/
|
||||||
|
public abstract void execute(@NotNull Player player, @Nullable M meta, @NotNull Map<String, Object> placeholders);
|
||||||
|
|
||||||
|
@Contract("_, _, null -> null; _, _, !null -> !null")
|
||||||
|
protected String setPlaceholders(@NotNull Player player, @NotNull Map<String, Object> placeholders,
|
||||||
|
@Nullable String content) {
|
||||||
|
if (content == null) return null;
|
||||||
|
return MessageUtils.parseMessage(player, TextParser.setPlaceholders(content, placeholders));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type.standard;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.SoundConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.NotifyType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SoundNotify extends NotifyType<SoundConfig> {
|
||||||
|
|
||||||
|
|
||||||
|
public SoundNotify(@NotNull String key) {
|
||||||
|
super(key, SoundConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable SoundConfig parseMeta(@Nullable String param, @Nullable String content) {
|
||||||
|
if (content == null) return null;
|
||||||
|
|
||||||
|
String[] args = param == null ? new String[0] : param.split(",");
|
||||||
|
try {
|
||||||
|
return new SoundConfig(content.trim(),
|
||||||
|
(args.length >= 1) ? Float.parseFloat(args[0]) : 1,
|
||||||
|
(args.length >= 2) ? Float.parseFloat(args[1]) : 1
|
||||||
|
);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String serializeConfig(@Nullable SoundConfig meta) {
|
||||||
|
if (meta == null) return "[" + key + "] ";
|
||||||
|
|
||||||
|
if (meta.getVolume() == 1 && meta.getPitch() == 1) {
|
||||||
|
return "[" + key + "] " + meta.getTypeName();
|
||||||
|
} else {
|
||||||
|
return "[" + key + "@" + +meta.getVolume() + "," + meta.getPitch() + "] " + meta.getTypeName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@NotNull Player player, @Nullable SoundConfig meta, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (meta != null) meta.playTo(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type.standard;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.NotifyType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
|
public abstract class StringNotify extends NotifyType<String> {
|
||||||
|
|
||||||
|
public static StringNotify of(String key, BiConsumer<Player, String> consumer) {
|
||||||
|
return of(key, consumer, (content) -> "[" + key + "] " + (content == null ? " " : content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StringNotify of(String key,
|
||||||
|
BiConsumer<Player, String> consumer,
|
||||||
|
UnaryOperator<String> serializer) {
|
||||||
|
return new StringNotify(key) {
|
||||||
|
@Override
|
||||||
|
public @NotNull String serializeConfig(@Nullable String meta) {
|
||||||
|
return serializer.apply(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void send(@NotNull Player player, @NotNull String parsedContent) {
|
||||||
|
consumer.accept(player, parsedContent);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected StringNotify(String key) {
|
||||||
|
super(key, String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void send(@NotNull Player player, @NotNull String parsedContent);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String parseMeta(@Nullable String param, @Nullable String content) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@NotNull Player player, @Nullable String content, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (content == null) return;
|
||||||
|
send(player, setPlaceholders(player, placeholders, content));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bukkit.value.notify.type.standard;
|
||||||
|
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.data.TitleConfig;
|
||||||
|
import cc.carm.lib.mineconfiguration.bukkit.value.notify.type.NotifyType;
|
||||||
|
import com.cryptomorin.xseries.messages.Titles;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class TitleNotify extends NotifyType<TitleConfig> {
|
||||||
|
|
||||||
|
//Param format fadeIn,stay,fadeOut
|
||||||
|
public static final Pattern PARAM_FORMAT = Pattern.compile("(?<fadeIn>\\d+),(?<stay>\\d+),(?<fadeOut>\\d+)");
|
||||||
|
|
||||||
|
public TitleNotify(String key) {
|
||||||
|
super(key, TitleConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable TitleConfig parseMeta(@Nullable String param, @Nullable String content) {
|
||||||
|
if (content == null) return null;
|
||||||
|
|
||||||
|
String[] lines = content.split("\\{n}");
|
||||||
|
if (lines.length == 0) return null;
|
||||||
|
|
||||||
|
String line1 = lines[0];
|
||||||
|
String line2 = lines.length > 1 ? lines[1] : null;
|
||||||
|
|
||||||
|
if (param == null) {
|
||||||
|
return TitleConfig.of(line1, line2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher paramMatcher = PARAM_FORMAT.matcher(param);
|
||||||
|
if (!paramMatcher.matches()) {
|
||||||
|
return TitleConfig.of(line1, line2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TitleConfig.of(
|
||||||
|
line1, line2,
|
||||||
|
Integer.parseInt(paramMatcher.group("fadeIn")),
|
||||||
|
Integer.parseInt(paramMatcher.group("stay")),
|
||||||
|
Integer.parseInt(paramMatcher.group("fadeOut"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String serializeConfig(@Nullable TitleConfig meta) {
|
||||||
|
if (meta == null || (meta.line1() == null && meta.line2() == null)) return "[" + key + "] ";
|
||||||
|
|
||||||
|
String line1 = meta.line1() == null ? "" : meta.line1();
|
||||||
|
String line2 = meta.line2() == null ? "" : meta.line2();
|
||||||
|
|
||||||
|
if (meta.isStandardTime()) {
|
||||||
|
return "[" + key + "] " + line1 + "{n}" + line2;
|
||||||
|
} else
|
||||||
|
return "[" + key + "@" + meta.fadeIn() + "," + meta.stay() + "," + meta.fadeOut() + "] " + line1 + "{n}" + line2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(@NotNull Player player, @Nullable TitleConfig meta, @NotNull Map<String, Object> placeholders) {
|
||||||
|
if (meta != null) meta.send(player, placeholders, Titles::sendTitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,38 +5,44 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0</version>
|
<version>3.1.4</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>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>mineconfiguration-bungee</artifactId>
|
<artifactId>mineconfiguration-bungee</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>MineConfiguration-Bungee</name>
|
||||||
|
<description>EasyConfiguration for BungeeCord.</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
<artifactId>mineconfiguration-common</artifactId>
|
||||||
<version>${easyconfiguration.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>configured-yaml</artifactId>
|
||||||
<version>1.18-R0.1-SNAPSHOT</version>
|
<version>${deps.configured.version}</version>
|
||||||
<type>jar</type>
|
<scope>compile</scope>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>bungeecord-api</artifactId>
|
||||||
<version>1.18-R0.1-SNAPSHOT</version>
|
<version>1.21-R0.4</version>
|
||||||
<type>javadoc</type>
|
<type>jar</type>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -44,18 +50,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>
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bungee;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.Configuration;
|
||||||
|
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||||
|
import cc.carm.lib.configuration.source.yaml.YAMLConfigFactory;
|
||||||
|
import cc.carm.lib.configuration.source.yaml.YAMLSource;
|
||||||
|
import cc.carm.lib.mineconfiguration.common.AbstractConfiguration;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MineConfiguration extends AbstractConfiguration<ConfigurationHolder<YAMLSource>> {
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull Plugin plugin) {
|
||||||
|
this(plugin.getDataFolder());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull Plugin plugin,
|
||||||
|
@NotNull Configuration configRoot,
|
||||||
|
@NotNull Configuration messageRoot) {
|
||||||
|
this(plugin.getDataFolder(), configRoot, messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull Plugin plugin,
|
||||||
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
|
this(plugin.getDataFolder(), configRoot, messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull File pluginDataFolder) {
|
||||||
|
super(
|
||||||
|
YAMLConfigFactory.from(pluginDataFolder, "config.yml").build(),
|
||||||
|
YAMLConfigFactory.from(pluginDataFolder, "messages.yml").build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||||
|
@NotNull Configuration configRoot,
|
||||||
|
@NotNull Configuration messageRoot) {
|
||||||
|
this(pluginDataFolder);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineConfiguration(@NotNull File pluginDataFolder,
|
||||||
|
@NotNull Class<? extends Configuration> configRoot,
|
||||||
|
@NotNull Class<? extends Configuration> messageRoot) {
|
||||||
|
this(pluginDataFolder);
|
||||||
|
initializeConfig(configRoot);
|
||||||
|
initializeMessage(messageRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package cc.carm.lib.mineconfiguration.bungee.value;
|
||||||
|
|
||||||
|
import cc.carm.lib.configuration.value.ValueManifest;
|
||||||
|
import cc.carm.lib.configuration.value.text.ConfiguredText;
|
||||||
|
import cc.carm.lib.configuration.value.text.data.TextContents;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class ConfiguredMessage extends ConfiguredText<BaseComponent[], CommandSender> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static ConfiguredMessage.Builder create() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfiguredMessage ofString(@NotNull String... messages) {
|
||||||
|
return create().defaults(messages).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfiguredMessage(@NotNull ValueManifest<TextContents, TextContents> manifest,
|
||||||
|
@NotNull BiFunction<CommandSender, String, String> parser,
|
||||||
|
@NotNull BiFunction<CommandSender, String, BaseComponent[]> compiler,
|
||||||
|
@NotNull BiConsumer<CommandSender, List<BaseComponent[]>> dispatcher,
|
||||||
|
@NotNull String[] params) {
|
||||||
|
super(manifest, parser, compiler, dispatcher, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print(Object... values) {
|
||||||
|
prepare(values).to(ProxyServer.getInstance().getConsole());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder extends ConfiguredText.Builder<BaseComponent[], CommandSender, Builder> {
|
||||||
|
|
||||||
|
public Builder() {
|
||||||
|
super();
|
||||||
|
this.parser = (sender, message) -> ColorParser.parse(message);
|
||||||
|
this.compiler = (sender, message) -> new BaseComponent[]{new TextComponent(message)};
|
||||||
|
this.dispatcher = (sender, message) -> {
|
||||||
|
for (BaseComponent[] component : message) {
|
||||||
|
sender.sendMessage(component);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage build() {
|
||||||
|
return new ConfiguredMessage(buildManifest(), this.parser, this.compiler, this.dispatcher, this.params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ConfiguredMessage.Builder self() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,26 +3,32 @@
|
|||||||
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>
|
|
||||||
</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>
|
<deps.configured.version>4.2.0</deps.configured.version>
|
||||||
|
<deps.yamlcommentwriter.version>1.2.1</deps.yamlcommentwriter.version>
|
||||||
|
<deps.easyplugin.version>1.5.13</deps.easyplugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
<artifactId>mineconfiguration-parent</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>3.1.4</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
<modules>
|
||||||
|
<module>common</module>
|
||||||
|
<module>platform/bukkit</module>
|
||||||
|
<module>platform/bungee</module>
|
||||||
|
<module>platform/adventure</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<name>MineConfiguration</name>
|
||||||
|
<description>EasyConfiguration for MineCraft.</description>
|
||||||
|
<url>https://github.com/CarmJos/MineConfiguration</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
@@ -35,7 +41,7 @@
|
|||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:CarmJos/Easy.MineConfiguration</connection>
|
<connection>scm:git:git@github.com:CarmJos/MineConfiguration</connection>
|
||||||
<developerConnection>scm:git:git@github.com:CarmJos/MineConfiguration.git</developerConnection>
|
<developerConnection>scm:git:git@github.com:CarmJos/MineConfiguration.git</developerConnection>
|
||||||
<url>https://github.com/CarmJos/MineConfiguration</url>
|
<url>https://github.com/CarmJos/MineConfiguration</url>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
@@ -43,8 +49,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>
|
||||||
|
|
||||||
@@ -60,37 +66,35 @@
|
|||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>carm-repo</id>
|
|
||||||
<name>Carm's Repo</name>
|
|
||||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>nexus</id>
|
|
||||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>central</id>
|
||||||
<url>https://repo1.maven.org/maven2/</url>
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>github</id>
|
<id>sonatype</id>
|
||||||
<name>GitHub Packages</name>
|
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/*</url>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>minebench-repo</id>
|
||||||
|
<url>https://repo.minebench.de/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>lumine</id>
|
||||||
|
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<downloadUrl>https://github.com/CarmJos/MineConfiguration/releases</downloadUrl>
|
<downloadUrl>https://github.com/CarmJos/MineConfiguration/releases</downloadUrl>
|
||||||
<site>
|
|
||||||
<id>javadoc</id>
|
|
||||||
<name>EasySQL JavaDoc (on Github Pages)</name>
|
|
||||||
<url>https://CarmJos.github.io/MineConfiguration</url>
|
|
||||||
</site>
|
|
||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -105,7 +109,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>23.0.0</version>
|
<version>26.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -118,7 +122,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>3.5.6</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -126,7 +130,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>3.2.8</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
@@ -146,7 +150,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
<version>2.5.3</version>
|
<version>3.3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||||
<useReleaseProfile>false</useReleaseProfile>
|
<useReleaseProfile>false</useReleaseProfile>
|
||||||
@@ -154,6 +158,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.15.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${project.jdk.version}</source>
|
||||||
|
<target>${project.jdk.version}</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
<compilerArgument>-parameters</compilerArgument>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
||||||
<pluginManagement>
|
<pluginManagement>
|
||||||
@@ -162,7 +196,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.4.0</version>
|
<version>3.12.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
@@ -170,11 +204,13 @@
|
|||||||
<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>
|
||||||
</dependencySourceIncludes>
|
</dependencySourceIncludes>
|
||||||
|
<additionalOptions>
|
||||||
|
<additionalOption>-Xdoclint:none</additionalOption>
|
||||||
|
</additionalOptions>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
@@ -186,42 +222,10 @@
|
|||||||
</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>
|
||||||
<version>3.3.0</version>
|
<version>3.6.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -262,18 +266,21 @@
|
|||||||
<profiles>
|
<profiles>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>ossrh</id>
|
<id>central</id>
|
||||||
<distributionManagement>
|
<build>
|
||||||
<snapshotRepository>
|
<plugins>
|
||||||
<id>ossrh</id>
|
<plugin>
|
||||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
<groupId>org.sonatype.central</groupId>
|
||||||
</snapshotRepository>
|
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||||
|
<version>0.10.0</version>
|
||||||
<repository>
|
<extensions>true</extensions>
|
||||||
<id>ossrh</id>
|
<configuration>
|
||||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
<publishingServerId>central</publishingServerId>
|
||||||
</repository>
|
<autoPublish>true</autoPublish>
|
||||||
</distributionManagement>
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
@@ -287,7 +294,7 @@
|
|||||||
</distributionManagement>
|
</distributionManagement>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>mineconfiguration-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>1.0.0</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>minecronfiguration-spigot</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
|
||||||
<version>${easyconfiguration.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>mineconfiguration-craftbukkit</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package cc.carm.lib.configuration;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.spigot.source.SpigotConfigProvider;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class MineConfiguration {
|
|
||||||
|
|
||||||
public static SpigotConfigProvider from(File file, String source) {
|
|
||||||
SpigotConfigProvider provider = new SpigotConfigProvider(file);
|
|
||||||
try {
|
|
||||||
provider.initializeFile(source);
|
|
||||||
provider.initializeConfig();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SpigotConfigProvider from(File file) {
|
|
||||||
return from(file, file.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SpigotConfigProvider from(String fileName) {
|
|
||||||
return from(fileName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SpigotConfigProvider from(String fileName, String source) {
|
|
||||||
return from(new File(fileName), source);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-57
@@ -1,57 +0,0 @@
|
|||||||
package cc.carm.lib.configuration.spigot.source;
|
|
||||||
|
|
||||||
import cc.carm.lib.configuration.core.ConfigInitializer;
|
|
||||||
import cc.carm.lib.configuration.core.source.ConfigCommentInfo;
|
|
||||||
import cc.carm.lib.configuration.craft.source.CraftConfigProvider;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SpigotConfigProvider extends CraftConfigProvider {
|
|
||||||
|
|
||||||
public SpigotConfigProvider(@NotNull File file) {
|
|
||||||
super(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initializeConfig() {
|
|
||||||
this.configuration = YamlConfiguration.loadConfiguration(file);
|
|
||||||
this.initializer = new ConfigInitializer<>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setComment(@Nullable String path, @Nullable ConfigCommentInfo commentInfo) {
|
|
||||||
if (path == null) {
|
|
||||||
if (commentInfo == null) this.configuration.options().setFooter(null);
|
|
||||||
else if (!String.join("", commentInfo.getComments()).isEmpty()) {
|
|
||||||
this.configuration.options().setFooter(Arrays.asList(commentInfo.getComments()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (commentInfo == null) this.configuration.setComments(path, null);
|
|
||||||
else {
|
|
||||||
List<String> comments = new ArrayList<>();
|
|
||||||
|
|
||||||
if (!String.join("", commentInfo.getComments()).isEmpty()) {
|
|
||||||
if (commentInfo.startWrap()) comments.add("");
|
|
||||||
comments.addAll(Arrays.asList(commentInfo.getComments()));
|
|
||||||
if (commentInfo.endWrap()) comments.add("");
|
|
||||||
} else if (commentInfo.startWrap() || commentInfo.endWrap()) {
|
|
||||||
comments.add("");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.configuration.setComments(path, comments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ConfigCommentInfo getComment(@Nullable String path) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user