mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 00:58:17 +08:00
Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| be798a981a | |||
| bbdfe313d5 | |||
| 2acc81185a | |||
| 5886f162af | |||
| fbc153c9e9 | |||
| 3c7508c348 | |||
| 5fa255d7c7 | |||
| ce1122712d | |||
| 45426e947b | |||
| 7e3a2ea13e | |||
| 226121c1df | |||
| 94c9cc382d | |||
| 892371f702 | |||
| 12ff00e1d9 | |||
| 10f5961ccd | |||
| d8cbf2825d | |||
| f4292e761a | |||
| 47018fbf7d | |||
| dd277e99e8 | |||
| b3078553e7 | |||
| e67e23a24c | |||
| 30e57e3945 | |||
| acea995996 | |||
| 511d8d77c4 | |||
| 96ff3398c8 | |||
| 42860c332f | |||
| 5ea196b6df | |||
| fe34bbc17d | |||
| c575805c72 | |||
| 9c73fa81bc | |||
| 5a61c2db14 | |||
| d15204a38e | |||
| dcbf1678ba | |||
| 116f3419f2 | |||
| 29321f2b25 | |||
| ef453d9481 | |||
| d0d36023c8 | |||
| 4fa3ffaa93 | |||
| 6ba1be457f | |||
| 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 | |||
| 1713fb1324 | |||
| f216aba5e3 |
@@ -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
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
name: Deploy
|
name: Project Deployment
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
@@ -11,7 +11,7 @@ on:
|
|||||||
types: [ published ]
|
types: [ published ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
maven-deploy:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
@@ -20,14 +20,79 @@ jobs:
|
|||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v2
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '8'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
cache: maven
|
cache: maven
|
||||||
server-id: github
|
server-id: github
|
||||||
server-username: MAVEN_USERNAME
|
server-username: MAVEN_USERNAME
|
||||||
server-password: MAVEN_TOKEN
|
server-password: MAVEN_TOKEN
|
||||||
- name: "Deploy"
|
|
||||||
|
- name: "Maven Deploy"
|
||||||
run: mvn -B deploy --file pom.xml -DskipTests
|
run: mvn -B deploy --file pom.xml -DskipTests
|
||||||
env:
|
env:
|
||||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
|
||||||
|
|
||||||
|
javadoc-deploy:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: "Set up JDK"
|
||||||
|
uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
java-version: '8'
|
||||||
|
distribution: 'adopt'
|
||||||
|
cache: maven
|
||||||
|
|
||||||
|
- name: "Generate Javadoc"
|
||||||
|
run: mvn -B javadoc:aggregate --file pom.xml -DskipTests
|
||||||
|
|
||||||
|
- name: "Copy Javadoc"
|
||||||
|
run: |
|
||||||
|
rm -rf docs
|
||||||
|
mkdir -vp docs
|
||||||
|
cp -vrf target/site/apidocs/* docs/
|
||||||
|
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
|
||||||
|
|
||||||
|
- name: "Generate Sitemap"
|
||||||
|
id: sitemap
|
||||||
|
uses: cicirello/generate-sitemap@v1
|
||||||
|
with:
|
||||||
|
base-url-path: https://carmjos.github.io/EasyPlugin
|
||||||
|
path-to-root: docs
|
||||||
|
|
||||||
|
- name: Output stats
|
||||||
|
run: |
|
||||||
|
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||||
|
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||||
|
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
||||||
|
ls -l docs
|
||||||
|
|
||||||
|
- name: Configure Git
|
||||||
|
env:
|
||||||
|
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
||||||
|
run: |
|
||||||
|
sudo timedatectl set-timezone "Asia/Shanghai"
|
||||||
|
mkdir -p ~/.ssh/
|
||||||
|
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||||
|
git config --global user.name 'CarmJos'
|
||||||
|
git config --global user.email 'carm@carm.cc'
|
||||||
|
|
||||||
|
- name: Commit documentation changes
|
||||||
|
run: |
|
||||||
|
cd docs
|
||||||
|
git init
|
||||||
|
git remote add origin git@github.com:CarmJos/EasyPlugin.git
|
||||||
|
git checkout -b gh-pages
|
||||||
|
git add -A
|
||||||
|
git commit -m "API Document generated."
|
||||||
|
|
||||||
|
- name: Javadoc Website Push
|
||||||
|
run: |
|
||||||
|
cd docs
|
||||||
|
git push origin HEAD:gh-pages --force
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
|
||||||
|
|
||||||
name: Javadoc
|
|
||||||
|
|
||||||
on:
|
|
||||||
# 支持手动触发构建
|
|
||||||
workflow_dispatch:
|
|
||||||
release:
|
|
||||||
# 创建release的时候触发
|
|
||||||
types: [ published ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
api-website:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout the repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up the Java JDK
|
|
||||||
uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
cache: maven
|
|
||||||
java-version: '11'
|
|
||||||
distribution: 'adopt'
|
|
||||||
|
|
||||||
- name: Generate docs
|
|
||||||
run: mvn clean package -DskipTests
|
|
||||||
|
|
||||||
- name: Copy to Location
|
|
||||||
run: |
|
|
||||||
rm -rf docs
|
|
||||||
mkdir -vp docs
|
|
||||||
cp -vrf EasyPlugin-api/target/apidocs/* docs/
|
|
||||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
|
||||||
|
|
||||||
- name: Generate the sitemap
|
|
||||||
id: sitemap
|
|
||||||
uses: cicirello/generate-sitemap@v1
|
|
||||||
with:
|
|
||||||
base-url-path: https://carmjos.github.io/EasyPlugin
|
|
||||||
path-to-root: docs
|
|
||||||
|
|
||||||
- name: Output stats
|
|
||||||
run: |
|
|
||||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
|
||||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
|
||||||
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
|
||||||
|
|
||||||
- name: Configure Git
|
|
||||||
env:
|
|
||||||
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
|
||||||
run: |
|
|
||||||
sudo timedatectl set-timezone "Asia/Shanghai"
|
|
||||||
mkdir -p ~/.ssh/
|
|
||||||
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
|
||||||
git config --global user.name 'CarmJos'
|
|
||||||
git config --global user.email 'carm@carm.cc'
|
|
||||||
|
|
||||||
- name: Commit documentation changes
|
|
||||||
run: |
|
|
||||||
cd docs
|
|
||||||
git init
|
|
||||||
git remote add origin git@github.com:CarmJos/EasyPlugin.git
|
|
||||||
git checkout -b gh-pages
|
|
||||||
git add -A
|
|
||||||
git commit -m "API Document generated."
|
|
||||||
- name: Push javadocs
|
|
||||||
run: |
|
|
||||||
cd docs
|
|
||||||
git push origin HEAD:gh-pages --force
|
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
name: Build
|
name: Project Build & Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
@@ -21,12 +21,11 @@ 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
|
||||||
- name: "Target Stage"
|
env:
|
||||||
run: mkdir staging && cp */target/*.jar staging
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
- name: "Upload artifact"
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
uses: actions/upload-artifact@v2
|
|
||||||
with:
|
|
||||||
name: Artifact
|
|
||||||
path: staging
|
|
||||||
@@ -23,26 +23,30 @@
|
|||||||
- 轻便独立的功能模块,按需使用,避免大量打包!
|
- 轻便独立的功能模块,按需使用,避免大量打包!
|
||||||
- 详细的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)
|
|
||||||
- Common [`easyplugin-common`](easyplugin-common)
|
|
||||||
|
|
||||||
### 主要部分
|
### 集合部分 (`/collection`)
|
||||||
|
|
||||||
- Main [`easyplugin-main`](easyplugin-main)
|
- All [`easyplugin-all`](collection/all)
|
||||||
- Command [`easyplugin-command`](easyplugin-command)
|
- Common [`easyplugin-common`](collection/common)
|
||||||
- Configuration [`easyplugin-configuration`](easyplugin-configuration)
|
|
||||||
- Database [`easyplugin-database`](easyplugin-database)
|
|
||||||
- GUI [`easyplugin-gui`](easyplugin-gui)
|
|
||||||
|
|
||||||
### 附属部分
|
### 主要部分 (`/base`)
|
||||||
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) [`easyplugin-placeholderapi`](easyplugin-placeholderapi)
|
|
||||||
- [Vault](https://github.com/MilkBowl/VaultAPI) [`easyplugin-vault`](easyplugin-vault)
|
- Main [`easyplugin-main`](base/main)
|
||||||
- [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/) [`easyplugin-lp`](easyplugin-lp)
|
- Command [`easyplugin-command`](base/command)
|
||||||
|
- ~~Messages*~~ (已独立项目到 [**EasyMessages**](https://github.com/CarmJos/EasyMessages))
|
||||||
|
- ~~Configuration~~ (已独立项目到 [**MineConfiguration**](https://github.com/CarmJos/MineConfiguration))
|
||||||
|
- ~~Database~~ (已独立项目到 [**EasySQL**](https://github.com/CarmJos/EasySQL))
|
||||||
|
- GUI [`easyplugin-gui`](base/main)
|
||||||
|
|
||||||
|
### 附属部分 (`/extension`)
|
||||||
|
|
||||||
|
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/)* [`easyplugin-placeholderapi`](extension/papi)
|
||||||
|
- [Vault](https://github.com/MilkBowl/VaultAPI)* [`easyplugin-vault`](extension/vault)
|
||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
|
|
||||||
@@ -54,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>
|
||||||
@@ -89,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>
|
||||||
@@ -97,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>
|
||||||
|
|
||||||
## 支持与捐赠
|
## 支持与捐赠
|
||||||
|
|
||||||
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
||||||
@@ -125,8 +167,8 @@
|
|||||||
> - 你可以自由使用,复制,修改,可以用于自己的项目。
|
> - 你可以自由使用,复制,修改,可以用于自己的项目。
|
||||||
> - 可以免费分发或用来盈利。
|
> - 可以免费分发或用来盈利。
|
||||||
> - 唯一的限制是必须包含许可声明。
|
> - 唯一的限制是必须包含许可声明。
|
||||||
>
|
>
|
||||||
> MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。
|
> MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。
|
||||||
>
|
>
|
||||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||||
</details>
|
</details>
|
||||||
@@ -5,18 +5,16 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<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-command</artifactId>
|
<artifactId>easyplugin-command</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
|
||||||
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public abstract class CommandHandler implements TabExecutor, NamedExecutor {
|
||||||
|
|
||||||
|
protected final @NotNull JavaPlugin plugin;
|
||||||
|
protected final @NotNull String cmd;
|
||||||
|
protected final @NotNull List<String> aliases;
|
||||||
|
|
||||||
|
protected final @NotNull Map<String, SubCommand> registeredCommands = new HashMap<>();
|
||||||
|
protected final @NotNull Map<String, CommandHandler> registeredHandlers = new HashMap<>();
|
||||||
|
|
||||||
|
protected final @NotNull Map<String, String> aliasesMap = new HashMap<>();
|
||||||
|
|
||||||
|
public CommandHandler(@NotNull JavaPlugin plugin) {
|
||||||
|
this(plugin, plugin.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandHandler(@NotNull JavaPlugin plugin, @NotNull String cmd) {
|
||||||
|
this(plugin, cmd, new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandHandler(@NotNull JavaPlugin plugin, @NotNull String cmd, @NotNull String... aliases) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.cmd = cmd;
|
||||||
|
this.aliases = Arrays.asList(aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void noArgs(CommandSender sender);
|
||||||
|
|
||||||
|
public abstract void unknownCommand(CommandSender sender, String[] args);
|
||||||
|
|
||||||
|
public abstract void noPermission(CommandSender sender);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull List<String> getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerSubCommand(SubCommand command) {
|
||||||
|
String name = command.getName().toLowerCase();
|
||||||
|
this.registeredCommands.put(name, command);
|
||||||
|
command.getAliases().forEach(alias -> this.aliasesMap.put(alias.toLowerCase(), name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerHandler(CommandHandler handler) {
|
||||||
|
String name = handler.getName().toLowerCase();
|
||||||
|
this.registeredHandlers.put(name, handler);
|
||||||
|
handler.getAliases().forEach(alias -> this.aliasesMap.put(alias.toLowerCase(), name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
this.noArgs(sender);
|
||||||
|
} else {
|
||||||
|
String input = args[0].toLowerCase();
|
||||||
|
|
||||||
|
CommandHandler handler = getHandler(input);
|
||||||
|
if (handler != null) {
|
||||||
|
if (!handler.hasPermission(sender)) {
|
||||||
|
this.noPermission(sender);
|
||||||
|
} else {
|
||||||
|
handler.onCommand(sender, command, label, this.shortenArgs(args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SubCommand subCommand = getSubCommand(input);
|
||||||
|
if (subCommand == null) {
|
||||||
|
this.unknownCommand(sender, args);
|
||||||
|
} else if (!subCommand.hasPermission(sender)) {
|
||||||
|
this.noPermission(sender);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
subCommand.execute(this.plugin, sender, this.shortenArgs(args));
|
||||||
|
} catch (ArrayIndexOutOfBoundsException var9) {
|
||||||
|
this.unknownCommand(sender, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||||
|
if (args.length == 0) return Collections.emptyList();
|
||||||
|
|
||||||
|
String input = args[0].toLowerCase();
|
||||||
|
if (args.length == 1) {
|
||||||
|
return getExecutors().stream()
|
||||||
|
.filter(e -> e.hasPermission(sender))
|
||||||
|
.map(NamedExecutor::getName)
|
||||||
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, input))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} else {
|
||||||
|
|
||||||
|
CommandHandler handler = getHandler(input);
|
||||||
|
if (handler != null && handler.hasPermission(sender)) {
|
||||||
|
return handler.onTabComplete(sender, command, alias, this.shortenArgs(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
SubCommand subCommand = getSubCommand(input);
|
||||||
|
if (subCommand != null && subCommand.hasPermission(sender)) {
|
||||||
|
return subCommand.tabComplete(this.plugin, sender, this.shortenArgs(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<NamedExecutor> getExecutors() {
|
||||||
|
Set<NamedExecutor> executors = new HashSet<>();
|
||||||
|
executors.addAll(this.registeredHandlers.values());
|
||||||
|
executors.addAll(this.registeredCommands.values());
|
||||||
|
List<NamedExecutor> sortedExecutors = new ArrayList<>(executors);
|
||||||
|
sortedExecutors.sort(Comparator.comparing(NamedExecutor::getName));
|
||||||
|
return sortedExecutors;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @Nullable CommandHandler getHandler(@NotNull String name) {
|
||||||
|
CommandHandler fromName = this.registeredHandlers.get(name);
|
||||||
|
if (fromName != null) return fromName;
|
||||||
|
|
||||||
|
String nameFromAlias = this.aliasesMap.get(name);
|
||||||
|
if (nameFromAlias == null) return null;
|
||||||
|
else return this.registeredHandlers.get(nameFromAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @Nullable SubCommand getSubCommand(@NotNull String name) {
|
||||||
|
SubCommand fromName = this.registeredCommands.get(name);
|
||||||
|
if (fromName != null) return fromName;
|
||||||
|
|
||||||
|
String nameFromAlias = this.aliasesMap.get(name);
|
||||||
|
if (nameFromAlias == null) return null;
|
||||||
|
else return this.registeredCommands.get(nameFromAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String[] shortenArgs(String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
return args;
|
||||||
|
} else {
|
||||||
|
List<String> argList = new ArrayList<>(Arrays.asList(args).subList(1, args.length));
|
||||||
|
return argList.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
|
import org.bukkit.permissions.Permissible;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface NamedExecutor {
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
List<String> getAliases();
|
||||||
|
|
||||||
|
default boolean hasPermission(Permissible permissible) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SimpleCompleter {
|
||||||
|
|
||||||
|
public static @NotNull List<String> objects(@NotNull String input, List<?> objects) {
|
||||||
|
return objects(input, objects.size(), objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> objects(@NotNull String input, int limit, List<?> objects) {
|
||||||
|
return objects.stream().filter(Objects::nonNull).map(Object::toString)
|
||||||
|
.filter(s -> StringUtil.startsWithIgnoreCase(s, input))
|
||||||
|
.limit(Math.min(0, limit)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> text(@NotNull String input, String... texts) {
|
||||||
|
return text(input, texts.length, texts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> text(@NotNull String input, int limit, String... texts) {
|
||||||
|
return text(input, limit, Arrays.asList(texts));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> text(@NotNull String input, List<String> texts) {
|
||||||
|
return text(input, texts.size(), texts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> text(@NotNull String input, int limit, List<String> texts) {
|
||||||
|
return objects(input, limit, texts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> onlinePlayers(@NotNull String input) {
|
||||||
|
return onlinePlayers(input, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> onlinePlayers(@NotNull String input, int limit) {
|
||||||
|
return text(input, limit, Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> allPlayers(@NotNull String input) {
|
||||||
|
return allPlayers(input, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> allPlayers(@NotNull String input, int limit) {
|
||||||
|
return text(input, limit, Arrays.stream(Bukkit.getOfflinePlayers()).map(OfflinePlayer::getName).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> worlds(@NotNull String input) {
|
||||||
|
return worlds(input, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> worlds(@NotNull String input, int limit) {
|
||||||
|
return text(input, limit, Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> materials(@NotNull String input) {
|
||||||
|
return materials(input, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> materials(@NotNull String input, int limit) {
|
||||||
|
return text(input, limit, Arrays.stream(Material.values()).map(Enum::name).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> effects(@NotNull String input) {
|
||||||
|
return effects(input, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull List<String> effects(@NotNull String input, int limit) {
|
||||||
|
return text(input, limit, Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
|
public abstract class SubCommand implements NamedExecutor {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final List<String> aliases;
|
||||||
|
|
||||||
|
public SubCommand(String name) {
|
||||||
|
this(name, new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubCommand(String name, String... aliases) {
|
||||||
|
this.name = name;
|
||||||
|
this.aliases = Arrays.asList(aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAliases() {
|
||||||
|
return this.aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Void execute(JavaPlugin plugin, CommandSender sender, String[] args);
|
||||||
|
|
||||||
|
public List<String> tabComplete(JavaPlugin plugin, CommandSender sender, String[] args) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,22 +5,23 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-all</artifactId>
|
<artifactId>easyplugin-gui</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-All</name>
|
<name>EasyPlugin-GUI</name>
|
||||||
<description>轻松插件全集,将打包全部工具类与工具接口。</description>
|
<description>轻松插件GUI接口模块,方便快捷的创建箱子GUI界面。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
@@ -34,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>
|
||||||
|
|
||||||
@@ -50,35 +51,12 @@
|
|||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-common</artifactId>
|
<artifactId>easyplugin-main</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</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>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -99,8 +77,10 @@
|
|||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+16
-11
@@ -16,28 +16,28 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class GUI {
|
public class GUI {
|
||||||
|
|
||||||
private static JavaPlugin plugin;
|
private static JavaPlugin plugin;
|
||||||
private static final HashMap<Player, GUI> openedGUIs = new HashMap<>();
|
private static final HashMap<UUID, GUI> openedGUIs = new HashMap<>();
|
||||||
|
|
||||||
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() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<Player, GUI> getOpenedGUIs() {
|
public static HashMap<UUID, GUI> getOpenedGUIs() {
|
||||||
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;
|
||||||
|
|
||||||
@@ -156,12 +156,17 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void openGUI(Player player) {
|
public void openGUI(Player player) {
|
||||||
if (this.type == GUIType.CANCEL) throw new NullPointerException("被取消或不存在的GUI");
|
if (this.type == GUIType.CANCEL) { throw new IllegalStateException("被取消或不存在的GUI"); }
|
||||||
|
|
||||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
||||||
IntStream.range(0, this.inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
IntStream.range(0, inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
||||||
|
|
||||||
|
GUI previous = getOpenedGUI(player);
|
||||||
|
if(previous != null){
|
||||||
|
previous.listener.close(player);
|
||||||
|
}
|
||||||
|
|
||||||
setOpenedGUI(player, this);
|
setOpenedGUI(player, this);
|
||||||
|
|
||||||
this.inv = inv;
|
this.inv = inv;
|
||||||
@@ -188,19 +193,19 @@ public class GUI {
|
|||||||
|
|
||||||
|
|
||||||
public static void setOpenedGUI(Player player, GUI gui) {
|
public static void setOpenedGUI(Player player, GUI gui) {
|
||||||
getOpenedGUIs().put(player, gui);
|
getOpenedGUIs().put(player.getUniqueId(), gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasOpenedGUI(Player player) {
|
public static boolean hasOpenedGUI(Player player) {
|
||||||
return getOpenedGUIs().containsKey(player);
|
return getOpenedGUIs().containsKey(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GUI getOpenedGUI(Player player) {
|
public static GUI getOpenedGUI(Player player) {
|
||||||
return getOpenedGUIs().get(player);
|
return getOpenedGUIs().get(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeOpenedGUI(Player player) {
|
public static void removeOpenedGUI(Player player) {
|
||||||
getOpenedGUIs().remove(player);
|
getOpenedGUIs().remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+6
-2
@@ -73,11 +73,15 @@ public class GUIListener implements Listener {
|
|||||||
if (!(event.getPlayer() instanceof Player)) return;
|
if (!(event.getPlayer() instanceof Player)) return;
|
||||||
if (!event.getInventory().equals(getCurrentGUI().inv)) return;
|
if (!event.getInventory().equals(getCurrentGUI().inv)) return;
|
||||||
|
|
||||||
|
close((Player) event.getPlayer());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void close(Player p){
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
getCurrentGUI().listener = null;
|
getCurrentGUI().listener = null;
|
||||||
GUI.removeOpenedGUI((Player) event.getPlayer());
|
GUI.removeOpenedGUI(p);
|
||||||
getCurrentGUI().onClose();
|
getCurrentGUI().onClose();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
|
||||||
|
import cc.carm.lib.easyplugin.gui.configuration.GUIConfiguration;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActionReadTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
List<String> actions = Arrays.asList(
|
||||||
|
"[CHAT] 123123",
|
||||||
|
"[SHIFT_LEFT:CHAT] /test qwq",
|
||||||
|
"[CONSOLE] say hello",
|
||||||
|
"[CLOSE]"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (String actionString : actions) {
|
||||||
|
int prefixStart = actionString.indexOf("[");
|
||||||
|
int prefixEnd = actionString.indexOf("]");
|
||||||
|
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||||
|
|
||||||
|
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||||
|
ClickType clickType = null;
|
||||||
|
GUIActionType actionType;
|
||||||
|
if (prefix.contains(":")) {
|
||||||
|
String[] args = prefix.split(":");
|
||||||
|
clickType = GUIConfiguration.readClickType(args[0]);
|
||||||
|
actionType = GUIActionType.readActionType(args[1]);
|
||||||
|
} else {
|
||||||
|
actionType = GUIActionType.readActionType(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionType == null) {
|
||||||
|
System.out.println("# " + actionString);
|
||||||
|
System.out.println("- actionType is Null");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("# " + actionType.name() + " " + (clickType == null ? "" : clickType.name()));
|
||||||
|
System.out.println("- " + actionString.substring(prefixEnd + 1).trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,13 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
<name>EasyPlugin-Main</name>
|
||||||
<description>轻松插件主要接口集,包含方便的插件入口类与相关工具类。</description>
|
<description>轻松插件主要接口模块,包含方便的插件入口类与相关工具类。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
@@ -35,8 +36,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,6 +51,17 @@
|
|||||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.10.9</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package cc.carm.lib.easyplugin;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
|
||||||
|
import cc.carm.lib.easyplugin.utils.JarResourceUtils;
|
||||||
|
import cc.carm.lib.easyplugin.utils.SchedulerUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public abstract class EasyPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
protected EasyPluginMessageProvider messageProvider;
|
||||||
|
|
||||||
|
public EasyPlugin() {
|
||||||
|
this(EasyPluginMessageProvider.ZH_CN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyPlugin(EasyPluginMessageProvider messageProvider) {
|
||||||
|
this.messageProvider = messageProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SchedulerUtils scheduler;
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onLoad() {
|
||||||
|
scheduler = new SchedulerUtils(this);
|
||||||
|
if (!hasOverride("load")) return;
|
||||||
|
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
log(messageProvider.loading(this));
|
||||||
|
load();
|
||||||
|
log(messageProvider.loaded(this, startTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onEnable() {
|
||||||
|
outputInfo();
|
||||||
|
|
||||||
|
log(messageProvider.enabling(this));
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
if (!(this.initialized = initialize())) {
|
||||||
|
setEnabled(false);
|
||||||
|
log(messageProvider.enableFailure(this, startTime));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log(messageProvider.enableSuccess(this, startTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void onDisable() {
|
||||||
|
if (!hasOverride("shutdown") || !isInitialized()) return;
|
||||||
|
outputInfo();
|
||||||
|
|
||||||
|
log(messageProvider.disabling(this));
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
shutdown();
|
||||||
|
log(messageProvider.disabled(this, startTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void load() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract boolean initialize();
|
||||||
|
|
||||||
|
protected void shutdown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写以展示插件的相关信息,如插件横幅、下载地址等。
|
||||||
|
*/
|
||||||
|
public void outputInfo() {
|
||||||
|
Optional.ofNullable(JarResourceUtils.readResource(this.getResource("PLUGIN_INFO"))).ifPresent(this::log);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInitialized() {
|
||||||
|
return initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDebugging() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SchedulerUtils getScheduler() {
|
||||||
|
return scheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerListener(@NotNull Listener... listeners) {
|
||||||
|
Arrays.stream(listeners).forEach(listener -> Bukkit.getPluginManager().registerEvents(listener, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommand(String commandName,
|
||||||
|
@NotNull CommandExecutor executor) {
|
||||||
|
registerCommand(commandName, executor, executor instanceof TabCompleter ? (TabCompleter) executor : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerCommand(String commandName,
|
||||||
|
@NotNull CommandExecutor executor,
|
||||||
|
@Nullable TabCompleter tabCompleter) {
|
||||||
|
PluginCommand command = Bukkit.getPluginCommand(commandName);
|
||||||
|
if (command == null) return;
|
||||||
|
command.setExecutor(executor);
|
||||||
|
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print(@Nullable String prefix, @Nullable String... messages) {
|
||||||
|
messageProvider.print(this, prefix, messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(@Nullable String... messages) {
|
||||||
|
print(null, messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String... messages) {
|
||||||
|
print("&c[ERROR] &r", messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void debug(@Nullable String... messages) {
|
||||||
|
if (isDebugging()) print("&8[DEBUG] &r", messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
|
private boolean hasOverride(String methodName) {
|
||||||
|
Map<Method, Method> methodMap = new HashMap<>();
|
||||||
|
Arrays.stream(EasyPlugin.class.getDeclaredMethods())
|
||||||
|
.filter(method -> method.getName().equals(methodName))
|
||||||
|
.forEach(method -> Arrays.stream(getClass().getDeclaredMethods())
|
||||||
|
.filter(extend -> extend.getName().equals(methodName))
|
||||||
|
.filter(extend -> extend.getReturnType().equals(method.getReturnType()))
|
||||||
|
.filter(extend -> extend.getParameterTypes().length == method.getParameterTypes().length)
|
||||||
|
.findFirst().ifPresent(extendMethod -> methodMap.put(method, extendMethod))
|
||||||
|
);
|
||||||
|
return !methodMap.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package cc.carm.lib.easyplugin.i18n;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public interface EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
EasyPluginMessageProvider ZH_CN = new zh_CN();
|
||||||
|
EasyPluginMessageProvider EN_US = new en_US();
|
||||||
|
|
||||||
|
String loading(Plugin plugin);
|
||||||
|
|
||||||
|
String loaded(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String enabling(Plugin plugin);
|
||||||
|
|
||||||
|
String enableSuccess(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String enableFailure(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String disabling(Plugin plugin);
|
||||||
|
|
||||||
|
String disabled(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
default void print(@NotNull Plugin plugin, @Nullable String prefix, @Nullable String... messages) {
|
||||||
|
Arrays.stream(messages)
|
||||||
|
.map(message -> "[" + plugin.getName() + "] " + (prefix == null ? "" : prefix) + message)
|
||||||
|
.map(ColorParser::parse)
|
||||||
|
.forEach(message -> Bukkit.getConsoleSender().sendMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
class zh_CN implements EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loading(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始加载...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loaded(Plugin plugin, long startMillis) {
|
||||||
|
return "&f加载完成 ,共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始启动...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableSuccess(Plugin plugin, long startMillis) {
|
||||||
|
return "&a启用完成! &f共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableFailure(Plugin plugin, long startMillis) {
|
||||||
|
return "&c启用失败! &f已耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始卸载...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabled(Plugin plugin, long startMillis) {
|
||||||
|
return "&f卸载完成! 共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class en_US implements EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loading(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " loading...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loaded(Plugin plugin, long startMillis) {
|
||||||
|
return "&fLoaded after " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " enabling...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableSuccess(Plugin plugin, long startMillis) {
|
||||||
|
return "&aEnabled successfully!&f Cost " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableFailure(Plugin plugin, long startMillis) {
|
||||||
|
return "&cEnabled failed after " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " begin to shutdown...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabled(Plugin plugin, long startMillis) {
|
||||||
|
return "&fShutdown successfully, cost " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package cc.carm.lib.easyplugin.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class ColorParser {
|
||||||
|
|
||||||
|
public static final Pattern HEX_PATTERN = Pattern.compile("&\\(&?#([0-9a-fA-F]{6})\\)");
|
||||||
|
|
||||||
|
public static String parse(String text) {
|
||||||
|
return parseBaseColor(parseHexColor(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 parseBaseColor(final String text) {
|
||||||
|
return text.replaceAll("&", "§").replace("§§", "&");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String parseHexColor(String text) {
|
||||||
|
Matcher matcher = HEX_PATTERN.matcher(text);
|
||||||
|
while (matcher.find()) {
|
||||||
|
text = matcher.replaceFirst(buildHexColor(matcher.group(1)).toLowerCase());
|
||||||
|
matcher.reset(text);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildHexColor(String hexCode) {
|
||||||
|
return Arrays.stream(hexCode.split(""))
|
||||||
|
.map(s -> '§' + s)
|
||||||
|
.collect(Collectors.joining("", '§' + "x", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package cc.carm.lib.easyplugin.utils;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public class JarResourceUtils {
|
||||||
|
public static final char JAR_SEPARATOR = '/';
|
||||||
|
|
||||||
|
public static @Nullable String[] readResource(@Nullable InputStream resourceStream) {
|
||||||
|
if (resourceStream == null) return null;
|
||||||
|
try (Scanner scanner = new Scanner(resourceStream, "UTF-8")) {
|
||||||
|
List<String> contents = new ArrayList<>();
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
contents.add(scanner.nextLine());
|
||||||
|
}
|
||||||
|
return contents.toArray(new String[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copyFolderFromJar(String folderName, File destFolder, CopyOption option)
|
||||||
|
throws IOException {
|
||||||
|
copyFolderFromJar(folderName, destFolder, option, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copyFolderFromJar(String folderName, File destFolder,
|
||||||
|
CopyOption option, PathTrimmer trimmer) throws IOException {
|
||||||
|
if (!destFolder.exists())
|
||||||
|
destFolder.mkdirs();
|
||||||
|
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
File fullPath;
|
||||||
|
String path = JarResourceUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
|
if (trimmer != null)
|
||||||
|
path = trimmer.trim(path);
|
||||||
|
try {
|
||||||
|
if (!path.startsWith("file"))
|
||||||
|
path = "file://" + path;
|
||||||
|
|
||||||
|
fullPath = new File(new URI(path));
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipInputStream zis = new ZipInputStream(new FileInputStream(fullPath));
|
||||||
|
|
||||||
|
ZipEntry entry;
|
||||||
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
|
if (!entry.getName().startsWith(folderName + JAR_SEPARATOR))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String fileName = entry.getName();
|
||||||
|
|
||||||
|
if (fileName.charAt(fileName.length() - 1) == JAR_SEPARATOR) {
|
||||||
|
File file = new File(destFolder + File.separator + fileName);
|
||||||
|
if (file.isFile()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
file.mkdirs();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(destFolder + File.separator + fileName);
|
||||||
|
if (option == CopyOption.COPY_IF_NOT_EXIST && file.exists())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!file.getParentFile().exists())
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
|
|
||||||
|
if (!file.exists())
|
||||||
|
file.createNewFile();
|
||||||
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
|
||||||
|
int len;
|
||||||
|
while ((len = zis.read(buffer)) > 0) {
|
||||||
|
fos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
zis.closeEntry();
|
||||||
|
zis.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CopyOption {
|
||||||
|
COPY_IF_NOT_EXIST, REPLACE_IF_EXIST
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface PathTrimmer {
|
||||||
|
String trim(String original);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package cc.carm.lib.easyplugin.utils;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class MessageUtils {
|
||||||
|
|
||||||
|
public static boolean hasPlaceholderAPI() {
|
||||||
|
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) {
|
||||||
|
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||||
|
for (String s : messages) {
|
||||||
|
sender.sendMessage(ColorParser.parse(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
||||||
|
sendWithPlaceholders(sender, Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
||||||
|
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||||
|
send(sender, setPlaceholders(sender, messages));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
|
||||||
|
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||||
|
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@Nullable CommandSender sender, @Nullable String message) {
|
||||||
|
if (message == null || sender == null) return message;
|
||||||
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
|
return PlaceholderAPI.setPlaceholders((Player) sender, message);
|
||||||
|
} else {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Contract("_, !null -> !null")
|
||||||
|
public static List<String> setPlaceholders(@Nullable CommandSender sender,
|
||||||
|
@Nullable List<String> messages) {
|
||||||
|
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
||||||
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
|
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
|
||||||
|
} else {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@Nullable CommandSender sender,
|
||||||
|
@NotNull String message,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
|
return setPlaceholders(sender, setCustomParams(message, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> setPlaceholders(@Nullable CommandSender sender,
|
||||||
|
@NotNull List<String> messages,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
|
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String setCustomParams(@NotNull String message,
|
||||||
|
@NotNull String param,
|
||||||
|
@NotNull Object value) {
|
||||||
|
return setCustomParams(message, new String[]{param}, new Object[]{value});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Contract("!null, _, _-> !null ; null, _, _->null ")
|
||||||
|
public static String setCustomParams(@Nullable String message,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
|
if (message == null) return null;
|
||||||
|
if (params == null || values == null) return message;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String setCustomParams(@NotNull String message, @NotNull 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<String> setCustomParams(@NotNull List<String> messages,
|
||||||
|
@NotNull String param,
|
||||||
|
@NotNull Object value) {
|
||||||
|
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<String> setCustomParams(@NotNull List<String> messages,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
|
if (params == null || values == null) return messages;
|
||||||
|
if (params.length != values.length) return messages;
|
||||||
|
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
|
paramsMap.put(params[i], values[i]);
|
||||||
|
}
|
||||||
|
return setCustomParams(messages, paramsMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
||||||
|
return messages.stream()
|
||||||
|
.map(message -> setCustomParams(message, params))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,23 +5,23 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-configuration</artifactId>
|
<artifactId>easyplugin-all</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>EasyPlugin-All</name>
|
||||||
<name>EasyPlugin-Configuration</name>
|
<description>轻松插件全集,将打包全部工具类与工具接口。</description>
|
||||||
<description>轻松插件配置,可以方便快捷的将配置文件作为静态参数使用。</description>
|
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
@@ -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>
|
||||||
|
|
||||||
@@ -51,12 +51,15 @@
|
|||||||
</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>provided</scope>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
<?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.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<artifactId>easyplugin-bom</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<name>EasyPlugin-Bom</name>
|
||||||
|
<description>轻松插件汇总导入模块,允许快捷导入相关的接口并避免版本不一致问题。</description>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>CarmJos</id>
|
||||||
|
<name>Carm Jos</name>
|
||||||
|
<email>carm@carm.cc</email>
|
||||||
|
<url>https://www.carm.cc</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>The MIT License</name>
|
||||||
|
<url>https://opensource.org/licenses/MIT</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub Issues</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<ciManagement>
|
||||||
|
<system>GitHub Actions</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||||
|
</ciManagement>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<downloadUrl>https://github.com/CarmJos/EasyPlugin/releases</downloadUrl>
|
||||||
|
<repository>
|
||||||
|
<id>github</id>
|
||||||
|
<name>GitHub Packages</name>
|
||||||
|
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>carm-repo</id>
|
||||||
|
<name>Carm's Repo</name>
|
||||||
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>central</id>
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>github</id>
|
||||||
|
<name>GitHub Packages</name>
|
||||||
|
<url>https://maven.pkg.github.com/CarmJos/*</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<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>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -5,22 +5,23 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-gui</artifactId>
|
<artifactId>easyplugin-common</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-GUI</name>
|
<name>EasyPlugin-Common</name>
|
||||||
<description>轻松插件界面相关接口,方便快捷的创建箱子GUI界面。</description>
|
<description>轻松插件常用接口集,包含除附属插件模块外的所有模块。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
@@ -34,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>
|
||||||
|
|
||||||
@@ -50,13 +51,35 @@
|
|||||||
</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>provided</scope>
|
<type>pom</type>
|
||||||
|
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-github</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<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>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>1.0.0-SNAPSHOT</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-common</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
|
||||||
<description>轻松插件常用接口集,包含除附属模块外的所有模块。</description>
|
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
|
||||||
|
|
||||||
<developers>
|
|
||||||
<developer>
|
|
||||||
<id>CarmJos</id>
|
|
||||||
<name>Carm Jos</name>
|
|
||||||
<email>carm@carm.cc</email>
|
|
||||||
<url>https://www.carm.cc</url>
|
|
||||||
</developer>
|
|
||||||
</developers>
|
|
||||||
|
|
||||||
<licenses>
|
|
||||||
<license>
|
|
||||||
<name>GNU General Public License v3.0</name>
|
|
||||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
|
||||||
</license>
|
|
||||||
</licenses>
|
|
||||||
|
|
||||||
<issueManagement>
|
|
||||||
<system>GitHub Issues</system>
|
|
||||||
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
|
||||||
</issueManagement>
|
|
||||||
|
|
||||||
<ciManagement>
|
|
||||||
<system>GitHub Actions</system>
|
|
||||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
|
||||||
</ciManagement>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
|
||||||
<artifactId>easyplugin-main</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</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>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
||||||
-91
@@ -1,91 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.file;
|
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public class FileConfig {
|
|
||||||
|
|
||||||
public static Supplier<FileConfig> pluginConfiguration = null;
|
|
||||||
public static Supplier<FileConfig> messageConfiguration = null;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static FileConfig getPluginConfiguration() {
|
|
||||||
return pluginConfiguration == null ? null : pluginConfiguration.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static FileConfig getMessageConfiguration() {
|
|
||||||
return messageConfiguration == null ? null : messageConfiguration.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private long updateTime;
|
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
|
||||||
private final String fileName;
|
|
||||||
|
|
||||||
|
|
||||||
private File file;
|
|
||||||
private FileConfiguration config;
|
|
||||||
|
|
||||||
public FileConfig(final JavaPlugin plugin) {
|
|
||||||
this(plugin, "config.yml");
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileConfig(final JavaPlugin plugin, final String name) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.fileName = name;
|
|
||||||
initFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initFile() {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFile() {
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
try {
|
|
||||||
getConfig().save(getFile());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
if (getFile().exists()) {
|
|
||||||
this.config = YamlConfiguration.loadConfiguration(getFile());
|
|
||||||
} else {
|
|
||||||
initFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getUpdateTime() {
|
|
||||||
return updateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExpired(long time) {
|
|
||||||
return getUpdateTime() > time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-110
@@ -1,110 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
|
||||||
|
|
||||||
public ConfigSound(@NotNull String configSection) {
|
|
||||||
this(configSection, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSound(@NotNull String configSection,
|
|
||||||
@Nullable Sound defaultValue) {
|
|
||||||
this(null, configSection, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection, @Nullable Sound defaultValue) {
|
|
||||||
super(source, configSection, string -> {
|
|
||||||
Sound finalSound = 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) {
|
|
||||||
if (value == null) {
|
|
||||||
set((String) null);
|
|
||||||
} else if (value.pitch != 1) {
|
|
||||||
set(value.type, value.volume, value.pitch);
|
|
||||||
} else if (value.volume != 1) {
|
|
||||||
set(value.type, value.volume);
|
|
||||||
} else {
|
|
||||||
set(value.type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(Sound value) {
|
|
||||||
set(value.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(Sound value, float volume) {
|
|
||||||
set(value.name() + (volume != 1 ? ":" + volume : ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(Sound value, float volume, float pitch) {
|
|
||||||
set(value.name() + ":" + volume + (pitch != 1 ? ":" + pitch : ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void play(Player player) {
|
|
||||||
SoundData data = get();
|
|
||||||
if (data != null) data.play(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SoundData {
|
|
||||||
Sound type;
|
|
||||||
float volume;
|
|
||||||
float pitch;
|
|
||||||
|
|
||||||
public SoundData(Sound type) {
|
|
||||||
this(type, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundData(Sound type, float volume) {
|
|
||||||
this(type, volume, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SoundData(Sound type, float volume, float pitch) {
|
|
||||||
this.type = type;
|
|
||||||
this.volume = volume;
|
|
||||||
this.pitch = pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void play(Player player) {
|
|
||||||
player.playSound(player.getLocation(), type, volume, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.message;
|
|
||||||
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConfigMessage extends ConfigValue<String> {
|
|
||||||
|
|
||||||
String[] messageParams;
|
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection) {
|
|
||||||
this(configSection, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection, @Nullable String defaultValue) {
|
|
||||||
this(configSection, defaultValue, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection, @Nullable String defaultValue, String[] messageParams) {
|
|
||||||
super(null, configSection, String.class, defaultValue);
|
|
||||||
this.messageParams = messageParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigMessage(@Nullable FileConfig config, @NotNull String configSection,
|
|
||||||
@Nullable String defaultValue, String[] messageParams) {
|
|
||||||
super(config, configSection, String.class, defaultValue);
|
|
||||||
this.messageParams = messageParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, Object[] values) {
|
|
||||||
if (messageParams != null) {
|
|
||||||
return get(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
return get(sender, new String[0], new Object[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, String[] params, Object[] values) {
|
|
||||||
List<String> messages = MessageUtils.setPlaceholders(sender, Collections.singletonList(get()), params, values);
|
|
||||||
return messages != null && !messages.isEmpty() ? messages.get(0) : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(CommandSender sender) {
|
|
||||||
MessageUtils.sendWithPlaceholders(sender, get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(CommandSender sender, Object[] values) {
|
|
||||||
if (messageParams != null) {
|
|
||||||
send(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
send(sender, new String[0], new Object[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(CommandSender sender, String[] params, Object[] values) {
|
|
||||||
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-73
@@ -1,73 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.message;
|
|
||||||
|
|
||||||
|
|
||||||
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.command.CommandSender;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConfigMessageList extends ConfigValueList<String> {
|
|
||||||
|
|
||||||
@Nullable String[] messageParams;
|
|
||||||
|
|
||||||
public ConfigMessageList(String configSection) {
|
|
||||||
this(configSection, new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String configSection, @Nullable String[] defaultValue) {
|
|
||||||
this(configSection, defaultValue, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String configSection, @Nullable String[] defaultValue, String[] messageParams) {
|
|
||||||
super(null, configSection, String.class, defaultValue);
|
|
||||||
this.messageParams = messageParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigMessageList(@Nullable FileConfig config, @NotNull String configSection,
|
|
||||||
@Nullable String[] defaultValue, String[] messageParams) {
|
|
||||||
super(config, configSection, String.class, defaultValue);
|
|
||||||
this.messageParams = messageParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender) {
|
|
||||||
return MessageUtils.setPlaceholders(sender, get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender, Object[] values) {
|
|
||||||
if (messageParams != null) {
|
|
||||||
return get(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
return get(sender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
|
||||||
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender) {
|
|
||||||
MessageUtils.sendWithPlaceholders(sender, get());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender, Object[] values) {
|
|
||||||
if (messageParams != null) {
|
|
||||||
send(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
send(sender);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender, String[] params, Object[] values) {
|
|
||||||
MessageUtils.sendWithPlaceholders(sender, get(), params, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-64
@@ -1,64 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class ConfigValue<V> {
|
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
|
||||||
|
|
||||||
private final @NotNull String configSection;
|
|
||||||
private final @NotNull Class<V> clazz;
|
|
||||||
@Nullable V defaultValue;
|
|
||||||
|
|
||||||
public ConfigValue(@NotNull String configSection, @NotNull Class<V> clazz) {
|
|
||||||
this(configSection, clazz, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigValue(@NotNull String configSection, @NotNull Class<V> clazz, @Nullable V defaultValue) {
|
|
||||||
this(null, configSection, clazz, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigValue(@Nullable FileConfig source, @NotNull String configSection,
|
|
||||||
@NotNull Class<V> clazz, @Nullable V defaultValue) {
|
|
||||||
this.source = source;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.clazz = clazz;
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public V get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return this.defaultValue;
|
|
||||||
|
|
||||||
if (source.getConfig().contains(this.configSection)) {
|
|
||||||
Object val = source.getConfig().get(this.configSection, this.defaultValue);
|
|
||||||
return this.clazz.isInstance(val) ? this.clazz.cast(val) : this.defaultValue;
|
|
||||||
} else {
|
|
||||||
// 如果没有默认值,就把配置写进去,便于配置
|
|
||||||
return setDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(@Nullable V value) {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return;
|
|
||||||
|
|
||||||
source.getConfig().set(this.configSection, value);
|
|
||||||
source.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public V setDefault() {
|
|
||||||
set(this.defaultValue);
|
|
||||||
return this.defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-79
@@ -1,79 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
|
||||||
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConfigValueList<V> {
|
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
|
||||||
|
|
||||||
private final @NotNull String configSection;
|
|
||||||
private final @NotNull Class<V> clazz;
|
|
||||||
|
|
||||||
@Nullable V[] defaultValue;
|
|
||||||
|
|
||||||
public ConfigValueList(@NotNull String configSection, @NotNull Class<V> clazz) {
|
|
||||||
this(configSection, clazz, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigValueList(@NotNull String configSection, @NotNull Class<V> clazz, @Nullable V[] defaultValue) {
|
|
||||||
this(null, configSection, clazz, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String configSection, Class<V> clazz) {
|
|
||||||
this(configuration, configSection, clazz, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String configSection,
|
|
||||||
@NotNull Class<V> clazz, @Nullable V[] defaultValue) {
|
|
||||||
this.source = configuration;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.clazz = clazz;
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NotNull ArrayList<V> get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return new ArrayList<>();
|
|
||||||
|
|
||||||
List<?> list = source.getConfig().getList(this.configSection);
|
|
||||||
if (list == null) {
|
|
||||||
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) {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-88
@@ -1,88 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
|
||||||
|
|
||||||
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.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ConfigValueMap<K, V> {
|
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
|
|
||||||
@NotNull Function<String, K> keyCast;
|
|
||||||
@NotNull Class<V> valueClazz;
|
|
||||||
|
|
||||||
@Nullable LinkedHashMap<K, V> valueCache;
|
|
||||||
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigValueMap(@NotNull String configSection, @NotNull Function<String, K> keyCast,
|
|
||||||
@NotNull Class<V> valueClazz) {
|
|
||||||
this(null, configSection, keyCast, valueClazz);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigValueMap(@Nullable FileConfig configuration, @NotNull String configSection,
|
|
||||||
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
|
||||||
this.source = configuration;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.keyCast = keyCast;
|
|
||||||
this.valueClazz = valueClazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearCache() {
|
|
||||||
this.valueCache = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Map<K, V> get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return new HashMap<>();
|
|
||||||
|
|
||||||
if (valueCache != null && !getSource().isExpired(this.updateTime)) return valueCache;
|
|
||||||
|
|
||||||
ConfigurationSection section = source.getConfig().getConfigurationSection(this.configSection);
|
|
||||||
if (section == null) return new LinkedHashMap<>();
|
|
||||||
|
|
||||||
Set<String> keys = 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);
|
|
||||||
Object val = section.get(key);
|
|
||||||
V finalValue = this.valueClazz.isInstance(val) ? this.valueClazz.cast(val) : null;
|
|
||||||
if (finalKey != null && finalValue != null) {
|
|
||||||
result.put(finalKey, finalValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
this.valueCache = result;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(@Nullable HashMap<K, V> valuesMap) {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>1.0.0-SNAPSHOT</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-database</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>EasySQL</id>
|
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<artifactId>easysql-beecp</artifactId>
|
|
||||||
<version>0.2.3</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
|
||||||
<groupId>cc.carm.lib</groupId>
|
|
||||||
<version>1.0.0-SNAPSHOT</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-lp</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
|
||||||
import cc.carm.lib.easyplugin.utils.SchedulerUtils;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public abstract class EasyPlugin extends JavaPlugin {
|
|
||||||
|
|
||||||
|
|
||||||
private SchedulerUtils scheduler;
|
|
||||||
private boolean initialized = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoad() {
|
|
||||||
scheduler = new SchedulerUtils(this);
|
|
||||||
|
|
||||||
if (!isOverride("load")) return;
|
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
load();
|
|
||||||
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始启动...");
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
this.initialized = initialize();
|
|
||||||
|
|
||||||
if (!isInitialized()) {
|
|
||||||
setEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log("启用完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
if (!isOverride("shutdown")) return;
|
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
shutdown();
|
|
||||||
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean initialize();
|
|
||||||
|
|
||||||
public void shutdown() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInitialized() {
|
|
||||||
return initialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDebugging() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SchedulerUtils getScheduler() {
|
|
||||||
return scheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void regListener(@NotNull Listener... listeners) {
|
|
||||||
Arrays.stream(listeners).forEach(listener -> Bukkit.getPluginManager().registerEvents(listener, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerCommand(String commandName,
|
|
||||||
@NotNull CommandExecutor executor) {
|
|
||||||
registerCommand(commandName, executor, executor instanceof TabCompleter ? (TabCompleter) executor : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerCommand(String commandName,
|
|
||||||
@NotNull CommandExecutor executor,
|
|
||||||
@Nullable TabCompleter tabCompleter) {
|
|
||||||
PluginCommand command = Bukkit.getPluginCommand(commandName);
|
|
||||||
if (command == null) return;
|
|
||||||
command.setExecutor(executor);
|
|
||||||
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void log(@Nullable String... messages) {
|
|
||||||
print(null, messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void print(@Nullable String prefix, @Nullable String... messages) {
|
|
||||||
Arrays.stream(messages)
|
|
||||||
.map(message -> "[" + getName() + "] " + (prefix == null ? "" : prefix) + message)
|
|
||||||
.map(ColorParser::parse)
|
|
||||||
.forEach(message -> Bukkit.getConsoleSender().sendMessage(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String... messages) {
|
|
||||||
print("&c[ERROR] &r", messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void debug(@Nullable String... messages) {
|
|
||||||
if (isDebugging()) print("&7[DEBUG] &r", messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private boolean isOverride(String methodName) {
|
|
||||||
Map<Method, Method> methodMap = new HashMap<>();
|
|
||||||
Arrays.stream(EasyPlugin.class.getDeclaredMethods())
|
|
||||||
.filter(method -> method.getName().equals(methodName))
|
|
||||||
.forEach(method -> Arrays.stream(getClass().getDeclaredMethods())
|
|
||||||
.filter(extend -> extend.getName().equals(methodName))
|
|
||||||
.filter(extend -> extend.getReturnType().equals(method.getReturnType()))
|
|
||||||
.filter(extend -> extend.getParameterTypes().length == method.getParameterTypes().length)
|
|
||||||
.findFirst().ifPresent(extendMethod -> methodMap.put(method, extendMethod))
|
|
||||||
);
|
|
||||||
return !methodMap.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
|
|
||||||
package cc.carm.lib.easyplugin.utils;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ColorParser {
|
|
||||||
|
|
||||||
public static String parse(String text) {
|
|
||||||
text = parseHexColor(text);
|
|
||||||
return parseColor(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String parseColor(final String text) {
|
|
||||||
return text.replaceAll("&", "§").replace("§§", "&");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String parseHexColor(String text) {
|
|
||||||
Pattern pattern = Pattern.compile("&\\((&?#[0-9a-fA-F]{6})\\)");
|
|
||||||
Matcher matcher = pattern.matcher(text);
|
|
||||||
while (matcher.find()) {
|
|
||||||
String hexColor = text.substring(matcher.start() + 2, matcher.end() - 1);
|
|
||||||
hexColor = hexColor.replace("&", "");
|
|
||||||
StringBuilder bukkitColorCode = new StringBuilder('§' + "x");
|
|
||||||
for (int i = 1; i < hexColor.length(); i++) {
|
|
||||||
bukkitColorCode.append('§').append(hexColor.charAt(i));
|
|
||||||
}
|
|
||||||
text = text.replaceAll("&\\(" + hexColor + "\\)", bukkitColorCode.toString().toLowerCase());
|
|
||||||
matcher.reset(text);
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.utils;
|
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class MessageUtils {
|
|
||||||
|
|
||||||
public static boolean hasPlaceholderAPI() {
|
|
||||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
|
||||||
for (String s : messages) {
|
|
||||||
sender.sendMessage(ColorParser.parse(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, String... messages) {
|
|
||||||
send(sender, Arrays.asList(messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
|
||||||
sendWithPlaceholders(sender, Arrays.asList(messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
|
||||||
send(sender, setPlaceholders(sender, messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String param, Object value) {
|
|
||||||
sendWithPlaceholders(sender, messages, new String[]{param}, new Object[]{value});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendWithPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
|
||||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
|
||||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
|
||||||
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
|
|
||||||
} else {
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
|
||||||
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
|
||||||
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
|
|
||||||
if (params.length != values.length) return messages;
|
|
||||||
HashMap<String, Object> paramsMap = new HashMap<>();
|
|
||||||
for (int i = 0; i < params.length; i++) {
|
|
||||||
paramsMap.put(params[i], values[i]);
|
|
||||||
}
|
|
||||||
return setCustomParams(messages, paramsMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
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,18 +5,21 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>EasyPlugin-PlaceholderAPI</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,13 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -19,6 +20,8 @@
|
|||||||
<artifactId>easyplugin-vault</artifactId>
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>EasyPlugin-Vault</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -5,8 +5,9 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<project.jdk.version>8</project.jdk.version>
|
||||||
<maven.compiler.target>11</maven.compiler.target>
|
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||||
|
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
@@ -14,21 +15,20 @@
|
|||||||
<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.0.0-SNAPSHOT</version>
|
<version>1.4.2</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>easyplugin-main</module>
|
|
||||||
|
|
||||||
<module>easyplugin-database</module>
|
<module>base/main</module>
|
||||||
<module>easyplugin-gui</module>
|
<module>base/command</module>
|
||||||
<module>easyplugin-configuration</module>
|
<module>base/gui</module>
|
||||||
<module>easyplugin-command</module>
|
|
||||||
|
|
||||||
<module>easyplugin-vault</module>
|
<module>extension/papi</module>
|
||||||
<module>easyplugin-placeholderapi</module>
|
<module>extension/vault</module>
|
||||||
|
|
||||||
|
<module>collection/all</module>
|
||||||
|
<module>collection/bom</module>
|
||||||
|
<module>collection/common</module>
|
||||||
|
|
||||||
<module>easyplugin-all</module>
|
|
||||||
<module>easyplugin-common</module>
|
|
||||||
<module>easyplugin-lp</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>EasyPlugin</name>
|
<name>EasyPlugin</name>
|
||||||
@@ -46,8 +46,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,14 +73,18 @@
|
|||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>github</id>
|
<id>central</id>
|
||||||
<name>GitHub Packages</name>
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>sonatype</id>
|
||||||
<url>https://repo1.maven.org/maven2/</url>
|
<url>https://oss.sonatype.org/content/groups/public</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
@@ -89,40 +93,21 @@
|
|||||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>nexus</id>
|
|
||||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.spigotmc</groupId>
|
|
||||||
<artifactId>spigot-api</artifactId>
|
|
||||||
<version>1.13-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</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>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>me.clip</groupId>
|
|
||||||
<artifactId>placeholderapi</artifactId>
|
|
||||||
<version>2.10.9</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>22.0.0</version>
|
<version>23.0.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -154,9 +139,6 @@
|
|||||||
<version>3.2.0</version>
|
<version>3.2.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<links>
|
|
||||||
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
|
|
||||||
</links>
|
|
||||||
<detectJavaApiLink>false</detectJavaApiLink>
|
<detectJavaApiLink>false</detectJavaApiLink>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
|
|||||||
Reference in New Issue
Block a user