mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 09:01:47 +08:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f170d654d6 | |||
| ff4da6b73e | |||
| d39951bf65 | |||
| 90a276c1c1 | |||
| f15e0a5bec | |||
| 2ac6fc1485 | |||
| 7701efa34f | |||
| ff25446fd4 | |||
| 40b66740e0 | |||
| af79d41cf6 | |||
| 6fad72c44f | |||
| a7ed8bc4fd | |||
| b18e6ec3d3 | |||
| 3d9748c48e | |||
| aaba1a8097 | |||
| 47966b0be3 | |||
| b1b6b95a07 | |||
| 55263a4d5b | |||
| d5632d371b | |||
| 43643ba423 | |||
| 80042aead7 | |||
| 024efc7690 | |||
| 54bf188c5c | |||
| 471bdab090 | |||
| 2628cb5c6a | |||
| f7f382a874 | |||
| c3119bb49a | |||
| b753a5c331 | |||
| eb073ce9dc | |||
| b2b5c41b86 | |||
| 422d93eb1f | |||
| 7be28a2c82 | |||
| fc948e7e24 | |||
| 33bef6b265 | |||
| 30832fc62b |
@@ -0,0 +1,38 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>EasyPlugin Javadocs</title>
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
width: 60%;
|
||||||
|
margin: 10% auto 0;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
padding: 2% 5%;
|
||||||
|
border-radius: 10px
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul li {
|
||||||
|
line-height: 2.3
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #20a53a
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>EasyPlugin Javadocs</h1>
|
||||||
|
<ul>
|
||||||
|
<li><a href="main/index.html">EasyPlugin-Main</a></li>
|
||||||
|
<li><a href="command/index.html">EasyPlugin-Command</a></li>
|
||||||
|
<li><a href="configuration/index.html">EasyPlugin-Configuration</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
github: [ CarmJos ]
|
||||||
|
custom: [ 'https://donate.carm.cc' ]
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
# For most projects, this workflow file will not need changing; you simply need
|
|
||||||
# to commit it to your repository.
|
|
||||||
#
|
|
||||||
# You may wish to alter this file to override the set of languages analyzed,
|
|
||||||
# or to provide custom queries or build logic.
|
|
||||||
#
|
|
||||||
# ******** NOTE ********
|
|
||||||
# We have attempted to detect the languages in your repository. Please check
|
|
||||||
# the `language` matrix defined below to confirm you have the correct set of
|
|
||||||
# supported CodeQL languages.
|
|
||||||
#
|
|
||||||
name: "CodeQL"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches: [ master ]
|
|
||||||
schedule:
|
|
||||||
- cron: '45 12 * * 1'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
analyze:
|
|
||||||
name: Analyze
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
language: [ 'java' ]
|
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
|
||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v1
|
|
||||||
with:
|
|
||||||
languages: ${{ matrix.language }}
|
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
||||||
# By default, queries listed here will override any specified in a config file.
|
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
||||||
|
|
||||||
# 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)
|
|
||||||
- name: Autobuild
|
|
||||||
uses: github/codeql-action/autobuild@v1
|
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
|
||||||
# 📚 https://git.io/JvXDl
|
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
||||||
# and modify them (or add more) to build your code if your project
|
|
||||||
# uses a compiled language
|
|
||||||
|
|
||||||
#- run: |
|
|
||||||
# make bootstrap
|
|
||||||
# make release
|
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v1
|
|
||||||
@@ -23,16 +23,19 @@ jobs:
|
|||||||
cache: maven
|
cache: maven
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
|
server-id: github
|
||||||
|
server-username: MAVEN_USERNAME
|
||||||
|
server-password: MAVEN_TOKEN
|
||||||
|
|
||||||
- name: Generate docs
|
- name: Generate docs
|
||||||
run: mvn clean package -DskipTests
|
run: mvn javadoc:javadoc -DskipTests
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
|
||||||
- name: Copy to Location
|
- name: Copy to Location
|
||||||
run: |
|
run: |
|
||||||
rm -rf docs
|
bash .scripts/copy-javadoc.sh
|
||||||
mkdir -vp docs
|
|
||||||
cp -vrf EasyPlugin-api/target/apidocs/* docs/
|
|
||||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
|
||||||
|
|
||||||
- name: Generate the sitemap
|
- name: Generate the sitemap
|
||||||
id: sitemap
|
id: sitemap
|
||||||
@@ -46,6 +49,7 @@ jobs:
|
|||||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||||
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
||||||
|
ls -l docs
|
||||||
|
|
||||||
- name: Configure Git
|
- name: Configure Git
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -21,8 +21,14 @@ jobs:
|
|||||||
cache: maven
|
cache: maven
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
|
server-id: github
|
||||||
|
server-username: MAVEN_USERNAME
|
||||||
|
server-password: MAVEN_TOKEN
|
||||||
- name: "Package"
|
- name: "Package"
|
||||||
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
- 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"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
rm -rf docs
|
||||||
|
mkdir -vp docs
|
||||||
|
|
||||||
|
DOC_URL="target/site/apidocs"
|
||||||
|
|
||||||
|
for FILE in easyplugin-*; do
|
||||||
|
|
||||||
|
if test -e "$FILE/$DOC_URL"; then
|
||||||
|
|
||||||
|
MODULE_FILE="docs/${FILE:11}/"
|
||||||
|
|
||||||
|
mkdir -vp "$MODULE_FILE"
|
||||||
|
|
||||||
|
cp -vrf "$FILE"/"$DOC_URL"/* "$MODULE_FILE"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
|
||||||
|
cp -vrf .documentation/javadoc/index.html docs/index.html
|
||||||
@@ -23,12 +23,14 @@
|
|||||||
- 轻便独立的功能模块,按需使用,避免大量打包!
|
- 轻便独立的功能模块,按需使用,避免大量打包!
|
||||||
- 详细的Javadoc与使用文档,轻松上手,方便使用!
|
- 详细的Javadoc与使用文档,轻松上手,方便使用!
|
||||||
- 持续的更新与优化,需求不止,更新不止!
|
- 持续的更新与优化,需求不止,更新不止!
|
||||||
- 如需新功能支持,请 [点击这里](https://github.com/CarmJos/EasyPlugin/issues/new?assignees=&labels=enhancement&template=feature_issues.md&title=) 提交功能需求。
|
- 如需新功能支持,请通过 [Issues](https://github.com/CarmJos/EasyPlugin/issues) 提交功能需求。
|
||||||
|
|
||||||
## 内容
|
## 内容
|
||||||
|
|
||||||
项目初创不久,加 * 的仍在开发更新中...
|
项目初创不久,加 * 的仍在开发更新中...
|
||||||
|
|
||||||
### 集合部分
|
### 集合部分
|
||||||
|
|
||||||
- All [`easyplugin-all`](easyplugin-all)
|
- All [`easyplugin-all`](easyplugin-all)
|
||||||
- Common [`easyplugin-common`](easyplugin-common)
|
- Common [`easyplugin-common`](easyplugin-common)
|
||||||
|
|
||||||
@@ -41,6 +43,7 @@
|
|||||||
- GUI [`easyplugin-gui`](easyplugin-gui)
|
- GUI [`easyplugin-gui`](easyplugin-gui)
|
||||||
|
|
||||||
### 附属部分
|
### 附属部分
|
||||||
|
|
||||||
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/)* [`easyplugin-placeholderapi`](easyplugin-placeholderapi)
|
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/)* [`easyplugin-placeholderapi`](easyplugin-placeholderapi)
|
||||||
- [Vault](https://github.com/MilkBowl/VaultAPI)* [`easyplugin-vault`](easyplugin-vault)
|
- [Vault](https://github.com/MilkBowl/VaultAPI)* [`easyplugin-vault`](easyplugin-vault)
|
||||||
- [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/)* [`easyplugin-lp`](easyplugin-lp)
|
- [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/)* [`easyplugin-lp`](easyplugin-lp)
|
||||||
@@ -55,32 +58,30 @@
|
|||||||
|
|
||||||
### 依赖方式
|
### 依赖方式
|
||||||
|
|
||||||
#### Maven 依赖
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>远程库配置</summary>
|
<summary>展开查看 Maven 依赖方式</summary>
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
|
|
||||||
<project>
|
<project>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
|
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||||
<id>EasyPlugin</id>
|
<id>EasyPlugin</id>
|
||||||
<name>GitHub Packages</name>
|
<name>GitHub Packages</name>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||||
|
<id>carm-repo</id>
|
||||||
|
<name>Carm's Repo</name>
|
||||||
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
</project>
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>原生依赖</summary>
|
|
||||||
|
|
||||||
```xml
|
|
||||||
|
|
||||||
<project>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!--大全集版本,包含项目内所有模块-->
|
<!--大全集版本,包含项目内所有模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -90,7 +91,15 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--轻松插件主要接口集,包含方便的插件入口类与相关工具类。-->
|
<!--常用接口集,包含除附属插件模块外的所有模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-common</artifactId>
|
||||||
|
<version>[LATEST RELEASE]</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--插件主要接口模块,包含方便的插件入口类与相关工具类-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-main</artifactId>
|
<artifactId>easyplugin-main</artifactId>
|
||||||
@@ -98,12 +107,44 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 其他模块自行选择,详见 “内容”-->
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>展开查看 Gradle 依赖方式</summary>
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
repositories {
|
||||||
|
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||||
|
maven { url 'https://maven.pkg.github.com/CarmJos/EasyPlugin' }
|
||||||
|
|
||||||
|
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||||
|
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
//大全集版本,包含项目内所有模块
|
||||||
|
api "cc.carm.lib:easyplugin-all:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
//常用接口集,包含除附属插件模块外的所有模块
|
||||||
|
api "cc.carm.lib:easyplugin-common:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
//插件主要接口模块,包含方便的插件入口类与相关工具类
|
||||||
|
api "cc.carm.lib:easyplugin-main:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
// 其他模块自行选择,详见 “内容”
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## 支持与捐赠
|
## 支持与捐赠
|
||||||
|
|
||||||
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
||||||
|
|||||||
+7
-27
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<artifactId>easyplugin-all</artifactId>
|
<artifactId>easyplugin-all</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-All</name>
|
<name>01-EasyPlugin-All</name>
|
||||||
<description>轻松插件全集,将打包全部工具类与工具接口。</description>
|
<description>轻松插件全集,将打包全部工具类与工具接口。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -51,32 +51,12 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!--通过 bom 快捷导入所有相关模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-common</artifactId>
|
<artifactId>easyplugin-bom</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<type>pom</type>
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-lp</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-vault</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
<?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>easyplugin-parent</artifactId>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<artifactId>easyplugin-bom</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<name>00-EasyPlugin-Bom</name>
|
||||||
|
<description>轻松插件汇总导入模块,允许快捷导入相关的接口并避免版本不一致问题。</description>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-main</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-configuration</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-command</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-database</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-gui</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-lp</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-main</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-configuration</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-database</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-gui</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-command</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
|
<artifactId>easyplugin-lp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-command</artifactId>
|
<artifactId>easyplugin-command</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>12-EasyPlugin-Command</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+25
-34
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
<artifactId>easyplugin-common</artifactId>
|
<artifactId>easyplugin-common</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
<name>02-EasyPlugin-Common</name>
|
||||||
<description>轻松插件常用接口集,包含除附属模块外的所有模块。</description>
|
<description>轻松插件常用接口集,包含除附属插件模块外的所有模块。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
@@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -50,40 +50,31 @@
|
|||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!--通过 bom 快捷导入所有相关模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-main</artifactId>
|
<artifactId>easyplugin-bom</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<type>pom</type>
|
||||||
|
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-lp</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-command</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-configuration</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-gui</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-database</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
<name>EasyPlugin-Configuration</name>
|
<name>11-EasyPlugin-Configuration</name>
|
||||||
<description>轻松插件配置模块,可以方便快捷的将配置文件作为静态参数使用。</description>
|
<description>轻松插件配置模块,可以方便快捷的将配置文件作为静态参数使用。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -57,6 +57,73 @@
|
|||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<!--
|
||||||
|
ConfigUpdater - to save the comments in default configuration.
|
||||||
|
-> https://github.com/tchristofferson/Config-Updater
|
||||||
|
-->
|
||||||
|
<groupId>com.tchristofferson</groupId>
|
||||||
|
<artifactId>ConfigUpdater</artifactId>
|
||||||
|
<version>2.0-SNAPSHOT</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<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-shade-plugin</artifactId>
|
||||||
|
<version>3.2.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.tchristofferson.configupdater</pattern>
|
||||||
|
<shadedPattern>cc.carm.lib.easyplugin.configuration.updater</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||||
|
<exclude>META-INF/*.txt</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.cast;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigCachedValue;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ConfigSectionCast<V> extends FileConfigCachedValue<V> {
|
||||||
|
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast;
|
||||||
|
@Nullable V defaultValue;
|
||||||
|
|
||||||
|
public ConfigSectionCast(@NotNull String configSection,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast) {
|
||||||
|
this(configSection, valueCast, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigSectionCast(@NotNull String sectionName,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
this(null, sectionName, valueCast, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigSectionCast(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(source, sectionName);
|
||||||
|
this.valueCast = valueCast;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @Nullable V get() {
|
||||||
|
V cached = getCachedValue();
|
||||||
|
if (cached != null && !isExpired()) {
|
||||||
|
return cached;
|
||||||
|
} else {
|
||||||
|
return getConfigOptional()
|
||||||
|
.map(config -> config.getConfigurationSection(getSectionName()))
|
||||||
|
.map(section -> updateCache(valueCast.apply(section)))
|
||||||
|
.orElse(defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Optional<V> getOptional() {
|
||||||
|
return Optional.ofNullable(get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void set(ConfigurationSection section) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.cast;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigCachedValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ConfigStringCast<V> extends FileConfigCachedValue<V> {
|
||||||
|
|
||||||
|
@NotNull Function<String, V> valueCast;
|
||||||
|
@Nullable V defaultValue;
|
||||||
|
|
||||||
|
public ConfigStringCast(@NotNull String configSection,
|
||||||
|
@NotNull Function<String, V> valueCast) {
|
||||||
|
this(configSection, valueCast, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigStringCast(@NotNull String configSection,
|
||||||
|
@NotNull Function<String, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
this(null, configSection, valueCast, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigStringCast(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
|
@NotNull Function<String, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(source, sectionName);
|
||||||
|
this.valueCast = valueCast;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable V get() {
|
||||||
|
V cached = getCachedValue();
|
||||||
|
if (cached != null && !isExpired()) {
|
||||||
|
return cached;
|
||||||
|
} else {
|
||||||
|
return getConfigOptional()
|
||||||
|
.map(config -> config.getString(getSectionName()))
|
||||||
|
.map(s -> updateCache(valueCast.apply(s)))
|
||||||
|
.orElse(defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Optional<V> getOptional() {
|
||||||
|
return Optional.ofNullable(get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@Nullable String value) {
|
||||||
|
setIfPresent(value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+63
-26
@@ -1,15 +1,17 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.file;
|
package cc.carm.lib.easyplugin.configuration.file;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tchristofferson.configupdater.ConfigUpdater;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public class FileConfig {
|
public class FileConfig {
|
||||||
|
|
||||||
public static Supplier<FileConfig> pluginConfiguration = null;
|
public static Supplier<FileConfig> pluginConfiguration = null;
|
||||||
@@ -25,37 +27,71 @@ public class FileConfig {
|
|||||||
return messageConfiguration == null ? null : messageConfiguration.get();
|
return messageConfiguration == null ? null : messageConfiguration.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long updateTime;
|
protected long updateTime;
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
protected final JavaPlugin plugin;
|
||||||
private final String fileName;
|
protected final File fileFolder;
|
||||||
|
protected final String fileName;
|
||||||
|
protected final String resourcePath;
|
||||||
|
|
||||||
|
protected File file;
|
||||||
|
protected FileConfiguration config;
|
||||||
|
|
||||||
private File file;
|
public FileConfig(@NotNull JavaPlugin plugin) throws IOException {
|
||||||
private FileConfiguration config;
|
|
||||||
|
|
||||||
public FileConfig(final JavaPlugin plugin) {
|
|
||||||
this(plugin, "config.yml");
|
this(plugin, "config.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfig(final JavaPlugin plugin, final String name) {
|
public FileConfig(@NotNull JavaPlugin plugin,
|
||||||
|
@NotNull String fileName) throws IOException {
|
||||||
|
this(plugin, fileName, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfig(@NotNull JavaPlugin plugin, @NotNull String resourcePath,
|
||||||
|
@NotNull String fileName) throws IOException {
|
||||||
|
this(plugin, resourcePath, plugin.getDataFolder(), fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfig(@NotNull JavaPlugin plugin, @NotNull String resourcePath,
|
||||||
|
@NotNull File fileFolder, @NotNull String fileName) throws IOException {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.fileName = name;
|
this.resourcePath = resourcePath;
|
||||||
|
this.fileFolder = fileFolder;
|
||||||
|
this.fileName = fileName;
|
||||||
initFile();
|
initFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFile() {
|
protected void initFile() throws IOException {
|
||||||
|
if (!getFileFolder().exists()) getFileFolder().mkdirs();
|
||||||
|
this.file = new File(getFileFolder(), fileName);
|
||||||
|
|
||||||
|
if (!file.exists()) {
|
||||||
|
InputStream resourceStream = plugin.getResource(resourcePath);
|
||||||
|
if (resourceStream == null) {
|
||||||
|
throw new IOException("The resource " + resourcePath + " cannot find in " + plugin.getName() + " !");
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputStream out = new FileOutputStream(file);
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
int readBytes;
|
||||||
|
while ((readBytes = resourceStream.read(buffer)) > 0) {
|
||||||
|
out.write(buffer, 0, readBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
out.close();
|
||||||
|
resourceStream.close();
|
||||||
|
|
||||||
|
ConfigUpdater.update(plugin, resourcePath, file); // Save comments
|
||||||
|
}
|
||||||
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
this.updateTime = System.currentTimeMillis();
|
||||||
this.file = new File(plugin.getDataFolder(), fileName);
|
|
||||||
if (!this.file.exists()) {
|
|
||||||
if (!this.file.getParentFile().exists()) {
|
|
||||||
boolean success = this.file.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
plugin.saveResource(fileName, true);
|
|
||||||
}
|
|
||||||
this.config = YamlConfiguration.loadConfiguration(this.file);
|
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getFileFolder() {
|
||||||
|
return fileFolder;
|
||||||
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public File getFile() {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@@ -64,15 +100,16 @@ public class FileConfig {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public JavaPlugin getPlugin() {
|
||||||
try {
|
return plugin;
|
||||||
getConfig().save(getFile());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
public void save() throws IOException {
|
||||||
|
getConfig().save(getFile());
|
||||||
|
ConfigUpdater.update(plugin, resourcePath, file); // Save comments
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload() throws IOException {
|
||||||
this.updateTime = System.currentTimeMillis();
|
this.updateTime = System.currentTimeMillis();
|
||||||
if (getFile().exists()) {
|
if (getFile().exists()) {
|
||||||
this.config = YamlConfiguration.loadConfiguration(getFile());
|
this.config = YamlConfiguration.loadConfiguration(getFile());
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.file;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class FileConfigCachedValue<V> extends FileConfigValue {
|
||||||
|
|
||||||
|
protected V cachedValue;
|
||||||
|
protected long updateTime;
|
||||||
|
|
||||||
|
public FileConfigCachedValue(@NotNull String sectionName) {
|
||||||
|
super(sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfigCachedValue(@Nullable FileConfig source, @NotNull String sectionName) {
|
||||||
|
super(source, sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public V updateCache(V value) {
|
||||||
|
this.updateTime = System.currentTimeMillis();
|
||||||
|
this.cachedValue = value;
|
||||||
|
return getCachedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExpired() {
|
||||||
|
return getSource() == null || getSource().isExpired(this.updateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public V getCachedValue() {
|
||||||
|
return cachedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearCache() {
|
||||||
|
this.cachedValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.file;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public abstract class FileConfigValue {
|
||||||
|
|
||||||
|
protected @Nullable FileConfig source;
|
||||||
|
private final @NotNull String sectionName;
|
||||||
|
|
||||||
|
public FileConfigValue(@NotNull String sectionName) {
|
||||||
|
this(null, sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfigValue(@Nullable FileConfig source, @NotNull String sectionName) {
|
||||||
|
this.source = source;
|
||||||
|
this.sectionName = sectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getSectionName() {
|
||||||
|
return sectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
getSourceOptional().ifPresent(fileConfig -> {
|
||||||
|
try {
|
||||||
|
fileConfig.save();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
fileConfig.getPlugin().getLogger().severe("Could not save the " + fileConfig.getFile() + " .");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIfPresent(@Nullable Object value, boolean save) {
|
||||||
|
getConfigOptional().ifPresent(configuration -> configuration.set(getSectionName(), value));
|
||||||
|
if (save) save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createSection(Map<?, ?> values) {
|
||||||
|
getConfigOptional().ifPresent(configuration -> {
|
||||||
|
if (values == null) {
|
||||||
|
configuration.set(getSectionName(), null);
|
||||||
|
} else {
|
||||||
|
configuration.createSection(getSectionName(), values);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable FileConfig getSource() {
|
||||||
|
return source == null ? FileConfig.getPluginConfiguration() : source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<FileConfig> getSourceOptional() {
|
||||||
|
return Optional.ofNullable(getSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<FileConfiguration> getConfigOptional() {
|
||||||
|
return getSourceOptional().map(FileConfig::getConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable <V> V castValue(@Nullable Object val, @NotNull Class<V> clazz) {
|
||||||
|
return castValue(val, clazz, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable <V> V castValue(@Nullable Object val, @NotNull Class<V> clazz, @Nullable V defaultValue) {
|
||||||
|
return clazz.isInstance(val) ? clazz.cast(val) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
-73
@@ -1,73 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ConfigSectionCast<V> {
|
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast;
|
|
||||||
@Nullable V defaultValue;
|
|
||||||
|
|
||||||
V valueCache;
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigSectionCast(@NotNull String configSection, @NotNull Function<ConfigurationSection, V> valueCast) {
|
|
||||||
this(configSection, valueCast, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSectionCast(@NotNull String configSection,
|
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
|
||||||
@Nullable V defaultValue) {
|
|
||||||
this(null, configSection, valueCast, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSectionCast(@Nullable FileConfig source, @NotNull String configSection,
|
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
|
||||||
@Nullable V defaultValue) {
|
|
||||||
this.source = source;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.valueCast = valueCast;
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public @Nullable V get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return defaultValue;
|
|
||||||
|
|
||||||
if (valueCache != null && !source.isExpired(this.updateTime)) return valueCache;
|
|
||||||
if (!source.getConfig().contains(this.configSection)) return defaultValue;
|
|
||||||
try {
|
|
||||||
V finalValue = this.valueCast.apply(source.getConfig().getConfigurationSection(this.configSection));
|
|
||||||
if (finalValue != null) {
|
|
||||||
this.valueCache = finalValue;
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
return finalValue;
|
|
||||||
} else {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(ConfigurationSection section) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+36
-28
@@ -1,5 +1,6 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
package cc.carm.lib.easyplugin.configuration.impl;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.cast.ConfigStringCast;
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@@ -7,6 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
||||||
|
|
||||||
public ConfigSound(@NotNull String configSection) {
|
public ConfigSound(@NotNull String configSection) {
|
||||||
@@ -18,30 +21,9 @@ public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
|||||||
this(null, configSection, defaultValue);
|
this(null, configSection, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection, @Nullable Sound defaultValue) {
|
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection,
|
||||||
super(source, configSection, string -> {
|
@Nullable Sound defaultValue) {
|
||||||
Sound finalSound = defaultValue;
|
super(source, configSection, getSoundParser(), defaultValue == null ? null : new SoundData(defaultValue));
|
||||||
float volume = 1;
|
|
||||||
float pitch = 1;
|
|
||||||
|
|
||||||
if (string != null) {
|
|
||||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
|
||||||
try {
|
|
||||||
if (args.length >= 1) finalSound = Sound.valueOf(args[0]);
|
|
||||||
if (args.length >= 2) volume = Float.parseFloat(args[1]);
|
|
||||||
if (args.length >= 3) pitch = Float.parseFloat(args[2]);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Bukkit.getLogger().severe("声音 " + configSection + " 配置错误,不存在 " + string + " ,请检查。");
|
|
||||||
Bukkit.getLogger().severe("In " + configSection + " (" + string + ") doesn't match any sound name.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finalSound != null) {
|
|
||||||
return new SoundData(finalSound, volume, pitch);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, defaultValue == null ? null : new SoundData(defaultValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable SoundData value) {
|
public void set(@Nullable SoundData value) {
|
||||||
@@ -73,12 +55,38 @@ public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
|||||||
if (data != null) data.play(player);
|
if (data != null) data.play(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void playToAll() {
|
||||||
if (getSource() != null) getSource().save();
|
SoundData data = get();
|
||||||
|
if (data != null) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(data::play);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
public static @NotNull Function<@Nullable String, @Nullable SoundData> getSoundParser() {
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
return string -> {
|
||||||
|
if (string == null) return null;
|
||||||
|
|
||||||
|
Sound finalSound = null;
|
||||||
|
float volume = 1;
|
||||||
|
float pitch = 1;
|
||||||
|
|
||||||
|
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||||
|
try {
|
||||||
|
if (args.length >= 1) finalSound = Sound.valueOf(args[0]);
|
||||||
|
if (args.length >= 2) volume = Float.parseFloat(args[1]);
|
||||||
|
if (args.length >= 3) pitch = Float.parseFloat(args[2]);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
Bukkit.getLogger().severe("声音 " + string + " 配置错误,不存在同名声音,请检查。");
|
||||||
|
Bukkit.getLogger().severe("Sound " + string + " doesn't match any sound name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (finalSound != null) {
|
||||||
|
return new SoundData(finalSound, volume, pitch);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SoundData {
|
public static class SoundData {
|
||||||
|
|||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ConfigStringCast<V> {
|
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
@NotNull Function<String, V> valueCast;
|
|
||||||
|
|
||||||
@Nullable V defaultValue;
|
|
||||||
|
|
||||||
V valueCache;
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigStringCast(@NotNull String configSection, @NotNull Function<String, V> valueCast) {
|
|
||||||
this(configSection, valueCast, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStringCast(@NotNull String configSection, @NotNull Function<String, V> valueCast, @Nullable V defaultValue) {
|
|
||||||
this(null, configSection, valueCast, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStringCast(@Nullable FileConfig source, @NotNull String configSection,
|
|
||||||
@NotNull Function<String, V> valueCast, @Nullable V defaultValue) {
|
|
||||||
this.source = source;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.valueCast = valueCast;
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable V get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return defaultValue;
|
|
||||||
|
|
||||||
if (valueCache != null && !source.isExpired(this.updateTime)) return valueCache;
|
|
||||||
if (!source.getConfig().contains(this.configSection)) return defaultValue;
|
|
||||||
try {
|
|
||||||
V finalValue = this.valueCast.apply(source.getConfig().getString(this.configSection));
|
|
||||||
if (finalValue != null) {
|
|
||||||
this.valueCache = finalValue;
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
return finalValue;
|
|
||||||
} else {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(@Nullable String value) {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source != null) {
|
|
||||||
source.getConfig().set(this.configSection, value);
|
|
||||||
source.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) {
|
|
||||||
getSource().save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+105
@@ -0,0 +1,105 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class EasyMessage {
|
||||||
|
|
||||||
|
@Nullable ConfigValue<String> configValue;
|
||||||
|
|
||||||
|
@Nullable String defaultValue;
|
||||||
|
@Nullable String[] messageParams;
|
||||||
|
|
||||||
|
public EasyMessage() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessage(@Nullable String defaultValue) {
|
||||||
|
this(defaultValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessage(@Nullable String defaultValue, @Nullable String[] messageParams) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
this.messageParams = messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(@NotNull FileConfig sourceConfig, @NotNull String sectionName) {
|
||||||
|
this.configValue = new ConfigValue<>(sourceConfig, sectionName, String.class, getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String[] getMessageParams() {
|
||||||
|
return messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull String getDefaultMessages() {
|
||||||
|
if (getDefaultValue() == null) return "";
|
||||||
|
else return getDefaultValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull String getMessages() {
|
||||||
|
if (configValue == null) {
|
||||||
|
return getDefaultMessages();
|
||||||
|
} else {
|
||||||
|
return configValue.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(@Nullable CommandSender sender) {
|
||||||
|
return get(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
return get(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (sender == null) return getMessages();
|
||||||
|
if (params == null || values == null) {
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(sender, getMessages()));
|
||||||
|
} else {
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(sender, getMessages(), params, values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender) {
|
||||||
|
send(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
send(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (params == null || values == null) {
|
||||||
|
MessageUtils.sendWithPlaceholders(sender, getMessages());
|
||||||
|
} else {
|
||||||
|
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(getMessages()), params, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
sendToAll(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable Object[] values) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
||||||
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EasyMessageList {
|
||||||
|
|
||||||
|
@Nullable ConfigValueList<String> configValue;
|
||||||
|
|
||||||
|
@Nullable String[] defaultValue;
|
||||||
|
@Nullable String[] messageParams;
|
||||||
|
|
||||||
|
public EasyMessageList() {
|
||||||
|
this((String[]) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessageList(@Nullable String... defaultValue) {
|
||||||
|
this(defaultValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessageList(@Nullable String[] defaultValue,
|
||||||
|
@Nullable String[] messageParams) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
this.messageParams = messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(FileConfig sourceConfig, String sectionName) {
|
||||||
|
configValue = new ConfigValueList<>(sourceConfig, sectionName, String.class, getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String[] getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unmodifiable
|
||||||
|
private @NotNull List<String> getDefaultMessages() {
|
||||||
|
if (getDefaultValue() == null) return new ArrayList<>();
|
||||||
|
else return Arrays.asList(getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private @Nullable String[] getMessageParams() {
|
||||||
|
return messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull List<String> getMessages() {
|
||||||
|
if (configValue == null) {
|
||||||
|
return getDefaultMessages();
|
||||||
|
} else {
|
||||||
|
return configValue.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> get(@Nullable CommandSender sender) {
|
||||||
|
return get(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
return get(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (sender == null) return getMessages();
|
||||||
|
if (params == null || values == null) {
|
||||||
|
return MessageUtils.setPlaceholders(sender, getMessages());
|
||||||
|
} else {
|
||||||
|
return MessageUtils.setPlaceholders(sender, getMessages(), params, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender) {
|
||||||
|
send(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
send(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (params == null || values == null) {
|
||||||
|
MessageUtils.sendWithPlaceholders(sender, getMessages());
|
||||||
|
} else {
|
||||||
|
MessageUtils.sendWithPlaceholders(sender, getMessages(), params, values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
sendToAll(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable Object[] values) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public class MessagesConfig extends FileConfig {
|
||||||
|
|
||||||
|
public MessagesConfig(@NotNull JavaPlugin plugin) throws IOException {
|
||||||
|
this(plugin, "messages.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagesConfig(@NotNull JavaPlugin plugin, @NotNull String fileName) throws IOException {
|
||||||
|
this(plugin, plugin.getDataFolder(), fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagesConfig(@NotNull JavaPlugin plugin, @NotNull File fileFolder, @NotNull String fileName) throws IOException {
|
||||||
|
super(plugin, fileName, fileFolder, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initFile() throws IOException {
|
||||||
|
if (!getFileFolder().exists()) getFileFolder().mkdirs();
|
||||||
|
this.file = new File(getFileFolder(), fileName);
|
||||||
|
if (!file.exists()) file.createNewFile();
|
||||||
|
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() throws IOException {
|
||||||
|
getConfig().save(getFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MessagesInitializer {
|
||||||
|
|
||||||
|
private MessagesInitializer() {
|
||||||
|
// 静态方法类,不应当实例化。
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initialize(FileConfig source, Class<? extends MessagesRoot> rootClazz) {
|
||||||
|
initialize(source, rootClazz, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initialize(FileConfig source, Class<? extends MessagesRoot> rootClazz, boolean saveDefault) {
|
||||||
|
MessagesSection sectionAnnotation = rootClazz.getAnnotation(MessagesSection.class);
|
||||||
|
|
||||||
|
String rootSection = null;
|
||||||
|
if (sectionAnnotation != null && sectionAnnotation.value().length() > 1) {
|
||||||
|
rootSection = sectionAnnotation.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Class<?> innerClass : rootClazz.getDeclaredClasses()) {
|
||||||
|
initSection(source, rootSection, innerClass, saveDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Field field : rootClazz.getFields()) {
|
||||||
|
initMessage(source, rootSection, rootClazz, field, saveDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveDefault) {
|
||||||
|
try {
|
||||||
|
source.save();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initSection(FileConfig source, String parentSection, Class<?> clazz, boolean saveDefault) {
|
||||||
|
if (!Modifier.isStatic(clazz.getModifiers()) || !Modifier.isPublic(clazz.getModifiers())) return;
|
||||||
|
|
||||||
|
String section = getSection(clazz.getSimpleName(), parentSection, clazz.getAnnotation(MessagesSection.class));
|
||||||
|
|
||||||
|
for (Class<?> innerClass : clazz.getDeclaredClasses()) initSection(source, section, innerClass, saveDefault);
|
||||||
|
for (Field field : clazz.getFields()) initMessage(source, section, clazz, field, saveDefault);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initMessage(FileConfig source, String parentSection, Class<?> clazz, Field field, boolean saveDefault) {
|
||||||
|
try {
|
||||||
|
String section = getSection(field.getName(), parentSection, field.getAnnotation(MessagesSection.class));
|
||||||
|
|
||||||
|
Object object = field.get(clazz);
|
||||||
|
|
||||||
|
if (object instanceof EasyMessage) {
|
||||||
|
EasyMessage message = ((EasyMessage) object);
|
||||||
|
if (saveDefault && message.defaultValue != null && !source.getConfig().contains(section)) {
|
||||||
|
source.getConfig().set(section, message.defaultValue);
|
||||||
|
}
|
||||||
|
message.initialize(source, section);
|
||||||
|
} else if (object instanceof EasyMessageList) {
|
||||||
|
EasyMessageList messageList = ((EasyMessageList) object);
|
||||||
|
|
||||||
|
if (saveDefault && messageList.defaultValue != null && !source.getConfig().contains(section)) {
|
||||||
|
source.getConfig().set(section, Arrays.asList(messageList.defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
messageList.initialize(source, section);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static String getSection(@NotNull String name,
|
||||||
|
@Nullable String parentSection,
|
||||||
|
@Nullable MessagesSection sectionAnnotation) {
|
||||||
|
String parent = parentSection != null ? parentSection + "." : "";
|
||||||
|
if (sectionAnnotation != null && sectionAnnotation.value().length() > 0) {
|
||||||
|
return parent + sectionAnnotation.value();
|
||||||
|
} else {
|
||||||
|
return parent + getSectionName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSectionName(String codeName) {
|
||||||
|
return codeName.toLowerCase().replace("_", "-");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
public abstract class MessagesRoot {
|
||||||
|
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface MessagesSection {
|
||||||
|
|
||||||
|
String value() default "";
|
||||||
|
|
||||||
|
}
|
||||||
+32
-12
@@ -4,47 +4,50 @@ package cc.carm.lib.easyplugin.configuration.message;
|
|||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConfigMessage extends ConfigValue<String> {
|
public class ConfigMessage extends ConfigValue<String> {
|
||||||
|
|
||||||
String[] messageParams;
|
String[] messageParams;
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection) {
|
public ConfigMessage(@NotNull String sectionName) {
|
||||||
this(configSection, null);
|
this(sectionName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection, @Nullable String defaultValue) {
|
public ConfigMessage(@NotNull String sectionName, @Nullable String defaultValue) {
|
||||||
this(configSection, defaultValue, null);
|
this(sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection, @Nullable String defaultValue, String[] messageParams) {
|
public ConfigMessage(@NotNull String sectionName, @Nullable String defaultValue, String[] messageParams) {
|
||||||
super(null, configSection, String.class, defaultValue);
|
super(null, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@Nullable FileConfig config, @NotNull String configSection,
|
public ConfigMessage(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@Nullable String defaultValue, String[] messageParams) {
|
@Nullable String defaultValue, String[] messageParams) {
|
||||||
super(config, configSection, String.class, defaultValue);
|
super(source, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(CommandSender sender) {
|
||||||
|
return MessageUtils.setPlaceholders(sender, get());
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, Object[] values) {
|
public @NotNull String get(CommandSender sender, Object[] values) {
|
||||||
if (messageParams != null) {
|
if (messageParams != null) {
|
||||||
return get(sender, messageParams, values);
|
return get(sender, messageParams, values);
|
||||||
} else {
|
} else {
|
||||||
return get(sender, new String[0], new Object[0]);
|
return get(sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, String[] params, Object[] values) {
|
public @NotNull String get(CommandSender sender, String[] params, Object[] values) {
|
||||||
List<String> messages = MessageUtils.setPlaceholders(sender, Collections.singletonList(get()), params, values);
|
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
||||||
return messages != null && !messages.isEmpty() ? messages.get(0) : "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(CommandSender sender) {
|
public void send(CommandSender sender) {
|
||||||
@@ -64,6 +67,23 @@ public class ConfigMessage extends ConfigValue<String> {
|
|||||||
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> MessageUtils.sendWithPlaceholders(player, Collections.singletonList(get())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(Object[] values) {
|
||||||
|
if (messageParams != null) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
} else {
|
||||||
|
sendToAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(String[] params, Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> MessageUtils.sendWithPlaceholders(pl, Collections.singletonList(get()), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public @Nullable FileConfig getSource() {
|
public @Nullable FileConfig getSource() {
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
return source == null ? FileConfig.getMessageConfiguration() : source;
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-9
@@ -4,6 +4,7 @@ package cc.carm.lib.easyplugin.configuration.message;
|
|||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -14,22 +15,22 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
|
|
||||||
@Nullable String[] messageParams;
|
@Nullable String[] messageParams;
|
||||||
|
|
||||||
public ConfigMessageList(String configSection) {
|
public ConfigMessageList(String sectionName) {
|
||||||
this(configSection, new String[0]);
|
this(sectionName, new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String configSection, @Nullable String[] defaultValue) {
|
public ConfigMessageList(@NotNull String sectionName, @Nullable String[] defaultValue) {
|
||||||
this(configSection, defaultValue, null);
|
this(sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String configSection, @Nullable String[] defaultValue, String[] messageParams) {
|
public ConfigMessageList(@NotNull String sectionName, @Nullable String[] defaultValue, String[] messageParams) {
|
||||||
super(null, configSection, String.class, defaultValue);
|
super(null, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@Nullable FileConfig config, @NotNull String configSection,
|
public ConfigMessageList(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@Nullable String[] defaultValue, String[] messageParams) {
|
@Nullable String[] defaultValue, String[] messageParams) {
|
||||||
super(config, configSection, String.class, defaultValue);
|
super(source, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +46,6 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
public @NotNull List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||||
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
||||||
}
|
}
|
||||||
@@ -66,8 +66,25 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
MessageUtils.sendWithPlaceholders(sender, get(), params, values);
|
MessageUtils.sendWithPlaceholders(sender, get(), params, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendToAll(String[] params, Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> MessageUtils.sendWithPlaceholders(pl, get(), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> MessageUtils.sendWithPlaceholders(player, get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(Object[] values) {
|
||||||
|
if (messageParams != null) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
} else {
|
||||||
|
sendToAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable FileConfig getSource() {
|
public @Nullable FileConfig getSource() {
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
return source == null ? FileConfig.getMessageConfiguration() : source;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-34
@@ -1,64 +1,57 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
package cc.carm.lib.easyplugin.configuration.values;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class ConfigValue<V> {
|
import java.util.Optional;
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
public class ConfigValue<V> extends FileConfigValue {
|
||||||
|
|
||||||
private final @NotNull String configSection;
|
|
||||||
private final @NotNull Class<V> clazz;
|
private final @NotNull Class<V> clazz;
|
||||||
@Nullable V defaultValue;
|
@Nullable V defaultValue;
|
||||||
|
|
||||||
public ConfigValue(@NotNull String configSection, @NotNull Class<V> clazz) {
|
public ConfigValue(@NotNull String sectionName,
|
||||||
this(configSection, clazz, null);
|
@NotNull Class<V> clazz) {
|
||||||
|
this(sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValue(@NotNull String configSection, @NotNull Class<V> clazz, @Nullable V defaultValue) {
|
public ConfigValue(@NotNull String sectionName,
|
||||||
this(null, configSection, clazz, defaultValue);
|
@NotNull Class<V> clazz,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
this(null, sectionName, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValue(@Nullable FileConfig source, @NotNull String configSection,
|
public ConfigValue(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz, @Nullable V defaultValue) {
|
@NotNull Class<V> clazz,
|
||||||
this.source = source;
|
@Nullable V defaultValue) {
|
||||||
this.configSection = configSection;
|
super(source, sectionName);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public V get() {
|
public V get() {
|
||||||
FileConfig source = getSource();
|
return getConfigOptional()
|
||||||
if (source == null) return this.defaultValue;
|
.map(config -> {
|
||||||
|
if (config.contains(getSectionName())) {
|
||||||
if (source.getConfig().contains(this.configSection)) {
|
return castValue(config.get(getSectionName()), clazz, this.defaultValue);
|
||||||
Object val = source.getConfig().get(this.configSection, this.defaultValue);
|
|
||||||
return this.clazz.isInstance(val) ? this.clazz.cast(val) : this.defaultValue;
|
|
||||||
} else {
|
} else {
|
||||||
// 如果没有默认值,就把配置写进去,便于配置
|
return setDefault(); // 如果没有默认值,就把配置写进去,便于配置
|
||||||
return setDefault();
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.orElse(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Optional<V> getOptional() {
|
||||||
|
return Optional.ofNullable(get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable V value) {
|
public void set(@Nullable V value) {
|
||||||
FileConfig source = getSource();
|
setIfPresent(value, true);
|
||||||
if (source == null) return;
|
|
||||||
|
|
||||||
source.getConfig().set(this.configSection, value);
|
|
||||||
source.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public V setDefault() {
|
public V setDefault() {
|
||||||
set(this.defaultValue);
|
if (this.defaultValue != null) set(this.defaultValue);
|
||||||
return this.defaultValue;
|
return this.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-44
@@ -2,78 +2,63 @@ package cc.carm.lib.easyplugin.configuration.values;
|
|||||||
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ConfigValueList<V> {
|
public class ConfigValueList<V> extends FileConfigValue {
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
|
||||||
|
|
||||||
private final @NotNull String configSection;
|
|
||||||
private final @NotNull Class<V> clazz;
|
private final @NotNull Class<V> clazz;
|
||||||
|
|
||||||
@Nullable V[] defaultValue;
|
@Nullable V[] defaultValue;
|
||||||
|
|
||||||
public ConfigValueList(@NotNull String configSection, @NotNull Class<V> clazz) {
|
public ConfigValueList(@NotNull String sectionName,
|
||||||
this(configSection, clazz, null);
|
@NotNull Class<V> clazz) {
|
||||||
|
this(sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@NotNull String configSection, @NotNull Class<V> clazz, @Nullable V[] defaultValue) {
|
public ConfigValueList(@NotNull String sectionName,
|
||||||
this(null, configSection, clazz, defaultValue);
|
@NotNull Class<V> clazz,
|
||||||
|
@Nullable V[] defaultValue) {
|
||||||
|
this(null, sectionName, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String configSection, Class<V> clazz) {
|
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String sectionName,
|
||||||
this(configuration, configSection, clazz, null);
|
Class<V> clazz) {
|
||||||
|
this(configuration, sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String configSection,
|
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz, @Nullable V[] defaultValue) {
|
@NotNull Class<V> clazz,
|
||||||
this.source = configuration;
|
@Nullable V[] defaultValue) {
|
||||||
this.configSection = configSection;
|
super(configuration, sectionName);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ArrayList<V> get() {
|
public @NotNull ArrayList<V> get() {
|
||||||
FileConfig source = getSource();
|
return getConfigOptional()
|
||||||
if (source == null) return new ArrayList<>();
|
.map(configuration -> configuration.getList(getSectionName()))
|
||||||
|
.map(list -> list.stream()
|
||||||
|
.map(o -> castValue(o, this.clazz))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new)))
|
||||||
|
.orElse(getDefaultList());
|
||||||
|
}
|
||||||
|
|
||||||
List<?> list = source.getConfig().getList(this.configSection);
|
public @NotNull ArrayList<V> getDefaultList() {
|
||||||
if (list == null) {
|
return defaultValue == null ? new ArrayList<>() : new ArrayList<>(Arrays.asList(defaultValue));
|
||||||
if (defaultValue != null) {
|
|
||||||
return new ArrayList<>(Arrays.asList(defaultValue));
|
|
||||||
} else {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ArrayList<V> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Object object : list) {
|
|
||||||
if (this.clazz.isInstance(object)) {
|
|
||||||
result.add(this.clazz.cast(object));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable ArrayList<V> value) {
|
public void set(@Nullable ArrayList<V> value) {
|
||||||
FileConfig source = getSource();
|
setIfPresent(value, true);
|
||||||
if (source == null) return;
|
|
||||||
source.getConfig().set(this.configSection, value);
|
|
||||||
this.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return this.source == null ? FileConfig.getPluginConfiguration() : this.source;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-52
@@ -1,88 +1,56 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
package cc.carm.lib.easyplugin.configuration.values;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigCachedValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ConfigValueMap<K, V> {
|
public class ConfigValueMap<K, V> extends FileConfigCachedValue<Map<K, V>> {
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
|
|
||||||
@NotNull Function<String, K> keyCast;
|
@NotNull Function<String, K> keyCast;
|
||||||
@NotNull Class<V> valueClazz;
|
@NotNull Class<V> valueClazz;
|
||||||
|
|
||||||
@Nullable LinkedHashMap<K, V> valueCache;
|
public ConfigValueMap(@NotNull String sectionName, @NotNull Function<String, K> keyCast,
|
||||||
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigValueMap(@NotNull String configSection, @NotNull Function<String, K> keyCast,
|
|
||||||
@NotNull Class<V> valueClazz) {
|
@NotNull Class<V> valueClazz) {
|
||||||
this(null, configSection, keyCast, valueClazz);
|
this(null, sectionName, keyCast, valueClazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueMap(@Nullable FileConfig configuration, @NotNull String configSection,
|
public ConfigValueMap(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
||||||
this.source = configuration;
|
super(source, sectionName);
|
||||||
this.configSection = configSection;
|
|
||||||
this.keyCast = keyCast;
|
this.keyCast = keyCast;
|
||||||
this.valueClazz = valueClazz;
|
this.valueClazz = valueClazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
|
||||||
this.valueCache = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Map<K, V> get() {
|
public Map<K, V> get() {
|
||||||
FileConfig source = getSource();
|
Map<K, V> cached = getCachedValue();
|
||||||
if (source == null) return new HashMap<>();
|
if (cached != null && !isExpired()) {
|
||||||
|
return cached;
|
||||||
if (valueCache != null && !getSource().isExpired(this.updateTime)) return valueCache;
|
} else {
|
||||||
|
return getConfigOptional()
|
||||||
ConfigurationSection section = source.getConfig().getConfigurationSection(this.configSection);
|
.map(config -> config.getConfigurationSection(getSectionName()))
|
||||||
if (section == null) return new LinkedHashMap<>();
|
.map(section -> {
|
||||||
|
Map<K, V> result = new LinkedHashMap<>();
|
||||||
Set<String> keys = section.getKeys(false);
|
for (String key : section.getKeys(false)) {
|
||||||
if (keys.isEmpty()) return new LinkedHashMap<>();
|
|
||||||
|
|
||||||
else {
|
|
||||||
LinkedHashMap<K, V> result = new LinkedHashMap<>();
|
|
||||||
for (String key : keys) {
|
|
||||||
K finalKey = keyCast.apply(key);
|
K finalKey = keyCast.apply(key);
|
||||||
Object val = section.get(key);
|
V finalValue = castValue(section.get(key), valueClazz);
|
||||||
V finalValue = this.valueClazz.isInstance(val) ? this.valueClazz.cast(val) : null;
|
|
||||||
if (finalKey != null && finalValue != null) {
|
if (finalKey != null && finalValue != null) {
|
||||||
result.put(finalKey, finalValue);
|
result.put(finalKey, finalValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.updateTime = System.currentTimeMillis();
|
return updateCache(result);
|
||||||
this.valueCache = result;
|
}).orElse(new LinkedHashMap<>());
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable HashMap<K, V> valuesMap) {
|
public void set(@Nullable Map<K, V> valuesMap) {
|
||||||
FileConfig source = getSource();
|
createSection(valuesMap);
|
||||||
if (source == null) return;
|
|
||||||
source.getConfig().createSection(this.configSection, valuesMap);
|
|
||||||
source.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<artifactId>easyplugin-database</artifactId>
|
<artifactId>easyplugin-database</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Database</name>
|
<name>14-EasyPlugin-Database</name>
|
||||||
<description>轻松插件数据库模块,包含快速实现数据库功能的工具。</description>
|
<description>轻松插件数据库模块,包含快速实现数据库功能的工具。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -49,19 +49,12 @@
|
|||||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>EasySQL</id>
|
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-beecp</artifactId>
|
<artifactId>easysql-beecp</artifactId>
|
||||||
<version>0.2.4</version>
|
<version>0.2.7</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
+30
-4
@@ -1,8 +1,9 @@
|
|||||||
package cc.carm.lib.easyplugin.database;
|
package cc.carm.lib.easyplugin.database;
|
||||||
|
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
import cc.carm.lib.easysql.api.builder.TableCreateBuilder;
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
||||||
import cc.carm.lib.easysql.api.builder.TableQueryBuilder;
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
||||||
|
import cc.carm.lib.easysql.api.builder.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ public class DatabaseTable {
|
|||||||
this(tableName, columns, null);
|
this(tableName, columns, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns, @Nullable String tableSettings) {
|
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns,
|
||||||
|
@Nullable String tableSettings) {
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
this.tableSettings = tableSettings;
|
this.tableSettings = tableSettings;
|
||||||
@@ -45,7 +47,31 @@ public class DatabaseTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TableQueryBuilder createQuery(SQLManager sqlManager) {
|
public TableQueryBuilder createQuery(SQLManager sqlManager) {
|
||||||
return sqlManager.createQuery().inTable(tableName);
|
return sqlManager.createQuery().inTable(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteBuilder createDelete(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createDelete(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateBuilder createUpdate(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createUpdate(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertBuilder<PreparedSQLUpdateAction> createInsert(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createInsert(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createInsertBatch(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplaceBuilder<PreparedSQLUpdateAction> createReplace(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createReplace(getTableName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createReplaceBatch(getTableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<artifactId>easyplugin-gui</artifactId>
|
<artifactId>easyplugin-gui</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-GUI</name>
|
<name>13-EasyPlugin-GUI</name>
|
||||||
<description>轻松插件GUI接口模块,方便快捷的创建箱子GUI界面。</description>
|
<description>轻松插件GUI接口模块,方便快捷的创建箱子GUI界面。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class GUI {
|
|||||||
|
|
||||||
public static void initialize(JavaPlugin plugin) {
|
public static void initialize(JavaPlugin plugin) {
|
||||||
GUI.plugin = plugin;
|
GUI.plugin = plugin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JavaPlugin getPlugin() {
|
public static JavaPlugin getPlugin() {
|
||||||
@@ -36,8 +35,8 @@ public class GUI {
|
|||||||
return openedGUIs;
|
return openedGUIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUIType type;
|
protected GUIType type;
|
||||||
String name;
|
protected String name;
|
||||||
public HashMap<Integer, GUIItem> items;
|
public HashMap<Integer, GUIItem> items;
|
||||||
public Inventory inv;
|
public Inventory inv;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package cc.carm.lib.easyplugin.gui.paged;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class AutoPagedGUI extends CommonPagedGUI {
|
||||||
|
|
||||||
|
public static Function<Player, ItemStack> defaultPreviousPage = null;
|
||||||
|
public static Function<Player, ItemStack> defaultNextPage = null;
|
||||||
|
|
||||||
|
ItemStack previousPageUI;
|
||||||
|
ItemStack nextPageUI;
|
||||||
|
int previousPageSlot = -1;
|
||||||
|
int nextPageSlot = -1;
|
||||||
|
|
||||||
|
public AutoPagedGUI(GUIType type, String name, int[] range) {
|
||||||
|
super(type, name, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoPagedGUI(GUIType type, String name, int a, int b) {
|
||||||
|
super(type, name, a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousPageUI(ItemStack lastPageUI) {
|
||||||
|
this.previousPageUI = lastPageUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextPageUI(ItemStack nextPageUI) {
|
||||||
|
this.nextPageUI = nextPageUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousPageSlot(int slot) {
|
||||||
|
this.previousPageSlot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextPageSlot(int slot) {
|
||||||
|
this.nextPageSlot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openGUI(Player user) {
|
||||||
|
if (previousPageSlot >= 0) {
|
||||||
|
if (hasPreviousPage()) {
|
||||||
|
setItem(previousPageSlot, new GUIItem(
|
||||||
|
previousPageUI == null ? getDefaultPreviousPage(user) : previousPageUI) {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickType type) {
|
||||||
|
if (type == ClickType.RIGHT) {
|
||||||
|
goFirstPage();
|
||||||
|
} else {
|
||||||
|
goPreviousPage();
|
||||||
|
}
|
||||||
|
openGUI(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setItem(previousPageSlot, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextPageSlot >= 0) {
|
||||||
|
if (hasNextPage()) {
|
||||||
|
setItem(nextPageSlot, new GUIItem(
|
||||||
|
nextPageUI == null ? getDefaultNextPage(user) : nextPageUI) {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickType type) {
|
||||||
|
if (type == ClickType.RIGHT) {
|
||||||
|
goLastPage();
|
||||||
|
} else {
|
||||||
|
goNextPage();
|
||||||
|
}
|
||||||
|
openGUI(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setItem(nextPageSlot, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
super.openGUI(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getDefaultNextPage(Player player) {
|
||||||
|
return defaultNextPage != null ? defaultNextPage.apply(player) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getDefaultPreviousPage(Player player) {
|
||||||
|
return defaultPreviousPage != null ? defaultPreviousPage.apply(player) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package cc.carm.lib.easyplugin.gui.paged;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommonPagedGUI extends PagedGUI {
|
||||||
|
|
||||||
|
private int[] range;
|
||||||
|
|
||||||
|
private CommonPagedGUI(GUIType type, String name) {
|
||||||
|
super(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonPagedGUI(GUIType type, String Name, int a, int b) {
|
||||||
|
this(type, Name, toRange(type, a, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonPagedGUI(GUIType type, String Name, int[] range) {
|
||||||
|
super(type, Name);
|
||||||
|
Arrays.sort(range);
|
||||||
|
this.range = range;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
int[] matrix = new int[]{
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||||
|
9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||||
|
18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||||
|
27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||||
|
36, 37, 38, 39, 40, 41, 42, 43, 44,
|
||||||
|
45, 46, 47, 48, 49, 50, 51, 52, 53
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static int[] toRange(GUIType type, int a, int b) {
|
||||||
|
if (a > b) {
|
||||||
|
a = a ^ b;
|
||||||
|
b = a ^ b;
|
||||||
|
a = a ^ b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineA = getLine(a);
|
||||||
|
int columnA = getColumn(a);
|
||||||
|
int lineB = getLine(b);
|
||||||
|
int columnB = getColumn(b);
|
||||||
|
|
||||||
|
if (lineB > type.getLines())
|
||||||
|
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
|
||||||
|
|
||||||
|
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
|
||||||
|
|
||||||
|
for (int i = 0, l = 0; i < type.getSize(); i++) {
|
||||||
|
int li = getLine(i);
|
||||||
|
int ci = getColumn(i);
|
||||||
|
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
|
||||||
|
range[l] = i;
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getLine(int i) {
|
||||||
|
return i / 9 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getColumn(int i) {
|
||||||
|
return i % 9 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPreviousPage() {
|
||||||
|
return page > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNextPage() {
|
||||||
|
return page < getLastPageNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往第一页
|
||||||
|
*/
|
||||||
|
public void goFirstPage() {
|
||||||
|
if (hasPreviousPage())
|
||||||
|
this.page = 1;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往最后一页
|
||||||
|
*/
|
||||||
|
public void goLastPage() {
|
||||||
|
if (hasNextPage())
|
||||||
|
this.page = getLastPageNumber();
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到最后一页的页码
|
||||||
|
*
|
||||||
|
* @return 最后一页的页码
|
||||||
|
*/
|
||||||
|
public int getLastPageNumber() {
|
||||||
|
return (this.container.size() / range.length) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到第一页的页码
|
||||||
|
*
|
||||||
|
* @return 第一页页码(默认为1)
|
||||||
|
*/
|
||||||
|
public int getFirstPageNumber() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openGUI(Player player) {
|
||||||
|
if (container.isEmpty()) {
|
||||||
|
super.openGUI(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<GUIItem> list = new ArrayList<>();
|
||||||
|
int start = (page - 1) * range.length;
|
||||||
|
for (int i = start; i < start + range.length; i++) {
|
||||||
|
if (i < container.size()) {
|
||||||
|
list.add(container.get(i));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
Arrays.stream(range).forEach(index -> setItem(index, null));
|
||||||
|
for (int index : range) {
|
||||||
|
if (i < list.size()) {
|
||||||
|
setItem(index, list.get(i));
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.openGUI(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package cc.carm.lib.easyplugin.gui.paged;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUI;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class PagedGUI extends GUI {
|
||||||
|
|
||||||
|
List<GUIItem> container = new ArrayList<>();
|
||||||
|
public int page = 1;
|
||||||
|
|
||||||
|
public PagedGUI(GUIType type, String name) {
|
||||||
|
super(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int addItem(GUIItem i) {
|
||||||
|
container.add(i);
|
||||||
|
return container.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从GUI中移除一个物品
|
||||||
|
*
|
||||||
|
* @param item 物品
|
||||||
|
*/
|
||||||
|
public void removeItem(GUIItem item) {
|
||||||
|
container.remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从GUI中移除一个物品
|
||||||
|
*
|
||||||
|
* @param slot 物品格子数
|
||||||
|
*/
|
||||||
|
public void removeItem(int slot) {
|
||||||
|
container.remove(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GUIItem> getItemsContainer() {
|
||||||
|
return new ArrayList<>(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往上一页
|
||||||
|
*/
|
||||||
|
public void goPreviousPage() {
|
||||||
|
if (hasPreviousPage())
|
||||||
|
page--;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往下一页
|
||||||
|
*/
|
||||||
|
public void goNextPage() {
|
||||||
|
if (hasNextPage())
|
||||||
|
page++;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否有上一页
|
||||||
|
*/
|
||||||
|
public abstract boolean hasPreviousPage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否有下一页
|
||||||
|
*/
|
||||||
|
public abstract boolean hasNextPage();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,5 +19,7 @@
|
|||||||
<artifactId>easyplugin-lp</artifactId>
|
<artifactId>easyplugin-lp</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>23-EasyPlugin-LuckPerms</name>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<artifactId>easyplugin-main</artifactId>
|
<artifactId>easyplugin-main</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
<name>10-EasyPlugin-Main</name>
|
||||||
<description>轻松插件主要接口模块,包含方便的插件入口类与相关工具类。</description>
|
<description>轻松插件主要接口模块,包含方便的插件入口类与相关工具类。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ public abstract class EasyPlugin extends JavaPlugin {
|
|||||||
log(messageProvider.disabled(this, startTime));
|
log(messageProvider.disabled(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
protected void load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean initialize();
|
protected abstract boolean initialize();
|
||||||
|
|
||||||
public void shutdown() {
|
protected void shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
|
||||||
package cc.carm.lib.easyplugin.utils;
|
package cc.carm.lib.easyplugin.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ColorParser {
|
public class ColorParser {
|
||||||
|
|
||||||
@@ -11,6 +14,14 @@ public class ColorParser {
|
|||||||
return parseColor(text);
|
return parseColor(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] parse(String... texts) {
|
||||||
|
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parse(List<String> texts) {
|
||||||
|
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public static String parseColor(final String text) {
|
public static String parseColor(final String text) {
|
||||||
return text.replaceAll("&", "§").replace("§§", "&");
|
return text.replaceAll("&", "§").replace("§§", "&");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
|
||||||
@@ -14,6 +18,11 @@ public class MessageUtils {
|
|||||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void send(@Nullable CommandSender sender, String... messages) {
|
||||||
|
send(sender, Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||||
for (String s : messages) {
|
for (String s : messages) {
|
||||||
@@ -21,10 +30,6 @@ public class MessageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, String... messages) {
|
|
||||||
send(sender, Arrays.asList(messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
||||||
sendWithPlaceholders(sender, Arrays.asList(messages));
|
sendWithPlaceholders(sender, Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
@@ -42,6 +47,15 @@ public class MessageUtils {
|
|||||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@Nullable CommandSender sender, String message) {
|
||||||
|
if (message == null || sender == null) return message;
|
||||||
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
|
return PlaceholderAPI.setPlaceholders((Player) sender, message);
|
||||||
|
} else {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
||||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
@@ -51,10 +65,36 @@ public class MessageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@Nullable CommandSender sender, String message, String[] params, Object[] values) {
|
||||||
|
return setPlaceholders(sender, setCustomParams(message, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||||
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String setCustomParams(String message, String param, Object value) {
|
||||||
|
return setCustomParams(message, new String[]{param}, new Object[]{value});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String setCustomParams(String message, String[] params, Object[] values) {
|
||||||
|
if (params.length != values.length) return message;
|
||||||
|
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
|
paramsMap.put(params[i], values[i]);
|
||||||
|
}
|
||||||
|
return setCustomParams(message, paramsMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String setCustomParams(String message, HashMap<String, Object> params) {
|
||||||
|
String afterMessage = message;
|
||||||
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
|
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
return afterMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
||||||
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
||||||
}
|
}
|
||||||
@@ -70,15 +110,7 @@ public class MessageUtils {
|
|||||||
|
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
||||||
List<String> list = new ArrayList<>();
|
return messages.stream().map(message -> setCustomParams(message, params)).collect(Collectors.toList());
|
||||||
for (String message : messages) {
|
|
||||||
String afterMessage = message;
|
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
|
||||||
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
|
||||||
}
|
|
||||||
list.add(afterMessage);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>21-EasyPlugin-PlaceholderAPI</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
<artifactId>easyplugin-vault</artifactId>
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>22-EasyPlugin-Vault</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -14,8 +14,13 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
<modules>
|
<modules>
|
||||||
|
|
||||||
|
<module>easyplugin-bom</module>
|
||||||
|
<module>easyplugin-all</module>
|
||||||
|
<module>easyplugin-common</module>
|
||||||
|
|
||||||
<module>easyplugin-main</module>
|
<module>easyplugin-main</module>
|
||||||
|
|
||||||
<module>easyplugin-database</module>
|
<module>easyplugin-database</module>
|
||||||
@@ -25,10 +30,8 @@
|
|||||||
|
|
||||||
<module>easyplugin-vault</module>
|
<module>easyplugin-vault</module>
|
||||||
<module>easyplugin-placeholderapi</module>
|
<module>easyplugin-placeholderapi</module>
|
||||||
|
|
||||||
<module>easyplugin-all</module>
|
|
||||||
<module>easyplugin-common</module>
|
|
||||||
<module>easyplugin-lp</module>
|
<module>easyplugin-lp</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>EasyPlugin</name>
|
<name>EasyPlugin</name>
|
||||||
@@ -46,8 +49,8 @@
|
|||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
<name>GNU General Public License v3.0</name>
|
<name>The MIT License</name>
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
@@ -73,9 +76,9 @@
|
|||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>github</id>
|
<id>carm-repo</id>
|
||||||
<name>GitHub Packages</name>
|
<name>Carm's Repo</name>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
@@ -84,14 +87,12 @@
|
|||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>carm-repo</id>
|
<id>github</id>
|
||||||
<name>Carm's Repo</name>
|
<name>GitHub Packages</name>
|
||||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
<url>https://maven.pkg.github.com/CarmJos/*</url>
|
||||||
</repository>
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
<repository>
|
</snapshots>
|
||||||
<id>nexus</id>
|
|
||||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
@@ -101,14 +102,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.13-R0.1-SNAPSHOT</version>
|
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.13-R0.1-SNAPSHOT</version>
|
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user