mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-06-05 09:01:39 +08:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b2eaf2519 | |||
| 75ee308174 | |||
| bed1651027 | |||
| 7dde64e699 | |||
| 9b88142676 | |||
| e0cfd87ac6 | |||
| fd764fa348 | |||
| 480cebd16a | |||
| 6cd25cf94a | |||
| 72071492b3 | |||
| b334c3476e | |||
| c94ed28b98 | |||
| 72aa4e3a82 | |||
| acc92d5fb4 | |||
| bc002f9a07 | |||
| f11749d4da | |||
| a52b703a75 | |||
| 86775cdbcd | |||
| 8951b7ac90 | |||
| 89b520b8d3 | |||
| b57ff5b2c5 | |||
| b4469f93d0 | |||
| d91dd6c7bd | |||
| ebd9f9fbfc | |||
| f5d256b5c4 | |||
| e43ce22551 | |||
| f821ab88ed | |||
| b03bb4a476 | |||
| 86326a168b | |||
| 672641259e | |||
| 5fc46eed8f | |||
| 50ded3fa11 | |||
| 951fe67117 | |||
| 442374da0a | |||
| 77a277ba58 | |||
| 1ead1a0692 | |||
| f519fa43df | |||
| da63cf8b1c | |||
| 9527e9fcbb | |||
| 5befd40706 | |||
| e1bedba01b | |||
| 5809659155 |
@@ -38,11 +38,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v3
|
uses: github/codeql-action/init@v4
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -53,7 +53,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v3
|
uses: github/codeql-action/autobuild@v4
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -67,4 +67,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v3
|
uses: github/codeql-action/analyze@v4
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
@@ -87,4 +87,27 @@ jobs:
|
|||||||
- name: "Push javadocs"
|
- name: "Push javadocs"
|
||||||
run: |
|
run: |
|
||||||
cd docs
|
cd docs
|
||||||
git push origin HEAD:gh-pages --force
|
git push origin HEAD:gh-pages --force
|
||||||
|
|
||||||
|
- name: "Modrinth Publish"
|
||||||
|
id: publish-modrinth
|
||||||
|
uses: Kir-Antipov/mc-publish@v3.3
|
||||||
|
with:
|
||||||
|
modrinth-id: tLcVHCPk
|
||||||
|
modrinth-featured: true
|
||||||
|
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
|
||||||
|
files: |
|
||||||
|
asset/*.jar
|
||||||
|
loaders: |
|
||||||
|
spigot
|
||||||
|
paper
|
||||||
|
purpur
|
||||||
|
folia
|
||||||
|
bukkit
|
||||||
|
game-versions: |
|
||||||
|
>=1.8 <=1.21.8
|
||||||
|
game-version-filter: releases
|
||||||
|
java: |
|
||||||
|
8
|
||||||
|
dependencies: |
|
||||||
|
placeholderapi(recommended)
|
||||||
@@ -14,9 +14,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
cp -vrf asset/*.jar artifacts
|
cp -vrf asset/*.jar artifacts
|
||||||
|
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Artifact
|
name: Artifact
|
||||||
path: artifacts
|
path: artifacts
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ development.
|
|||||||
|
|
||||||
> This plugin has been published on [SpigotMC](https://www.spigotmc.org/resources/userprefix.96277/) .
|
> This plugin has been published on [SpigotMC](https://www.spigotmc.org/resources/userprefix.96277/) .
|
||||||
|
|
||||||
> 本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503) 上发布,欢迎中文用户来这里下载。
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -15,8 +15,7 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
|
|||||||
|
|
||||||
本插件基于Spigot实现,**理论上支持全版本**。
|
本插件基于Spigot实现,**理论上支持全版本**。
|
||||||
|
|
||||||
> 本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503)
|
> 本插件已在 [SpigotMC](https://www.spigotmc.org/resources/userprefix-hex-color-support-all-version.96277/) 上发布。
|
||||||
> 与 [SpigotMC](https://www.spigotmc.org/resources/userprefix-hex-color-support-all-version.96277/) 上发布。
|
|
||||||
|
|
||||||
## 示例
|
## 示例
|
||||||
|
|
||||||
@@ -40,6 +39,7 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
|
|||||||
- TabList自动按照前缀的权重排序 (如有冲突可关掉)
|
- TabList自动按照前缀的权重排序 (如有冲突可关掉)
|
||||||
- 玩家头顶前缀显示 (如有冲突可关掉)
|
- 玩家头顶前缀显示 (如有冲突可关掉)
|
||||||
- 简单的聊天变量修改功能!(不推荐使用) `[自 v2.1.0 版本起]`
|
- 简单的聊天变量修改功能!(不推荐使用) `[自 v2.1.0 版本起]`
|
||||||
|
- 支持动态前缀内容轮换!`[自 v3.3.0 版本起]`
|
||||||
- 自动排序,且可翻页的GUI!
|
- 自动排序,且可翻页的GUI!
|
||||||
- 支持PlaceholderAPI变量!(凡支持的都可以使用,如BungeeTabListPlus)
|
- 支持PlaceholderAPI变量!(凡支持的都可以使用,如BungeeTabListPlus)
|
||||||
- 支持[Hex颜色](https://www.hexcolortool.com/)!(1.16以上版本) `[自 v1.2.3 版本起]`
|
- 支持[Hex颜色](https://www.hexcolortool.com/)!(1.16以上版本) `[自 v1.2.3 版本起]`
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<artifactId>userprefix</artifactId>
|
<artifactId>userprefix</artifactId>
|
||||||
<version>3.2.7</version>
|
<version>3.3.1</version>
|
||||||
|
|
||||||
<name>UserPrefix</name>
|
<name>UserPrefix</name>
|
||||||
<description>轻便、高效、实时的用户前缀系统。</description>
|
<description>轻便、高效、实时的用户前缀系统。</description>
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.cryptomorin</groupId>
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
<artifactId>XSeries</artifactId>
|
<artifactId>XSeries</artifactId>
|
||||||
<version>13.3.3</version>
|
<version>13.8.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -188,14 +188,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.17-R0.1-SNAPSHOT</version>
|
<version>1.19-R0.1-20220725.090125-47</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.6</version>
|
<version>2.12.2</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -209,14 +209,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>26.0.2</version>
|
<version>26.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.14.0</version>
|
<version>3.15.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${project.jdk.version}</source>
|
<source>${project.jdk.version}</source>
|
||||||
<target>${project.jdk.version}</target>
|
<target>${project.jdk.version}</target>
|
||||||
@@ -267,12 +267,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.5.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>3.4.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -285,7 +285,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.6.0</version>
|
<version>3.6.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -331,7 +331,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.11.2</version>
|
<version>3.12.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<classifier>javadoc</classifier>
|
<classifier>javadoc</classifier>
|
||||||
<links>
|
<links>
|
||||||
@@ -358,7 +358,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.5.3</version>
|
<version>3.5.6</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class Main extends EasyPlugin {
|
|||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent");
|
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||||
this.onFolia = true;
|
this.onFolia = true;
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
this.onFolia = false;
|
this.onFolia = false;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ListCommand extends SubCommand<AdminCommand> {
|
public class ListCommand extends SubCommand<AdminCommand> {
|
||||||
|
|
||||||
public ListCommand(@NotNull AdminCommand parent, String name, String... aliases) {
|
public ListCommand(@NotNull AdminCommand parent, String name, String... aliases) {
|
||||||
@@ -21,7 +23,7 @@ public class ListCommand extends SubCommand<AdminCommand> {
|
|||||||
for (PrefixConfig value : UserPrefixAPI.getPrefixManager().getPrefixes().values()) {
|
for (PrefixConfig value : UserPrefixAPI.getPrefixManager().getPrefixes().values()) {
|
||||||
PluginMessages.LIST.VALUE.sendTo(sender,
|
PluginMessages.LIST.VALUE.sendTo(sender,
|
||||||
value.getWeight(), value.getIdentifier(),
|
value.getWeight(), value.getIdentifier(),
|
||||||
value.getName(), value.getPermission(),
|
value.getName(), Optional.ofNullable(value.getPermission()).orElse("~"),
|
||||||
value.getContent(sender), sender.getName()
|
value.getContent(sender), sender.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cc.carm.plugin.userprefix.conf;
|
package cc.carm.plugin.userprefix.conf;
|
||||||
|
|
||||||
import cc.carm.lib.configuration.Configuration;
|
import cc.carm.lib.configuration.Configuration;
|
||||||
|
import cc.carm.lib.configuration.adapter.ValueType;
|
||||||
import cc.carm.lib.configuration.annotation.ConfigPath;
|
import cc.carm.lib.configuration.annotation.ConfigPath;
|
||||||
import cc.carm.lib.configuration.annotation.HeaderComments;
|
import cc.carm.lib.configuration.annotation.HeaderComments;
|
||||||
import cc.carm.lib.configuration.value.standard.ConfiguredList;
|
import cc.carm.lib.configuration.value.standard.ConfiguredList;
|
||||||
@@ -12,6 +13,10 @@ import cc.carm.plugin.userprefix.folia.MajorUtil;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PluginConfig implements Configuration {
|
public class PluginConfig implements Configuration {
|
||||||
|
|
||||||
@HeaderComments({"开发者查错模式"})
|
@HeaderComments({"开发者查错模式"})
|
||||||
@@ -148,7 +153,32 @@ public class PluginConfig implements Configuration {
|
|||||||
public static final ConfiguredValue<Integer> WEIGHT = ConfiguredValue.of(Integer.class, 0);
|
public static final ConfiguredValue<Integer> WEIGHT = ConfiguredValue.of(Integer.class, 0);
|
||||||
|
|
||||||
@HeaderComments({"默认前缀的内容,即用于显示的实际前缀"})
|
@HeaderComments({"默认前缀的内容,即用于显示的实际前缀"})
|
||||||
public static final ConfiguredValue<String> CONTENT = ConfiguredValue.of(String.class, "&r");
|
public static final ConfiguredValue<List<String>> CONTENT = ConfiguredValue
|
||||||
|
.builderOf(ValueType.ofList(String.class))
|
||||||
|
.from(Object.class)
|
||||||
|
.parse(obj -> {
|
||||||
|
if (obj instanceof List<?>) {
|
||||||
|
List<?> list = (List<?>) obj;
|
||||||
|
return list.stream()
|
||||||
|
.map(Object::toString)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
} else return Collections.singletonList(String.valueOf(obj));
|
||||||
|
})
|
||||||
|
.serialize(list -> {
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
} else if (list.size() == 1) {
|
||||||
|
return list.get(0);
|
||||||
|
} else {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.defaults(Collections.singletonList("&r"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
@HeaderComments({"默认前缀的切换周期,单位为毫秒。(小于0则表示不进行切换,等于0则代表所及选取)"})
|
||||||
|
public static final ConfiguredValue<Long> PERIOD = ConfiguredValue.of(-1L);
|
||||||
|
|
||||||
@HeaderComments({"选择默认前缀时执行的操作"})
|
@HeaderComments({"选择默认前缀时执行的操作"})
|
||||||
public static final ConfiguredList<String> ACTIONS = ConfiguredList.builderOf(String.class).fromString()
|
public static final ConfiguredList<String> ACTIONS = ConfiguredList.builderOf(String.class).fromString()
|
||||||
@@ -162,7 +192,7 @@ public class PluginConfig implements Configuration {
|
|||||||
public static final ConfiguredItem NOT_USING = ConfiguredItem.create()
|
public static final ConfiguredItem NOT_USING = ConfiguredItem.create()
|
||||||
.defaultType(Material.NAME_TAG)
|
.defaultType(Material.NAME_TAG)
|
||||||
.defaultName("&f默认玩家前缀 &f(点击切换)")
|
.defaultName("&f默认玩家前缀 &f(点击切换)")
|
||||||
.defaultLore("","{&f&o }#description#{1,1}", "&a➥ 点击切换到该前缀")
|
.defaultLore("", "{&f&o }#description#{1,1}", "&a➥ 点击切换到该前缀")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@HeaderComments({"当选择了默认前缀时显示的物品"})
|
@HeaderComments({"当选择了默认前缀时显示的物品"})
|
||||||
@@ -171,7 +201,7 @@ public class PluginConfig implements Configuration {
|
|||||||
.defaultEnchant(MajorUtil.getEnchantProtection(), 1) // 附魔改过名
|
.defaultEnchant(MajorUtil.getEnchantProtection(), 1) // 附魔改过名
|
||||||
.defaultFlags(ItemFlag.HIDE_ENCHANTS)
|
.defaultFlags(ItemFlag.HIDE_ENCHANTS)
|
||||||
.defaultName("&f默认玩家前缀")
|
.defaultName("&f默认玩家前缀")
|
||||||
.defaultLore("","{&f&o }#description#{1,1}", "&a✔ 您正在使用该前缀")
|
.defaultLore("", "{&f&o }#description#{1,1}", "&a✔ 您正在使用该前缀")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cc.carm.plugin.userprefix.conf.prefix;
|
|||||||
|
|
||||||
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
|
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
|
||||||
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
|
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
|
||||||
|
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
|
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
|
||||||
import cc.carm.plugin.userprefix.Main;
|
import cc.carm.plugin.userprefix.Main;
|
||||||
@@ -14,16 +15,22 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class PrefixConfig {
|
public class PrefixConfig {
|
||||||
|
|
||||||
|
static final Random RANDOM = new Random();
|
||||||
|
|
||||||
protected final @NotNull String identifier;
|
protected final @NotNull String identifier;
|
||||||
|
|
||||||
protected final @NotNull String name;
|
protected final @NotNull String name;
|
||||||
protected final @NotNull String content;
|
protected final @NotNull List<String> content;
|
||||||
protected final @NotNull List<String> description;
|
protected final @NotNull List<String> description;
|
||||||
|
|
||||||
|
protected final long period; // 内容变更周期,单位为毫秒
|
||||||
|
|
||||||
protected final int weight;
|
protected final int weight;
|
||||||
|
|
||||||
protected final @Nullable String permission;
|
protected final @Nullable String permission;
|
||||||
@@ -54,10 +61,26 @@ public class PrefixConfig {
|
|||||||
@NotNull ItemStack itemHasPermission,
|
@NotNull ItemStack itemHasPermission,
|
||||||
@Nullable ItemStack itemWhenUsing,
|
@Nullable ItemStack itemWhenUsing,
|
||||||
@Nullable ItemStack itemNoPermission) {
|
@Nullable ItemStack itemNoPermission) {
|
||||||
|
this(
|
||||||
|
identifier, name, description,
|
||||||
|
Collections.singletonList(content), 0, weight, permission, actions,
|
||||||
|
itemHasPermission, itemWhenUsing, itemNoPermission
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrefixConfig(@NotNull String identifier,
|
||||||
|
@NotNull String name, @NotNull List<String> description,
|
||||||
|
@NotNull List<String> content, long period,
|
||||||
|
int weight, @Nullable String permission,
|
||||||
|
@NotNull List<GUIActionConfiguration> actions,
|
||||||
|
@NotNull ItemStack itemHasPermission,
|
||||||
|
@Nullable ItemStack itemWhenUsing,
|
||||||
|
@Nullable ItemStack itemNoPermission) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
this.period = period;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.actions = actions;
|
this.actions = actions;
|
||||||
@@ -73,17 +96,31 @@ public class PrefixConfig {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return ColorParser.parse(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> getDescription() {
|
public List<String> getDescription() {
|
||||||
return description;
|
return ColorParser.parse(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getContent(CommandSender viewer) {
|
public String getContent(CommandSender viewer) {
|
||||||
return MessageUtils.setPlaceholders(viewer, content);
|
if (content.isEmpty()) return "?";
|
||||||
|
if (period < 0 || content.size() == 1) {
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(viewer, content.get(0)));
|
||||||
|
}
|
||||||
|
if (period == 0) {
|
||||||
|
// PERIOD 为0时,随机返回一个内容
|
||||||
|
int index = RANDOM.nextInt(content.size());
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(viewer, content.get(index)));
|
||||||
|
} else {
|
||||||
|
// 可变化的内容,则基于偏移量与时间戳计算目标index
|
||||||
|
long curr = System.currentTimeMillis();
|
||||||
|
long offset = curr % period; // 计算偏移量
|
||||||
|
int index = (int) (offset / (period / content.size())); // 计算索引
|
||||||
|
return ColorParser.parse(MessageUtils.setPlaceholders(viewer, content.get(index)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWeight() {
|
public int getWeight() {
|
||||||
@@ -114,6 +151,8 @@ public class PrefixConfig {
|
|||||||
protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) {
|
protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) {
|
||||||
PreparedItem prepared = PreparedItem.of(item);
|
PreparedItem prepared = PreparedItem.of(item);
|
||||||
|
|
||||||
|
prepared.parser((p, s) -> ColorParser.parse(MessageUtils.setPlaceholders(p, s)));
|
||||||
|
|
||||||
if (!getDescription().isEmpty()) {
|
if (!getDescription().isEmpty()) {
|
||||||
prepared.insert("description", getDescription());
|
prepared.insert("description", getDescription());
|
||||||
prepared.placeholder("description", String.join("\n", getDescription()));
|
prepared.placeholder("description", String.join("\n", getDescription()));
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ public class PrefixManager {
|
|||||||
"default",
|
"default",
|
||||||
PluginConfig.DEFAULT_PREFIX.NAME.getNotNull(),
|
PluginConfig.DEFAULT_PREFIX.NAME.getNotNull(),
|
||||||
PluginConfig.DEFAULT_PREFIX.DESCRIPTION.getNotNull(),
|
PluginConfig.DEFAULT_PREFIX.DESCRIPTION.getNotNull(),
|
||||||
PluginConfig.DEFAULT_PREFIX.CONTENT.getNotNull(),
|
PluginConfig.DEFAULT_PREFIX.CONTENT.resolve(),
|
||||||
|
PluginConfig.DEFAULT_PREFIX.PERIOD.resolve(),
|
||||||
PluginConfig.DEFAULT_PREFIX.WEIGHT.getNotNull(),
|
PluginConfig.DEFAULT_PREFIX.WEIGHT.getNotNull(),
|
||||||
null,
|
null,
|
||||||
readActions(PluginConfig.DEFAULT_PREFIX.ACTIONS.get()),
|
readActions(PluginConfig.DEFAULT_PREFIX.ACTIONS.get()),
|
||||||
@@ -134,10 +135,21 @@ public class PrefixManager {
|
|||||||
String name = conf.getString("name");
|
String name = conf.getString("name");
|
||||||
if (name == null) throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的显示名称。");
|
if (name == null) throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的显示名称。");
|
||||||
|
|
||||||
|
|
||||||
|
List<String> content = new ArrayList<>();
|
||||||
|
if (conf.isList("content")) {
|
||||||
|
content = conf.getStringList("content");
|
||||||
|
} else {
|
||||||
|
String single = conf.getString("content");
|
||||||
|
if (single != null) content.add(single);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return new PrefixConfig(
|
return new PrefixConfig(
|
||||||
identifier, name,
|
identifier, name,
|
||||||
conf.getStringList("description"),
|
conf.getStringList("description"),
|
||||||
conf.getString("content", "&r"),
|
content,
|
||||||
|
conf.getLong("period", -1L),
|
||||||
conf.getInt("weight", 1),
|
conf.getInt("weight", 1),
|
||||||
conf.getString("permission"),
|
conf.getString("permission"),
|
||||||
readActions(conf.getStringList("actions")),
|
readActions(conf.getStringList("actions")),
|
||||||
|
|||||||
@@ -8,8 +8,16 @@ name: "&b&lPro&b"
|
|||||||
|
|
||||||
# Content [Necessary]
|
# Content [Necessary]
|
||||||
# Use in Placeholders
|
# Use in Placeholders
|
||||||
|
# Supports multiple lines for content rotation.
|
||||||
content: "&b&lPro &b"
|
content: "&b&lPro &b"
|
||||||
|
|
||||||
|
# Period [Unnecessary]
|
||||||
|
# Set the rotation period of the prefix content, in milliseconds.
|
||||||
|
# If set to -1, it will not rotate.
|
||||||
|
# If set to 0, it will randomly select a line each time the prefix is fetched
|
||||||
|
# If set to a value greater than 0, it will rotate the content every specified milliseconds.
|
||||||
|
period: -1
|
||||||
|
|
||||||
# Weight [Necessary]
|
# Weight [Necessary]
|
||||||
# used for sorting in the GUI and TabList
|
# used for sorting in the GUI and TabList
|
||||||
# In GUI : the larger is displayed at the back
|
# In GUI : the larger is displayed at the back
|
||||||
|
|||||||
@@ -5,8 +5,18 @@ name: "&b&lPro&b"
|
|||||||
|
|
||||||
# Contenido [Necesario]
|
# Contenido [Necesario]
|
||||||
# Uso en Placeholders
|
# Uso en Placeholders
|
||||||
|
# Soporta múltiples líneas para la rotación de contenido.
|
||||||
content: "&b&lPro &b"
|
content: "&b&lPro &b"
|
||||||
|
|
||||||
|
# Periodo [Innecesario]
|
||||||
|
# Establece el periodo de rotación del contenido del prefijo, en milisegundos.
|
||||||
|
# Si se establece en -1, no rotará.
|
||||||
|
# Si se establece en 0, seleccionará aleatoriamente una línea cada vez que se
|
||||||
|
# obtenga el prefijo.
|
||||||
|
# Si se establece en un valor mayor que 0, rotará el contenido cada los mil
|
||||||
|
# segundos especificados.
|
||||||
|
period: -1
|
||||||
|
|
||||||
# Weight [Necesario]
|
# Weight [Necesario]
|
||||||
# utilizado para ordenar en la GUI y TabList
|
# utilizado para ordenar en la GUI y TabList
|
||||||
# En GUI : el más grande se muestra en la parte posterior
|
# En GUI : el más grande se muestra en la parte posterior
|
||||||
|
|||||||
@@ -9,8 +9,16 @@ name: "&b&lPro &b会员"
|
|||||||
|
|
||||||
# 内容 [必须]
|
# 内容 [必须]
|
||||||
# 显示在名字前面的内容
|
# 显示在名字前面的内容
|
||||||
|
# 支持多行内容以实现前缀内容的轮换
|
||||||
content: "&b&lPro &b"
|
content: "&b&lPro &b"
|
||||||
|
|
||||||
|
# 轮换周期 [非必须]
|
||||||
|
# 设置前缀内容的轮换周期,单位为毫秒。
|
||||||
|
# 若数值为-1,则表示不轮换。
|
||||||
|
# 若数值为0,则每次获取前缀时都会随机选择一行内容。
|
||||||
|
# 若数值大于0,则表示每隔指定毫秒数轮换一次内容
|
||||||
|
period: -1
|
||||||
|
|
||||||
# 权重 [必须]
|
# 权重 [必须]
|
||||||
# 用于GUI、TabList的排序和自动前缀显示
|
# 用于GUI、TabList的排序和自动前缀显示
|
||||||
# 在GUI中,权重越高的会显示在越后面
|
# 在GUI中,权重越高的会显示在越后面
|
||||||
|
|||||||
Reference in New Issue
Block a user