mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-07-16 08:51:09 +08:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 762d366b59 | |||
| 8e775a7b15 | |||
| 74c3964883 | |||
| dfe072b1fd | |||
| 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:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v7
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# 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).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
uses: github/codeql-action/autobuild@v4
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -67,4 +67,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- 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
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
@@ -88,3 +88,26 @@ jobs:
|
||||
run: |
|
||||
cd docs
|
||||
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
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v7
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
cp -vrf asset/*.jar artifacts
|
||||
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Artifact
|
||||
path: artifacts
|
||||
|
||||
@@ -20,8 +20,6 @@ development.
|
||||
|
||||
> 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
|
||||
|
||||

|
||||
|
||||
@@ -15,8 +15,7 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
|
||||
|
||||
本插件基于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自动按照前缀的权重排序 (如有冲突可关掉)
|
||||
- 玩家头顶前缀显示 (如有冲突可关掉)
|
||||
- 简单的聊天变量修改功能!(不推荐使用) `[自 v2.1.0 版本起]`
|
||||
- 支持动态前缀内容轮换!`[自 v3.3.0 版本起]`
|
||||
- 自动排序,且可翻页的GUI!
|
||||
- 支持PlaceholderAPI变量!(凡支持的都可以使用,如BungeeTabListPlus)
|
||||
- 支持[Hex颜色](https://www.hexcolortool.com/)!(1.16以上版本) `[自 v1.2.3 版本起]`
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>userprefix</artifactId>
|
||||
<version>3.2.7</version>
|
||||
<version>3.4.0</version>
|
||||
|
||||
<name>UserPrefix</name>
|
||||
<description>轻便、高效、实时的用户前缀系统。</description>
|
||||
@@ -173,7 +173,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.cryptomorin</groupId>
|
||||
<artifactId>XSeries</artifactId>
|
||||
<version>13.3.3</version>
|
||||
<version>13.8.0</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@@ -188,14 +188,14 @@
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<version>1.19-R0.1-20220725.090125-47</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.6</version>
|
||||
<version>2.12.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -209,14 +209,14 @@
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>26.0.2</version>
|
||||
<version>26.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -256,7 +256,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<version>3.15.0</version>
|
||||
<configuration>
|
||||
<source>${project.jdk.version}</source>
|
||||
<target>${project.jdk.version}</target>
|
||||
@@ -267,12 +267,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<version>3.5.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<version>3.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -285,7 +285,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>3.6.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -331,14 +331,12 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<version>3.12.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<links>
|
||||
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
|
||||
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
|
||||
<link>https://carmjos.github.io/EasyPlugin/</link>
|
||||
<link>https://carmjos.github.io/MineConfiguration/</link>
|
||||
</links>
|
||||
<detectJavaApiLink>true</detectJavaApiLink>
|
||||
<encoding>UTF-8</encoding>
|
||||
@@ -358,7 +356,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.5.3</version>
|
||||
<version>3.5.6</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Main extends EasyPlugin {
|
||||
instance = this;
|
||||
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServerInitEvent");
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
this.onFolia = true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
this.onFolia = false;
|
||||
|
||||
@@ -1,33 +1,81 @@
|
||||
package cc.carm.plugin.userprefix.command;
|
||||
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.manager.PrefixManager;
|
||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class UserCommand implements CommandExecutor {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
if (sender instanceof Player) {
|
||||
PrefixSelectGUI.open((Player) sender);
|
||||
Player player = (Player) sender;
|
||||
String group = strings.length > 0 ? strings[0] : null;
|
||||
PrefixSelectGUI.open(player, group);
|
||||
} else {
|
||||
if (strings.length != 1) {
|
||||
if (strings.length < 1) {
|
||||
PluginMessages.COMMAND_USAGE.CONSOLE.sendTo(sender);
|
||||
} else {
|
||||
Player player = Bukkit.getPlayer(strings[0]);
|
||||
if (player != null) {
|
||||
PrefixSelectGUI.open(player);
|
||||
String group = strings.length > 1 ? strings[1] : null;
|
||||
PrefixSelectGUI.open(player, group);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] strings) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (strings.length == 1) {
|
||||
// 补全 group 名称
|
||||
Set<String> groups = UserPrefixAPI.getPrefixManager().getGroups();
|
||||
String input = strings[0].toLowerCase();
|
||||
completions.addAll(groups.stream()
|
||||
.filter(g -> g.toLowerCase().startsWith(input))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
} else {
|
||||
// 控制台
|
||||
if (strings.length == 1) {
|
||||
// 补全在线玩家名
|
||||
String input = strings[0].toLowerCase();
|
||||
completions.addAll(Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(input))
|
||||
.collect(Collectors.toList()));
|
||||
} else if (strings.length == 2) {
|
||||
// 补全 group 名称
|
||||
Set<String> groups = UserPrefixAPI.getPrefixManager().getGroups();
|
||||
String input = strings[1].toLowerCase();
|
||||
completions.addAll(groups.stream()
|
||||
.filter(g -> g.toLowerCase().startsWith(input))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
return completions;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ListCommand extends SubCommand<AdminCommand> {
|
||||
|
||||
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()) {
|
||||
PluginMessages.LIST.VALUE.sendTo(sender,
|
||||
value.getWeight(), value.getIdentifier(),
|
||||
value.getName(), value.getPermission(),
|
||||
value.getName(), Optional.ofNullable(value.getPermission()).orElse("~"),
|
||||
value.getContent(sender), sender.getName()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.carm.plugin.userprefix.conf;
|
||||
|
||||
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.HeaderComments;
|
||||
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.inventory.ItemFlag;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PluginConfig implements Configuration {
|
||||
|
||||
@HeaderComments({"开发者查错模式"})
|
||||
@@ -148,7 +153,32 @@ public class PluginConfig implements Configuration {
|
||||
public static final ConfiguredValue<Integer> WEIGHT = ConfiguredValue.of(Integer.class, 0);
|
||||
|
||||
@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({"选择默认前缀时执行的操作"})
|
||||
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()
|
||||
.defaultType(Material.NAME_TAG)
|
||||
.defaultName("&f默认玩家前缀 &f(点击切换)")
|
||||
.defaultLore("","{&f&o }#description#{1,1}", "&a➥ 点击切换到该前缀")
|
||||
.defaultLore("", "{&f&o }#description#{1,1}", "&a➥ 点击切换到该前缀")
|
||||
.build();
|
||||
|
||||
@HeaderComments({"当选择了默认前缀时显示的物品"})
|
||||
@@ -171,7 +201,7 @@ public class PluginConfig implements Configuration {
|
||||
.defaultEnchant(MajorUtil.getEnchantProtection(), 1) // 附魔改过名
|
||||
.defaultFlags(ItemFlag.HIDE_ENCHANTS)
|
||||
.defaultName("&f默认玩家前缀")
|
||||
.defaultLore("","{&f&o }#description#{1,1}", "&a✔ 您正在使用该前缀")
|
||||
.defaultLore("", "{&f&o }#description#{1,1}", "&a✔ 您正在使用该前缀")
|
||||
.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.GUIActionType;
|
||||
import cc.carm.lib.easyplugin.utils.ColorParser;
|
||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
@@ -14,20 +15,28 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class PrefixConfig {
|
||||
|
||||
static final Random RANDOM = new Random();
|
||||
|
||||
protected final @NotNull String identifier;
|
||||
|
||||
protected final @NotNull String name;
|
||||
protected final @NotNull String content;
|
||||
protected final @NotNull List<String> content;
|
||||
protected final @NotNull List<String> description;
|
||||
|
||||
protected final long period; // 内容变更周期,单位为毫秒
|
||||
|
||||
protected final int weight;
|
||||
|
||||
protected final @Nullable String permission;
|
||||
|
||||
protected final @Nullable String group;
|
||||
|
||||
protected final @NotNull List<GUIActionConfiguration> actions;
|
||||
|
||||
protected final @NotNull ItemStack itemHasPermission;
|
||||
@@ -54,12 +63,44 @@ public class PrefixConfig {
|
||||
@NotNull ItemStack itemHasPermission,
|
||||
@Nullable ItemStack itemWhenUsing,
|
||||
@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, name, description,
|
||||
content, period, weight, permission, null, 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, @Nullable String group,
|
||||
@NotNull List<GUIActionConfiguration> actions,
|
||||
@NotNull ItemStack itemHasPermission,
|
||||
@Nullable ItemStack itemWhenUsing,
|
||||
@Nullable ItemStack itemNoPermission) {
|
||||
this.identifier = identifier;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.content = content;
|
||||
this.period = period;
|
||||
this.weight = weight;
|
||||
this.permission = permission;
|
||||
this.group = group;
|
||||
this.actions = actions;
|
||||
this.itemHasPermission = itemHasPermission;
|
||||
this.itemNoPermission = itemNoPermission;
|
||||
@@ -73,17 +114,36 @@ public class PrefixConfig {
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
return ColorParser.parse(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
return ColorParser.parse(description);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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() {
|
||||
@@ -114,6 +174,8 @@ public class PrefixConfig {
|
||||
protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) {
|
||||
PreparedItem prepared = PreparedItem.of(item);
|
||||
|
||||
prepared.parser((p, s) -> ColorParser.parse(MessageUtils.setPlaceholders(p, s)));
|
||||
|
||||
if (!getDescription().isEmpty()) {
|
||||
prepared.insert("description", getDescription());
|
||||
prepared.placeholder("description", String.join("\n", getDescription()));
|
||||
|
||||
@@ -27,6 +27,7 @@ public class PrefixManager {
|
||||
protected @NotNull Map<String, PrefixConfig> prefixes = new HashMap<>();
|
||||
protected PrefixConfig defaultPrefix;
|
||||
|
||||
|
||||
public int loadPrefixes() {
|
||||
loadDefaultPrefix();
|
||||
loadConfiguredPrefixes();
|
||||
@@ -38,47 +39,72 @@ public class PrefixManager {
|
||||
|
||||
File prefixDataFolder = getStorageFolder();
|
||||
if (!prefixDataFolder.isDirectory() || !prefixDataFolder.exists()) {
|
||||
prefixDataFolder.mkdir();
|
||||
prefixDataFolder.mkdirs();
|
||||
}
|
||||
|
||||
String[] filesList = prefixDataFolder.list();
|
||||
if (filesList == null || filesList.length < 1) {
|
||||
List<File> files = new ArrayList<>();
|
||||
collectYamlFiles(prefixDataFolder, files);
|
||||
|
||||
if (files.isEmpty()) {
|
||||
Main.severe("配置文件夹中暂无任何前缀配置问,请检查。");
|
||||
Main.severe("There's no configured prefix.");
|
||||
Main.severe("Path: " + prefixDataFolder.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
List<File> files = Arrays.stream(filesList)
|
||||
.map(s -> new File(prefixDataFolder, s))
|
||||
.filter(File::isFile)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
HashMap<String, PrefixConfig> loaded = new HashMap<>();
|
||||
|
||||
if (files.size() > 0) {
|
||||
for (File file : files) {
|
||||
try {
|
||||
PrefixConfig prefix = addPrefix(file);
|
||||
Main.debugging("完成前缀加载 " + prefix.getIdentifier() + " : " + prefix.getName());
|
||||
loaded.put(prefix.getIdentifier(), prefix);
|
||||
} catch (Exception ex) {
|
||||
Main.severe("在加载前缀 " + file.getAbsolutePath() + " 时出错,请检查配置!");
|
||||
Main.severe("Error occurred when loading prefix #" + file.getAbsolutePath() + " !");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
for (File file : files) {
|
||||
try {
|
||||
PrefixConfig prefix = addPrefix(file);
|
||||
Main.debugging("完成前缀加载 " + prefix.getIdentifier() + " : " + prefix.getName());
|
||||
loaded.put(prefix.getIdentifier(), prefix);
|
||||
} catch (Exception ex) {
|
||||
Main.severe("在加载前缀 " + file.getAbsolutePath() + " 时出错,请检查配置!");
|
||||
Main.severe("Error occurred when loading prefix #" + file.getAbsolutePath() + " !");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.prefixes = loaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归收集文件夹下的所有YAML文件
|
||||
*
|
||||
* @param folder 目标文件夹
|
||||
* @param files 文件列表
|
||||
*/
|
||||
private void collectYamlFiles(@NotNull File folder, @NotNull List<File> files) {
|
||||
File[] children = folder.listFiles();
|
||||
if (children == null) return;
|
||||
for (File child : children) {
|
||||
if (child.isDirectory()) {
|
||||
collectYamlFiles(child, files);
|
||||
} else if (child.isFile() && isYamlFile(child)) {
|
||||
files.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断文件是否为YAML文件
|
||||
*
|
||||
* @param file 文件
|
||||
* @return 如果是.yml或.yaml文件返回true
|
||||
*/
|
||||
private boolean isYamlFile(@NotNull File file) {
|
||||
String name = file.getName().toLowerCase();
|
||||
return name.endsWith(".yml") || name.endsWith(".yaml");
|
||||
}
|
||||
|
||||
public void loadDefaultPrefix() {
|
||||
this.defaultPrefix = new PrefixConfig(
|
||||
"default",
|
||||
PluginConfig.DEFAULT_PREFIX.NAME.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(),
|
||||
null,
|
||||
readActions(PluginConfig.DEFAULT_PREFIX.ACTIONS.get()),
|
||||
@@ -95,6 +121,36 @@ public class PrefixManager {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据group获取可见的前缀列表
|
||||
*
|
||||
* @param player 玩家
|
||||
* @param group 分组名称,为null时返回所有前缀
|
||||
* @return 过滤后的前缀列表
|
||||
*/
|
||||
public List<PrefixConfig> getVisiblePrefix(Player player, @Nullable String group) {
|
||||
if (group == null || group.isEmpty()) {
|
||||
return getVisiblePrefix(player);
|
||||
}
|
||||
return getPrefixes().values().stream()
|
||||
.filter(c -> c.isVisible(player))
|
||||
.filter(c -> group.equalsIgnoreCase(c.getGroup()))
|
||||
.sorted(Comparator.comparingInt(PrefixConfig::getWeight))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有已配置的group列表
|
||||
*
|
||||
* @return group名称集合
|
||||
*/
|
||||
public Set<String> getGroups() {
|
||||
return getPrefixes().values().stream()
|
||||
.map(PrefixConfig::getGroup)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PrefixConfig getDefaultPrefix() {
|
||||
return defaultPrefix;
|
||||
@@ -134,12 +190,24 @@ public class PrefixManager {
|
||||
String name = conf.getString("name");
|
||||
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(
|
||||
identifier, name,
|
||||
conf.getStringList("description"),
|
||||
conf.getString("content", "&r"),
|
||||
content,
|
||||
conf.getLong("period", -1L),
|
||||
conf.getInt("weight", 1),
|
||||
conf.getString("permission"),
|
||||
conf.getString("group"),
|
||||
readActions(conf.getStringList("actions")),
|
||||
readItem(
|
||||
conf.getConfigurationSection("item.has-perm"),
|
||||
|
||||
@@ -10,6 +10,7 @@ import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -20,11 +21,17 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
|
||||
public static HashSet<Player> openingUsers = new HashSet<>();
|
||||
|
||||
protected final Player player;
|
||||
protected final Player player;
|
||||
protected final @Nullable String group;
|
||||
|
||||
public PrefixSelectGUI(Player player) {
|
||||
this(player, null);
|
||||
}
|
||||
|
||||
public PrefixSelectGUI(Player player, @Nullable String group) {
|
||||
super(GUIType.SIX_BY_NINE, PluginConfig.GUI.TITLE.get(), 10, 43);
|
||||
this.player = player;
|
||||
this.group = group;
|
||||
|
||||
setPreviousPageSlot(18);
|
||||
setNextPageSlot(26);
|
||||
@@ -37,6 +44,11 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void loadExtraIcons() {
|
||||
PluginConfig.GUI.ITEMS.getNotNull().getItems().values().forEach(v -> v.setupItems(player, this));
|
||||
}
|
||||
@@ -44,7 +56,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
public void loadItems() {
|
||||
List<PrefixConfig> prefixList = new ArrayList<>();
|
||||
prefixList.add(UserPrefixAPI.getPrefixManager().getDefaultPrefix());
|
||||
prefixList.addAll(UserPrefixAPI.getPrefixManager().getVisiblePrefix(player)); //只需要读取看得见的
|
||||
prefixList.addAll(UserPrefixAPI.getPrefixManager().getVisiblePrefix(player, group));
|
||||
|
||||
PrefixConfig usingPrefix = UserPrefixAPI.getUserManager().getPrefix(getPlayer());
|
||||
|
||||
@@ -60,10 +72,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
@Override
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
player.closeInventory();
|
||||
//再次检查,防止打开GUI后、选择前的时间段内权限消失
|
||||
if (prefix.checkPermission(player)) {
|
||||
|
||||
// 发送消息与提示
|
||||
PluginConfig.SOUNDS.PREFIX_CHANGE.playTo(player);
|
||||
PluginMessages.SELECTED.sendTo(player, prefix.getName());
|
||||
|
||||
@@ -86,8 +95,6 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,11 +114,12 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
}
|
||||
|
||||
public static void open(Player player) {
|
||||
// player.closeInventory(); // 防止冲突
|
||||
PluginConfig.SOUNDS.GUI_OPEN.playTo(player);
|
||||
new PrefixSelectGUI(player).openGUI(player);
|
||||
openingUsers.add(player);
|
||||
open(player, null);
|
||||
}
|
||||
|
||||
|
||||
public static void open(Player player, @Nullable String group) {
|
||||
PluginConfig.SOUNDS.GUI_OPEN.playTo(player);
|
||||
new PrefixSelectGUI(player, group).openGUI(player);
|
||||
openingUsers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,27 @@ name: "&b&lPro&b"
|
||||
|
||||
# Content [Necessary]
|
||||
# Use in Placeholders
|
||||
# Supports multiple lines for content rotation.
|
||||
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]
|
||||
# used for sorting in the GUI and TabList
|
||||
# In GUI : the larger is displayed at the back
|
||||
# At TabList : the larger is displayed at the top
|
||||
weight: 1
|
||||
|
||||
# Group [Unnecessary]
|
||||
# Used to group prefixes, players can use /prefix <group> to view prefixes in the corresponding group
|
||||
# If not configured, it means the prefix is not in any group
|
||||
group: vip
|
||||
|
||||
# Permission [Unnecessary]
|
||||
# If there is no permission for detection, everyone can use it,
|
||||
# which means there is no need to configure "itemNoPermission"
|
||||
|
||||
@@ -5,14 +5,29 @@ name: "&b&lPro&b"
|
||||
|
||||
# Contenido [Necesario]
|
||||
# Uso en Placeholders
|
||||
# Soporta múltiples líneas para la rotación de contenido.
|
||||
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]
|
||||
# utilizado para ordenar en la GUI y TabList
|
||||
# En GUI : el más grande se muestra en la parte posterior
|
||||
# En TabList : el más grande se muestra en la parte superior
|
||||
weight: 1
|
||||
|
||||
# Grupo [Innecesario]
|
||||
# Se utiliza para agrupar prefijos, los jugadores pueden usar /prefix <group> para ver prefijos en el grupo correspondiente
|
||||
# Si no se configura, significa que el prefijo no está en ningún grupo
|
||||
group: vip
|
||||
|
||||
# Permisos [Innecesario]
|
||||
# Si no hay permiso para la detección, todo el mundo puede utilizarlo,
|
||||
# lo que significa que no es necesario configurar "itemNoPermission"
|
||||
|
||||
@@ -9,14 +9,27 @@ name: "&b&lPro &b会员"
|
||||
|
||||
# 内容 [必须]
|
||||
# 显示在名字前面的内容
|
||||
# 支持多行内容以实现前缀内容的轮换
|
||||
content: "&b&lPro &b"
|
||||
|
||||
# 轮换周期 [非必须]
|
||||
# 设置前缀内容的轮换周期,单位为毫秒。
|
||||
# 若数值为-1,则表示不轮换。
|
||||
# 若数值为0,则每次获取前缀时都会随机选择一行内容。
|
||||
# 若数值大于0,则表示每隔指定毫秒数轮换一次内容
|
||||
period: -1
|
||||
|
||||
# 权重 [必须]
|
||||
# 用于GUI、TabList的排序和自动前缀显示
|
||||
# 在GUI中,权重越高的会显示在越后面
|
||||
# 在TabList中,显示顺序可以在 config.yml 中自定义
|
||||
weight: 1
|
||||
|
||||
# 分组 [非必须]
|
||||
# 用于将前缀分组,玩家可以通过 /prefix <group> 查看对应分组的前缀
|
||||
# 若不配置则代表不在任何分组中
|
||||
group: vip
|
||||
|
||||
|
||||
# 检测的权限 [非必须]
|
||||
# 如果没有就是人人都能用,也代表不用配置“itemNoPermission”了(因为压根不可能显示没权限时候的物品)
|
||||
|
||||
Reference in New Issue
Block a user