1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2026-06-13 11:21:15 +08:00

Compare commits

...

20 Commits

Author SHA1 Message Date
carm 99f2b6ff28 补充英文介绍。 2022-02-27 23:26:24 +08:00
carm 5c5a57af5b Merge pull request #14 from zhangnelson/master
修复order-desc不生效的问题
2022-02-27 23:18:35 +08:00
Nelsoniwork 044cd1a84f 修复order-desc不生效的问题 2022-02-27 23:15:21 +08:00
carm 29796ec455 [#12] 修复order-desc不生效的问题 2022-02-27 22:34:40 +08:00
carm 898ba5bf27 [#12] 修复玩家前缀未生效order的问题 2022-02-27 18:27:38 +08:00
carm 2e46888019 [#12] 优化代码格式 2022-02-27 18:22:51 +08:00
carm ac55fc135c [2.4.3] 版本更新
- [F] 修复 #12 相关问题。
- [R] 修改配置文件中两个字段的名称使其符合yaml规范。
- [A] 添加“functions.on-name-prefix.order-desc”选项,用于决定在TabList中排序顺序。
2022-02-26 23:43:20 +08:00
carm 774e9b764e [2.4.2] 修复跨版本时配置文件不全而导致序列化异常的问题 2022-02-21 04:46:39 +08:00
carm a31da83531 Merge pull request #11 from Ghost-chu/master
Fixed #10, 自定义物品反序列化工具
2022-02-20 19:48:11 +08:00
Ghost_chu 61857d6305 清理debug 2022-02-20 19:46:26 +08:00
Ghost_chu dd96188b22 use FileConfiguration 2022-02-20 19:44:36 +08:00
Ghost_chu eb4ecaada9 Fixed #10, 自定义物品反序列化工具 2022-02-20 19:36:39 +08:00
carm acc9ea7e7c Update plugin.yml 2022-02-20 18:08:14 +08:00
carm 83b3c45d57 Update plugin.yml 2022-02-20 00:37:17 +08:00
carm 3ec39b9ca3 [2.4.1] 尝试修复 #9 问题。 2022-02-18 18:26:12 +08:00
carm 821b42cc03 每次构建同时提供“测试产物”与“最终产物”。 2022-02-17 21:42:14 +08:00
carm 81e0c0960f 每次构建同时提供“测试产物”与“最终产物”。 2022-02-17 21:40:52 +08:00
carm 99c577c361 [2.4.0] 添加自动检查更新机制,并允许开关。 2022-02-07 03:27:59 +08:00
carm 5df6e1fe34 [v2.3.3] 修改构建配置 2022-01-16 09:08:10 +08:00
carm 7c887822ba [v2.3.3] [R] 移除“v”前缀。 2022-01-16 08:18:16 +08:00
21 changed files with 640 additions and 434 deletions
+10 -11
View File
@@ -1,30 +1,29 @@
--- ---
name: 问题提交 name: 问题提交 about: 描述问题并提交,帮助我们对其进行检查与修复。 title: ''
about: 描述问题并提交,帮助我们对其进行检查与修复。 labels: bug assignees: ''
title: ''
labels: bug
assignees: ''
--- ---
### **问题简述** ### **问题简述**
用简短的话语描述一下大概问题。 <!--用简短的话语描述一下大概问题。-->
### **问题来源** ### **问题来源**
<!--
描述一下通过哪些操作才发现的问题,如: 描述一下通过哪些操作才发现的问题,如:
1. 打开 '...' 1. 打开 '...'
2. 点击了 '....' 2. 点击了 '....'
3. 出现了报错 '....' 3. 出现了报错 '....'
-->
### **预期结果**(可选) ### **预期结果**(可选)
如果问题不发生,应该是什么情况 <!--如果问题不发生,应该是什么情况-->
### **问题截图/问题报错** ### **问题截图/问题报错**
如果有报错或输出,请提供截图。 <!--如果有报错或输出,请提供截图。-->
### **操作环境** ### **操作环境**
请在后台输入 `version` 并复制相关输出。 <!--请在后台输入 `version` 并复制相关输出。-->
### **其他补充** ### **其他补充**
如有其他补充,可以在这里描述。 <!--如有其他补充,可以在这里描述。-->
+4 -4
View File
@@ -8,13 +8,13 @@ assignees: ''
--- ---
### **功能简述** ### **功能简述**
简单的描述一下你想要的功能 <!--简单的描述一下你想要的功能-->
### **需求来源** ### **需求来源**
简单的描述一下为什么需要这个功能。 <!--简单的描述一下为什么需要这个功能。-->
### **功能参考**(可选) ### **功能参考**(可选)
如果有相关功能的参考,如文本、截图,请提供给我们。 <!--如果有相关功能的参考,如文本、截图,请提供给我们。-->
### **附加内容** ### **附加内容**
如果有什么小细节需要重点注意,请在这里告诉我们。 <!--如果有什么小细节需要重点注意,请在这里告诉我们。-->
+6 -2
View File
@@ -31,9 +31,13 @@ jobs:
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}} MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: "Target Staging" - name: "Target Staging"
run: mkdir staging && cp target/*.jar staging run: |
mkdir artifacts
cp -vrf target/ artifacts/target/
cp -vrf asset/*.jar artifacts
- name: "Upload artifact" - name: "Upload artifact"
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: Artifact name: Artifact
path: staging path: artifacts
+2
View File
@@ -1,5 +1,7 @@
![BANNER](.documentation/images/banner.png) ![BANNER](.documentation/images/banner.png)
README LANGUAGES [ [中文](README.md) | [**English**](README-en.md) ]
# UserPrefix Plugin # UserPrefix Plugin
[![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix) [![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix)
+2 -2
View File
@@ -1,5 +1,7 @@
![BANNER](.documentation/images/banner.png) ![BANNER](.documentation/images/banner.png)
README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
# 用户前缀系统插件 # 用户前缀系统插件
[![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix) [![CodeFactor](https://www.codefactor.io/repository/github/carmjos/userprefix/badge?s=b76fec1f64726b5f19989aace6adb5f85fdab840)](https://www.codefactor.io/repository/github/carmjos/userprefix)
@@ -13,8 +15,6 @@
本插件基于Spigot实现,**理论上支持全版本**。 本插件基于Spigot实现,**理论上支持全版本**。
The **English version** of the introduction is [here](README-en.md).
> 本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503) 与 [SpigotMC](https://www.spigotmc.org/resources/userprefix-hex-color-support-all-version.96277/) 上发布。 > 本插件已在 [MCBBS](https://www.mcbbs.net/forum.php?mod=viewthread&tid=1261503) 与 [SpigotMC](https://www.spigotmc.org/resources/userprefix-hex-color-support-all-version.96277/) 上发布。
## 示例 ## 示例
+24 -7
View File
@@ -13,7 +13,7 @@
<groupId>cc.carm.plugin</groupId> <groupId>cc.carm.plugin</groupId>
<artifactId>userprefix</artifactId> <artifactId>userprefix</artifactId>
<version>v2.3.2</version> <version>2.4.3</version>
<name>UserPrefix</name> <name>UserPrefix</name>
<description>轻便、高效、实时的用户前缀系统。</description> <description>轻便、高效、实时的用户前缀系统。</description>
@@ -80,6 +80,11 @@
<url>https://repo1.maven.org/maven2/</url> <url>https://repo1.maven.org/maven2/</url>
</repository> </repository>
<repository>
<id>sonatype-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
<repository> <repository>
<id>github</id> <id>github</id>
<name>GitHub Packages</name> <name>GitHub Packages</name>
@@ -123,7 +128,14 @@
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId> <artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version> <version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>githubreleases4j</artifactId>
<version>1.3.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -200,20 +212,25 @@
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
</execution>
</executions>
<configuration> <configuration>
<finalName>${project.name}-${project.version}</finalName> <finalName>${project.name}-${project.version}</finalName>
<outputDirectory>${project.basedir}/asset/</outputDirectory> <outputDirectory>${project.basedir}/asset/</outputDirectory>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
<configuration>
<relocations> <relocations>
<relocation> <relocation>
<pattern>org.bstats</pattern> <pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>cc.carm.plugin.userprefix.bstats</shadedPattern> <shadedPattern>cc.carm.plugin.userprefix.bstats</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>cc.carm.lib.githubreleases4j</pattern>
<shadedPattern>cc.carm.plugin.userprefix.lib.github</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>cc.carm.plugin.userprefix.lib.json</shadedPattern>
</relocation>
</relocations> </relocations>
<filters> <filters>
<filter> <filter>
@@ -3,6 +3,7 @@ package cc.carm.plugin.userprefix;
import cc.carm.plugin.userprefix.command.UserPrefixAdminCommand; import cc.carm.plugin.userprefix.command.UserPrefixAdminCommand;
import cc.carm.plugin.userprefix.command.UserPrefixCommand; import cc.carm.plugin.userprefix.command.UserPrefixCommand;
import cc.carm.plugin.userprefix.configuration.PluginConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import cc.carm.plugin.userprefix.hooker.UpdateChecker;
import cc.carm.plugin.userprefix.hooker.UserPrefixExpansion; import cc.carm.plugin.userprefix.hooker.UserPrefixExpansion;
import cc.carm.plugin.userprefix.listener.ChatListener; import cc.carm.plugin.userprefix.listener.ChatListener;
import cc.carm.plugin.userprefix.listener.UserListener; import cc.carm.plugin.userprefix.listener.UserListener;
@@ -13,6 +14,7 @@ import cc.carm.plugin.userprefix.manager.ServiceManager;
import cc.carm.plugin.userprefix.manager.UserManager; import cc.carm.plugin.userprefix.manager.UserManager;
import cc.carm.plugin.userprefix.util.ColorParser; import cc.carm.plugin.userprefix.util.ColorParser;
import cc.carm.plugin.userprefix.util.MessageUtil; import cc.carm.plugin.userprefix.util.MessageUtil;
import cc.carm.plugin.userprefix.wrapper.ItemStackWrapper;
import net.luckperms.api.event.user.UserDataRecalculateEvent; import net.luckperms.api.event.user.UserDataRecalculateEvent;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie; import org.bstats.charts.SimplePie;
@@ -21,6 +23,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -38,6 +41,9 @@ public class Main extends JavaPlugin {
log(getName() + " " + getDescription().getVersion() + " &7开始加载..."); log(getName() + " " + getDescription().getVersion() + " &7开始加载...");
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
log("注入序列化处理工具...");
ConfigurationSerialization.registerClass(ItemStackWrapper.class);
log("加载配置文件..."); log("加载配置文件...");
ConfigManager.initConfig(); ConfigManager.initConfig();
PrefixManager.init(); PrefixManager.init();
@@ -72,6 +78,13 @@ public class Main extends JavaPlugin {
})); }));
} }
if (PluginConfig.CHECK_UPDATE.get()) {
log("开始检查更新...");
UpdateChecker.checkUpdate(getDescription().getVersion());
} else {
log("已禁用检查更新,跳过。");
}
log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。"); log("加载完成 ,共耗时 " + (System.currentTimeMillis() - startTime) + " ms 。");
showAD(); showAD();
@@ -13,6 +13,8 @@ public class PluginConfig {
public static ConfigValue<Boolean> METRICS = new ConfigValue<>("metrics", Boolean.class, true); public static ConfigValue<Boolean> METRICS = new ConfigValue<>("metrics", Boolean.class, true);
public static final ConfigValue<Boolean> CHECK_UPDATE = new ConfigValue<>("check-update", Boolean.class, true);
public static class CustomStorage { public static class CustomStorage {
public static ConfigValue<Boolean> ENABLE = new ConfigValue<>("custom-storage.enable", Boolean.class, false); public static ConfigValue<Boolean> ENABLE = new ConfigValue<>("custom-storage.enable", Boolean.class, false);
@@ -23,8 +25,10 @@ public class PluginConfig {
public static class Functions { public static class Functions {
public static ConfigValue<Boolean> NAME_PREFIX = new ConfigValue<>("functions.OnNamePrefix", Boolean.class, true); public static ConfigValue<Boolean> NAME_PREFIX = new ConfigValue<>("functions.on-name-prefix.enable", Boolean.class, true);
public static ConfigValue<Boolean> AUTO_USE = new ConfigValue<>("functions.autoUsePrefix", Boolean.class, true); public static ConfigValue<Boolean> NAME_ORDER_DESC = new ConfigValue<>("functions.on-name-prefix.order-desc", Boolean.class, true);
public static ConfigValue<Boolean> AUTO_USE = new ConfigValue<>("functions.auto-prefix-use", Boolean.class, true);
public static class Chat { public static class Chat {
@@ -1,8 +1,8 @@
package cc.carm.plugin.userprefix.configuration.file; package cc.carm.plugin.userprefix.configuration.file;
import cc.carm.plugin.userprefix.util.ConfigurationUtil;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
@@ -35,7 +35,7 @@ public class FileConfig {
} }
plugin.saveResource(fileName, true); plugin.saveResource(fileName, true);
} }
this.config = YamlConfiguration.loadConfiguration(this.file); this.config = ConfigurationUtil.bang(this.file);
} }
public File getFile() { public File getFile() {
@@ -56,7 +56,7 @@ public class FileConfig {
public void reload() { public void reload() {
if (getFile().exists()) { if (getFile().exists()) {
this.config = YamlConfiguration.loadConfiguration(getFile()); this.config = ConfigurationUtil.bang(getFile());
} else { } else {
initFile(); initFile();
} }
@@ -1,12 +1,17 @@
package cc.carm.plugin.userprefix.event; package cc.carm.plugin.userprefix.event;
import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix; import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
public class UserPrefixChangeEvent extends UserPrefixEvent implements Cancellable { public class UserPrefixChangeEvent extends UserPrefixEvent implements Cancellable {
public static HandlerList handler = new HandlerList(); public static HandlerList handler = new HandlerList();
@@ -52,4 +57,19 @@ public class UserPrefixChangeEvent extends UserPrefixEvent implements Cancellabl
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handler; return handler;
} }
public static void call(@NotNull Player who,
@Nullable ConfiguredPrefix before,
@NotNull ConfiguredPrefix after,
@Nullable Consumer<@Nullable ConfiguredPrefix> finish) {
new BukkitRunnable() {
@Override
public void run() {
UserPrefixChangeEvent event = new UserPrefixChangeEvent(who, before, after);
Bukkit.getPluginManager().callEvent(event);
if (finish != null) finish.accept(event.isCancelled() ? null : event.getAfter());
}
}.runTask(Main.getInstance());
}
} }
@@ -1,8 +1,11 @@
package cc.carm.plugin.userprefix.event; package cc.carm.plugin.userprefix.event;
import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix; import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class UserPrefixExpireEvent extends UserPrefixEvent { public class UserPrefixExpireEvent extends UserPrefixEvent {
@@ -27,4 +30,14 @@ public class UserPrefixExpireEvent extends UserPrefixEvent {
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handler; return handler;
} }
public static void call(@NotNull Player player, @NotNull ConfiguredPrefix currentPrefix) {
new BukkitRunnable() {
@Override
public void run() {
Bukkit.getPluginManager().callEvent(new UserPrefixExpireEvent(player, currentPrefix));
}
}.runTask(Main.getInstance());
}
} }
@@ -0,0 +1,35 @@
package cc.carm.plugin.userprefix.hooker;
import cc.carm.lib.githubreleases4j.GithubReleases4J;
import cc.carm.plugin.userprefix.Main;
import org.bukkit.scheduler.BukkitRunnable;
public class UpdateChecker {
public static void checkUpdate(String currentVersion) {
new BukkitRunnable() {
@Override
public void run() {
String downloadURL = GithubReleases4J.getReleasesURL("CarmJos", "UserPrefix");
Integer behindVersions = GithubReleases4J.getVersionBehind(
"CarmJos", "UserPrefix", currentVersion
);
if (behindVersions == null) {
Main.error("检查更新失败,请您定期查看插件是否更新,避免安全问题。");
Main.error("下载地址 " + downloadURL);
} else if (behindVersions == 0) {
Main.log("检查完成,当前已是最新版本。");
} else if (behindVersions > 0) {
Main.log("发现新版本! 目前已落后 " + behindVersions + " 个版本。");
Main.log("最新版下载地址 " + downloadURL);
} else {
Main.error("检查更新失败! 当前版本未知,请您使用原生版本以避免安全问题。");
Main.error("最新版下载地址 " + downloadURL);
}
}
}.runTaskAsynchronously(Main.getInstance());
}
}
@@ -73,18 +73,20 @@ public class UserManager {
if (tag == null) return; //未启用的情况下,不需要进行任何操作。 if (tag == null) return; //未启用的情况下,不需要进行任何操作。
ConfiguredPrefix playerPrefix = UserManager.getPrefix(player); ConfiguredPrefix playerPrefix = UserManager.getPrefix(player);
boolean descOrder = PluginConfig.Functions.NAME_ORDER_DESC.get();
tag.setPrefix(playerPrefix.getContent()); tag.setPrefix(playerPrefix.getContent());
tag.setOrder(playerPrefix.getWeight()); tag.setOrder(descOrder ? 999 - playerPrefix.getWeight() : playerPrefix.getWeight());
Main.debug("为玩家 " + player.getName() + " 设置了 " + player.getName() + "的前缀为 #" + playerPrefix.getWeight() + " " + playerPrefix.getName()); Main.debug("为玩家 " + player.getName() + " 设置了 " + player.getName() + "的前缀为 #" + playerPrefix.getWeight() + " " + playerPrefix.getName());
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.equals(player)) continue; if (onlinePlayer.equals(player)) continue;
UserNameTag onlinePlayerTag = getNameTag(onlinePlayer); UserNameTag onlinePlayerTag = getNameTag(onlinePlayer);
if (onlinePlayerTag != null) { if (onlinePlayerTag != null) {
onlinePlayerTag.setPrefix(player, playerPrefix.getContent()); onlinePlayerTag.setPrefix(player, playerPrefix.getContent());
onlinePlayerTag.setOrder(player, playerPrefix.getWeight()); onlinePlayerTag.setOrder(player, descOrder ? 999 - playerPrefix.getWeight() : playerPrefix.getWeight());
Main.debug("为玩家 " + onlinePlayer.getName() + " 设置了 " + player.getName() + "的前缀为 #" + playerPrefix.getWeight() + " " + playerPrefix.getName()); Main.debug("为玩家 " + onlinePlayer.getName() + " 设置了 " + player.getName() + "的前缀为 #" + playerPrefix.getWeight() + " " + playerPrefix.getName());
} }
@@ -92,7 +94,7 @@ public class UserManager {
if (loadOthers) { if (loadOthers) {
ConfiguredPrefix onlinePlayerPrefix = UserManager.getPrefix(onlinePlayer); ConfiguredPrefix onlinePlayerPrefix = UserManager.getPrefix(onlinePlayer);
tag.setPrefix(onlinePlayer, onlinePlayerPrefix.getContent()); tag.setPrefix(onlinePlayer, onlinePlayerPrefix.getContent());
tag.setOrder(onlinePlayer, onlinePlayerPrefix.getWeight()); tag.setOrder(onlinePlayer, descOrder ? 999 - onlinePlayerPrefix.getWeight() : onlinePlayerPrefix.getWeight());
Main.debug("为玩家 " + player.getName() + " 设置了 " + onlinePlayer.getName() + "的前缀为 #" + onlinePlayerPrefix.getWeight() + " " + onlinePlayerPrefix.getName()); Main.debug("为玩家 " + player.getName() + " 设置了 " + onlinePlayer.getName() + "的前缀为 #" + onlinePlayerPrefix.getWeight() + " " + onlinePlayerPrefix.getName());
} }
} }
@@ -121,7 +123,7 @@ public class UserManager {
if (currentPrefix != null) { if (currentPrefix != null) {
//当前前缀不为空,则代表属于前缀过期的情况 //当前前缀不为空,则代表属于前缀过期的情况
Bukkit.getPluginManager().callEvent(new UserPrefixExpireEvent(player, currentPrefix)); UserPrefixExpireEvent.call(player, currentPrefix);
// 发送消息 // 发送消息
PluginConfig.Messages.EXPIRED.sendWithPlaceholders(player, PluginConfig.Messages.EXPIRED.sendWithPlaceholders(player,
@@ -139,17 +141,16 @@ public class UserManager {
); );
} }
UserPrefixChangeEvent event = new UserPrefixChangeEvent(player, currentPrefix, newPrefix); UserPrefixChangeEvent.call(player, currentPrefix, newPrefix, (after) -> {
Bukkit.getPluginManager().callEvent(event); if (after != null) {
UserManager.setPrefix(player, after, updateView);
if (!event.isCancelled()) {
// 更新前缀
UserManager.setPrefix(player, event.getAfter(), updateView);
} }
}
checkingPlayers.remove(player.getUniqueId()); checkingPlayers.remove(player.getUniqueId());
});
} else {
checkingPlayers.remove(player.getUniqueId());
}
} }
public static void unloadNameTag(UUID uuid) { public static void unloadNameTag(UUID uuid) {
@@ -226,6 +227,7 @@ public class UserManager {
* @param prefixIdentifier 前缀标识 * @param prefixIdentifier 前缀标识
* @return 若前缀标识不存在,则返回false;若前缀为默认前缀,或该前缀无权限,或玩家有该前缀的权限,则返回true。 * @return 若前缀标识不存在,则返回false;若前缀为默认前缀,或该前缀无权限,或玩家有该前缀的权限,则返回true。
*/ */
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public static boolean isPrefixUsable(Player player, String prefixIdentifier) { public static boolean isPrefixUsable(Player player, String prefixIdentifier) {
if (prefixIdentifier == null || prefixIdentifier.equalsIgnoreCase("default")) return true; if (prefixIdentifier == null || prefixIdentifier.equalsIgnoreCase("default")) return true;
ConfiguredPrefix prefix = PrefixManager.getPrefix(prefixIdentifier); ConfiguredPrefix prefix = PrefixManager.getPrefix(prefixIdentifier);
@@ -1,11 +1,11 @@
package cc.carm.plugin.userprefix.model; package cc.carm.plugin.userprefix.model;
import cc.carm.plugin.userprefix.util.ColorParser; import cc.carm.plugin.userprefix.util.ColorParser;
import cc.carm.plugin.userprefix.util.ConfigurationUtil;
import cc.carm.plugin.userprefix.util.ItemStackFactory; import cc.carm.plugin.userprefix.util.ItemStackFactory;
import cc.carm.plugin.userprefix.util.MessageUtil; import cc.carm.plugin.userprefix.util.MessageUtil;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@@ -38,7 +38,11 @@ public class ConfiguredPrefix {
public ConfiguredPrefix(@NotNull File dataFile) { public ConfiguredPrefix(@NotNull File dataFile) {
this.dataFile = dataFile; this.dataFile = dataFile;
this.configuration = YamlConfiguration.loadConfiguration(dataFile); try {
this.configuration = ConfigurationUtil.bang(dataFile);
} catch (Exception e) {
e.printStackTrace();
}
if (getConfiguration() != null) { if (getConfiguration() != null) {
this.identifier = getConfiguration().getString("identifier", "ERROR"); this.identifier = getConfiguration().getString("identifier", "ERROR");
this.name = getConfiguration().getString("name", "ERROR"); this.name = getConfiguration().getString("name", "ERROR");
@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.Range;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -12,10 +13,12 @@ import java.util.UUID;
public class UserNameTag { public class UserNameTag {
public static final int MAX_ORDER = 999;
private final Player viewer; private final Player viewer;
private Team team; private Team team;
private final Scoreboard sb; private final Scoreboard sb;
private int order = 99999; private int order = MAX_ORDER;
private final Map<UUID, Integer> targetOrders = new HashMap<>(); private final Map<UUID, Integer> targetOrders = new HashMap<>();
private final Map<UUID, String> previousTeamNames = new HashMap<>(); private final Map<UUID, String> previousTeamNames = new HashMap<>();
@@ -35,7 +38,7 @@ public class UserNameTag {
/** /**
* 设置自己的前缀 * 设置自己的前缀
* *
* @param prefix * @param prefix 前缀内容
*/ */
public void setPrefix(String prefix) { public void setPrefix(String prefix) {
team.setPrefix(prefix); team.setPrefix(prefix);
@@ -45,8 +48,8 @@ public class UserNameTag {
/** /**
* 设置某个玩家的前缀 * 设置某个玩家的前缀
* *
* @param target * @param target 目标
* @param prefix * @param prefix 前缀内容
*/ */
public void setPrefix(Player target, String prefix) { public void setPrefix(Player target, String prefix) {
if (target == viewer) { if (target == viewer) {
@@ -63,11 +66,9 @@ public class UserNameTag {
/** /**
* 设置名字在TabList中的顺序 * 设置名字在TabList中的顺序
* *
* @param order * @param order 顺序 (0~999)
*/ */
public void setOrder(int order) { public void setOrder(@Range(from = 0, to = 999) int order) {
if (order < 0 || order > 99999)
throw new IllegalArgumentException("order must be in 0~99999");
this.order = order; this.order = order;
targetOrders.put(viewer.getUniqueId(), order); targetOrders.put(viewer.getUniqueId(), order);
update(viewer); update(viewer);
@@ -78,16 +79,13 @@ public class UserNameTag {
* *
* @param order 顺序 * @param order 顺序
*/ */
public void setOrder(Player target, int order) { public void setOrder(Player target, @Range(from = 0, to = 999) int order) {
if (order < 0 || order > 99999)
throw new IllegalArgumentException("order must be in 0~99999");
Team targetTeam = checkTeam(target); Team targetTeam = checkTeam(target);
String teamName = order + UUID.randomUUID().toString().substring(0, 10); String teamName = order + UUID.randomUUID().toString().substring(0, 10);
targetTeam.setDisplayName(teamName); targetTeam.setDisplayName(teamName);
targetOrders.put(target.getUniqueId(), order); targetOrders.put(target.getUniqueId(), order);
update(viewer); update(viewer);
if (viewer != target) if (viewer != target) update(target);
update(target);
} }
public void update(Player target) { public void update(Player target) {
@@ -110,7 +108,7 @@ public class UserNameTag {
team = newTeam; team = newTeam;
} }
} else { } else {
int order = targetOrders.getOrDefault(target.getUniqueId(), 99999); int order = targetOrders.getOrDefault(target.getUniqueId(), 999);
String previousTeamName = previousTeamNames.get(target.getUniqueId()); String previousTeamName = previousTeamNames.get(target.getUniqueId());
if (previousTeamName == null) { if (previousTeamName == null) {
return; return;
@@ -138,7 +136,7 @@ public class UserNameTag {
} }
private Team checkTeam(Player target) { private Team checkTeam(Player target) {
int order = targetOrders.getOrDefault(target.getUniqueId(), 99999); int order = targetOrders.getOrDefault(target.getUniqueId(), 999);
String name = order + target.getUniqueId().toString().substring(0, 10); String name = order + target.getUniqueId().toString().substring(0, 10);
Team targetTeam = this.sb.getTeam(name); Team targetTeam = this.sb.getTeam(name);
if (targetTeam == null) { if (targetTeam == null) {
@@ -0,0 +1,38 @@
package cc.carm.plugin.userprefix.util;
import cc.carm.plugin.userprefix.wrapper.ItemStackWrapper;
import com.google.common.io.Files;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;
public class ConfigurationUtil {
public static FileConfiguration bang(File file) {
YamlConfiguration conf = new YamlConfiguration();
StringJoiner builder = new StringJoiner("\n");
try {
//noinspection UnstableApiUsage
Files.readLines(file, StandardCharsets.UTF_8).forEach(builder::add);
} catch (IOException e) {
e.printStackTrace();
return conf;
}
String tmpConf = builder.toString().replace("==: "+ ItemStack.class.getName(), "==: "+ ItemStackWrapper.class.getName());
try {
conf.loadFromString(tmpConf);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
return conf;
}
public static String dong(FileConfiguration conf) {
return conf.saveToString().replace("==: "+ ItemStackWrapper.class.getName(),"==: "+ ItemStack.class.getName());
}
}
@@ -0,0 +1,43 @@
package cc.carm.plugin.userprefix.wrapper;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class ItemStackWrapper implements ConfigurationSerializable {
private static boolean unsafeAvailable;
static {
try {
Class.forName("org.bukkit.UnsafeValues");
unsafeAvailable = true;
} catch (ClassNotFoundException e) {
unsafeAvailable = false;
}
}
@NotNull
@Override
public Map<String, Object> serialize() {
throw new UnsupportedOperationException("Use ConfigurationUtil#dong to save configuration");
}
@NotNull
public static ItemStack deserialize(@NotNull Map<String, Object> args) {
// static define will cause problem, lazy load it
if (unsafeAvailable) {
if (!args.containsKey("v")) {
Material material = Material.matchMaterial(args.get("type").toString());
if (material == null) {
throw new IllegalArgumentException("物品 "+args.get("type")+" 不存在");
}
args.put("v", Bukkit.getServer().getUnsafe().getDataVersion());
}
}
return ItemStack.deserialize(args);
}
}
+10 -2
View File
@@ -7,6 +7,11 @@ debug: false
# 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。 # 当然,您也可以选择在这里关闭,或在plugins/bStats下的配置文件中关闭。
metrics: true metrics: true
# 检查更新设定
# 该选项用于插件判断是否要检查更新,若您不希望插件检查更新并提示您,可以选择关闭。
# 检查更新为异步操作,绝不会影响性能与使用体验。
check-update: true
custom-storage: custom-storage:
# 自定义存储位置 # 自定义存储位置
# 默认存储位置为 “插件文件夹”/prefixes # 默认存储位置为 “插件文件夹”/prefixes
@@ -16,8 +21,11 @@ custom-storage:
path: "prefixes/" # 一定要指向一个文件夹! path: "prefixes/" # 一定要指向一个文件夹!
functions: functions:
OnNamePrefix: true # 是否给头顶上添加前缀,该方法用到了头顶的那个计分板,如有冲突请关掉哦~ # 头顶与TabList前缀功能,该方法用到了玩家名计分板接口,如有冲突请关掉哦~
autoUsePrefix: true # 自动前缀显示 当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个 on-name-prefix:
enable: true # 是否开启本功能
order-desc: true # 是否按降序排列,即权重越高的前缀显示在越上面;若为false则按升序排列。
auto-prefix-use: true # 自动使用前缀,即当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个
chat: chat:
# 聊天功能 # 聊天功能
# - 我不推荐使用本插件的聊天功能,而是建议使用其他的聊天插件。 # - 我不推荐使用本插件的聊天功能,而是建议使用其他的聊天插件。
+8 -3
View File
@@ -4,6 +4,9 @@ debug: false #DEBUG OUT PUT
metrics: true #Metrics stats (to help developer know the stats) metrics: true #Metrics stats (to help developer know the stats)
# Auto check the updates.
check-update: true
custom-storage: custom-storage:
# Custom storage location # Custom storage location
# default location is "./prefixes" # default location is "./prefixes"
@@ -36,14 +39,16 @@ GUI:
- "§fRight-Click to the first page" - "§fRight-Click to the first page"
functions: functions:
# Whether to add a prefix to the top of the head, # Add a prefix to the top of the head,
# this method uses the scoreboard above the head, # this method uses the scoreboard above the head,
# please turn it off if there is a conflict. # please turn it off if there is a conflict.
OnNamePrefix: true on-name-prefix:
enable: true # enable or disable
order-desc: true # using desc ( higher weight for higher display in TabList)
# Automatic prefix select. # Automatic prefix select.
# When the player does not choose a prefix by himself, # When the player does not choose a prefix by himself,
# the prefix with the highest weight will be used automatically # the prefix with the highest weight will be used automatically
autoUsePrefix: true auto-prefix-use: true
chat: chat:
# Chat Function # Chat Function
# - I recommend using other chat plugins instead of using this plugin, # - I recommend using other chat plugins instead of using this plugin,
+1
View File
@@ -7,6 +7,7 @@ authors:
- SakuraGame - SakuraGame
website: ${project.url} website: ${project.url}
description: ${project.description} description: ${project.description}
api-version: 1.13
depend: depend:
- LuckPerms - LuckPerms
@@ -14,7 +14,7 @@ content: "&b&lPro &b"
# 权重 [必须] # 权重 [必须]
# 用于GUI、TabList的排序和自动前缀显示 # 用于GUI、TabList的排序和自动前缀显示
# 在GUI中,权重越高的会显示在越后面 # 在GUI中,权重越高的会显示在越后面
# 在TabList中,权重越高的会显示在越上面 # 在TabList中,显示顺序可以在 config.yml 中自定义
weight: 1 weight: 1