1
mirror of https://github.com/CarmJos/EasyPlugin.git synced 2024-09-19 19:25:45 +00:00

feat(papi): 提供便捷的PlaceholderAPI变量实现类。

This commit is contained in:
Carm Jos 2023-02-19 03:32:19 +08:00
parent 3019216801
commit a9d26e179c
20 changed files with 154 additions and 20 deletions

View File

@ -108,3 +108,27 @@ jobs:
git add -A
git commit -m "API Document generated."
git push origin HEAD:gh-pages --force
central-deploy:
name: "Deploy Project (Central)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Set up JDK"
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
cache: maven
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: "Central Deploy"
run: mvn -B -Possrh deploy --file pom.xml -DskipTests
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASS }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-parent</artifactId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

21
base/messages/pom.xml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-parent</artifactId>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>easyplugin-messages</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -9,8 +9,10 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class EasyPlaceholder extends PlaceholderExpansion {
@ -108,20 +110,66 @@ public class EasyPlaceholder extends PlaceholderExpansion {
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 变量的处理器返回值将会被转换为字符串
* @param handler 变量的处理器返回值将会被转换为字符串
* @param aliases 该变量的别称
* @return {@link EasyPlaceholder}
*/
public final EasyPlaceholder handle(String identifier, @NotNull PlaceholderHandler handler, @NotNull String... aliases) {
public final EasyPlaceholder handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull String... aliases) {
this.rootExpansion.handle(identifier, handler, aliases);
return this;
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param paramsConsumer 用于提供该变量的可用参数
* @param aliases 该变量的别称
* @return {@link EasyPlaceholder}
*/
public final EasyPlaceholder handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull Consumer<ArrayList<String>> paramsConsumer, @NotNull String... aliases) {
this.rootExpansion.handle(identifier, handler, paramsConsumer, aliases);
return this;
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param availableParams 该变量的可用参数
* @param aliases 该变量的别称
* @return {@link EasyPlaceholder}
*/
public final EasyPlaceholder handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull List<String> availableParams, @NotNull String... aliases) {
this.rootExpansion.handle(identifier, handler, availableParams, aliases);
return this;
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param availableParams 该变量的可用参数
* @param aliases 该变量的别称
* @return {@link EasyPlaceholder}
*/
public final EasyPlaceholder handle(String identifier, @NotNull PlaceholderHandler handler,
@NotNull Supplier<List<String>> availableParams, @NotNull String... aliases) {
this.rootExpansion.handle(identifier, handler, availableParams, aliases);
return this;
}
/**
* 处理一组变量
*
* @param section 该组变量的标识符
* @param consumer 该组变量的处理器
* @param consumer 该组变量的处理器操作方法
* <br> 在其中可调用 {@link SectionExpansion#handle(String, PlaceholderHandler, String...)} 方法处理子变量,
* <br> 或者调用 {@link SectionExpansion#handleSection(String, Consumer, String...)} 方法处理下一层组变量
* @param aliases 该变量的别称

View File

@ -61,11 +61,26 @@ public class SectionExpansion implements EasyExpansion {
placeholder.getAliases().forEach(alias -> this.aliasesMap.put(alias.toLowerCase(), name));
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param aliases 该变量的别称
*/
public final void handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull String... aliases) {
handle(identifier, handler, Collections.emptyList(), aliases);
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param paramsConsumer 用于提供该变量的可用参数
* @param aliases 该变量的别称
*/
public final void handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull Consumer<ArrayList<String>> paramsConsumer, @NotNull String... aliases) {
handle(identifier, handler, () -> {
@ -75,11 +90,27 @@ public class SectionExpansion implements EasyExpansion {
}, aliases);
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param availableParams 该变量的可用参数
* @param aliases 该变量的别称
*/
public final void handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull List<String> availableParams, @NotNull String... aliases) {
handle(identifier, handler, () -> availableParams, aliases);
}
/**
* 处理变量并返回对应内容
*
* @param identifier 该变量的标识符
* @param handler 该变量的处理器返回值将会被转换为字符串
* @param availableParams 该变量的可用参数
* @param aliases 该变量的别称
*/
public final void handle(@NotNull String identifier, @NotNull PlaceholderHandler handler,
@NotNull Supplier<List<String>> availableParams, @NotNull String... aliases) {
register(new SubExpansion<SectionExpansion>(this, identifier, aliases) {
@ -95,6 +126,15 @@ public class SectionExpansion implements EasyExpansion {
});
}
/**
* 处理一组变量
*
* @param section 该组变量的标识符
* @param consumer 该组变量的处理器操作方法
* <br> 在其中可调用 {@link SectionExpansion#handle(String, PlaceholderHandler, String...)} 方法处理子变量,
* <br> 或者调用 {@link SectionExpansion#handleSection(String, Consumer, String...)} 方法处理下一层组变量
* @param aliases 该变量的别称
*/
public final void handleSection(@NotNull String section, @NotNull Consumer<SectionExpansion> consumer,
@NotNull String... aliases) {
SectionExpansion sectionExpansion = new SectionExpansion(getRoot(), section, aliases);

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>easyplugin-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>1.4.20</version>
<version>1.5.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -15,12 +15,14 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-parent</artifactId>
<packaging>pom</packaging>
<version>1.4.20</version>
<version>1.5.0</version>
<modules>
<module>base/color</module>
<module>base/utils</module>
<module>base/main</module>
<module>base/conf</module>
<module>base/messages</module>
<module>base/gui</module>
<module>base/command</module>
<module>base/storage</module>
@ -34,7 +36,6 @@
<module>collection/all</module>
<module>collection/bom</module>
<module>collection/common</module>
<module>base/color</module>
</modules>