mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 09:01:47 +08:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
@@ -0,0 +1,40 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>EasyPlugin Javadocs</title>
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
width: 60%;
|
||||||
|
margin: 10% auto 0;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
padding: 2% 5%;
|
||||||
|
border-radius: 10px
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul li {
|
||||||
|
line-height: 2.3
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #7531c4
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>EasyPlugin Javadocs</h1>
|
||||||
|
<ul>
|
||||||
|
<li><a href="main">EasyPlugin-Main</a></li>
|
||||||
|
<li><a href="command">EasyPlugin-Command</a></li>
|
||||||
|
<li><a href="configuration">EasyPlugin-Configuration</a></li>
|
||||||
|
<li><a href="gui">EasyPlugin-GUI</a></li>
|
||||||
|
<li><a href="database">EasyPlugin-Database</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#github: [ CarmJos ]
|
||||||
|
custom: [ 'https://donate.carm.cc' ]
|
||||||
@@ -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
|
||||||
|
|
||||||
@@ -26,8 +26,53 @@ jobs:
|
|||||||
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}}
|
||||||
|
|
||||||
|
- name: "Copy Javadoc"
|
||||||
|
run: |
|
||||||
|
bash .scripts/copy-javadoc.sh
|
||||||
|
|
||||||
|
- 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,77 +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
|
|
||||||
env:
|
|
||||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
|
||||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
||||||
|
|
||||||
- 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:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
rm -rf docs
|
||||||
|
mkdir -vp docs
|
||||||
|
|
||||||
|
DOC_URL="target/apidocs"
|
||||||
|
|
||||||
|
for FILE in easyplugin-*; do
|
||||||
|
|
||||||
|
if test -e "$FILE/$DOC_URL"; then
|
||||||
|
|
||||||
|
MODULE_FILE="docs/${FILE:11}/"
|
||||||
|
|
||||||
|
mkdir -vp "$MODULE_FILE"
|
||||||
|
|
||||||
|
cp -vrf "$FILE"/"$DOC_URL"/* "$MODULE_FILE"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
|
||||||
|
cp -vrf .documentation/javadoc/index.html docs/index.html
|
||||||
+1
-23
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -61,26 +61,4 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+68
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -23,6 +23,65 @@
|
|||||||
<description>轻松插件汇总导入模块,允许快捷导入相关的接口并避免版本不一致问题。</description>
|
<description>轻松插件汇总导入模块,允许快捷导入相关的接口并避免版本不一致问题。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<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>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -72,36 +131,43 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-main</artifactId>
|
<artifactId>easyplugin-main</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-configuration</artifactId>
|
<artifactId>easyplugin-configuration</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-database</artifactId>
|
<artifactId>easyplugin-database</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-gui</artifactId>
|
<artifactId>easyplugin-gui</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-command</artifactId>
|
<artifactId>easyplugin-command</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-vault</artifactId>
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>${project.parent.groupId}</groupId>
|
<groupId>${project.parent.groupId}</groupId>
|
||||||
<artifactId>easyplugin-lp</artifactId>
|
<artifactId>easyplugin-lp</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package cc.carm.lib.easyplugin.command;
|
||||||
|
|
||||||
|
public class CommandsManager {
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -59,6 +59,10 @@
|
|||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
|
|
||||||
<exclusions>
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-github</artifactId>
|
||||||
|
</exclusion>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
@@ -77,26 +81,4 @@
|
|||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
+9
-3
@@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigSectionCast<V> extends FileConfigCachedValue<V> {
|
public class ConfigSectionCast<V> extends FileConfigCachedValue<V> {
|
||||||
|
|
||||||
@@ -22,13 +23,19 @@ public class ConfigSectionCast<V> extends FileConfigCachedValue<V> {
|
|||||||
public ConfigSectionCast(@NotNull String sectionName,
|
public ConfigSectionCast(@NotNull String sectionName,
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
@Nullable V defaultValue) {
|
@Nullable V defaultValue) {
|
||||||
this(null, sectionName, valueCast, defaultValue);
|
this((Supplier<FileConfig>) null, sectionName, valueCast, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigSectionCast(@Nullable FileConfig source, @NotNull String sectionName,
|
public ConfigSectionCast(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
@Nullable V defaultValue) {
|
@Nullable V defaultValue) {
|
||||||
super(source, sectionName);
|
this(source == null ? null : () -> source, sectionName, valueCast, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigSectionCast(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(provider, sectionName);
|
||||||
this.valueCast = valueCast;
|
this.valueCast = valueCast;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
@@ -51,7 +58,6 @@ public class ConfigSectionCast<V> extends FileConfigCachedValue<V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void set(ConfigurationSection section) {
|
public void set(ConfigurationSection section) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigStringCast<V> extends FileConfigCachedValue<V> {
|
public class ConfigStringCast<V> extends FileConfigCachedValue<V> {
|
||||||
|
|
||||||
@@ -21,13 +22,19 @@ public class ConfigStringCast<V> extends FileConfigCachedValue<V> {
|
|||||||
public ConfigStringCast(@NotNull String configSection,
|
public ConfigStringCast(@NotNull String configSection,
|
||||||
@NotNull Function<String, V> valueCast,
|
@NotNull Function<String, V> valueCast,
|
||||||
@Nullable V defaultValue) {
|
@Nullable V defaultValue) {
|
||||||
this(null, configSection, valueCast, defaultValue);
|
this((Supplier<FileConfig>) null, configSection, valueCast, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigStringCast(@Nullable FileConfig source, @NotNull String sectionName,
|
public ConfigStringCast(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Function<String, V> valueCast,
|
@NotNull Function<String, V> valueCast,
|
||||||
@Nullable V defaultValue) {
|
@Nullable V defaultValue) {
|
||||||
super(source, sectionName);
|
this(source == null ? null : () -> source, sectionName, valueCast, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigStringCast(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName,
|
||||||
|
@NotNull Function<String, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(provider, sectionName);
|
||||||
this.valueCast = valueCast;
|
this.valueCast = valueCast;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-9
@@ -27,15 +27,15 @@ public class FileConfig {
|
|||||||
return messageConfiguration == null ? null : messageConfiguration.get();
|
return messageConfiguration == null ? null : messageConfiguration.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private long updateTime;
|
protected long updateTime;
|
||||||
|
|
||||||
private final JavaPlugin plugin;
|
protected final JavaPlugin plugin;
|
||||||
private final File fileFolder;
|
protected final File fileFolder;
|
||||||
private final String fileName;
|
protected final String fileName;
|
||||||
private final String resourcePath;
|
protected final String resourcePath;
|
||||||
|
|
||||||
private File file;
|
protected File file;
|
||||||
private FileConfiguration config;
|
protected FileConfiguration config;
|
||||||
|
|
||||||
public FileConfig(@NotNull JavaPlugin plugin) throws IOException {
|
public FileConfig(@NotNull JavaPlugin plugin) throws IOException {
|
||||||
this(plugin, "config.yml");
|
this(plugin, "config.yml");
|
||||||
@@ -57,11 +57,10 @@ public class FileConfig {
|
|||||||
this.resourcePath = resourcePath;
|
this.resourcePath = resourcePath;
|
||||||
this.fileFolder = fileFolder;
|
this.fileFolder = fileFolder;
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
|
||||||
initFile();
|
initFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFile() throws IOException {
|
protected void initFile() throws IOException {
|
||||||
if (!getFileFolder().exists()) getFileFolder().mkdirs();
|
if (!getFileFolder().exists()) getFileFolder().mkdirs();
|
||||||
this.file = new File(getFileFolder(), fileName);
|
this.file = new File(getFileFolder(), fileName);
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -3,6 +3,8 @@ package cc.carm.lib.easyplugin.configuration.file;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public abstract class FileConfigCachedValue<V> extends FileConfigValue {
|
public abstract class FileConfigCachedValue<V> extends FileConfigValue {
|
||||||
|
|
||||||
protected V cachedValue;
|
protected V cachedValue;
|
||||||
@@ -12,8 +14,8 @@ public abstract class FileConfigCachedValue<V> extends FileConfigValue {
|
|||||||
super(sectionName);
|
super(sectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfigCachedValue(@Nullable FileConfig source, @NotNull String sectionName) {
|
public FileConfigCachedValue(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName) {
|
||||||
super(source, sectionName);
|
super(provider, sectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public V updateCache(V value) {
|
public V updateCache(V value) {
|
||||||
|
|||||||
+9
-4
@@ -6,18 +6,19 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public abstract class FileConfigValue {
|
public abstract class FileConfigValue {
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
protected @Nullable Supplier<FileConfig> provider;
|
||||||
private final @NotNull String sectionName;
|
private final @NotNull String sectionName;
|
||||||
|
|
||||||
public FileConfigValue(@NotNull String sectionName) {
|
public FileConfigValue(@NotNull String sectionName) {
|
||||||
this(null, sectionName);
|
this(null, sectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileConfigValue(@Nullable FileConfig source, @NotNull String sectionName) {
|
public FileConfigValue(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName) {
|
||||||
this.source = source;
|
this.provider = provider;
|
||||||
this.sectionName = sectionName;
|
this.sectionName = sectionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ public abstract class FileConfigValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
public @Nullable FileConfig getSource() {
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
return provider == null || provider.get() == null ? defaultSource() : provider.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<FileConfig> getSourceOptional() {
|
public Optional<FileConfig> getSourceOptional() {
|
||||||
@@ -71,4 +72,8 @@ public abstract class FileConfigValue {
|
|||||||
return clazz.isInstance(val) ? clazz.cast(val) : defaultValue;
|
return clazz.isInstance(val) ? clazz.cast(val) : defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FileConfig defaultSource() {
|
||||||
|
return FileConfig.getPluginConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.impl;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.cast.ConfigSectionCast;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ItemStackFactory;
|
||||||
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public class ConfigItem extends ConfigSectionCast<ConfigItem.ItemConfiguration> {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String[] itemParams;
|
||||||
|
|
||||||
|
public ConfigItem(@NotNull String configSection) {
|
||||||
|
this(configSection, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigItem(@NotNull String configSection,
|
||||||
|
@Nullable String[] itemParams) {
|
||||||
|
this(configSection, itemParams, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigItem(@NotNull String configSection,
|
||||||
|
@Nullable ItemConfiguration defaultValue) {
|
||||||
|
this(configSection, null, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigItem(@NotNull String sectionName,
|
||||||
|
@Nullable String[] itemParams,
|
||||||
|
@Nullable ItemConfiguration defaultValue) {
|
||||||
|
this(null, sectionName, itemParams, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigItem(@Nullable Supplier<FileConfig> provider,
|
||||||
|
@NotNull String sectionName,
|
||||||
|
@Nullable String[] itemParams,
|
||||||
|
@Nullable ItemConfiguration defaultValue) {
|
||||||
|
this(provider, sectionName, ConfigItem::parseItemConfiguration, itemParams, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigItem(@Nullable Supplier<FileConfig> provider,
|
||||||
|
@NotNull String sectionName,
|
||||||
|
@NotNull Function<ConfigurationSection, ItemConfiguration> valueCast,
|
||||||
|
@Nullable String[] itemParams,
|
||||||
|
@Nullable ItemConfiguration defaultValue) {
|
||||||
|
super(provider, sectionName, valueCast, defaultValue);
|
||||||
|
this.itemParams = itemParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItem(@NotNull Player player) {
|
||||||
|
return getItem(player, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItem(@NotNull Player player,
|
||||||
|
@Nullable Object[] values) {
|
||||||
|
if (values != null && itemParams != null && itemParams.length > 0) {
|
||||||
|
return getItem(player, itemParams, values);
|
||||||
|
} else {
|
||||||
|
return getItem(player, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItem(@NotNull Player player,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
|
params = params == null ? new String[0] : params;
|
||||||
|
values = values == null ? new Object[0] : values;
|
||||||
|
|
||||||
|
ItemConfiguration configuration = get();
|
||||||
|
if (configuration == null) return null;
|
||||||
|
|
||||||
|
ItemStackFactory factory = new ItemStackFactory(configuration.getType());
|
||||||
|
if (configuration.getName() != null) {
|
||||||
|
factory.setDisplayName(MessageUtils.setCustomParams(configuration.getName(), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configuration.getLore() != null) {
|
||||||
|
factory.setLore(MessageUtils.setCustomParams(configuration.getLore(), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
return factory.toItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ItemConfiguration {
|
||||||
|
|
||||||
|
@NotNull Material type;
|
||||||
|
@Nullable String name;
|
||||||
|
@Nullable List<String> lore;
|
||||||
|
|
||||||
|
public ItemConfiguration(@NotNull Material type, @Nullable String name, @Nullable List<String> lore) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
this.lore = lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @NotNull Material getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @Nullable List<String> getLore() {
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemConfiguration readFrom(@NotNull ConfigurationSection section) {
|
||||||
|
String typeName = section.getString("type");
|
||||||
|
if (typeName == null) return null;
|
||||||
|
Material type = Material.matchMaterial(typeName);
|
||||||
|
if (type == null) return null;
|
||||||
|
String name = section.getString("name");
|
||||||
|
List<String> lore = section.getStringList("lore");
|
||||||
|
return new ItemConfiguration(type, name, lore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemConfiguration parseItemConfiguration(@NotNull ConfigurationSection section) {
|
||||||
|
return ItemConfiguration.readFrom(section);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static ItemConfiguration create(@NotNull Material type) {
|
||||||
|
return create(type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static ItemConfiguration create(@NotNull Material type,
|
||||||
|
@Nullable String name) {
|
||||||
|
return create(type, name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static ItemConfiguration create(@NotNull Material type,
|
||||||
|
@Nullable String name,
|
||||||
|
@Nullable String[] lore) {
|
||||||
|
return new ItemConfiguration(type, name, lore == null ? null : Arrays.asList(lore));
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-2
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
||||||
|
|
||||||
@@ -18,12 +19,20 @@ public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
|||||||
|
|
||||||
public ConfigSound(@NotNull String configSection,
|
public ConfigSound(@NotNull String configSection,
|
||||||
@Nullable Sound defaultValue) {
|
@Nullable Sound defaultValue) {
|
||||||
this(null, configSection, defaultValue);
|
this((Supplier<FileConfig>) null, configSection, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection,
|
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection,
|
||||||
@Nullable Sound defaultValue) {
|
@Nullable Sound defaultValue) {
|
||||||
super(source, configSection, getSoundParser(), defaultValue == null ? null : new SoundData(defaultValue));
|
this(source == null ? null : () -> source, configSection, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigSound(@Nullable Supplier<FileConfig> provider, @NotNull String configSection,
|
||||||
|
@Nullable Sound defaultValue) {
|
||||||
|
super(provider, configSection,
|
||||||
|
getSoundParser(),
|
||||||
|
defaultValue == null ? null : new SoundData(defaultValue)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable SoundData value) {
|
public void set(@Nullable SoundData value) {
|
||||||
|
|||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class EasyMessage {
|
||||||
|
|
||||||
|
@Nullable ConfigValue<String> configValue;
|
||||||
|
|
||||||
|
@Nullable String defaultValue;
|
||||||
|
@Nullable String[] messageParams;
|
||||||
|
|
||||||
|
public EasyMessage() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessage(@Nullable String defaultValue) {
|
||||||
|
this(defaultValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessage(@Nullable String defaultValue, @Nullable String[] messageParams) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
this.messageParams = messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(@NotNull FileConfig source, @NotNull String sectionName) {
|
||||||
|
this.configValue = new ConfigValue<>(() -> source, sectionName, String.class, getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String[] getMessageParams() {
|
||||||
|
return messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull String getDefaultMessages() {
|
||||||
|
if (getDefaultValue() == null) return "";
|
||||||
|
else return getDefaultValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull String getMessages() {
|
||||||
|
if (configValue == null) {
|
||||||
|
return getDefaultMessages();
|
||||||
|
} else {
|
||||||
|
return configValue.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(@Nullable CommandSender sender) {
|
||||||
|
return get(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
return get(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
String messages = getMessages();
|
||||||
|
if (sender == null || messages.length() < 1) return messages;
|
||||||
|
params = params == null ? new String[0] : params;
|
||||||
|
values = values == null ? new Object[0] : values;
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(sender, messages, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender) {
|
||||||
|
send(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
send(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
String message = get(sender, params, values);
|
||||||
|
if (message.length() < 1) return;
|
||||||
|
MessageUtils.send(sender, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBar(@Nullable Player player) {
|
||||||
|
sendBar(player, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBar(@Nullable Player player, @Nullable Object[] values) {
|
||||||
|
sendBar(player, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBar(@Nullable Player player, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (player == null) return;
|
||||||
|
String message = get(player, params, values);
|
||||||
|
|
||||||
|
if (message.length() < 1) return;
|
||||||
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(get(player, params, values)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
sendToAll(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable Object[] values) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+108
@@ -0,0 +1,108 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.annotations.Unmodifiable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EasyMessageList {
|
||||||
|
|
||||||
|
@Nullable ConfigValueList<String> configValue;
|
||||||
|
|
||||||
|
@Nullable String[] defaultValue;
|
||||||
|
@Nullable String[] messageParams;
|
||||||
|
|
||||||
|
public EasyMessageList() {
|
||||||
|
this((String[]) null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessageList(@Nullable String... defaultValue) {
|
||||||
|
this(defaultValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyMessageList(@Nullable String[] defaultValue,
|
||||||
|
@Nullable String[] messageParams) {
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
this.messageParams = messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(FileConfig sourceConfig, String sectionName) {
|
||||||
|
configValue = new ConfigValueList<>(() -> sourceConfig, sectionName, String.class, getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String[] getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unmodifiable
|
||||||
|
private @NotNull List<String> getDefaultMessages() {
|
||||||
|
if (getDefaultValue() == null) return new ArrayList<>();
|
||||||
|
else return Arrays.asList(getDefaultValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable String[] getMessageParams() {
|
||||||
|
return messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @NotNull List<String> getMessages() {
|
||||||
|
if (configValue == null) {
|
||||||
|
return getDefaultMessages();
|
||||||
|
} else {
|
||||||
|
return configValue.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> get(@Nullable CommandSender sender) {
|
||||||
|
return get(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
return get(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (sender == null) return getMessages();
|
||||||
|
params = params == null ? new String[0] : params;
|
||||||
|
values = values == null ? new Object[0] : values;
|
||||||
|
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(sender, getMessages(), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender) {
|
||||||
|
send(sender, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
send(sender, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
List<String> messages = get(sender, params, values);
|
||||||
|
if (messages.isEmpty()) return;
|
||||||
|
if (messages.size() == 1 && messages.get(0).length() == 0) return; //空消息不再发送
|
||||||
|
MessageUtils.send(sender, messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
sendToAll(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable Object[] values) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
|
public class MessagesConfig extends FileConfig {
|
||||||
|
|
||||||
|
public MessagesConfig(@NotNull JavaPlugin plugin) throws IOException {
|
||||||
|
this(plugin, "messages.yml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagesConfig(@NotNull JavaPlugin plugin, @NotNull String fileName) throws IOException {
|
||||||
|
this(plugin, plugin.getDataFolder(), fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessagesConfig(@NotNull JavaPlugin plugin, @NotNull File fileFolder, @NotNull String fileName) throws IOException {
|
||||||
|
super(plugin, fileName, fileFolder, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initFile() throws IOException {
|
||||||
|
if (!getFileFolder().exists()) getFileFolder().mkdirs();
|
||||||
|
this.file = new File(getFileFolder(), fileName);
|
||||||
|
if (!file.exists()) file.createNewFile();
|
||||||
|
this.config = YamlConfiguration.loadConfiguration(this.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save() throws IOException {
|
||||||
|
getConfig().save(getFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MessagesInitializer {
|
||||||
|
|
||||||
|
private MessagesInitializer() {
|
||||||
|
// 静态方法类,不应当实例化。
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initialize(FileConfig source, Class<? extends MessagesRoot> rootClazz) {
|
||||||
|
initialize(source, rootClazz, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initialize(FileConfig source, Class<? extends MessagesRoot> rootClazz, boolean saveDefault) {
|
||||||
|
MessagesSection sectionAnnotation = rootClazz.getAnnotation(MessagesSection.class);
|
||||||
|
|
||||||
|
String rootSection = null;
|
||||||
|
if (sectionAnnotation != null && sectionAnnotation.value().length() > 1) {
|
||||||
|
rootSection = sectionAnnotation.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Class<?> innerClass : rootClazz.getDeclaredClasses()) {
|
||||||
|
initSection(source, rootSection, innerClass, saveDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Field field : rootClazz.getFields()) {
|
||||||
|
initMessage(source, rootSection, rootClazz, field, saveDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveDefault) {
|
||||||
|
try {
|
||||||
|
source.save();
|
||||||
|
} catch (IOException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initSection(FileConfig source, String parentSection, Class<?> clazz, boolean saveDefault) {
|
||||||
|
if (!Modifier.isStatic(clazz.getModifiers()) || !Modifier.isPublic(clazz.getModifiers())) return;
|
||||||
|
|
||||||
|
String section = getSection(clazz.getSimpleName(), parentSection, clazz.getAnnotation(MessagesSection.class));
|
||||||
|
|
||||||
|
for (Class<?> innerClass : clazz.getDeclaredClasses()) initSection(source, section, innerClass, saveDefault);
|
||||||
|
for (Field field : clazz.getFields()) initMessage(source, section, clazz, field, saveDefault);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initMessage(FileConfig source, String parentSection, Class<?> clazz, Field field, boolean saveDefault) {
|
||||||
|
try {
|
||||||
|
String section = getSection(field.getName(), parentSection, field.getAnnotation(MessagesSection.class));
|
||||||
|
|
||||||
|
Object object = field.get(clazz);
|
||||||
|
|
||||||
|
if (object instanceof EasyMessage) {
|
||||||
|
EasyMessage message = ((EasyMessage) object);
|
||||||
|
if (saveDefault && message.defaultValue != null && !source.getConfig().contains(section)) {
|
||||||
|
source.getConfig().set(section, message.defaultValue);
|
||||||
|
}
|
||||||
|
message.initialize(source, section);
|
||||||
|
} else if (object instanceof EasyMessageList) {
|
||||||
|
EasyMessageList messageList = ((EasyMessageList) object);
|
||||||
|
|
||||||
|
if (saveDefault && messageList.defaultValue != null && !source.getConfig().contains(section)) {
|
||||||
|
source.getConfig().set(section, Arrays.asList(messageList.defaultValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
messageList.initialize(source, section);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static String getSection(@NotNull String name,
|
||||||
|
@Nullable String parentSection,
|
||||||
|
@Nullable MessagesSection sectionAnnotation) {
|
||||||
|
String parent = parentSection != null ? parentSection + "." : "";
|
||||||
|
if (sectionAnnotation != null && sectionAnnotation.value().length() > 0) {
|
||||||
|
return parent + sectionAnnotation.value();
|
||||||
|
} else {
|
||||||
|
return parent + getSectionName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSectionName(String codeName) {
|
||||||
|
return codeName.toLowerCase().replace("_", "-");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
public abstract class MessagesRoot {
|
||||||
|
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.language;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ElementType.TYPE, ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface MessagesSection {
|
||||||
|
|
||||||
|
String value() default "";
|
||||||
|
|
||||||
|
}
|
||||||
+58
-36
@@ -3,13 +3,17 @@ package cc.carm.lib.easyplugin.configuration.message;
|
|||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigMessage extends ConfigValue<String> {
|
public class ConfigMessage extends ConfigValue<String> {
|
||||||
|
|
||||||
@@ -23,70 +27,88 @@ public class ConfigMessage extends ConfigValue<String> {
|
|||||||
this(sectionName, defaultValue, null);
|
this(sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String sectionName, @Nullable String defaultValue, String[] messageParams) {
|
public ConfigMessage(@NotNull String sectionName,
|
||||||
super(null, sectionName, String.class, defaultValue);
|
@Nullable String defaultValue,
|
||||||
this.messageParams = messageParams;
|
String[] messageParams) {
|
||||||
|
this((Supplier<FileConfig>) null, sectionName, defaultValue, messageParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@Nullable FileConfig source, @NotNull String sectionName,
|
public ConfigMessage(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@Nullable String defaultValue, String[] messageParams) {
|
@Nullable String defaultValue, String[] messageParams) {
|
||||||
super(source, sectionName, String.class, defaultValue);
|
this(source == null ? null : () -> source, sectionName, defaultValue, messageParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigMessage(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName,
|
||||||
|
@Nullable String defaultValue, String[] messageParams) {
|
||||||
|
super(provider, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender) {
|
public String[] getMessageParams() {
|
||||||
return MessageUtils.setPlaceholders(sender, get());
|
return messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, Object[] values) {
|
public @NotNull String get(@Nullable CommandSender sender) {
|
||||||
if (messageParams != null) {
|
return get(sender, null);
|
||||||
return get(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
return get(sender);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, String[] params, Object[] values) {
|
public @NotNull String get(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
return get(sender, getMessageParams(), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(CommandSender sender) {
|
public @NotNull String get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
MessageUtils.sendWithPlaceholders(sender, get());
|
String messages = get();
|
||||||
|
if (sender == null || messages.length() < 1) return messages;
|
||||||
|
params = params == null ? new String[0] : params;
|
||||||
|
values = values == null ? new Object[0] : values;
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(sender, messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(CommandSender sender, Object[] values) {
|
public void send(@Nullable CommandSender sender) {
|
||||||
if (messageParams != null) {
|
send(sender, null);
|
||||||
send(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
send(sender, new String[0], new Object[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
|
send(sender, getMessageParams(), values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(CommandSender sender, String[] params, Object[] values) {
|
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
String message = get(sender, params, values);
|
||||||
|
if (message.length() < 1) return;
|
||||||
|
|
||||||
|
MessageUtils.send(sender, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBar(@Nullable Player player) {
|
||||||
|
sendBar(player, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBar(@Nullable Player player, @Nullable Object[] values) {
|
||||||
|
sendBar(player, getMessageParams(), values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendBar(@Nullable Player player, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
if (player == null) return;
|
||||||
|
String message = get(player, params, values);
|
||||||
|
if (message.length() < 1) return;
|
||||||
|
|
||||||
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(get(player, params, values)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAll() {
|
public void sendToAll() {
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> MessageUtils.sendWithPlaceholders(player, Collections.singletonList(get())));
|
sendToAll(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAll(Object[] values) {
|
public void sendToAll(@Nullable Object[] values) {
|
||||||
if (messageParams != null) {
|
|
||||||
sendToAll(messageParams, values);
|
sendToAll(messageParams, values);
|
||||||
} else {
|
|
||||||
sendToAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAll(String[] params, Object[] values) {
|
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
Bukkit.getOnlinePlayers().forEach(pl -> MessageUtils.sendWithPlaceholders(pl, Collections.singletonList(get()), params, values));
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable FileConfig getSource() {
|
public FileConfig defaultSource() {
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
return FileConfig.getMessageConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-34
@@ -3,6 +3,7 @@ package cc.carm.lib.easyplugin.configuration.message;
|
|||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@@ -10,6 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigMessageList extends ConfigValueList<String> {
|
public class ConfigMessageList extends ConfigValueList<String> {
|
||||||
|
|
||||||
@@ -23,68 +25,73 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
this(sectionName, defaultValue, null);
|
this(sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String sectionName, @Nullable String[] defaultValue, String[] messageParams) {
|
public ConfigMessageList(@NotNull String sectionName,
|
||||||
super(null, sectionName, String.class, defaultValue);
|
@Nullable String[] defaultValue,
|
||||||
this.messageParams = messageParams;
|
String[] messageParams) {
|
||||||
|
this((Supplier<FileConfig>) null, sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@Nullable FileConfig source, @NotNull String sectionName,
|
public ConfigMessageList(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@Nullable String[] defaultValue, String[] messageParams) {
|
@Nullable String[] defaultValue, String[] messageParams) {
|
||||||
super(source, sectionName, String.class, defaultValue);
|
this(source == null ? null : () -> source, sectionName, defaultValue, messageParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigMessageList(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName,
|
||||||
|
@Nullable String[] defaultValue, String[] messageParams) {
|
||||||
|
super(provider, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String[] getMessageParams() {
|
||||||
|
return messageParams;
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender) {
|
public @NotNull List<String> get(@Nullable CommandSender sender) {
|
||||||
return MessageUtils.setPlaceholders(sender, get());
|
return get(sender, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender, Object[] values) {
|
|
||||||
if (messageParams != null) {
|
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
return get(sender, messageParams, values);
|
return get(sender, getMessageParams(), values);
|
||||||
} else {
|
|
||||||
return get(sender);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
public @NotNull List<String> get(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
if (sender == null) return get();
|
||||||
|
params = params == null ? new String[0] : params;
|
||||||
|
values = values == null ? new Object[0] : values;
|
||||||
|
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(sender, get(), params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender) {
|
public void send(@Nullable CommandSender sender) {
|
||||||
MessageUtils.sendWithPlaceholders(sender, get());
|
send(sender, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender, Object[] values) {
|
public void send(@Nullable CommandSender sender, @Nullable Object[] values) {
|
||||||
if (messageParams != null) {
|
send(sender, getMessageParams(), values);
|
||||||
send(sender, messageParams, values);
|
|
||||||
} else {
|
|
||||||
send(sender);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender, String[] params, Object[] values) {
|
public void send(@Nullable CommandSender sender, @Nullable String[] params, @Nullable Object[] values) {
|
||||||
MessageUtils.sendWithPlaceholders(sender, get(), params, values);
|
List<String> messages = get(sender, params, values);
|
||||||
}
|
if (messages.isEmpty()) return;
|
||||||
|
if (messages.size() == 1 && messages.get(0).length() == 0) return; //空消息不再发送
|
||||||
public void sendToAll(String[] params, Object[] values) {
|
MessageUtils.send(sender, messages);
|
||||||
Bukkit.getOnlinePlayers().forEach(pl -> MessageUtils.sendWithPlaceholders(pl, get(), params, values));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAll() {
|
public void sendToAll() {
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> MessageUtils.sendWithPlaceholders(player, get()));
|
sendToAll(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToAll(Object[] values) {
|
public void sendToAll(@Nullable Object[] values) {
|
||||||
if (messageParams != null) {
|
|
||||||
sendToAll(messageParams, values);
|
sendToAll(messageParams, values);
|
||||||
} else {
|
|
||||||
sendToAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendToAll(@Nullable String[] params, @Nullable Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> send(pl, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable FileConfig getSource() {
|
public FileConfig defaultSource() {
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
return FileConfig.getMessageConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigValue<V> extends FileConfigValue {
|
public class ConfigValue<V> extends FileConfigValue {
|
||||||
private final @NotNull Class<V> clazz;
|
private final @NotNull Class<V> clazz;
|
||||||
@@ -19,13 +20,19 @@ public class ConfigValue<V> extends FileConfigValue {
|
|||||||
public ConfigValue(@NotNull String sectionName,
|
public ConfigValue(@NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz,
|
@NotNull Class<V> clazz,
|
||||||
@Nullable V defaultValue) {
|
@Nullable V defaultValue) {
|
||||||
this(null, sectionName, clazz, defaultValue);
|
this((Supplier<FileConfig>) null, sectionName, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValue(@Nullable FileConfig source, @NotNull String sectionName,
|
public ConfigValue(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz,
|
@NotNull Class<V> clazz,
|
||||||
@Nullable V defaultValue) {
|
@Nullable V defaultValue) {
|
||||||
super(source, sectionName);
|
this(source == null ? null : () -> source, sectionName, clazz, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigValue(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName,
|
||||||
|
@NotNull Class<V> clazz,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(provider, sectionName);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ConfigValueList<V> extends FileConfigValue {
|
public class ConfigValueList<V> extends FileConfigValue {
|
||||||
@@ -28,15 +29,17 @@ public class ConfigValueList<V> extends FileConfigValue {
|
|||||||
this(null, sectionName, clazz, defaultValue);
|
this(null, sectionName, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String sectionName,
|
public ConfigValueList(@Nullable Supplier<FileConfig> provider,
|
||||||
|
@NotNull String sectionName,
|
||||||
Class<V> clazz) {
|
Class<V> clazz) {
|
||||||
this(configuration, sectionName, clazz, null);
|
this(provider, sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String sectionName,
|
public ConfigValueList(@Nullable Supplier<FileConfig> provider,
|
||||||
|
@NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz,
|
@NotNull Class<V> clazz,
|
||||||
@Nullable V[] defaultValue) {
|
@Nullable V[] defaultValue) {
|
||||||
super(configuration, sectionName);
|
super(provider, sectionName);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class ConfigValueMap<K, V> extends FileConfigCachedValue<Map<K, V>> {
|
public class ConfigValueMap<K, V> extends FileConfigCachedValue<Map<K, V>> {
|
||||||
|
|
||||||
@@ -16,12 +17,18 @@ public class ConfigValueMap<K, V> extends FileConfigCachedValue<Map<K, V>> {
|
|||||||
|
|
||||||
public ConfigValueMap(@NotNull String sectionName, @NotNull Function<String, K> keyCast,
|
public ConfigValueMap(@NotNull String sectionName, @NotNull Function<String, K> keyCast,
|
||||||
@NotNull Class<V> valueClazz) {
|
@NotNull Class<V> valueClazz) {
|
||||||
this(null, sectionName, keyCast, valueClazz);
|
this((Supplier<FileConfig>) null, sectionName, keyCast, valueClazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ConfigValueMap(@Nullable FileConfig source, @NotNull String sectionName,
|
public ConfigValueMap(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
||||||
super(source, sectionName);
|
this(source == null ? null : () -> source, sectionName, keyCast, valueClazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigValueMap(@Nullable Supplier<FileConfig> provider, @NotNull String sectionName,
|
||||||
|
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
||||||
|
super(provider, sectionName);
|
||||||
this.keyCast = keyCast;
|
this.keyCast = keyCast;
|
||||||
this.valueClazz = valueClazz;
|
this.valueClazz = valueClazz;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-beecp</artifactId>
|
<artifactId>easysql-beecp</artifactId>
|
||||||
<version>0.2.6</version>
|
<version>0.3.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
+25
-2
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -58,5 +58,28 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -25,7 +25,6 @@ public class GUI {
|
|||||||
|
|
||||||
public static void initialize(JavaPlugin plugin) {
|
public static void initialize(JavaPlugin plugin) {
|
||||||
GUI.plugin = plugin;
|
GUI.plugin = plugin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JavaPlugin getPlugin() {
|
public static JavaPlugin getPlugin() {
|
||||||
@@ -36,8 +35,8 @@ public class GUI {
|
|||||||
return openedGUIs;
|
return openedGUIs;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUIType type;
|
protected GUIType type;
|
||||||
String name;
|
protected String name;
|
||||||
public HashMap<Integer, GUIItem> items;
|
public HashMap<Integer, GUIItem> items;
|
||||||
public Inventory inv;
|
public Inventory inv;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package cc.carm.lib.easyplugin.gui.paged;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class AutoPagedGUI extends CommonPagedGUI {
|
||||||
|
|
||||||
|
public static Function<Player, ItemStack> defaultPreviousPage = null;
|
||||||
|
public static Function<Player, ItemStack> defaultNextPage = null;
|
||||||
|
|
||||||
|
ItemStack previousPageUI;
|
||||||
|
ItemStack nextPageUI;
|
||||||
|
int previousPageSlot = -1;
|
||||||
|
int nextPageSlot = -1;
|
||||||
|
|
||||||
|
public AutoPagedGUI(GUIType type, String name, int[] range) {
|
||||||
|
super(type, name, range);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoPagedGUI(GUIType type, String name, int a, int b) {
|
||||||
|
super(type, name, a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousPageUI(ItemStack lastPageUI) {
|
||||||
|
this.previousPageUI = lastPageUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextPageUI(ItemStack nextPageUI) {
|
||||||
|
this.nextPageUI = nextPageUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPreviousPageSlot(int slot) {
|
||||||
|
this.previousPageSlot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextPageSlot(int slot) {
|
||||||
|
this.nextPageSlot = slot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openGUI(Player user) {
|
||||||
|
if (previousPageSlot >= 0) {
|
||||||
|
if (hasPreviousPage()) {
|
||||||
|
setItem(previousPageSlot, new GUIItem(
|
||||||
|
previousPageUI == null ? getDefaultPreviousPage(user) : previousPageUI) {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickType type) {
|
||||||
|
if (type == ClickType.RIGHT) {
|
||||||
|
goFirstPage();
|
||||||
|
} else {
|
||||||
|
goPreviousPage();
|
||||||
|
}
|
||||||
|
openGUI(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setItem(previousPageSlot, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextPageSlot >= 0) {
|
||||||
|
if (hasNextPage()) {
|
||||||
|
setItem(nextPageSlot, new GUIItem(
|
||||||
|
nextPageUI == null ? getDefaultNextPage(user) : nextPageUI) {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickType type) {
|
||||||
|
if (type == ClickType.RIGHT) {
|
||||||
|
goLastPage();
|
||||||
|
} else {
|
||||||
|
goNextPage();
|
||||||
|
}
|
||||||
|
openGUI(user);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setItem(nextPageSlot, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
super.openGUI(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getDefaultNextPage(Player player) {
|
||||||
|
return defaultNextPage != null ? defaultNextPage.apply(player) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getDefaultPreviousPage(Player player) {
|
||||||
|
return defaultPreviousPage != null ? defaultPreviousPage.apply(player) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package cc.carm.lib.easyplugin.gui.paged;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommonPagedGUI extends PagedGUI {
|
||||||
|
|
||||||
|
private int[] range;
|
||||||
|
|
||||||
|
private CommonPagedGUI(GUIType type, String name) {
|
||||||
|
super(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonPagedGUI(GUIType type, String Name, int a, int b) {
|
||||||
|
this(type, Name, toRange(type, a, b));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommonPagedGUI(GUIType type, String Name, int[] range) {
|
||||||
|
super(type, Name);
|
||||||
|
Arrays.sort(range);
|
||||||
|
this.range = range;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
int[] matrix = new int[]{
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||||
|
9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||||
|
18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||||
|
27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||||
|
36, 37, 38, 39, 40, 41, 42, 43, 44,
|
||||||
|
45, 46, 47, 48, 49, 50, 51, 52, 53
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static int[] toRange(GUIType type, int a, int b) {
|
||||||
|
if (a > b) {
|
||||||
|
a = a ^ b;
|
||||||
|
b = a ^ b;
|
||||||
|
a = a ^ b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineA = getLine(a);
|
||||||
|
int columnA = getColumn(a);
|
||||||
|
int lineB = getLine(b);
|
||||||
|
int columnB = getColumn(b);
|
||||||
|
|
||||||
|
if (lineB > type.getLines())
|
||||||
|
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
|
||||||
|
|
||||||
|
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
|
||||||
|
|
||||||
|
for (int i = 0, l = 0; i < type.getSize(); i++) {
|
||||||
|
int li = getLine(i);
|
||||||
|
int ci = getColumn(i);
|
||||||
|
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
|
||||||
|
range[l] = i;
|
||||||
|
l++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getLine(int i) {
|
||||||
|
return i / 9 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getColumn(int i) {
|
||||||
|
return i % 9 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPreviousPage() {
|
||||||
|
return page > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNextPage() {
|
||||||
|
return page < getLastPageNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往第一页
|
||||||
|
*/
|
||||||
|
public void goFirstPage() {
|
||||||
|
if (hasPreviousPage())
|
||||||
|
this.page = 1;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往最后一页
|
||||||
|
*/
|
||||||
|
public void goLastPage() {
|
||||||
|
if (hasNextPage())
|
||||||
|
this.page = getLastPageNumber();
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到最后一页的页码
|
||||||
|
*
|
||||||
|
* @return 最后一页的页码
|
||||||
|
*/
|
||||||
|
public int getLastPageNumber() {
|
||||||
|
return (this.container.size() / range.length) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到第一页的页码
|
||||||
|
*
|
||||||
|
* @return 第一页页码(默认为1)
|
||||||
|
*/
|
||||||
|
public int getFirstPageNumber() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openGUI(Player player) {
|
||||||
|
if (container.isEmpty()) {
|
||||||
|
super.openGUI(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<GUIItem> list = new ArrayList<>();
|
||||||
|
int start = (page - 1) * range.length;
|
||||||
|
for (int i = start; i < start + range.length; i++) {
|
||||||
|
if (i < container.size()) {
|
||||||
|
list.add(container.get(i));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
Arrays.stream(range).forEach(index -> setItem(index, null));
|
||||||
|
for (int index : range) {
|
||||||
|
if (i < list.size()) {
|
||||||
|
setItem(index, list.get(i));
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.openGUI(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package cc.carm.lib.easyplugin.gui.paged;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUI;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||||
|
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class PagedGUI extends GUI {
|
||||||
|
|
||||||
|
List<GUIItem> container = new ArrayList<>();
|
||||||
|
public int page = 1;
|
||||||
|
|
||||||
|
public PagedGUI(GUIType type, String name) {
|
||||||
|
super(type, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int addItem(GUIItem i) {
|
||||||
|
container.add(i);
|
||||||
|
return container.size() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从GUI中移除一个物品
|
||||||
|
*
|
||||||
|
* @param item 物品
|
||||||
|
*/
|
||||||
|
public void removeItem(GUIItem item) {
|
||||||
|
container.remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从GUI中移除一个物品
|
||||||
|
*
|
||||||
|
* @param slot 物品格子数
|
||||||
|
*/
|
||||||
|
public void removeItem(int slot) {
|
||||||
|
container.remove(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GUIItem> getItemsContainer() {
|
||||||
|
return new ArrayList<>(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往上一页
|
||||||
|
*/
|
||||||
|
public void goPreviousPage() {
|
||||||
|
if (hasPreviousPage())
|
||||||
|
page--;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 前往下一页
|
||||||
|
*/
|
||||||
|
public void goNextPage() {
|
||||||
|
if (hasNextPage())
|
||||||
|
page++;
|
||||||
|
else
|
||||||
|
throw new IndexOutOfBoundsException();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否有上一页
|
||||||
|
*/
|
||||||
|
public abstract boolean hasPreviousPage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否有下一页
|
||||||
|
*/
|
||||||
|
public abstract boolean hasNextPage();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
|
||||||
package cc.carm.lib.easyplugin.utils;
|
package cc.carm.lib.easyplugin.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ColorParser {
|
public class ColorParser {
|
||||||
|
|
||||||
@@ -11,6 +14,14 @@ public class ColorParser {
|
|||||||
return parseColor(text);
|
return parseColor(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] parse(String... texts) {
|
||||||
|
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> parse(List<String> texts) {
|
||||||
|
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public static String parseColor(final String text) {
|
public static String parseColor(final String text) {
|
||||||
return text.replaceAll("&", "§").replace("§§", "&");
|
return text.replaceAll("&", "§").replace("§§", "&");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -18,6 +20,11 @@ public class MessageUtils {
|
|||||||
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void send(@Nullable CommandSender sender, String... messages) {
|
||||||
|
send(sender, Arrays.asList(messages));
|
||||||
|
}
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
public static void send(@Nullable CommandSender sender, List<String> messages) {
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return;
|
if (messages == null || messages.isEmpty() || sender == null) return;
|
||||||
for (String s : messages) {
|
for (String s : messages) {
|
||||||
@@ -25,10 +32,6 @@ public class MessageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void send(@Nullable CommandSender sender, String... messages) {
|
|
||||||
send(sender, Arrays.asList(messages));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
public static void sendWithPlaceholders(CommandSender sender, String... messages) {
|
||||||
sendWithPlaceholders(sender, Arrays.asList(messages));
|
sendWithPlaceholders(sender, Arrays.asList(messages));
|
||||||
}
|
}
|
||||||
@@ -46,7 +49,7 @@ public class MessageUtils {
|
|||||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String setPlaceholders(@Nullable CommandSender sender, String message) {
|
public static String setPlaceholders(@Nullable CommandSender sender, @Nullable String message) {
|
||||||
if (message == null || sender == null) return message;
|
if (message == null || sender == null) return message;
|
||||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
return PlaceholderAPI.setPlaceholders((Player) sender, message);
|
return PlaceholderAPI.setPlaceholders((Player) sender, message);
|
||||||
@@ -55,7 +58,11 @@ public class MessageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
|
||||||
|
@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 (messages == null || messages.isEmpty() || sender == null) return messages;
|
||||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
|
return PlaceholderAPI.setPlaceholders((Player) sender, messages);
|
||||||
@@ -64,20 +71,35 @@ public class MessageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String setPlaceholders(@Nullable CommandSender sender, String message, String[] params, Object[] values) {
|
public static String setPlaceholders(@Nullable CommandSender sender,
|
||||||
|
@NotNull String message,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
return setPlaceholders(sender, setCustomParams(message, params, values));
|
return setPlaceholders(sender, setCustomParams(message, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
public static List<String> setPlaceholders(@Nullable CommandSender sender,
|
||||||
|
@NotNull List<String> messages,
|
||||||
|
@Nullable String[] params,
|
||||||
|
@Nullable Object[] values) {
|
||||||
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String setCustomParams(String message, String param, Object value) {
|
public static String setCustomParams(@NotNull String message,
|
||||||
|
@NotNull String param,
|
||||||
|
@NotNull Object value) {
|
||||||
return setCustomParams(message, new String[]{param}, new Object[]{value});
|
return setCustomParams(message, new String[]{param}, new Object[]{value});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String setCustomParams(String message, String[] params, Object[] values) {
|
@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;
|
if (params.length != values.length) return message;
|
||||||
|
|
||||||
HashMap<String, Object> paramsMap = new HashMap<>();
|
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
paramsMap.put(params[i], values[i]);
|
paramsMap.put(params[i], values[i]);
|
||||||
@@ -85,8 +107,8 @@ public class MessageUtils {
|
|||||||
return setCustomParams(message, paramsMap);
|
return setCustomParams(message, paramsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static String setCustomParams(String message, HashMap<String, Object> params) {
|
public static String setCustomParams(@NotNull String message, @NotNull HashMap<String, Object> params) {
|
||||||
String afterMessage = message;
|
String afterMessage = message;
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
||||||
@@ -94,11 +116,18 @@ public class MessageUtils {
|
|||||||
return afterMessage;
|
return afterMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
@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});
|
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String[] params, Object[] values) {
|
@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;
|
if (params.length != values.length) return messages;
|
||||||
HashMap<String, Object> paramsMap = new HashMap<>();
|
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||||
for (int i = 0; i < params.length; i++) {
|
for (int i = 0; i < params.length; i++) {
|
||||||
@@ -107,9 +136,11 @@ public class MessageUtils {
|
|||||||
return setCustomParams(messages, paramsMap);
|
return setCustomParams(messages, paramsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
||||||
return messages.stream().map(message -> setCustomParams(message, params)).collect(Collectors.toList());
|
return messages.stream()
|
||||||
|
.map(message -> setCustomParams(message, params))
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.2.0</version>
|
<version>1.3.6</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,9 @@
|
|||||||
<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.2.0</version>
|
<version>1.3.6</version>
|
||||||
<modules>
|
<modules>
|
||||||
|
|
||||||
<module>easyplugin-bom</module>
|
|
||||||
<module>easyplugin-all</module>
|
|
||||||
<module>easyplugin-common</module>
|
|
||||||
|
|
||||||
<module>easyplugin-main</module>
|
<module>easyplugin-main</module>
|
||||||
|
|
||||||
<module>easyplugin-database</module>
|
<module>easyplugin-database</module>
|
||||||
@@ -32,6 +28,10 @@
|
|||||||
<module>easyplugin-placeholderapi</module>
|
<module>easyplugin-placeholderapi</module>
|
||||||
<module>easyplugin-lp</module>
|
<module>easyplugin-lp</module>
|
||||||
|
|
||||||
|
<module>easyplugin-bom</module>
|
||||||
|
<module>easyplugin-all</module>
|
||||||
|
<module>easyplugin-common</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<name>EasyPlugin</name>
|
<name>EasyPlugin</name>
|
||||||
@@ -75,11 +75,6 @@
|
|||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>central</id>
|
|
||||||
<url>https://repo1.maven.org/maven2/</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>carm-repo</id>
|
<id>carm-repo</id>
|
||||||
<name>Carm's Repo</name>
|
<name>Carm's Repo</name>
|
||||||
@@ -87,14 +82,19 @@
|
|||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>EasySQL</id>
|
<id>central</id>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>github</id>
|
<id>github</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/*</url>
|
||||||
<snapshots>
|
<snapshots>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
@@ -107,14 +107,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.13-R0.1-SNAPSHOT</version>
|
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
<version>1.13-R0.1-SNAPSHOT</version>
|
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user