mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 09:01:47 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 471bdab090 | |||
| 2628cb5c6a | |||
| f7f382a874 | |||
| c3119bb49a | |||
| b753a5c331 | |||
| eb073ce9dc | |||
| b2b5c41b86 | |||
| 422d93eb1f | |||
| 7be28a2c82 | |||
| fc948e7e24 | |||
| 33bef6b265 | |||
| 30832fc62b | |||
| 1713fb1324 | |||
| f216aba5e3 |
@@ -1,70 +0,0 @@
|
|||||||
# For most projects, this workflow file will not need changing; you simply need
|
|
||||||
# to commit it to your repository.
|
|
||||||
#
|
|
||||||
# You may wish to alter this file to override the set of languages analyzed,
|
|
||||||
# or to provide custom queries or build logic.
|
|
||||||
#
|
|
||||||
# ******** NOTE ********
|
|
||||||
# We have attempted to detect the languages in your repository. Please check
|
|
||||||
# the `language` matrix defined below to confirm you have the correct set of
|
|
||||||
# supported CodeQL languages.
|
|
||||||
#
|
|
||||||
name: "CodeQL"
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
# The branches below must be a subset of the branches above
|
|
||||||
branches: [ master ]
|
|
||||||
schedule:
|
|
||||||
- cron: '45 12 * * 1'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
analyze:
|
|
||||||
name: Analyze
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
actions: read
|
|
||||||
contents: read
|
|
||||||
security-events: write
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
language: [ 'java' ]
|
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
|
||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
|
||||||
- name: Initialize CodeQL
|
|
||||||
uses: github/codeql-action/init@v1
|
|
||||||
with:
|
|
||||||
languages: ${{ matrix.language }}
|
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
||||||
# By default, queries listed here will override any specified in a config file.
|
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
|
||||||
- name: Autobuild
|
|
||||||
uses: github/codeql-action/autobuild@v1
|
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
|
||||||
# 📚 https://git.io/JvXDl
|
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
||||||
# and modify them (or add more) to build your code if your project
|
|
||||||
# uses a compiled language
|
|
||||||
|
|
||||||
#- run: |
|
|
||||||
# make bootstrap
|
|
||||||
# make release
|
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
|
||||||
uses: github/codeql-action/analyze@v1
|
|
||||||
@@ -26,6 +26,9 @@ jobs:
|
|||||||
|
|
||||||
- name: Generate docs
|
- name: Generate docs
|
||||||
run: mvn clean package -DskipTests
|
run: mvn clean package -DskipTests
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
|
||||||
- name: Copy to Location
|
- name: Copy to Location
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -21,8 +21,14 @@ jobs:
|
|||||||
cache: maven
|
cache: maven
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
|
server-id: github
|
||||||
|
server-username: MAVEN_USERNAME
|
||||||
|
server-password: MAVEN_TOKEN
|
||||||
- name: "Package"
|
- name: "Package"
|
||||||
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||||
|
env:
|
||||||
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
- name: "Target Stage"
|
- name: "Target Stage"
|
||||||
run: mkdir staging && cp */target/*.jar staging
|
run: mkdir staging && cp */target/*.jar staging
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
|
|||||||
@@ -23,26 +23,30 @@
|
|||||||
- 轻便独立的功能模块,按需使用,避免大量打包!
|
- 轻便独立的功能模块,按需使用,避免大量打包!
|
||||||
- 详细的Javadoc与使用文档,轻松上手,方便使用!
|
- 详细的Javadoc与使用文档,轻松上手,方便使用!
|
||||||
- 持续的更新与优化,需求不止,更新不止!
|
- 持续的更新与优化,需求不止,更新不止!
|
||||||
- 如需新功能支持,请 [点击这里](https://github.com/CarmJos/EasyPlugin/issues/new?assignees=&labels=enhancement&template=feature_issues.md&title=) 提交功能需求。
|
- 如需新功能支持,请通过 [Issues](https://github.com/CarmJos/EasyPlugin/issues) 提交功能需求。
|
||||||
|
|
||||||
## 内容
|
## 内容
|
||||||
|
|
||||||
|
项目初创不久,加 * 的仍在开发更新中...
|
||||||
|
|
||||||
### 集合部分
|
### 集合部分
|
||||||
|
|
||||||
- All [`easyplugin-all`](easyplugin-all)
|
- All [`easyplugin-all`](easyplugin-all)
|
||||||
- Common [`easyplugin-common`](easyplugin-common)
|
- Common [`easyplugin-common`](easyplugin-common)
|
||||||
|
|
||||||
### 主要部分
|
### 主要部分
|
||||||
|
|
||||||
- Main [`easyplugin-main`](easyplugin-main)
|
- Main [`easyplugin-main`](easyplugin-main)
|
||||||
- Command [`easyplugin-command`](easyplugin-command)
|
- Command* [`easyplugin-command`](easyplugin-command)
|
||||||
- Configuration [`easyplugin-configuration`](easyplugin-configuration)
|
- Configuration [`easyplugin-configuration`](easyplugin-configuration)
|
||||||
- Database [`easyplugin-database`](easyplugin-database)
|
- Database* [`easyplugin-database`](easyplugin-database)
|
||||||
- GUI [`easyplugin-gui`](easyplugin-gui)
|
- GUI [`easyplugin-gui`](easyplugin-gui)
|
||||||
|
|
||||||
### 附属部分
|
### 附属部分
|
||||||
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) [`easyplugin-placeholderapi`](easyplugin-placeholderapi)
|
|
||||||
- [Vault](https://github.com/MilkBowl/VaultAPI) [`easyplugin-vault`](easyplugin-vault)
|
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/)* [`easyplugin-placeholderapi`](easyplugin-placeholderapi)
|
||||||
- [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/) [`easyplugin-lp`](easyplugin-lp)
|
- [Vault](https://github.com/MilkBowl/VaultAPI)* [`easyplugin-vault`](easyplugin-vault)
|
||||||
|
- [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/)* [`easyplugin-lp`](easyplugin-lp)
|
||||||
|
|
||||||
## 开发
|
## 开发
|
||||||
|
|
||||||
@@ -54,32 +58,30 @@
|
|||||||
|
|
||||||
### 依赖方式
|
### 依赖方式
|
||||||
|
|
||||||
#### Maven 依赖
|
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>远程库配置</summary>
|
<summary>展开查看 Maven 依赖方式</summary>
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
|
|
||||||
<project>
|
<project>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
|
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||||
<id>EasyPlugin</id>
|
<id>EasyPlugin</id>
|
||||||
<name>GitHub Packages</name>
|
<name>GitHub Packages</name>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||||
|
<id>carm-repo</id>
|
||||||
|
<name>Carm's Repo</name>
|
||||||
|
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
</project>
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>原生依赖</summary>
|
|
||||||
|
|
||||||
```xml
|
|
||||||
|
|
||||||
<project>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!--大全集版本,包含项目内所有模块-->
|
<!--大全集版本,包含项目内所有模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -89,7 +91,15 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--轻松插件主要接口集,包含方便的插件入口类与相关工具类。-->
|
<!--常用接口集,包含除附属插件模块外的所有模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cc.carm.lib</groupId>
|
||||||
|
<artifactId>easyplugin-common</artifactId>
|
||||||
|
<version>[LATEST RELEASE]</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--插件主要接口模块,包含方便的插件入口类与相关工具类-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-main</artifactId>
|
<artifactId>easyplugin-main</artifactId>
|
||||||
@@ -97,12 +107,44 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 其他模块自行选择,详见 “内容”-->
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>展开查看 Gradle 依赖方式</summary>
|
||||||
|
|
||||||
|
```groovy
|
||||||
|
repositories {
|
||||||
|
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||||
|
maven { url 'https://maven.pkg.github.com/CarmJos/EasyPlugin' }
|
||||||
|
|
||||||
|
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||||
|
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
//大全集版本,包含项目内所有模块
|
||||||
|
api "cc.carm.lib:easyplugin-all:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
//常用接口集,包含除附属插件模块外的所有模块
|
||||||
|
api "cc.carm.lib:easyplugin-common:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
//插件主要接口模块,包含方便的插件入口类与相关工具类
|
||||||
|
api "cc.carm.lib:easyplugin-main:[LATEST RELEASE]"
|
||||||
|
|
||||||
|
// 其他模块自行选择,详见 “内容”
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## 支持与捐赠
|
## 支持与捐赠
|
||||||
|
|
||||||
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
||||||
|
|||||||
@@ -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.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<artifactId>easyplugin-all</artifactId>
|
<artifactId>easyplugin-all</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-All</name>
|
<name>01-EasyPlugin-All</name>
|
||||||
<description>轻松插件全集,将打包全部工具类与工具接口。</description>
|
<description>轻松插件全集,将打包全部工具类与工具接口。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
|
|||||||
@@ -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.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-command</artifactId>
|
<artifactId>easyplugin-command</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>12-EasyPlugin-Command</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -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.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
<artifactId>easyplugin-common</artifactId>
|
<artifactId>easyplugin-common</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
<name>02-EasyPlugin-Common</name>
|
||||||
<description>轻松插件常用接口集,包含除附属模块外的所有模块。</description>
|
<description>轻松插件常用接口集,包含除附属插件模块外的所有模块。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -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.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
<name>EasyPlugin-Configuration</name>
|
<name>11-EasyPlugin-Configuration</name>
|
||||||
<description>轻松插件配置,可以方便快捷的将配置文件作为静态参数使用。</description>
|
<description>轻松插件配置模块,可以方便快捷的将配置文件作为静态参数使用。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.cast;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigCachedValue;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ConfigSectionCast<V> extends FileConfigCachedValue<V> {
|
||||||
|
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast;
|
||||||
|
@Nullable V defaultValue;
|
||||||
|
|
||||||
|
public ConfigSectionCast(@NotNull String configSection,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast) {
|
||||||
|
this(configSection, valueCast, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigSectionCast(@NotNull String sectionName,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
this(null, sectionName, valueCast, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigSectionCast(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
|
@NotNull Function<ConfigurationSection, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(source, sectionName);
|
||||||
|
this.valueCast = valueCast;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public @Nullable V get() {
|
||||||
|
V cached = getCachedValue();
|
||||||
|
if (cached != null && !isExpired()) {
|
||||||
|
return cached;
|
||||||
|
} else {
|
||||||
|
return getConfigOptional()
|
||||||
|
.map(config -> config.getConfigurationSection(getSectionName()))
|
||||||
|
.map(section -> updateCache(valueCast.apply(section)))
|
||||||
|
.orElse(defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Optional<V> getOptional() {
|
||||||
|
return Optional.ofNullable(get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void set(ConfigurationSection section) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.cast;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigCachedValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class ConfigStringCast<V> extends FileConfigCachedValue<V> {
|
||||||
|
|
||||||
|
@NotNull Function<String, V> valueCast;
|
||||||
|
@Nullable V defaultValue;
|
||||||
|
|
||||||
|
public ConfigStringCast(@NotNull String configSection,
|
||||||
|
@NotNull Function<String, V> valueCast) {
|
||||||
|
this(configSection, valueCast, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigStringCast(@NotNull String configSection,
|
||||||
|
@NotNull Function<String, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
this(null, configSection, valueCast, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigStringCast(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
|
@NotNull Function<String, V> valueCast,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
super(source, sectionName);
|
||||||
|
this.valueCast = valueCast;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable V get() {
|
||||||
|
V cached = getCachedValue();
|
||||||
|
if (cached != null && !isExpired()) {
|
||||||
|
return cached;
|
||||||
|
} else {
|
||||||
|
return getConfigOptional()
|
||||||
|
.map(config -> config.getString(getSectionName()))
|
||||||
|
.map(s -> updateCache(valueCast.apply(s)))
|
||||||
|
.orElse(defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Optional<V> getOptional() {
|
||||||
|
return Optional.ofNullable(get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@Nullable String value) {
|
||||||
|
getSourceOptional().ifPresent(source -> {
|
||||||
|
source.getConfig().set(getSectionName(), value);
|
||||||
|
source.save();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.file;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class FileConfigCachedValue<V> extends FileConfigValue {
|
||||||
|
|
||||||
|
protected V cachedValue;
|
||||||
|
protected long updateTime;
|
||||||
|
|
||||||
|
public FileConfigCachedValue(@NotNull String sectionName) {
|
||||||
|
super(sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfigCachedValue(@Nullable FileConfig source, @NotNull String sectionName) {
|
||||||
|
super(source, sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public V updateCache(V value) {
|
||||||
|
this.updateTime = System.currentTimeMillis();
|
||||||
|
this.cachedValue = value;
|
||||||
|
return getCachedValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExpired() {
|
||||||
|
return getSource() == null || getSource().isExpired(this.updateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public V getCachedValue() {
|
||||||
|
return cachedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearCache() {
|
||||||
|
this.cachedValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.easyplugin.configuration.file;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public abstract class FileConfigValue {
|
||||||
|
|
||||||
|
protected @Nullable FileConfig source;
|
||||||
|
private final @NotNull String sectionName;
|
||||||
|
|
||||||
|
public FileConfigValue(@NotNull String sectionName) {
|
||||||
|
this(null, sectionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfigValue(@Nullable FileConfig source, @NotNull String sectionName) {
|
||||||
|
this.source = source;
|
||||||
|
this.sectionName = sectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getSectionName() {
|
||||||
|
return sectionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
getSourceOptional().ifPresent(FileConfig::save);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable FileConfig getSource() {
|
||||||
|
return source == null ? FileConfig.getPluginConfiguration() : source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<FileConfig> getSourceOptional() {
|
||||||
|
return Optional.ofNullable(getSource());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<FileConfiguration> getConfigOptional() {
|
||||||
|
return getSourceOptional().map(FileConfig::getConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable <V> V castValue(@Nullable Object val, @NotNull Class<V> clazz) {
|
||||||
|
return castValue(val, clazz, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable <V> V castValue(@Nullable Object val, @NotNull Class<V> clazz, @Nullable V defaultValue) {
|
||||||
|
return clazz.isInstance(val) ? clazz.cast(val) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
-73
@@ -1,73 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ConfigSectionCast<V> {
|
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast;
|
|
||||||
@Nullable V defaultValue;
|
|
||||||
|
|
||||||
V valueCache;
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigSectionCast(@NotNull String configSection, @NotNull Function<ConfigurationSection, V> valueCast) {
|
|
||||||
this(configSection, valueCast, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSectionCast(@NotNull String configSection,
|
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
|
||||||
@Nullable V defaultValue) {
|
|
||||||
this(null, configSection, valueCast, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigSectionCast(@Nullable FileConfig source, @NotNull String configSection,
|
|
||||||
@NotNull Function<ConfigurationSection, V> valueCast,
|
|
||||||
@Nullable V defaultValue) {
|
|
||||||
this.source = source;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.valueCast = valueCast;
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public @Nullable V get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return defaultValue;
|
|
||||||
|
|
||||||
if (valueCache != null && !source.isExpired(this.updateTime)) return valueCache;
|
|
||||||
if (!source.getConfig().contains(this.configSection)) return defaultValue;
|
|
||||||
try {
|
|
||||||
V finalValue = this.valueCast.apply(source.getConfig().getConfigurationSection(this.configSection));
|
|
||||||
if (finalValue != null) {
|
|
||||||
this.valueCache = finalValue;
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
return finalValue;
|
|
||||||
} else {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(ConfigurationSection section) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+36
-28
@@ -1,5 +1,6 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
package cc.carm.lib.easyplugin.configuration.impl;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.configuration.cast.ConfigStringCast;
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
@@ -7,6 +8,8 @@ import org.bukkit.entity.Player;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
||||||
|
|
||||||
public ConfigSound(@NotNull String configSection) {
|
public ConfigSound(@NotNull String configSection) {
|
||||||
@@ -18,30 +21,9 @@ public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
|||||||
this(null, configSection, defaultValue);
|
this(null, configSection, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection, @Nullable Sound defaultValue) {
|
public ConfigSound(@Nullable FileConfig source, @NotNull String configSection,
|
||||||
super(source, configSection, string -> {
|
@Nullable Sound defaultValue) {
|
||||||
Sound finalSound = defaultValue;
|
super(source, configSection, getSoundParser(), defaultValue == null ? null : new SoundData(defaultValue));
|
||||||
float volume = 1;
|
|
||||||
float pitch = 1;
|
|
||||||
|
|
||||||
if (string != null) {
|
|
||||||
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
|
||||||
try {
|
|
||||||
if (args.length >= 1) finalSound = Sound.valueOf(args[0]);
|
|
||||||
if (args.length >= 2) volume = Float.parseFloat(args[1]);
|
|
||||||
if (args.length >= 3) pitch = Float.parseFloat(args[2]);
|
|
||||||
} catch (Exception exception) {
|
|
||||||
Bukkit.getLogger().severe("声音 " + configSection + " 配置错误,不存在 " + string + " ,请检查。");
|
|
||||||
Bukkit.getLogger().severe("In " + configSection + " (" + string + ") doesn't match any sound name.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finalSound != null) {
|
|
||||||
return new SoundData(finalSound, volume, pitch);
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, defaultValue == null ? null : new SoundData(defaultValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable SoundData value) {
|
public void set(@Nullable SoundData value) {
|
||||||
@@ -73,12 +55,38 @@ public class ConfigSound extends ConfigStringCast<ConfigSound.SoundData> {
|
|||||||
if (data != null) data.play(player);
|
if (data != null) data.play(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void playToAll() {
|
||||||
if (getSource() != null) getSource().save();
|
SoundData data = get();
|
||||||
|
if (data != null) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(data::play);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
public static @NotNull Function<@Nullable String, @Nullable SoundData> getSoundParser() {
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
return string -> {
|
||||||
|
if (string == null) return null;
|
||||||
|
|
||||||
|
Sound finalSound = null;
|
||||||
|
float volume = 1;
|
||||||
|
float pitch = 1;
|
||||||
|
|
||||||
|
String[] args = string.contains(":") ? string.split(":") : new String[]{string};
|
||||||
|
try {
|
||||||
|
if (args.length >= 1) finalSound = Sound.valueOf(args[0]);
|
||||||
|
if (args.length >= 2) volume = Float.parseFloat(args[1]);
|
||||||
|
if (args.length >= 3) pitch = Float.parseFloat(args[2]);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
Bukkit.getLogger().severe("声音 " + string + " 配置错误,不存在同名声音,请检查。");
|
||||||
|
Bukkit.getLogger().severe("Sound " + string + " doesn't match any sound name.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (finalSound != null) {
|
||||||
|
return new SoundData(finalSound, volume, pitch);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SoundData {
|
public static class SoundData {
|
||||||
|
|||||||
-76
@@ -1,76 +0,0 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.impl;
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class ConfigStringCast<V> {
|
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
@NotNull Function<String, V> valueCast;
|
|
||||||
|
|
||||||
@Nullable V defaultValue;
|
|
||||||
|
|
||||||
V valueCache;
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigStringCast(@NotNull String configSection, @NotNull Function<String, V> valueCast) {
|
|
||||||
this(configSection, valueCast, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStringCast(@NotNull String configSection, @NotNull Function<String, V> valueCast, @Nullable V defaultValue) {
|
|
||||||
this(null, configSection, valueCast, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigStringCast(@Nullable FileConfig source, @NotNull String configSection,
|
|
||||||
@NotNull Function<String, V> valueCast, @Nullable V defaultValue) {
|
|
||||||
this.source = source;
|
|
||||||
this.configSection = configSection;
|
|
||||||
this.valueCast = valueCast;
|
|
||||||
this.defaultValue = defaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable V get() {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source == null) return defaultValue;
|
|
||||||
|
|
||||||
if (valueCache != null && !source.isExpired(this.updateTime)) return valueCache;
|
|
||||||
if (!source.getConfig().contains(this.configSection)) return defaultValue;
|
|
||||||
try {
|
|
||||||
V finalValue = this.valueCast.apply(source.getConfig().getString(this.configSection));
|
|
||||||
if (finalValue != null) {
|
|
||||||
this.valueCache = finalValue;
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
return finalValue;
|
|
||||||
} else {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
return defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(@Nullable String value) {
|
|
||||||
FileConfig source = getSource();
|
|
||||||
if (source != null) {
|
|
||||||
source.getConfig().set(this.configSection, value);
|
|
||||||
source.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) {
|
|
||||||
getSource().save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
+32
-12
@@ -4,47 +4,50 @@ package cc.carm.lib.easyplugin.configuration.message;
|
|||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValue;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ConfigMessage extends ConfigValue<String> {
|
public class ConfigMessage extends ConfigValue<String> {
|
||||||
|
|
||||||
String[] messageParams;
|
String[] messageParams;
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection) {
|
public ConfigMessage(@NotNull String sectionName) {
|
||||||
this(configSection, null);
|
this(sectionName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection, @Nullable String defaultValue) {
|
public ConfigMessage(@NotNull String sectionName, @Nullable String defaultValue) {
|
||||||
this(configSection, defaultValue, null);
|
this(sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@NotNull String configSection, @Nullable String defaultValue, String[] messageParams) {
|
public ConfigMessage(@NotNull String sectionName, @Nullable String defaultValue, String[] messageParams) {
|
||||||
super(null, configSection, String.class, defaultValue);
|
super(null, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessage(@Nullable FileConfig config, @NotNull String configSection,
|
public ConfigMessage(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@Nullable String defaultValue, String[] messageParams) {
|
@Nullable String defaultValue, String[] messageParams) {
|
||||||
super(config, configSection, String.class, defaultValue);
|
super(source, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull String get(CommandSender sender) {
|
||||||
|
return MessageUtils.setPlaceholders(sender, get());
|
||||||
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, Object[] values) {
|
public @NotNull String get(CommandSender sender, Object[] values) {
|
||||||
if (messageParams != null) {
|
if (messageParams != null) {
|
||||||
return get(sender, messageParams, values);
|
return get(sender, messageParams, values);
|
||||||
} else {
|
} else {
|
||||||
return get(sender, new String[0], new Object[0]);
|
return get(sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull String get(CommandSender sender, String[] params, Object[] values) {
|
public @NotNull String get(CommandSender sender, String[] params, Object[] values) {
|
||||||
List<String> messages = MessageUtils.setPlaceholders(sender, Collections.singletonList(get()), params, values);
|
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
||||||
return messages != null && !messages.isEmpty() ? messages.get(0) : "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void send(CommandSender sender) {
|
public void send(CommandSender sender) {
|
||||||
@@ -64,6 +67,23 @@ public class ConfigMessage extends ConfigValue<String> {
|
|||||||
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
MessageUtils.sendWithPlaceholders(sender, Collections.singletonList(get()), params, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> MessageUtils.sendWithPlaceholders(player, Collections.singletonList(get())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(Object[] values) {
|
||||||
|
if (messageParams != null) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
} else {
|
||||||
|
sendToAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(String[] params, Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> MessageUtils.sendWithPlaceholders(pl, Collections.singletonList(get()), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public @Nullable FileConfig getSource() {
|
public @Nullable FileConfig getSource() {
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
return source == null ? FileConfig.getMessageConfiguration() : source;
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-9
@@ -4,6 +4,7 @@ package cc.carm.lib.easyplugin.configuration.message;
|
|||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
import cc.carm.lib.easyplugin.configuration.values.ConfigValueList;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -14,22 +15,22 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
|
|
||||||
@Nullable String[] messageParams;
|
@Nullable String[] messageParams;
|
||||||
|
|
||||||
public ConfigMessageList(String configSection) {
|
public ConfigMessageList(String sectionName) {
|
||||||
this(configSection, new String[0]);
|
this(sectionName, new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String configSection, @Nullable String[] defaultValue) {
|
public ConfigMessageList(@NotNull String sectionName, @Nullable String[] defaultValue) {
|
||||||
this(configSection, defaultValue, null);
|
this(sectionName, defaultValue, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@NotNull String configSection, @Nullable String[] defaultValue, String[] messageParams) {
|
public ConfigMessageList(@NotNull String sectionName, @Nullable String[] defaultValue, String[] messageParams) {
|
||||||
super(null, configSection, String.class, defaultValue);
|
super(null, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigMessageList(@Nullable FileConfig config, @NotNull String configSection,
|
public ConfigMessageList(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@Nullable String[] defaultValue, String[] messageParams) {
|
@Nullable String[] defaultValue, String[] messageParams) {
|
||||||
super(config, configSection, String.class, defaultValue);
|
super(source, sectionName, String.class, defaultValue);
|
||||||
this.messageParams = messageParams;
|
this.messageParams = messageParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +46,6 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public @NotNull List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
public @NotNull List<String> get(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||||
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
return MessageUtils.setPlaceholders(sender, get(), params, values);
|
||||||
}
|
}
|
||||||
@@ -62,6 +62,22 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendToAll(String[] params, Object[] values) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(pl -> MessageUtils.sendWithPlaceholders(pl, get(), params, values));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll() {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> MessageUtils.sendWithPlaceholders(player, get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendToAll(Object[] values) {
|
||||||
|
if (messageParams != null) {
|
||||||
|
sendToAll(messageParams, values);
|
||||||
|
} else {
|
||||||
|
sendToAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void send(@Nullable CommandSender sender, String[] params, Object[] values) {
|
public void send(@Nullable CommandSender sender, String[] params, Object[] values) {
|
||||||
MessageUtils.sendWithPlaceholders(sender, get(), params, values);
|
MessageUtils.sendWithPlaceholders(sender, get(), params, values);
|
||||||
}
|
}
|
||||||
@@ -70,4 +86,5 @@ public class ConfigMessageList extends ConfigValueList<String> {
|
|||||||
public @Nullable FileConfig getSource() {
|
public @Nullable FileConfig getSource() {
|
||||||
return source == null ? FileConfig.getMessageConfiguration() : source;
|
return source == null ? FileConfig.getMessageConfiguration() : source;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-35
@@ -1,64 +1,54 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
package cc.carm.lib.easyplugin.configuration.values;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class ConfigValue<V> {
|
import java.util.Optional;
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
public class ConfigValue<V> extends FileConfigValue {
|
||||||
|
|
||||||
private final @NotNull String configSection;
|
|
||||||
private final @NotNull Class<V> clazz;
|
private final @NotNull Class<V> clazz;
|
||||||
@Nullable V defaultValue;
|
@Nullable V defaultValue;
|
||||||
|
|
||||||
public ConfigValue(@NotNull String configSection, @NotNull Class<V> clazz) {
|
public ConfigValue(@NotNull String sectionName,
|
||||||
this(configSection, clazz, null);
|
@NotNull Class<V> clazz) {
|
||||||
|
this(sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValue(@NotNull String configSection, @NotNull Class<V> clazz, @Nullable V defaultValue) {
|
public ConfigValue(@NotNull String sectionName,
|
||||||
this(null, configSection, clazz, defaultValue);
|
@NotNull Class<V> clazz,
|
||||||
|
@Nullable V defaultValue) {
|
||||||
|
this(null, sectionName, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValue(@Nullable FileConfig source, @NotNull String configSection,
|
public ConfigValue(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz, @Nullable V defaultValue) {
|
@NotNull Class<V> clazz,
|
||||||
this.source = source;
|
@Nullable V defaultValue) {
|
||||||
this.configSection = configSection;
|
super(source, sectionName);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public V get() {
|
public V get() {
|
||||||
FileConfig source = getSource();
|
return getConfigOptional()
|
||||||
if (source == null) return this.defaultValue;
|
.map(config -> castValue(config.get(getSectionName()), clazz, this.defaultValue))
|
||||||
|
.orElse(setDefault()); // 如果没有默认值,就把配置写进去,便于配置
|
||||||
|
}
|
||||||
|
|
||||||
if (source.getConfig().contains(this.configSection)) {
|
public @NotNull Optional<V> getOptional() {
|
||||||
Object val = source.getConfig().get(this.configSection, this.defaultValue);
|
return Optional.ofNullable(get());
|
||||||
return this.clazz.isInstance(val) ? this.clazz.cast(val) : this.defaultValue;
|
|
||||||
} else {
|
|
||||||
// 如果没有默认值,就把配置写进去,便于配置
|
|
||||||
return setDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable V value) {
|
public void set(@Nullable V value) {
|
||||||
FileConfig source = getSource();
|
getSourceOptional().ifPresent(source -> {
|
||||||
if (source == null) return;
|
source.getConfig().set(getSectionName(), value);
|
||||||
|
source.save();
|
||||||
source.getConfig().set(this.configSection, value);
|
});
|
||||||
source.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public V setDefault() {
|
public V setDefault() {
|
||||||
set(this.defaultValue);
|
if (this.defaultValue != null) set(this.defaultValue);
|
||||||
return this.defaultValue;
|
return this.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-44
@@ -2,78 +2,66 @@ package cc.carm.lib.easyplugin.configuration.values;
|
|||||||
|
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ConfigValueList<V> {
|
public class ConfigValueList<V> extends FileConfigValue {
|
||||||
|
|
||||||
protected @Nullable FileConfig source;
|
|
||||||
|
|
||||||
private final @NotNull String configSection;
|
|
||||||
private final @NotNull Class<V> clazz;
|
private final @NotNull Class<V> clazz;
|
||||||
|
|
||||||
@Nullable V[] defaultValue;
|
@Nullable V[] defaultValue;
|
||||||
|
|
||||||
public ConfigValueList(@NotNull String configSection, @NotNull Class<V> clazz) {
|
public ConfigValueList(@NotNull String sectionName,
|
||||||
this(configSection, clazz, null);
|
@NotNull Class<V> clazz) {
|
||||||
|
this(sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@NotNull String configSection, @NotNull Class<V> clazz, @Nullable V[] defaultValue) {
|
public ConfigValueList(@NotNull String sectionName,
|
||||||
this(null, configSection, clazz, defaultValue);
|
@NotNull Class<V> clazz,
|
||||||
|
@Nullable V[] defaultValue) {
|
||||||
|
this(null, sectionName, clazz, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String configSection, Class<V> clazz) {
|
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String sectionName,
|
||||||
this(configuration, configSection, clazz, null);
|
Class<V> clazz) {
|
||||||
|
this(configuration, sectionName, clazz, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String configSection,
|
public ConfigValueList(@Nullable FileConfig configuration, @NotNull String sectionName,
|
||||||
@NotNull Class<V> clazz, @Nullable V[] defaultValue) {
|
@NotNull Class<V> clazz,
|
||||||
this.source = configuration;
|
@Nullable V[] defaultValue) {
|
||||||
this.configSection = configSection;
|
super(configuration, sectionName);
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull ArrayList<V> get() {
|
public @NotNull ArrayList<V> get() {
|
||||||
FileConfig source = getSource();
|
return getConfigOptional()
|
||||||
if (source == null) return new ArrayList<>();
|
.map(configuration -> configuration.getList(getSectionName()))
|
||||||
|
.map(list -> list.stream()
|
||||||
|
.map(o -> castValue(o, this.clazz))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new)))
|
||||||
|
.orElse(getDefaultList());
|
||||||
|
}
|
||||||
|
|
||||||
List<?> list = source.getConfig().getList(this.configSection);
|
public @NotNull ArrayList<V> getDefaultList() {
|
||||||
if (list == null) {
|
return defaultValue == null ? new ArrayList<>() : new ArrayList<>(Arrays.asList(defaultValue));
|
||||||
if (defaultValue != null) {
|
|
||||||
return new ArrayList<>(Arrays.asList(defaultValue));
|
|
||||||
} else {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ArrayList<V> result = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Object object : list) {
|
|
||||||
if (this.clazz.isInstance(object)) {
|
|
||||||
result.add(this.clazz.cast(object));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable ArrayList<V> value) {
|
public void set(@Nullable ArrayList<V> value) {
|
||||||
FileConfig source = getSource();
|
getSourceOptional().ifPresent(source -> {
|
||||||
if (source == null) return;
|
source.getConfig().set(getSectionName(), value);
|
||||||
source.getConfig().set(this.configSection, value);
|
source.save();
|
||||||
this.save();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return this.source == null ? FileConfig.getPluginConfiguration() : this.source;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-57
@@ -1,88 +1,59 @@
|
|||||||
package cc.carm.lib.easyplugin.configuration.values;
|
package cc.carm.lib.easyplugin.configuration.values;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfig;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import cc.carm.lib.easyplugin.configuration.file.FileConfigCachedValue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ConfigValueMap<K, V> {
|
public class ConfigValueMap<K, V> extends FileConfigCachedValue<Map<K, V>> {
|
||||||
|
|
||||||
@Nullable FileConfig source;
|
|
||||||
|
|
||||||
@NotNull String configSection;
|
|
||||||
|
|
||||||
@NotNull Function<String, K> keyCast;
|
@NotNull Function<String, K> keyCast;
|
||||||
@NotNull Class<V> valueClazz;
|
@NotNull Class<V> valueClazz;
|
||||||
|
|
||||||
@Nullable LinkedHashMap<K, V> valueCache;
|
public ConfigValueMap(@NotNull String sectionName, @NotNull Function<String, K> keyCast,
|
||||||
|
|
||||||
long updateTime;
|
|
||||||
|
|
||||||
public ConfigValueMap(@NotNull String configSection, @NotNull Function<String, K> keyCast,
|
|
||||||
@NotNull Class<V> valueClazz) {
|
@NotNull Class<V> valueClazz) {
|
||||||
this(null, configSection, keyCast, valueClazz);
|
this(null, sectionName, keyCast, valueClazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigValueMap(@Nullable FileConfig configuration, @NotNull String configSection,
|
public ConfigValueMap(@Nullable FileConfig source, @NotNull String sectionName,
|
||||||
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
@NotNull Function<String, K> keyCast, @NotNull Class<V> valueClazz) {
|
||||||
this.source = configuration;
|
super(source, sectionName);
|
||||||
this.configSection = configSection;
|
|
||||||
this.keyCast = keyCast;
|
this.keyCast = keyCast;
|
||||||
this.valueClazz = valueClazz;
|
this.valueClazz = valueClazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
|
||||||
this.valueCache = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Map<K, V> get() {
|
public Map<K, V> get() {
|
||||||
FileConfig source = getSource();
|
Map<K, V> cached = getCachedValue();
|
||||||
if (source == null) return new HashMap<>();
|
if (cached != null && !isExpired()) {
|
||||||
|
return cached;
|
||||||
if (valueCache != null && !getSource().isExpired(this.updateTime)) return valueCache;
|
} else {
|
||||||
|
return getConfigOptional()
|
||||||
ConfigurationSection section = source.getConfig().getConfigurationSection(this.configSection);
|
.map(config -> config.getConfigurationSection(getSectionName()))
|
||||||
if (section == null) return new LinkedHashMap<>();
|
.map(section -> {
|
||||||
|
Map<K, V> result = new LinkedHashMap<>();
|
||||||
Set<String> keys = section.getKeys(false);
|
for (String key : section.getKeys(false)) {
|
||||||
if (keys.isEmpty()) return new LinkedHashMap<>();
|
K finalKey = keyCast.apply(key);
|
||||||
|
V finalValue = castValue(section.get(key), valueClazz);
|
||||||
else {
|
if (finalKey != null && finalValue != null) {
|
||||||
LinkedHashMap<K, V> result = new LinkedHashMap<>();
|
result.put(finalKey, finalValue);
|
||||||
for (String key : keys) {
|
}
|
||||||
K finalKey = keyCast.apply(key);
|
}
|
||||||
Object val = section.get(key);
|
return updateCache(result);
|
||||||
V finalValue = this.valueClazz.isInstance(val) ? this.valueClazz.cast(val) : null;
|
}).orElse(new LinkedHashMap<>());
|
||||||
if (finalKey != null && finalValue != null) {
|
|
||||||
result.put(finalKey, finalValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.updateTime = System.currentTimeMillis();
|
|
||||||
this.valueCache = result;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(@Nullable HashMap<K, V> valuesMap) {
|
public void set(@Nullable Map<K, V> valuesMap) {
|
||||||
FileConfig source = getSource();
|
getSourceOptional().ifPresent(source -> {
|
||||||
if (source == null) return;
|
source.getConfig().createSection(getSectionName(), valuesMap);
|
||||||
source.getConfig().createSection(this.configSection, valuesMap);
|
source.save();
|
||||||
source.save();
|
});
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
|
||||||
if (getSource() != null) getSource().save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable FileConfig getSource() {
|
|
||||||
return source == null ? FileConfig.getPluginConfiguration() : source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,23 +19,100 @@
|
|||||||
<artifactId>easyplugin-database</artifactId>
|
<artifactId>easyplugin-database</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>14-EasyPlugin-Database</name>
|
||||||
|
<description>轻松插件数据库模块,包含快速实现数据库功能的工具。</description>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<repositories>
|
<developers>
|
||||||
<repository>
|
<developer>
|
||||||
<id>EasySQL</id>
|
<id>CarmJos</id>
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
<name>Carm Jos</name>
|
||||||
</repository>
|
<email>carm@carm.cc</email>
|
||||||
</repositories>
|
<url>https://www.carm.cc</url>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU General Public License v3.0</name>
|
||||||
|
<url>https://opensource.org/licenses/GPL-3.0</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub Issues</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<ciManagement>
|
||||||
|
<system>GitHub Actions</system>
|
||||||
|
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||||
|
</ciManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easysql-beecp</artifactId>
|
<artifactId>easysql-beecp</artifactId>
|
||||||
<version>0.2.3</version>
|
<version>0.2.4</version>
|
||||||
|
<optional>true</optional>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</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>
|
||||||
|
<version>3.2.3</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>cc.carm.lib.easysql</pattern>
|
||||||
|
<shadedPattern>cc.carm.lib.easyplugin.database</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
<filters>
|
||||||
|
<filter>
|
||||||
|
<artifact>*:*</artifact>
|
||||||
|
<excludes>
|
||||||
|
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||||
|
<exclude>META-INF/*.txt</exclude>
|
||||||
|
</excludes>
|
||||||
|
</filter>
|
||||||
|
</filters>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package cc.carm.lib.easyplugin.database;
|
||||||
|
|
||||||
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.api.builder.TableCreateBuilder;
|
||||||
|
import cc.carm.lib.easysql.api.builder.TableQueryBuilder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DatabaseTable {
|
||||||
|
|
||||||
|
private final @NotNull String tableName;
|
||||||
|
private final @NotNull String[] columns;
|
||||||
|
|
||||||
|
@Nullable String tableSettings;
|
||||||
|
|
||||||
|
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns) {
|
||||||
|
this(tableName, columns, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DatabaseTable(@NotNull String tableName, @NotNull String[] columns, @Nullable String tableSettings) {
|
||||||
|
this.tableName = tableName;
|
||||||
|
this.columns = columns;
|
||||||
|
this.tableSettings = tableSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String getTableName() {
|
||||||
|
return tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull String[] getColumns() {
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getTableSettings() {
|
||||||
|
return tableSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int createTable(SQLManager sqlManager) throws SQLException {
|
||||||
|
TableCreateBuilder createAction = sqlManager.createTable(getTableName());
|
||||||
|
createAction.setColumns(getColumns());
|
||||||
|
if (getTableSettings() != null) createAction.setTableSettings(getTableSettings());
|
||||||
|
return createAction.build().execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableQueryBuilder createQuery(SQLManager sqlManager) {
|
||||||
|
return sqlManager.createQuery().inTable(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
<artifactId>easyplugin-gui</artifactId>
|
<artifactId>easyplugin-gui</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-GUI</name>
|
<name>13-EasyPlugin-GUI</name>
|
||||||
<description>轻松插件界面相关接口,方便快捷的创建箱子GUI界面。</description>
|
<description>轻松插件GUI接口模块,方便快捷的创建箱子GUI界面。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public class GUI {
|
|||||||
if (this.type == GUIType.CANCEL) throw new NullPointerException("被取消或不存在的GUI");
|
if (this.type == GUIType.CANCEL) throw new NullPointerException("被取消或不存在的GUI");
|
||||||
|
|
||||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
||||||
IntStream.range(0, this.inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
IntStream.range(0, inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
||||||
|
|
||||||
setOpenedGUI(player, this);
|
setOpenedGUI(player, this);
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
|
||||||
|
import cc.carm.lib.easyplugin.gui.configuration.GUIConfiguration;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActionReadTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
List<String> actions = Arrays.asList(
|
||||||
|
"[CHAT] 123123",
|
||||||
|
"[SHIFT_LEFT:CHAT] /test qwq",
|
||||||
|
"[CONSOLE] say hello",
|
||||||
|
"[CLOSE]"
|
||||||
|
);
|
||||||
|
|
||||||
|
for (String actionString : actions) {
|
||||||
|
int prefixStart = actionString.indexOf("[");
|
||||||
|
int prefixEnd = actionString.indexOf("]");
|
||||||
|
if (prefixStart < 0 || prefixEnd < 0) continue;
|
||||||
|
|
||||||
|
String prefix = actionString.substring(prefixStart + 1, prefixEnd);
|
||||||
|
ClickType clickType = null;
|
||||||
|
GUIActionType actionType;
|
||||||
|
if (prefix.contains(":")) {
|
||||||
|
String[] args = prefix.split(":");
|
||||||
|
clickType = GUIConfiguration.readClickType(args[0]);
|
||||||
|
actionType = GUIActionType.readActionType(args[1]);
|
||||||
|
} else {
|
||||||
|
actionType = GUIActionType.readActionType(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (actionType == null) {
|
||||||
|
System.out.println("# " + actionString);
|
||||||
|
System.out.println("- actionType is Null");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("# " + actionType.name() + " " + (clickType == null ? "" : clickType.name()));
|
||||||
|
System.out.println("- " + actionString.substring(prefixEnd + 1).trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,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.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,5 +19,7 @@
|
|||||||
<artifactId>easyplugin-lp</artifactId>
|
<artifactId>easyplugin-lp</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>23-EasyPlugin-LuckPerms</name>
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
<artifactId>easyplugin-main</artifactId>
|
<artifactId>easyplugin-main</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>EasyPlugin-Main</name>
|
<name>10-EasyPlugin-Main</name>
|
||||||
<description>轻松插件主要接口集,包含方便的插件入口类与相关工具类。</description>
|
<description>轻松插件主要接口模块,包含方便的插件入口类与相关工具类。</description>
|
||||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||||
|
|
||||||
<developers>
|
<developers>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package cc.carm.lib.easyplugin;
|
package cc.carm.lib.easyplugin;
|
||||||
|
|
||||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
|
||||||
import cc.carm.lib.easyplugin.utils.SchedulerUtils;
|
import cc.carm.lib.easyplugin.utils.SchedulerUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@@ -18,55 +18,71 @@ import java.util.Map;
|
|||||||
|
|
||||||
public abstract class EasyPlugin extends JavaPlugin {
|
public abstract class EasyPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
protected EasyPluginMessageProvider messageProvider;
|
||||||
|
|
||||||
|
public EasyPlugin() {
|
||||||
|
this(new EasyPluginMessageProvider.en_US());
|
||||||
|
}
|
||||||
|
|
||||||
|
public EasyPlugin(EasyPluginMessageProvider messageProvider) {
|
||||||
|
this.messageProvider = messageProvider;
|
||||||
|
}
|
||||||
|
|
||||||
private SchedulerUtils scheduler;
|
private SchedulerUtils scheduler;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public final void onLoad() {
|
||||||
scheduler = new SchedulerUtils(this);
|
scheduler = new SchedulerUtils(this);
|
||||||
|
if (!hasOverride("load")) return;
|
||||||
|
|
||||||
if (!isOverride("load")) return;
|
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
log(messageProvider.loading(this));
|
||||||
load();
|
load();
|
||||||
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log(messageProvider.loaded(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public final void onEnable() {
|
||||||
|
outputInfo();
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " &7开始启动...");
|
log(messageProvider.enabling(this));
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
this.initialized = initialize();
|
if (!(this.initialized = initialize())) {
|
||||||
|
|
||||||
if (!isInitialized()) {
|
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
log(messageProvider.enableFailure(this, startTime));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log("启用完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log(messageProvider.enableSuccess(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public final void onDisable() {
|
||||||
if (!isOverride("shutdown")) return;
|
if (!hasOverride("shutdown") || !isInitialized()) return;
|
||||||
|
outputInfo();
|
||||||
|
|
||||||
log(getName() + " " + getDescription().getVersion() + " 开始卸载...");
|
log(messageProvider.disabling(this));
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
shutdown();
|
shutdown();
|
||||||
log("卸载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
|
log(messageProvider.disabled(this, startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load() {
|
protected void load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean initialize();
|
protected abstract boolean initialize();
|
||||||
|
|
||||||
public void shutdown() {
|
protected void shutdown() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重写以展示插件的相关信息,如插件横幅、下载地址等。
|
||||||
|
*/
|
||||||
|
public void outputInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
@@ -99,28 +115,25 @@ public abstract class EasyPlugin extends JavaPlugin {
|
|||||||
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
if (tabCompleter != null) command.setTabCompleter(tabCompleter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void print(@Nullable String prefix, @Nullable String... messages) {
|
||||||
|
messageProvider.print(this, prefix, messages);
|
||||||
|
}
|
||||||
|
|
||||||
public void log(@Nullable String... messages) {
|
public void log(@Nullable String... messages) {
|
||||||
print(null, messages);
|
print(null, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void print(@Nullable String prefix, @Nullable String... messages) {
|
|
||||||
Arrays.stream(messages)
|
|
||||||
.map(message -> "[" + getName() + "] " + (prefix == null ? "" : prefix) + message)
|
|
||||||
.map(ColorParser::parse)
|
|
||||||
.forEach(message -> Bukkit.getConsoleSender().sendMessage(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String... messages) {
|
public void error(String... messages) {
|
||||||
print("&c[ERROR] &r", messages);
|
print("&c[ERROR] &r", messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(@Nullable String... messages) {
|
public void debug(@Nullable String... messages) {
|
||||||
if (isDebugging()) print("&7[DEBUG] &r", messages);
|
if (isDebugging()) print("&8[DEBUG] &r", messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isOverride(String methodName) {
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
|
private boolean hasOverride(String methodName) {
|
||||||
Map<Method, Method> methodMap = new HashMap<>();
|
Map<Method, Method> methodMap = new HashMap<>();
|
||||||
Arrays.stream(EasyPlugin.class.getDeclaredMethods())
|
Arrays.stream(EasyPlugin.class.getDeclaredMethods())
|
||||||
.filter(method -> method.getName().equals(methodName))
|
.filter(method -> method.getName().equals(methodName))
|
||||||
@@ -132,4 +145,5 @@ public abstract class EasyPlugin extends JavaPlugin {
|
|||||||
);
|
);
|
||||||
return !methodMap.isEmpty();
|
return !methodMap.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
package cc.carm.lib.easyplugin.i18n;
|
||||||
|
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public interface EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
String loading(Plugin plugin);
|
||||||
|
|
||||||
|
String loaded(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String enabling(Plugin plugin);
|
||||||
|
|
||||||
|
String enableSuccess(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String enableFailure(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
String disabling(Plugin plugin);
|
||||||
|
|
||||||
|
String disabled(Plugin plugin, long startMillis);
|
||||||
|
|
||||||
|
default void print(@NotNull Plugin plugin, @Nullable String prefix, @Nullable String... messages) {
|
||||||
|
Arrays.stream(messages)
|
||||||
|
.map(message -> "[" + plugin.getName() + "] " + (prefix == null ? "" : prefix) + message)
|
||||||
|
.map(ColorParser::parse)
|
||||||
|
.forEach(message -> Bukkit.getConsoleSender().sendMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
class zh_CN implements EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loading(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始加载...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loaded(Plugin plugin, long startMillis) {
|
||||||
|
return "&f加载完成 ,共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始启动...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableSuccess(Plugin plugin, long startMillis) {
|
||||||
|
return "&a启用完成! &f共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableFailure(Plugin plugin, long startMillis) {
|
||||||
|
return "&c启用失败! &f已耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " 开始卸载...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabled(Plugin plugin, long startMillis) {
|
||||||
|
return "&f卸载完成! 共耗时 " + (System.currentTimeMillis() - startMillis) + " ms 。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class en_US implements EasyPluginMessageProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loading(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " loading...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String loaded(Plugin plugin, long startMillis) {
|
||||||
|
return "&fLoaded after " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " enabling...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableSuccess(Plugin plugin, long startMillis) {
|
||||||
|
return "&aEnabled successfully!&f Cost " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String enableFailure(Plugin plugin, long startMillis) {
|
||||||
|
return "&cEnabled failed after " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabling(Plugin plugin) {
|
||||||
|
return "&f" + plugin.getName() + " " + plugin.getDescription().getVersion() + " begin to shutdown...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String disabled(Plugin plugin, long startMillis) {
|
||||||
|
return "&fShutdown successfully, cost " + (System.currentTimeMillis() - startMillis) + " ms.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,7 +6,11 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
|
||||||
@@ -42,6 +46,15 @@ public class MessageUtils {
|
|||||||
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
sendWithPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@Nullable CommandSender sender, String message) {
|
||||||
|
if (message == null || sender == null) return message;
|
||||||
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
|
return PlaceholderAPI.setPlaceholders((Player) sender, message);
|
||||||
|
} else {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages) {
|
||||||
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
if (messages == null || messages.isEmpty() || sender == null) return messages;
|
||||||
if (hasPlaceholderAPI() && sender instanceof Player) {
|
if (hasPlaceholderAPI() && sender instanceof Player) {
|
||||||
@@ -51,10 +64,36 @@ public class MessageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String setPlaceholders(@Nullable CommandSender sender, String message, String[] params, Object[] values) {
|
||||||
|
return setPlaceholders(sender, setCustomParams(message, params, values));
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
public static List<String> setPlaceholders(@Nullable CommandSender sender, List<String> messages, String[] params, Object[] values) {
|
||||||
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
return setPlaceholders(sender, setCustomParams(messages, params, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String setCustomParams(String message, String param, Object value) {
|
||||||
|
return setCustomParams(message, new String[]{param}, new Object[]{value});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String setCustomParams(String message, String[] params, Object[] values) {
|
||||||
|
if (params.length != values.length) return message;
|
||||||
|
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||||
|
for (int i = 0; i < params.length; i++) {
|
||||||
|
paramsMap.put(params[i], values[i]);
|
||||||
|
}
|
||||||
|
return setCustomParams(message, paramsMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String setCustomParams(String message, HashMap<String, Object> params) {
|
||||||
|
String afterMessage = message;
|
||||||
|
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||||
|
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
return afterMessage;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
public static List<String> setCustomParams(List<String> messages, String param, Object value) {
|
||||||
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
return setCustomParams(messages, new String[]{param}, new Object[]{value});
|
||||||
}
|
}
|
||||||
@@ -70,15 +109,7 @@ public class MessageUtils {
|
|||||||
|
|
||||||
|
|
||||||
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
public static List<String> setCustomParams(List<String> messages, HashMap<String, Object> params) {
|
||||||
List<String> list = new ArrayList<>();
|
return messages.stream().map(message -> setCustomParams(message, params)).collect(Collectors.toList());
|
||||||
for (String message : messages) {
|
|
||||||
String afterMessage = message;
|
|
||||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
|
||||||
afterMessage = afterMessage.replace(entry.getKey(), entry.getValue().toString());
|
|
||||||
}
|
|
||||||
list.add(afterMessage);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>21-EasyPlugin-PlaceholderAPI</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
<artifactId>easyplugin-vault</artifactId>
|
<artifactId>easyplugin-vault</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>22-EasyPlugin-Vault</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyplugin-parent</artifactId>
|
<artifactId>easyplugin-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>easyplugin-main</module>
|
<module>easyplugin-main</module>
|
||||||
|
|
||||||
@@ -72,12 +72,6 @@
|
|||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
||||||
<repository>
|
|
||||||
<id>github</id>
|
|
||||||
<name>GitHub Packages</name>
|
|
||||||
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
|
||||||
</repository>
|
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>central</id>
|
||||||
<url>https://repo1.maven.org/maven2/</url>
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
@@ -90,8 +84,17 @@
|
|||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>nexus</id>
|
<id>EasySQL</id>
|
||||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>github</id>
|
||||||
|
<name>GitHub Packages</name>
|
||||||
|
<url>https://maven.pkg.github.com/CarmJos/EasyPlugin</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|||||||
Reference in New Issue
Block a user