mirror of
https://github.com/CarmJos/EasyPlugin.git
synced 2026-06-05 00:58:17 +08:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba8e2b2929 | |||
| ed505357f3 | |||
| 54939f0f14 | |||
| bc3dd32f85 | |||
| 22ee1a157a | |||
| 00f1ff20fa | |||
| 91136a506d | |||
| edb8e0849a | |||
| 4e6caae8c9 | |||
| dd592cb764 | |||
| 5784215209 | |||
| 0eb774f560 | |||
| 4e24a87f12 | |||
| 44357d401f | |||
| d758e460f8 | |||
| 2caa33eb76 | |||
| 9450ef79fc | |||
| 89a17264f2 | |||
| 7923de25fb | |||
| bc046c02e4 | |||
| 1d279a16a8 | |||
| 17b7c23c54 | |||
| 1b7f60fe43 | |||
| de4dbbe637 | |||
| d26987c0d2 | |||
| 906fbf016e | |||
| 9d97837a24 | |||
| 2efdc5f5a6 | |||
| 19f25db0b7 | |||
| 046e901ec1 | |||
| 6685480957 | |||
| ce1538003b | |||
| fa4a97d60d | |||
| 85b7179867 | |||
| 391f9b6389 | |||
| 0e74d6864c | |||
| f5d2022d8b | |||
| d7303719dd | |||
| 76b15f0cda | |||
| f97fd97a3c | |||
| 0c0249cab6 | |||
| 25eae114ad | |||
| edab1a822d |
@@ -14,9 +14,9 @@ jobs:
|
||||
packages-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
server-password: MAVEN_TOKEN
|
||||
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B -Pgithub deploy --file pom.xml -DskipTests
|
||||
run: mvn -B -Pgithub deploy --file pom.xml -DskipTests -Dgpg.skip
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
@@ -35,16 +35,15 @@ jobs:
|
||||
github-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B -Plocal deploy --file pom.xml -DskipTests
|
||||
run: mvn -B -Plocal deploy --file pom.xml -DskipTests -Dgpg.skip
|
||||
|
||||
- name: "Copy artifacts"
|
||||
run: |
|
||||
@@ -60,7 +59,7 @@ jobs:
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf target/site/apidocs/* docs/
|
||||
cp -vrf target/reports/apidocs/* docs/
|
||||
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: "Generate Javadoc sitemap"
|
||||
@@ -113,21 +112,21 @@ jobs:
|
||||
name: "Deploy Project (Central)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '11'
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
server-id: ossrh
|
||||
server-id: central
|
||||
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
|
||||
run: mvn -B -Pcentral deploy --file pom.xml -DskipTests
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
|
||||
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASS }}
|
||||
|
||||
@@ -14,9 +14,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
cache: maven
|
||||
java-version: '8'
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
server-username: MAVEN_USERNAME
|
||||
server-password: MAVEN_TOKEN
|
||||
- name: "Package"
|
||||
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true
|
||||
run: mvn -B package --file pom.xml -Dmaven.javadoc.skip=true -Dgpg.skip
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
@@ -36,6 +36,9 @@
|
||||
|
||||
### 主要部分 (`/base`)
|
||||
|
||||
- Color [`easyplugin-color`](base/color)
|
||||
- 颜色工具类模块,提供功能全面的MC颜色解析转换工具。
|
||||
- 支持 `&+颜色代码`(原版颜色)、`§(#XXXXXX)`(RGB颜色) 与 `&<#XXXXXX>`(前后标注RGB颜色渐变)。
|
||||
- Utils [`easyplugin-utils`](base/utils)
|
||||
- 通用工具类模块,该模块中的内容支持在Bungee、Bukkit使用。
|
||||
- 本模块提供
|
||||
@@ -58,18 +61,18 @@
|
||||
- 支持多种消息配置,包括文本消息、ActionBar消息、Title消息、声音、粒子效果播放等。
|
||||
- 支持消息间的延迟发送。
|
||||
|
||||
> 以下项目均已独立出单独项目,仅仅是按照包名规则打包到EasyPlugin的子项目中。
|
||||
>
|
||||
> 如需使用,**强烈建议自行引用对应的项目**,以支持完整的Javadoc并获取源码内容!
|
||||
### 独立项目部分
|
||||
|
||||
- _Listener_ [`easyplugin-listener`](base/listener) (打包自 [**EasyListener**](https://github.com/CarmJos/EasyListener))
|
||||
- _Configuration_ [`easyplugin-conf`](base/conf) (打包自 [**MineConfiguration
|
||||
**](https://github.com/CarmJos/MineConfiguration))
|
||||
- _Database_ [`easyplugin-database`](base/database) (打包自 [**EasySQL**](https://github.com/CarmJos/EasySQL))
|
||||
> 以下项目均已独立出单独项目,如需使用,**强烈建议自行引用对应的项目**,以支持完整的Javadoc并获取源码内容!
|
||||
|
||||
- _Listener_ -> [**EasyListener**](https://github.com/CarmJos/EasyListener)
|
||||
- _Configuration_ -> [**MineConfiguration**](https://github.com/CarmJos/MineConfiguration)
|
||||
- _Database_ -> [**EasySQL**](https://github.com/CarmJos/EasySQL)
|
||||
|
||||
### 附属部分 (`/extension`)
|
||||
|
||||
- [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) [`easyplugin-placeholderapi`](extension/papi)
|
||||
- PlaceholderAPI 扩展模块,提供了方便的 PlaceholderAPI 变量注册方法。
|
||||
- [Vault](https://github.com/MilkBowl/VaultAPI)* [`easyplugin-vault`](extension/vault)
|
||||
|
||||
## 开发
|
||||
|
||||
+10
-1
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
@@ -47,4 +47,13 @@
|
||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -34,7 +34,7 @@ public class ColorParser {
|
||||
public static @NotNull String clear(@NotNull String text) {
|
||||
text = HEX_PATTERN.matcher(text).replaceAll("");
|
||||
text = GRADIENT_PATTERN.matcher(text).replaceAll("");
|
||||
text = COLOR_PATTERN.matcher(text).replaceAll("");
|
||||
text = FORMAT_PATTERN.matcher(text).replaceAll("");
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -162,9 +162,14 @@ public class ColorParser {
|
||||
startColor.getBlue() + bStep * i * bDirection
|
||||
)).toArray(String[]::new);
|
||||
|
||||
return IntStream.range(0, characters.length)
|
||||
.mapToObj(i -> colorText(characters[i], extraFormats.get(i), buildHexColor(hexes[i])))
|
||||
.collect(Collectors.joining());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String extra = null;
|
||||
for (int i = 0; i < characters.length; i++) {
|
||||
extra = buildExtraFormat(extra, extraFormats.get(i));
|
||||
String s = colorText(characters[i], extra, buildHexColor(hexes[i]));
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
|
||||
@@ -205,4 +210,13 @@ public class ColorParser {
|
||||
.collect(Collectors.joining("", '§' + "x", ""));
|
||||
}
|
||||
|
||||
protected static String buildExtraFormat(String current, String extra) {
|
||||
if (extra != null) current = (current == null ? "" : current) + extra;
|
||||
return isResetCode(current) ? null : current;
|
||||
}
|
||||
|
||||
protected static boolean isResetCode(String input) {
|
||||
return input != null && (input.toLowerCase().endsWith("&r") || input.toLowerCase().endsWith("§r"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,36 +15,11 @@ public class ColorParseTest {
|
||||
System.out.println(parseGradientColor("&<#AAAAAA>我真的&<#BBBBBB>爱死&<#111111>你&<#FFFFFF>!"));
|
||||
|
||||
// 测试穿插
|
||||
System.out.println(parse("&<#AAAAAA>&l我&r真&b的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||
System.out.println(parse("&<#AAAAAA>&l&m我真的&o尊的&r真的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||
System.out.println(parse("&<#AAAAAA>&l我&r真&(#666666)的&<#BBBBBB>&o爱死&<#111111>你&<#FFFFFF>了&r!"));
|
||||
System.out.println(parse("&r正常的颜色理应&c&l不受影响&r。"));
|
||||
|
||||
System.out.println(clear("&f测试&<#AAAAAA>清理颜色代码&<#111111> &&这样应该&(#666666)不被影响 &f。"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatReadTest() {
|
||||
LinkedHashMap<Integer, String> formats = new LinkedHashMap<>();
|
||||
String text = "&k&l &m&1我&k爱你爱你爱你&o吗?";
|
||||
Matcher matcher = ColorParser.FORMAT_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
String code = matcher.group();
|
||||
formats.put(matcher.start(), code);
|
||||
text = matcher.replaceFirst("");
|
||||
matcher.reset(text);
|
||||
}
|
||||
|
||||
formats.forEach((index, code) -> System.out.println(index + " -> " + code));
|
||||
|
||||
String[] parts = text.split("");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String format = formats.get(i);
|
||||
if (format != null) builder.append(ColorParser.parseBaseColor(format));
|
||||
builder.append(parts[i]);
|
||||
}
|
||||
|
||||
System.out.println(builder);
|
||||
System.out.println(clear("&f&l测试&<#AAAAAA>清理颜色代码&<#111111> &&这样应该&(#666666)不被影响 &f。"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>easyplugin-command-alias</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasyPlugin-Command-Alias</name>
|
||||
<description>轻松插件指令别名映射模块,支持将插件内复杂的子指令简化为一个单独的指令,方便玩家使用。</description>
|
||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>CarmJos</id>
|
||||
<name>Carm Jos</name>
|
||||
<email>carm@carm.cc</email>
|
||||
<url>https://www.carm.cc</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The MIT License</name>
|
||||
<url>https://opensource.org/licenses/MIT</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package cc.carm.lib.easyplugin.command.alias;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AliasCommand extends Command {
|
||||
|
||||
protected final AliasCommandManager aliasCommandManager;
|
||||
protected final String targetCommand;
|
||||
|
||||
public AliasCommand(String name, AliasCommandManager aliasCommandManager, String targetCommand) {
|
||||
super(name);
|
||||
this.aliasCommandManager = aliasCommandManager;
|
||||
this.targetCommand = targetCommand;
|
||||
}
|
||||
|
||||
protected SimpleCommandMap getCommandMap() {
|
||||
return this.aliasCommandManager.getCommandMap();
|
||||
}
|
||||
|
||||
protected String buildCommand(String[] args) {
|
||||
return this.targetCommand + " " + String.join(" ", args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
return getCommandMap().dispatch(sender, buildCommand(args));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
|
||||
@NotNull String[] args, @Nullable Location location) throws IllegalArgumentException {
|
||||
return Optional.ofNullable(getCommandMap().tabComplete(sender, buildCommand(args))).orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
||||
return tabComplete(sender, alias, args, null);
|
||||
}
|
||||
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package cc.carm.lib.easyplugin.command.alias;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.plugin.SimplePluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 指令简化别名(简化映射)管理器
|
||||
* <br>支持将插件内复杂的子指令简化为一个单独的指令,方便玩家使用。
|
||||
*/
|
||||
public class AliasCommandManager {
|
||||
|
||||
protected final @NotNull JavaPlugin plugin;
|
||||
protected final @NotNull String prefix;
|
||||
|
||||
protected final @NotNull SimpleCommandMap commandMap;
|
||||
protected final @NotNull Field knownCommandsFiled;
|
||||
|
||||
protected final @NotNull Map<String, AliasCommand> registeredCommands = new HashMap<>();
|
||||
|
||||
public AliasCommandManager(@NotNull JavaPlugin plugin) throws Exception {
|
||||
this(plugin, plugin.getName());
|
||||
}
|
||||
|
||||
public AliasCommandManager(@NotNull JavaPlugin plugin, @NotNull String prefix) throws Exception {
|
||||
this.plugin = plugin;
|
||||
this.prefix = prefix.trim();
|
||||
|
||||
SimplePluginManager manager = (SimplePluginManager) Bukkit.getPluginManager();
|
||||
Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
this.commandMap = (SimpleCommandMap) commandMapField.get(manager);
|
||||
|
||||
this.knownCommandsFiled = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
this.knownCommandsFiled.setAccessible(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Command> getKnownCommands() {
|
||||
try {
|
||||
return (Map<String, Command>) knownCommandsFiled.get(commandMap);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
protected @NotNull SimpleCommandMap getCommandMap() {
|
||||
return commandMap;
|
||||
}
|
||||
|
||||
public String getCommandPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public void register(@NotNull String alias, @NotNull String subCommand) {
|
||||
AliasCommand current = this.registeredCommands.get(alias);
|
||||
if (current != null) current.unregister(getCommandMap());
|
||||
|
||||
AliasCommand cmd = new AliasCommand(alias, this, getCommandPrefix() + " " + subCommand);
|
||||
this.registeredCommands.put(alias, cmd);
|
||||
getCommandMap().register(plugin.getName(), cmd);
|
||||
}
|
||||
|
||||
public void unregister(@NotNull String alias) {
|
||||
AliasCommand current = this.registeredCommands.remove(alias);
|
||||
if (current != null) {
|
||||
getKnownCommands().remove(alias);
|
||||
current.unregister(getCommandMap());
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterAll() {
|
||||
registeredCommands.forEach((k, v) -> {
|
||||
getKnownCommands().remove(k);
|
||||
v.unregister(getCommandMap());
|
||||
});
|
||||
registeredCommands.clear();
|
||||
}
|
||||
|
||||
}
|
||||
+11
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -48,4 +48,14 @@
|
||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>easyplugin-conf</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasyPlugin-Configuration</name>
|
||||
<description>轻松插件配置文件接口模块,基于 MineConfiguration 项目。</description>
|
||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<!-- https://github.com/CarmJos/MineConfiguration -->
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</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.configuration.core</pattern>
|
||||
<shadedPattern>cc.carm.lib.easyplugin.conf</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.mineconfiguration.common</pattern>
|
||||
<shadedPattern>cc.carm.lib.easyplugin.conf</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.mineconfiguration.bukkit</pattern>
|
||||
<shadedPattern>cc.carm.lib.easyplugin.conf</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>
|
||||
@@ -1,73 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>easyplugin-database</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasyPlugin-Database</name>
|
||||
<description>轻松插件数据库接口模块,基于 EasySQL 项目。</description>
|
||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<!-- https://github.com/CarmJos/EasySQL -->
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-beecp</artifactId>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</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>
|
||||
+10
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -59,4 +59,13 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -19,7 +19,7 @@ import java.util.stream.IntStream;
|
||||
public class GUI {
|
||||
|
||||
private static JavaPlugin plugin;
|
||||
private static final HashMap<UUID, GUI> openedGUIs = new HashMap<>();
|
||||
private static final Map<UUID, GUI> openedGUIs = new HashMap<>();
|
||||
|
||||
public static void initialize(JavaPlugin plugin) {
|
||||
GUI.plugin = plugin;
|
||||
@@ -29,43 +29,32 @@ public class GUI {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static HashMap<UUID, GUI> getOpenedGUIs() {
|
||||
public static Map<UUID, GUI> getOpenedGUIs() {
|
||||
return openedGUIs;
|
||||
}
|
||||
|
||||
protected GUIType type;
|
||||
protected String name;
|
||||
public HashMap<Integer, GUIItem> items;
|
||||
public Inventory inv;
|
||||
protected final @NotNull GUIType type;
|
||||
protected @NotNull String title;
|
||||
protected Inventory inv;
|
||||
|
||||
/**
|
||||
* 当玩家点击目标GUI时是否取消
|
||||
*/
|
||||
boolean cancelOnTarget = true;
|
||||
protected final SortedMap<Integer, GUIItem> items = new TreeMap<>();
|
||||
protected ItemStack emptyItem = null;
|
||||
|
||||
/**
|
||||
* 当玩家点击自己背包时是否取消
|
||||
*/
|
||||
boolean cancelOnSelf = true;
|
||||
|
||||
/**
|
||||
* 当玩家点击界面外时是否取消
|
||||
*/
|
||||
boolean cancelOnOuter = true;
|
||||
protected boolean cancelOnTarget = true; // 当玩家点击GUI时是否取消对应事件
|
||||
protected boolean cancelOnSelf = true; // 当玩家点击自己背包时是否取消对应事件
|
||||
protected boolean cancelOnOuter = true; // 当玩家点击界面外时是否取消对应事件
|
||||
|
||||
protected final Map<String, Object> flags = new LinkedHashMap<>();
|
||||
|
||||
protected GUIListener listener;
|
||||
|
||||
public GUI(GUIType type, String name) {
|
||||
public GUI(@NotNull GUIType type, @NotNull String title) {
|
||||
this.type = type;
|
||||
this.name = ColorParser.parse(name);
|
||||
this.items = new HashMap<>();
|
||||
this.title = ColorParser.parse(title);
|
||||
}
|
||||
|
||||
|
||||
public HashMap<@NotNull Integer, @NotNull GUIItem> getItems() {
|
||||
return new HashMap<>(items);
|
||||
public SortedMap<@NotNull Integer, @NotNull GUIItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public final void setItem(int index, @Nullable GUIItem item) {
|
||||
@@ -76,24 +65,72 @@ public class GUI {
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemStack(int index, @Nullable ItemStack item) {
|
||||
setItem(index, item == null ? null : new GUIItem(item));
|
||||
}
|
||||
|
||||
public void setItem(GUIItem item, int... index) {
|
||||
for (int i : index) {
|
||||
setItem(i, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemStack(ItemStack item, int... index) {
|
||||
for (int i : index) {
|
||||
setItemStack(i, item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置GUI上方(箱子部分)
|
||||
* @param row 行数,1为第1行
|
||||
* @param column 列数,1为第1列
|
||||
* @param item GUIItem
|
||||
*/
|
||||
public void setItem(int row, int column, @NotNull GUIItem item){
|
||||
if(row <= 0 || column <= 0) throw new IllegalArgumentException("行数和列数都不能小于等于零");
|
||||
if(row > type.getLines()) throw new IllegalArgumentException("行数("+row+")大于GUI大小限制("+type.getLines()+")");
|
||||
if(column > 9) throw new IllegalArgumentException("列数("+column+")不能大于9");
|
||||
setItem(9*(row-1)+column-1, item);
|
||||
}
|
||||
|
||||
public GUIItem getItem(int index) {
|
||||
return this.items.get(index);
|
||||
}
|
||||
|
||||
public void setEmptyItem(ItemStack item) {
|
||||
this.emptyItem = item;
|
||||
}
|
||||
|
||||
protected void fillEmptySlots(@NotNull Inventory inventory) {
|
||||
if (emptyItem == null) return;
|
||||
IntStream.range(0, inventory.getSize())
|
||||
.filter(i -> inventory.getItem(i) == null)
|
||||
.forEach(index -> inventory.setItem(index, emptyItem));
|
||||
}
|
||||
|
||||
protected void applyToInventory(Inventory inventory) {
|
||||
IntStream.range(0, inventory.getSize()).forEach(index -> inventory.setItem(index, new ItemStack(Material.AIR)));
|
||||
getItems().forEach((index, item) -> inventory.setItem(index, item.getDisplay()));
|
||||
fillEmptySlots(inventory);
|
||||
}
|
||||
|
||||
public void updateTitle(@NotNull String title) {
|
||||
this.title = ColorParser.parse(title);
|
||||
if (this.inv != null) {
|
||||
this.inv = Bukkit.createInventory(null, this.type.getSize(), this.title);
|
||||
applyToInventory(this.inv);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新玩家箱子的视图
|
||||
*/
|
||||
public void updateView() {
|
||||
this.onUpdate();
|
||||
if (this.inv != null) {
|
||||
List<HumanEntity> viewers = this.inv.getViewers();
|
||||
IntStream.range(0, this.inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
||||
applyToInventory(this.inv);
|
||||
viewers.forEach(p -> ((Player) p).updateInventory());
|
||||
}
|
||||
}
|
||||
@@ -148,22 +185,22 @@ public class GUI {
|
||||
throw new IllegalStateException("被取消或不存在的GUI");
|
||||
}
|
||||
|
||||
Inventory inv = Bukkit.createInventory(null, this.type.getSize(), this.name);
|
||||
IntStream.range(0, inv.getSize()).forEach(index -> inv.setItem(index, new ItemStack(Material.AIR)));
|
||||
getItems().forEach((index, item) -> inv.setItem(index, item.getDisplay()));
|
||||
Inventory ui = Bukkit.createInventory(null, this.type.getSize(), this.title);
|
||||
applyToInventory(ui);
|
||||
|
||||
GUI previous = getOpenedGUI(player);
|
||||
if (previous != null) {
|
||||
if (previous != null && previous.listener != null) {
|
||||
previous.listener.close(player);
|
||||
}
|
||||
|
||||
setOpenedGUI(player, this);
|
||||
|
||||
this.inv = inv;
|
||||
player.openInventory(inv);
|
||||
this.inv = ui;
|
||||
player.openInventory(ui);
|
||||
|
||||
if (listener == null) {
|
||||
Bukkit.getPluginManager().registerEvents(listener = new GUIListener(this), getPlugin());
|
||||
this.listener = new GUIListener(this);
|
||||
Bukkit.getPluginManager().registerEvents(this.listener, getPlugin());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,12 +218,18 @@ public class GUI {
|
||||
public void onClose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 当GUI更新时执行的代码
|
||||
*/
|
||||
public void onUpdate() {
|
||||
}
|
||||
|
||||
public GUIType getGUIType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getGUIName() {
|
||||
return name;
|
||||
return title;
|
||||
}
|
||||
|
||||
public static void setOpenedGUI(Player player, GUI gui) {
|
||||
@@ -205,4 +248,11 @@ public class GUI {
|
||||
getOpenedGUIs().remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static void closeAll() {
|
||||
Set<HumanEntity> viewers = new HashSet<>();
|
||||
getOpenedGUIs().values().stream().flatMap(gui -> gui.inv.getViewers().stream()).forEach(viewers::add);
|
||||
viewers.forEach(HumanEntity::closeInventory);
|
||||
getOpenedGUIs().clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import java.util.Set;
|
||||
|
||||
public class GUIItem {
|
||||
|
||||
ItemStack display;
|
||||
boolean actionActive = true;
|
||||
protected ItemStack display;
|
||||
protected boolean actionActive = true;
|
||||
|
||||
public Set<GUIClickAction> actions = new HashSet<>();
|
||||
public Set<GUIClickAction> actionsIgnoreActive = new HashSet<>();
|
||||
protected final Set<GUIClickAction> actions = new HashSet<>();
|
||||
protected final Set<GUIClickAction> actionsIgnoreActive = new HashSet<>();
|
||||
|
||||
public GUIItem(ItemStack display) {
|
||||
this.display = display;
|
||||
@@ -78,6 +78,14 @@ public class GUIItem {
|
||||
|
||||
}
|
||||
|
||||
public Set<GUIClickAction> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public Set<GUIClickAction> getActionsIgnoreActive() {
|
||||
return actionsIgnoreActive;
|
||||
}
|
||||
|
||||
public abstract static class GUIClickAction {
|
||||
public abstract void run(ClickType type, Player player);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class GUIListener implements Listener {
|
||||
|
||||
GUI currentGUI;
|
||||
protected final GUI currentGUI;
|
||||
|
||||
public GUIListener(GUI gui) {
|
||||
this.currentGUI = gui;
|
||||
|
||||
@@ -12,6 +12,7 @@ public enum GUIType {
|
||||
FOUR_BY_NINE(4, 36),
|
||||
FIVE_BY_NINE(5, 45),
|
||||
SIX_BY_NINE(6, 54),
|
||||
|
||||
CANCEL(0, 0);
|
||||
|
||||
private final int lines;
|
||||
|
||||
@@ -4,36 +4,54 @@ import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class AutoPagedGUI extends CommonPagedGUI {
|
||||
|
||||
public static Function<Player, ItemStack> defaultPreviousPage = null;
|
||||
public static Function<Player, ItemStack> defaultNextPage = null;
|
||||
|
||||
ItemStack previousPageUI;
|
||||
ItemStack nextPageUI;
|
||||
int previousPageSlot = -1;
|
||||
int nextPageSlot = -1;
|
||||
protected ItemStack previousPageUI;
|
||||
protected ItemStack nextPageUI;
|
||||
protected ItemStack noPreviousPageUI;
|
||||
protected ItemStack noNextPageUI;
|
||||
protected int previousPageSlot = -1;
|
||||
protected int nextPageSlot = -1;
|
||||
|
||||
public AutoPagedGUI(GUIType type, String name, int[] range) {
|
||||
super(type, name, range);
|
||||
public AutoPagedGUI(@NotNull GUIType type, @NotNull String title, int[] range) {
|
||||
super(type, title, range);
|
||||
}
|
||||
|
||||
public AutoPagedGUI(GUIType type, String name, int a, int b) {
|
||||
super(type, name, a, b);
|
||||
public AutoPagedGUI(@NotNull GUIType type, @NotNull String title, int a, int b) {
|
||||
super(type, title, a, b);
|
||||
}
|
||||
|
||||
public void setPreviousPageUI(ItemStack lastPageUI) {
|
||||
public void setPreviousPageUI(@Nullable ItemStack lastPageUI) {
|
||||
this.previousPageUI = lastPageUI;
|
||||
}
|
||||
|
||||
public void setNextPageUI(ItemStack nextPageUI) {
|
||||
public void setNoPreviousPageUI(@Nullable ItemStack noPreviousPageUI) {
|
||||
this.noPreviousPageUI = noPreviousPageUI;
|
||||
}
|
||||
|
||||
public void setNextPageUI(@Nullable ItemStack nextPageUI) {
|
||||
this.nextPageUI = nextPageUI;
|
||||
}
|
||||
|
||||
public void setNoNextPageUI(@Nullable ItemStack noNextPageUI) {
|
||||
this.noNextPageUI = noNextPageUI;
|
||||
}
|
||||
|
||||
public void setPreviousPageSlot(int slot) {
|
||||
this.previousPageSlot = slot;
|
||||
}
|
||||
@@ -42,12 +60,31 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
||||
this.nextPageSlot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillEmptySlots(@NotNull Inventory inventory) {
|
||||
if (emptyItem == null) return;
|
||||
Set<Integer> rangeSet = Arrays.stream(this.range).boxed().collect(Collectors.toSet());
|
||||
if (previousPageSlot >= 0) rangeSet.add(previousPageSlot);
|
||||
if (nextPageSlot >= 0) rangeSet.add(nextPageSlot);
|
||||
IntStream.range(0, inventory.getSize())
|
||||
.filter(i -> inventory.getItem(i) == null)
|
||||
.filter(i -> !rangeSet.contains(i))
|
||||
.forEach(index -> inventory.setItem(index, emptyItem));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void openGUI(Player user) {
|
||||
if (previousPageSlot >= 0) {
|
||||
if (hasPreviousPage()) {
|
||||
setItem(previousPageSlot, new GUIItem(
|
||||
previousPageUI == null ? getDefaultPreviousPage(user) : previousPageUI) {
|
||||
ItemStack finalPreviousPageUI;
|
||||
if(previousPageUI != null)
|
||||
finalPreviousPageUI = previousPageUI;
|
||||
else if (defaultPreviousPage != null)
|
||||
finalPreviousPageUI = defaultPreviousPage.apply(user);
|
||||
else
|
||||
finalPreviousPageUI = null;
|
||||
setItem(previousPageSlot, new GUIItem(finalPreviousPageUI) {
|
||||
@Override
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
if (type == ClickType.RIGHT) {
|
||||
@@ -59,14 +96,20 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setItem(previousPageSlot, null);
|
||||
setItem(previousPageSlot, this.noPreviousPageUI == null ? null : new GUIItem(noPreviousPageUI));
|
||||
}
|
||||
}
|
||||
|
||||
if (nextPageSlot >= 0) {
|
||||
if (hasNextPage()) {
|
||||
setItem(nextPageSlot, new GUIItem(
|
||||
nextPageUI == null ? getDefaultNextPage(user) : nextPageUI) {
|
||||
ItemStack finalNextPageUI;
|
||||
if(previousPageUI != null)
|
||||
finalNextPageUI = nextPageUI;
|
||||
else if (defaultNextPage != null)
|
||||
finalNextPageUI = defaultNextPage.apply(user);
|
||||
else
|
||||
finalNextPageUI = null;
|
||||
setItem(nextPageSlot, new GUIItem(finalNextPageUI) {
|
||||
@Override
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
if (type == ClickType.RIGHT) {
|
||||
@@ -78,19 +121,12 @@ public class AutoPagedGUI extends CommonPagedGUI {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setItem(nextPageSlot, null);
|
||||
setItem(nextPageSlot, this.noNextPageUI == null ? null : new GUIItem(noNextPageUI));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
super.openGUI(user);
|
||||
}
|
||||
|
||||
private static ItemStack getDefaultNextPage(Player player) {
|
||||
return defaultNextPage != null ? defaultNextPage.apply(player) : null;
|
||||
}
|
||||
|
||||
private static ItemStack getDefaultPreviousPage(Player player) {
|
||||
return defaultPreviousPage != null ? defaultPreviousPage.apply(player) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,70 +4,38 @@ package cc.carm.lib.easyplugin.gui.paged;
|
||||
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class CommonPagedGUI extends PagedGUI {
|
||||
|
||||
private int[] range;
|
||||
protected final int[] range;
|
||||
|
||||
private CommonPagedGUI(GUIType type, String name) {
|
||||
super(type, name);
|
||||
public CommonPagedGUI(@NotNull GUIType type, @NotNull String title, int a, int b) {
|
||||
this(type, title, toRange(type, a, b));
|
||||
}
|
||||
|
||||
public CommonPagedGUI(GUIType type, String Name, int a, int b) {
|
||||
this(type, Name, toRange(type, a, b));
|
||||
}
|
||||
|
||||
public CommonPagedGUI(GUIType type, String Name, int[] range) {
|
||||
super(type, Name);
|
||||
public CommonPagedGUI(@NotNull GUIType type, @NotNull String title, int[] range) {
|
||||
super(type, title);
|
||||
Arrays.sort(range);
|
||||
this.range = range;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
int[] matrix = new int[]{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||
27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44,
|
||||
45, 46, 47, 48, 49, 50, 51, 52, 53
|
||||
}
|
||||
*/
|
||||
|
||||
private static int[] toRange(GUIType type, int a, int b) {
|
||||
if (a > b) {
|
||||
a = a ^ b;
|
||||
b = a ^ b;
|
||||
a = a ^ b;
|
||||
}
|
||||
|
||||
int lineA = getLine(a);
|
||||
int columnA = getColumn(a);
|
||||
int lineB = getLine(b);
|
||||
int columnB = getColumn(b);
|
||||
|
||||
if (lineB > type.getLines())
|
||||
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
|
||||
|
||||
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
|
||||
|
||||
for (int i = 0, l = 0; i < type.getSize(); i++) {
|
||||
int li = getLine(i);
|
||||
int ci = getColumn(i);
|
||||
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
|
||||
range[l] = i;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
|
||||
return range;
|
||||
@Override
|
||||
protected void fillEmptySlots(@NotNull Inventory inventory) {
|
||||
if (emptyItem == null) return;
|
||||
Set<Integer> rangeSet = Arrays.stream(this.range).boxed().collect(Collectors.toSet());
|
||||
IntStream.range(0, inventory.getSize())
|
||||
.filter(i -> inventory.getItem(i) == null)
|
||||
.filter(i -> !rangeSet.contains(i))
|
||||
.forEach(index -> inventory.setItem(index, emptyItem));
|
||||
}
|
||||
|
||||
private static int getLine(int i) {
|
||||
@@ -93,10 +61,8 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
* 前往第一页
|
||||
*/
|
||||
public void goFirstPage() {
|
||||
if (hasPreviousPage())
|
||||
this.page = 1;
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
this.page = 1;
|
||||
onPageChange(this.page);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,10 +70,8 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
* 前往最后一页
|
||||
*/
|
||||
public void goLastPage() {
|
||||
if (hasNextPage())
|
||||
this.page = getLastPageNumber();
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
this.page = getLastPageNumber();
|
||||
onPageChange(this.page);
|
||||
}
|
||||
|
||||
|
||||
@@ -116,8 +80,9 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
*
|
||||
* @return 最后一页的页码
|
||||
*/
|
||||
@Override
|
||||
public int getLastPageNumber() {
|
||||
return (this.container.size() / range.length) + 1;
|
||||
return getLastPageNumber(range.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,6 +101,8 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
super.openGUI(player);
|
||||
return;
|
||||
}
|
||||
if(page > getLastPageNumber())
|
||||
page = getLastPageNumber();
|
||||
List<GUIItem> list = new ArrayList<>();
|
||||
int start = (page - 1) * range.length;
|
||||
for (int i = start; i < start + range.length; i++) {
|
||||
@@ -159,4 +126,44 @@ public class CommonPagedGUI extends PagedGUI {
|
||||
super.openGUI(player);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int[] matrix = new int[]{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||
27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44,
|
||||
45, 46, 47, 48, 49, 50, 51, 52, 53
|
||||
}
|
||||
*/
|
||||
private static int[] toRange(GUIType type, int a, int b) {
|
||||
if (a > b) {
|
||||
a = a ^ b;
|
||||
b = a ^ b;
|
||||
a = a ^ b;
|
||||
}
|
||||
|
||||
int lineA = getLine(a);
|
||||
int columnA = getColumn(a);
|
||||
int lineB = getLine(b);
|
||||
int columnB = getColumn(b);
|
||||
|
||||
if (lineB > type.getLines())
|
||||
throw new IndexOutOfBoundsException("页面内容范围超过了GUI的大小");
|
||||
|
||||
int[] range = new int[(lineB - lineA + 1) * (columnB - columnA + 1)];
|
||||
|
||||
int l = 0;
|
||||
for (int i = 0; i < type.getSize(); i++) {
|
||||
int li = getLine(i);
|
||||
int ci = getColumn(i);
|
||||
if (li >= lineA && li <= lineB && ci >= columnA && ci <= columnB) {
|
||||
range[l] = i;
|
||||
l++;
|
||||
}
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,54 +4,94 @@ package cc.carm.lib.easyplugin.gui.paged;
|
||||
import cc.carm.lib.easyplugin.gui.GUI;
|
||||
import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PagedGUI extends GUI {
|
||||
|
||||
List<GUIItem> container = new ArrayList<>();
|
||||
public int page = 1;
|
||||
protected List<GUIItem> container = new ArrayList<>();
|
||||
protected int page = 1;
|
||||
|
||||
public PagedGUI(GUIType type, String name) {
|
||||
super(type, name);
|
||||
protected PagedGUI(@NotNull GUIType type, @NotNull String title) {
|
||||
super(type, title);
|
||||
}
|
||||
|
||||
public int addItem(GUIItem i) {
|
||||
public int setCurrentPage(int page) {
|
||||
this.page = Math.max(1, page);
|
||||
return this.page;
|
||||
}
|
||||
|
||||
public int getCurrentPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
public int getLastPageNumber() {
|
||||
return getLastPageNumber(getGUIType().getSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到最后一页的页码
|
||||
*
|
||||
* @return 最后一页的页码
|
||||
*/
|
||||
public int getLastPageNumber(int size) {
|
||||
return (this.container.size() / size) + ((this.container.size() % size) == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
public int addItem(@NotNull GUIItem i) {
|
||||
container.add(i);
|
||||
return container.size() - 1;
|
||||
}
|
||||
|
||||
public int addItem(int index, @NotNull GUIItem i) {
|
||||
container.add(index, i);
|
||||
return container.size() - 1;
|
||||
}
|
||||
|
||||
public int addItemStack(@NotNull ItemStack itemStack) {
|
||||
return addItem(new GUIItem(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从GUI中移除一个物品
|
||||
*
|
||||
* @param item 物品
|
||||
*/
|
||||
public void removeItem(GUIItem item) {
|
||||
public void removeItem(@NotNull GUIItem item) {
|
||||
container.remove(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从GUI中移除一个物品
|
||||
*
|
||||
* @param slot 物品格子数
|
||||
* @param index 物品格子数
|
||||
*/
|
||||
public void removeItem(int slot) {
|
||||
container.remove(slot);
|
||||
public void removeItem(int index) {
|
||||
container.remove(index);
|
||||
}
|
||||
|
||||
public List<GUIItem> getItemsContainer() {
|
||||
return new ArrayList<>(container);
|
||||
public @NotNull List<GUIItem> getPagedContainer() {
|
||||
return this.container;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当GUI改变页码时执行的代码
|
||||
*/
|
||||
public void onPageChange(int pageNum) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 前往上一页
|
||||
*/
|
||||
public void goPreviousPage() {
|
||||
if (hasPreviousPage())
|
||||
page--;
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (hasPreviousPage()) {
|
||||
this.page--;
|
||||
this.onPageChange(this.page);
|
||||
} else throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,10 +99,10 @@ public abstract class PagedGUI extends GUI {
|
||||
* 前往下一页
|
||||
*/
|
||||
public void goNextPage() {
|
||||
if (hasNextPage())
|
||||
page++;
|
||||
else
|
||||
throw new IndexOutOfBoundsException();
|
||||
if (hasNextPage()) {
|
||||
this.page++;
|
||||
this.onPageChange(this.page);
|
||||
} else throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import org.junit.Test;
|
||||
|
||||
public class PageTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
System.out.println(maxPage(0, 10));
|
||||
System.out.println(maxPage(10, 10));
|
||||
System.out.println(maxPage(5, 10));
|
||||
System.out.println(maxPage(15, 10));
|
||||
System.out.println(maxPage(19, 10));
|
||||
System.out.println(maxPage(20, 10));
|
||||
|
||||
}
|
||||
|
||||
int maxPage(int contents, int size) {
|
||||
if (contents == 0 || size == 0) return 1;
|
||||
return (contents / size) + ((contents % size) == 0 ? 0 : 1);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>easyplugin-listener</artifactId>
|
||||
|
||||
<name>EasyPlugin-Listener</name>
|
||||
<description>轻松插件监听器接口模块,基于 EasyListener 项目。</description>
|
||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU LESSER GENERAL PUBLIC LICENSE</name>
|
||||
<url>https://www.gnu.org/licenses/lgpl-3.0.html</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<!-- https://github.com/CarmJos/EasyListener -->
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easylistener</artifactId>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0</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.easylistener</pattern>
|
||||
<shadedPattern>cc.carm.lib.easyplugin.listener</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>
|
||||
+10
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -68,4 +68,13 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,208 +0,0 @@
|
||||
package cc.carm.lib.easyplugin.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
/**
|
||||
* 颜色解析器。
|
||||
* <br> 普通颜色 格式 {@code &+颜色代码 },如 {@literal &c} 、{@literal &a}
|
||||
* <br> RGB颜色(版本需要≥1.14) 格式 {@code &(#XXXXXX) },如 {@literal &(#aaaaaa)}
|
||||
* <br> 渐变RBG颜色(版本需要≥1.14) 格式 {@code &<#XXXXXX>FOOBAR&<#XXXXXX> }
|
||||
* <p> 注意:当使用渐变RGB颜色时,普通颜色代码与RGB颜色代码将失效。
|
||||
*/
|
||||
public class ColorParser {
|
||||
|
||||
public static final Pattern HEX_PATTERN = Pattern.compile("&\\(&?#([\\da-fA-F]{6})\\)");
|
||||
public static final Pattern GRADIENT_PATTERN = Pattern.compile("&<&?#([\\da-fA-F]{6})>");
|
||||
public static final Pattern COLOR_PATTERN = Pattern.compile("([&§][0-9a-fA-FrRxX])+"); // 会影响颜色的代码
|
||||
public static final Pattern FORMAT_PATTERN = Pattern.compile("([&§][0-9a-fA-Fk-oK-OrRxX])+"); // MC可用的格式化代码
|
||||
|
||||
/**
|
||||
* 清除一条消息中的全部颜色代码 (包括RGB颜色代码与渐变颜色代码)
|
||||
*
|
||||
* @param text 源消息内容
|
||||
* @return 清理颜色后的消息
|
||||
*/
|
||||
public static @NotNull String clear(@NotNull String text) {
|
||||
text = HEX_PATTERN.matcher(text).replaceAll("");
|
||||
text = GRADIENT_PATTERN.matcher(text).replaceAll("");
|
||||
text = COLOR_PATTERN.matcher(text).replaceAll("");
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对一条消息进行颜色解析,包括普通颜色代码、RGB颜色代码与RBG渐变代码。
|
||||
*
|
||||
* @param text 源消息内容
|
||||
* @return 解析后的消息
|
||||
*/
|
||||
public static @NotNull String parse(@NotNull String text) {
|
||||
return parseBaseColor(parseGradientColor(parseHexColor(text)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 对多条消息进行颜色解析,包括普通颜色代码、RGB颜色代码与RBG渐变代码。
|
||||
*
|
||||
* @param texts 源消息内容
|
||||
* @return 解析后的消息
|
||||
*/
|
||||
public static @NotNull String[] parse(@NotNull String... texts) {
|
||||
return parse(Arrays.asList(texts)).toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对多条消息进行颜色解析,包括普通颜色代码、RGB颜色代码与RBG渐变代码。
|
||||
*
|
||||
* @param texts 源消息内容
|
||||
* @return 解析后的消息
|
||||
*/
|
||||
public static @NotNull List<String> parse(@NotNull Collection<String> texts) {
|
||||
return texts.stream().map(ColorParser::parse).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析消息中的基本颜色代码格式 {@code &+颜色代码 },如 {@literal &c} 、{@literal &a}
|
||||
*
|
||||
* @param text 消息内容
|
||||
* @return RGB处理后的消息
|
||||
* @see net.md_5.bungee.api.ChatColor
|
||||
*/
|
||||
public static String parseBaseColor(final String text) {
|
||||
return text.replaceAll("&", "§").replace("§§", "&");
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析消息中的RGB颜色代码(版本需要≥1.14) 格式 {@code &(#XXXXXX) },如 {@literal &(#aaaaaa)}
|
||||
*
|
||||
* @param text 消息内容
|
||||
* @return RGB处理后的消息
|
||||
*/
|
||||
public static String parseHexColor(String text) {
|
||||
Matcher matcher = HEX_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
text = matcher.replaceFirst(buildHexColor(matcher.group(1)).toLowerCase());
|
||||
matcher.reset(text);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对一条消息进行RGB渐变处理(版本需要≥1.14),格式 {@code &<#XXXXXX>FOOBAR&<#XXXXXX> }。
|
||||
*
|
||||
* @param text 消息内容
|
||||
* @return RGB渐变处理后的消息
|
||||
*/
|
||||
public static @NotNull String parseGradientColor(@NotNull String text) {
|
||||
List<String> colors = new ArrayList<>();
|
||||
|
||||
Matcher matcher = ColorParser.GRADIENT_PATTERN.matcher(text);
|
||||
while (matcher.find()) colors.add(matcher.group(1));
|
||||
|
||||
if (colors.isEmpty()) return text; // 无渐变颜色,直接跳出
|
||||
|
||||
String[] parts = ColorParser.GRADIENT_PATTERN.split(text);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String startHex = i - 1 >= 0 && colors.size() > i - 1 ? colors.get(i - 1) : null; // 本条消息的起始颜色
|
||||
String endHex = colors.size() > i ? colors.get(i) : null; // 本条消息的结束颜色
|
||||
builder.append(gradientText(parts[i], startHex, endHex));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static @NotNull String gradientText(@NotNull String text,
|
||||
@Nullable Color startColor, @Nullable Color endColor) {
|
||||
Objects.requireNonNull(text, "Text to be gradient should not be null!");
|
||||
if (startColor == null || endColor == null || text.isEmpty()) {
|
||||
// 起始颜色有任一为空,则不进行渐变上色。
|
||||
// 若有起始颜色,则代表其跟在某个渐变之后,应当添加"&r"阻断前面的渐变。
|
||||
return (startColor != null ? "&r" : "") + text;
|
||||
}
|
||||
|
||||
// 用于记录消息中特殊格式的位置
|
||||
// 在渐变中,允许使用格式字符与颜色字符来改变其中某个字的颜色/格式,以支持更多形式内容。
|
||||
LinkedHashMap<Integer, String> extraFormats = new LinkedHashMap<>();
|
||||
Matcher matcher = ColorParser.FORMAT_PATTERN.matcher(text);
|
||||
while (matcher.find()) {
|
||||
extraFormats.put(matcher.start(), matcher.group());
|
||||
text = matcher.replaceFirst("");
|
||||
matcher.reset(text);
|
||||
}
|
||||
|
||||
if (text.length() == 1) {
|
||||
// 当只有一个实际字符时,无需进行渐变计算,直接返回 中间颜色+起始格式(如果有)+消息 即可。
|
||||
return colorText(text, extraFormats.get(0), buildHexColor(mediumHex(startColor, endColor)));
|
||||
}
|
||||
|
||||
String[] characters = text.split("");
|
||||
int step = characters.length; // 变换次数
|
||||
|
||||
// 决定每种颜色变换的方向
|
||||
int rDirection = startColor.getRed() < endColor.getRed() ? 1 : -1;
|
||||
int gDirection = startColor.getGreen() < endColor.getGreen() ? 1 : -1;
|
||||
int bDirection = startColor.getBlue() < endColor.getBlue() ? 1 : -1;
|
||||
|
||||
// 决定每种颜色每次变换的度
|
||||
int rStep = Math.abs(startColor.getRed() - endColor.getRed()) / (step - 1);
|
||||
int gStep = Math.abs(startColor.getGreen() - endColor.getGreen()) / (step - 1);
|
||||
int bStep = Math.abs(startColor.getBlue() - endColor.getBlue()) / (step - 1);
|
||||
|
||||
String[] hexes = IntStream.range(0, step).mapToObj(i -> colorToHex(
|
||||
startColor.getRed() + rStep * i * rDirection,
|
||||
startColor.getGreen() + gStep * i * gDirection,
|
||||
startColor.getBlue() + bStep * i * bDirection
|
||||
)).toArray(String[]::new);
|
||||
|
||||
return IntStream.range(0, characters.length)
|
||||
.mapToObj(i -> colorText(characters[i], extraFormats.get(i), buildHexColor(hexes[i])))
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
|
||||
protected static String gradientText(@NotNull String text, @Nullable String startHex, @Nullable String endHex) {
|
||||
return gradientText(text,
|
||||
startHex == null ? null : Color.decode("0x" + startHex),
|
||||
endHex == null ? null : Color.decode("0x" + endHex)
|
||||
);
|
||||
}
|
||||
|
||||
private static String mediumHex(@NotNull Color start, @NotNull Color end) {
|
||||
return colorToHex(
|
||||
Math.abs(start.getRed() - end.getRed()) / 2,
|
||||
Math.abs(start.getGreen() - end.getGreen()) / 2,
|
||||
Math.abs(start.getBlue() - end.getBlue()) / 2
|
||||
);
|
||||
}
|
||||
|
||||
private static String colorText(String message, @Nullable String format, @Nullable String color) {
|
||||
if (format != null && COLOR_PATTERN.matcher(format).find()) {
|
||||
// format中存在影响颜色的内容,则当前消息的颜色会被覆盖。
|
||||
// 为了减少最终消息的长度,故直接返回键入的FORMAT和对应消息的内容。
|
||||
return format + message;
|
||||
}
|
||||
return (color == null ? "" : color) + (format == null ? "" : parseBaseColor(format)) + message;
|
||||
}
|
||||
|
||||
protected static String colorToHex(Color color) {
|
||||
return colorToHex(color.getRed(), color.getGreen(), color.getBlue());
|
||||
}
|
||||
|
||||
protected static String colorToHex(int r, int g, int b) {
|
||||
// 将R、G、B转换为16进制(若非2位则补0)输出
|
||||
return String.format("%02X%02X%02X", r, g, b);
|
||||
}
|
||||
|
||||
protected static String buildHexColor(String hexCode) {
|
||||
return Arrays.stream(hexCode.split("")).map(s -> '§' + s)
|
||||
.collect(Collectors.joining("", '§' + "x", ""));
|
||||
}
|
||||
|
||||
}
|
||||
+57
-7
@@ -6,16 +6,66 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
<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>
|
||||
<name>EasyPlugin-Messages</name>
|
||||
<description>
|
||||
轻松插件消息配置模块,支持多种消息配置,包括文本消息、ActionBar消息、Title消息、声音、粒子效果播放等。
|
||||
</description>
|
||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>easyplugin-color</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>CarmJos</id>
|
||||
<name>Carm Jos</name>
|
||||
<email>carm@carm.cc</email>
|
||||
<url>https://www.carm.cc</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The MIT License</name>
|
||||
<url>https://opensource.org/licenses/MIT</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -23,5 +23,13 @@
|
||||
<description>轻松插件存储接口模块,包含存储相关的统一接口。</description>
|
||||
<url>https://github.com/CarmJos/EasyPlugin</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
<artifactId>easyplugin-user</artifactId>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>CarmJos</id>
|
||||
<name>Carm Jos</name>
|
||||
<email>carm@carm.cc</email>
|
||||
<url>https://www.carm.cc</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The MIT License</name>
|
||||
<url>https://opensource.org/licenses/MIT</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasyPlugin/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyplugin-main</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,52 @@
|
||||
package cc.carm.lib.easyplugin.user;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractUserData<K> implements UserData<K> {
|
||||
|
||||
protected final @NotNull K key;
|
||||
|
||||
/**
|
||||
* Used to mark the data as dropping (save and unload) status.
|
||||
*/
|
||||
protected boolean dropping = false;
|
||||
|
||||
protected AbstractUserData(@NotNull K key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull K key() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dropping true if the data is dropping, false otherwise
|
||||
*/
|
||||
public void setDropping(boolean dropping) {
|
||||
this.dropping = dropping;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the data is dropping, false otherwise
|
||||
*/
|
||||
public boolean isDropping() {
|
||||
return dropping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AbstractUserData<?> abstractUserData = (AbstractUserData<?>) o;
|
||||
return key.equals(abstractUserData.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cc.carm.lib.easyplugin.user;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface UserData<K> {
|
||||
|
||||
@NotNull K key();
|
||||
|
||||
/**
|
||||
* @param dropping true if the data is dropping, false otherwise
|
||||
*/
|
||||
void setDropping(boolean dropping);
|
||||
|
||||
/**
|
||||
* @return true if the data is dropping, false otherwise
|
||||
*/
|
||||
boolean isDropping();
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package cc.carm.lib.easyplugin.user;
|
||||
|
||||
import cc.carm.lib.easyplugin.EasyPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class UserDataManager<K, U extends AbstractUserData<K>> implements UserDataRegistry<K, U> {
|
||||
|
||||
protected final @NotNull EasyPlugin plugin;
|
||||
|
||||
protected final @NotNull ExecutorService executor;
|
||||
protected final @NotNull Map<K, U> dataCache;
|
||||
|
||||
public UserDataManager(@NotNull EasyPlugin plugin) {
|
||||
this(plugin, Executors.newCachedThreadPool((r) -> {
|
||||
Thread t = new Thread(r);
|
||||
t.setDaemon(true);
|
||||
t.setName(plugin.getName() + "-UserManager");
|
||||
return t;
|
||||
}), new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
public UserDataManager(@NotNull EasyPlugin plugin, @NotNull ExecutorService executor) {
|
||||
this(plugin, executor, new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
public UserDataManager(@NotNull EasyPlugin plugin, @NotNull ExecutorService executor, @NotNull Map<K, U> cacheMap) {
|
||||
this.plugin = plugin;
|
||||
this.executor = executor;
|
||||
this.dataCache = cacheMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
this.executor.shutdown();
|
||||
}
|
||||
|
||||
protected @NotNull EasyPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Logger getLogger() {
|
||||
return getPlugin().getLogger();
|
||||
}
|
||||
|
||||
public abstract @NotNull U emptyUser(@NotNull K key);
|
||||
|
||||
public @NotNull U errorUser(@NotNull K key) {
|
||||
return emptyUser(key);
|
||||
}
|
||||
|
||||
protected abstract @Nullable U loadData(@NotNull K key) throws Exception;
|
||||
|
||||
protected abstract void saveData(@NotNull U data) throws Exception;
|
||||
|
||||
@Override
|
||||
public @NotNull Map<K, U> cache() {
|
||||
return dataCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<U> load(@NotNull K key, @NotNull Supplier<Boolean> cacheCondition) {
|
||||
U cached = getNullable(key);
|
||||
if (cached != null) {
|
||||
return CompletableFuture.supplyAsync(() -> cached); // Return cached data async.
|
||||
}
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
String identifier = serializeKey(key);
|
||||
|
||||
try {
|
||||
long s1 = System.currentTimeMillis();
|
||||
getPlugin().debug("开始加载用户 " + identifier + " 的数据...");
|
||||
U data = loadData(key);
|
||||
if (data == null) {
|
||||
getPlugin().debug("数据库内不存在用户 " + identifier + " 的数据,视作新档案。");
|
||||
return emptyUser(key);
|
||||
} else {
|
||||
getPlugin().debug("加载用户 " + identifier + " 的数据完成,耗时 " + (System.currentTimeMillis() - s1) + " ms.");
|
||||
return data;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
getPlugin().error("加载用户 " + serializeKey(key) + " 数据失败,请检查相关配置!");
|
||||
ex.printStackTrace();
|
||||
return errorUser(key);
|
||||
}
|
||||
|
||||
}, executor).thenApply((data) -> {
|
||||
if (cacheCondition.get() && !data.isDropping()) dataCache.put(key, data);
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> save(@NotNull U user) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
String identifier = serializeKey(user.key());
|
||||
|
||||
try {
|
||||
long s1 = System.currentTimeMillis();
|
||||
getPlugin().debug("开始保存用户 " + identifier + " 的数据...");
|
||||
saveData(user);
|
||||
getPlugin().debug("保存用户 " + identifier + " 的数据完成,耗时 " + (System.currentTimeMillis() - s1) + " ms.");
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
getPlugin().error("保存用户 " + identifier + " 数据失败,请检查相关配置!");
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
}, executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> unload(@NotNull K key, boolean save) {
|
||||
U data = getNullable(key);
|
||||
if (data == null) return CompletableFuture.completedFuture(false);
|
||||
data.setDropping(true); // Mark the data as unloading.
|
||||
if (save) {
|
||||
return save(data).thenApply(result -> {
|
||||
// Check if the data is still unloading,
|
||||
// which cloud be interrupted by the next load.
|
||||
if (data.isDropping()) {
|
||||
this.dataCache.remove(key);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
} else {
|
||||
this.dataCache.remove(key);
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CompletableFuture<Boolean> modify(@NotNull K key, @NotNull Consumer<U> consumer) {
|
||||
U cached = getNullable(key);
|
||||
if (cached != null) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
consumer.accept(cached);
|
||||
return true;
|
||||
}, executor);
|
||||
} else {
|
||||
return load(key, true).thenApply((data) -> {
|
||||
consumer.accept(data);
|
||||
return data;
|
||||
}).thenCompose(data -> unload(key, true));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V> @NotNull CompletableFuture<V> peek(@NotNull K key, @NotNull Function<U, V> function) {
|
||||
U cached = getNullable(key);
|
||||
if (cached != null) {
|
||||
return CompletableFuture.supplyAsync(() -> function.apply(cached), executor);
|
||||
} else {
|
||||
return load(key, false).thenApply(function);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> @NotNull CompletableFuture<Map<K, U>> loadGroup(@NotNull Collection<? extends T> users,
|
||||
@NotNull Function<? super T, ? extends K> function,
|
||||
@NotNull Predicate<T> cacheCondition) {
|
||||
CompletableFuture<Map<K, U>> task = CompletableFuture.completedFuture(new ConcurrentHashMap<>());
|
||||
if (users.isEmpty()) return task;
|
||||
|
||||
Map<K, T> usersMap = users.stream().collect(Collectors.toMap(function, Function.identity()));
|
||||
for (Map.Entry<K, T> entry : usersMap.entrySet()) {
|
||||
K key = entry.getKey();
|
||||
T user = entry.getValue();
|
||||
task = task.thenCombine(
|
||||
load(key, () -> cacheCondition.test(user)),
|
||||
(map, result) -> {
|
||||
map.put(key, result);
|
||||
return map;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return task.thenApply(Collections::unmodifiableMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAll() {
|
||||
if (cache().isEmpty()) return;
|
||||
for (U u : cache().values()) {
|
||||
try {
|
||||
saveData(u);
|
||||
} catch (Exception e) {
|
||||
getPlugin().error("保存用户 " + serializeKey(u.key()) + " 数据失败,请检查相关配置!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int unloadAll(boolean save) {
|
||||
if (save) saveAll();
|
||||
int size = cache().size();
|
||||
cache().clear();
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package cc.carm.lib.easyplugin.user;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface UserDataRegistry<K, U extends UserData<K>> {
|
||||
|
||||
void shutdown();
|
||||
|
||||
@NotNull Logger getLogger();
|
||||
|
||||
@NotNull Map<K, U> cache();
|
||||
|
||||
default String serializeKey(@NotNull K key) {
|
||||
return key.toString();
|
||||
}
|
||||
|
||||
default @NotNull CompletableFuture<U> load(@NotNull K key) {
|
||||
return load(key, false);
|
||||
}
|
||||
|
||||
default @NotNull CompletableFuture<U> load(@NotNull K key, boolean cache) {
|
||||
return load(key, () -> cache);
|
||||
}
|
||||
|
||||
@Unmodifiable
|
||||
default @NotNull Set<U> list() {
|
||||
return ImmutableSet.copyOf(cache().values());
|
||||
}
|
||||
|
||||
default @NotNull U get(@NotNull K key) {
|
||||
return Optional.ofNullable(getNullable(key)).orElseThrow(() -> new NullPointerException("User " + key + " not found."));
|
||||
}
|
||||
|
||||
default @Nullable U getNullable(@NotNull K key) {
|
||||
return cache().get(key);
|
||||
}
|
||||
|
||||
default @NotNull Optional<@Nullable U> getOptional(@NotNull K key) {
|
||||
return Optional.ofNullable(getNullable(key));
|
||||
}
|
||||
|
||||
@NotNull CompletableFuture<U> load(@NotNull K key, @NotNull Supplier<Boolean> cacheCondition);
|
||||
|
||||
@NotNull CompletableFuture<Boolean> save(@NotNull U user);
|
||||
|
||||
default @NotNull CompletableFuture<Boolean> unload(@NotNull K key) {
|
||||
return unload(key, true);
|
||||
}
|
||||
|
||||
@NotNull CompletableFuture<Boolean> unload(@NotNull K key, boolean save);
|
||||
|
||||
@NotNull CompletableFuture<Boolean> modify(@NotNull K key, @NotNull Consumer<U> consumer);
|
||||
|
||||
<V> @NotNull CompletableFuture<V> peek(@NotNull K key, @NotNull Function<U, V> function);
|
||||
|
||||
default @NotNull CompletableFuture<Map<K, U>> loadOnline(@NotNull Function<Player, ? extends K> function) {
|
||||
return loadGroup(Bukkit.getOnlinePlayers(), function, OfflinePlayer::isOnline);
|
||||
}
|
||||
|
||||
<T> @NotNull CompletableFuture<Map<K, U>> loadGroup(@NotNull Collection<? extends T> users,
|
||||
@NotNull Function<? super T, ? extends K> function,
|
||||
@NotNull Predicate<T> cacheCondition);
|
||||
|
||||
default @NotNull CompletableFuture<Map<K, U>> loadGroup(@NotNull Collection<K> allKeys,
|
||||
@NotNull Predicate<K> cacheCondition) {
|
||||
return loadGroup(allKeys, Function.identity(), cacheCondition);
|
||||
}
|
||||
|
||||
default @NotNull CompletableFuture<Map<K, U>> loadGroup(@NotNull Collection<K> allKeys) {
|
||||
return loadGroup(allKeys, (v) -> false);
|
||||
}
|
||||
|
||||
void saveAll();
|
||||
|
||||
int unloadAll(boolean save);
|
||||
}
|
||||
+11
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -57,4 +57,14 @@
|
||||
<url>https://github.com/CarmJos/EasyPlugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+11
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -62,4 +62,14 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+12
-18
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -75,23 +75,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyplugin-listener</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyplugin-database</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyplugin-conf</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyplugin-papi</artifactId>
|
||||
<artifactId>easyplugin-placeholderapi</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -137,4 +121,14 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -68,10 +68,6 @@
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-vault</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-database</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-storage</artifactId>
|
||||
@@ -82,4 +78,13 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
@@ -30,5 +31,13 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+9
-3
@@ -1,7 +1,9 @@
|
||||
package cc.carm.lib.easyplugin.updatechecker;
|
||||
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,11 +26,15 @@ public class GHUpdateChecker {
|
||||
public static @NotNull Runnable runner(@NotNull Logger logger,
|
||||
@NotNull String owner, @NotNull String repo,
|
||||
@NotNull String currentVersion) {
|
||||
return of(logger, owner, repo).runner(currentVersion);
|
||||
return of(logger, owner, repo).createRunner(currentVersion);
|
||||
}
|
||||
|
||||
public static @NotNull Runnable runner(@NotNull Plugin plugin) {
|
||||
return of(plugin).runner(plugin.getDescription().getVersion());
|
||||
return of(plugin).createRunner(plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
public static @NotNull BukkitTask run(@NotNull Plugin plugin) {
|
||||
return Bukkit.getScheduler().runTaskAsynchronously(plugin, runner(plugin));
|
||||
}
|
||||
|
||||
protected final @NotNull Logger logger;
|
||||
@@ -59,7 +65,7 @@ public class GHUpdateChecker {
|
||||
}
|
||||
}
|
||||
|
||||
public Runnable runner(@NotNull String currentVersion) {
|
||||
public Runnable createRunner(@NotNull String currentVersion) {
|
||||
return () -> checkUpdate(currentVersion);
|
||||
}
|
||||
|
||||
|
||||
+11
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -21,6 +21,7 @@
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasyPlugin-PlaceholderAPI</name>
|
||||
<description>EasyPlugin的 PlaceholderAPI 扩展模块,提供了方便的 PlaceholderAPI 变量注册方法。</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -32,4 +33,13 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+11
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -33,4 +33,14 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,79 @@
|
||||
package cc.carm.lib.easyplugin.vault;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EasyVault {
|
||||
public static boolean hasVault() {
|
||||
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null;
|
||||
}
|
||||
|
||||
public static @NotNull EasyVault create() throws Exception {
|
||||
return new EasyVault();
|
||||
}
|
||||
|
||||
private Economy economy = null;
|
||||
|
||||
public EasyVault() throws Exception {
|
||||
if (!setupEconomy()) throw new Exception("Vault not found!");
|
||||
}
|
||||
|
||||
public boolean setupEconomy() {
|
||||
if (!hasVault()) return false;
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) return false;
|
||||
|
||||
this.economy = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
public Economy getEconomy() {
|
||||
return economy;
|
||||
}
|
||||
|
||||
public double getMoney(@NotNull Player player) {
|
||||
try {
|
||||
return getEconomy().getBalance(player);
|
||||
} catch (NullPointerException ignore) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public double getMoney(@NotNull OfflinePlayer player) {
|
||||
try {
|
||||
return getEconomy().getBalance(player);
|
||||
} catch (NullPointerException ignore) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkMoney(@NotNull OfflinePlayer player, double amount) {
|
||||
return getMoney(player) >= amount;
|
||||
}
|
||||
|
||||
public boolean checkMoney(@NotNull Player player, double amount) {
|
||||
return getMoney(player) >= amount;
|
||||
}
|
||||
|
||||
public EconomyResponse removeMoney(Player player, double amount) {
|
||||
return getEconomy().withdrawPlayer(player, amount);
|
||||
}
|
||||
|
||||
public EconomyResponse removeMoney(OfflinePlayer player, double amount) {
|
||||
return getEconomy().withdrawPlayer(player, amount);
|
||||
}
|
||||
|
||||
public EconomyResponse addMoney(Player player, double amount) {
|
||||
return getEconomy().depositPlayer(player, amount);
|
||||
}
|
||||
|
||||
public EconomyResponse addMoney(OfflinePlayer player, double amount) {
|
||||
return getEconomy().depositPlayer(player, amount);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,19 +15,18 @@
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.14</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/command-alias</module>
|
||||
<module>base/storage</module>
|
||||
<module>base/listener</module>
|
||||
<module>base/database</module>
|
||||
<module>base/user</module>
|
||||
|
||||
<module>extension/papi</module>
|
||||
<module>extension/vault</module>
|
||||
@@ -36,7 +35,6 @@
|
||||
<module>collection/all</module>
|
||||
<module>collection/bom</module>
|
||||
<module>collection/common</module>
|
||||
|
||||
</modules>
|
||||
|
||||
<name>EasyPlugin</name>
|
||||
@@ -83,13 +81,22 @@
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
<id>sonatype</id>
|
||||
<name>Sonatype Snapshot Repository</name>
|
||||
<url>https://s01.oss.sonatype.org/content/groups/public/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public</url>
|
||||
<id>minebench-repo</id>
|
||||
<url>https://repo.minebench.de/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>codemc-snapshots</id>
|
||||
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
@@ -117,7 +124,7 @@
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>23.0.0</version>
|
||||
<version>26.0.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -135,32 +142,17 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.10.9</version>
|
||||
<version>2.11.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>githubreleases4j</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easylistener</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>mineconfiguration-bukkit</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-beecp</artifactId>
|
||||
<version>0.4.3</version>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
@@ -170,7 +162,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<version>3.5.2</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
@@ -178,7 +170,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.14.0</version>
|
||||
<configuration>
|
||||
<source>${project.jdk.version}</source>
|
||||
<target>${project.jdk.version}</target>
|
||||
@@ -189,12 +181,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.4.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -208,13 +200,44 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.2.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>deploy</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.11.2</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<detectJavaApiLink>false</detectJavaApiLink>
|
||||
@@ -235,7 +258,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -273,17 +296,24 @@
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>ossrh</id>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<id>central</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.7.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<autoPublish>true</autoPublish>
|
||||
<excludeArtifacts>
|
||||
<excludeArtifact>configured-demo</excludeArtifact>
|
||||
</excludeArtifacts>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user