1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2026-06-05 00:35:02 +08:00

[v2.3.0] 版本更新

- [A] 添加数个事件,方便其他插件调用使用。
- [A] 当原前缀已不存在的情况下的向玩家发送消息。
This commit is contained in:
2022-01-07 08:37:25 +08:00
parent 9164541e4f
commit b4f8404648
18 changed files with 466 additions and 328 deletions
+7 -7
View File
@@ -1,30 +1,30 @@
--- ---
name: 问题提交 name: 问题提交
about: 提交并描述问题,帮助我们对其进行检查与修复。 about: 描述问题并提交,帮助我们对其进行检查与修复。
title: '' title: ''
labels: bug labels: bug
assignees: '' assignees: ''
--- ---
**问题简述** ### **问题简述**
用简短的话语描述一下大概问题。 用简短的话语描述一下大概问题。
**问题来源** ### **问题来源**
描述一下通过哪些操作才发现的问题,如: 描述一下通过哪些操作才发现的问题,如:
1. 打开 '...' 1. 打开 '...'
2. 点击了 '....' 2. 点击了 '....'
3. 出现了报错 '....' 3. 出现了报错 '....'
**预期结果**(可选) ### **预期结果**(可选)
如果问题不发生,应该是什么情况 如果问题不发生,应该是什么情况
**问题截图/问题报错** ### **问题截图/问题报错**
如果有报错或输出,请提供截图。 如果有报错或输出,请提供截图。
**操作环境** ### **操作环境**
请在后台输入 `version` 并复制相关输出。 请在后台输入 `version` 并复制相关输出。
**其他补充** ### **其他补充**
如有其他补充,可以在这里描述。 如有其他补充,可以在这里描述。
+4 -4
View File
@@ -7,14 +7,14 @@ assignees: ''
--- ---
**功能简述** ### **功能简述**
简单的描述一下你想要的功能 简单的描述一下你想要的功能
**需求来源** ### **需求来源**
简单的描述一下为什么需要这个功能。 简单的描述一下为什么需要这个功能。
**功能参考**(可选) ### **功能参考**(可选)
如果有相关功能的参考,如文本、截图,请提供给我们。 如果有相关功能的参考,如文本、截图,请提供给我们。
**附加内容** ### **附加内容**
如果有什么小细节需要重点注意,请在这里告诉我们。 如果有什么小细节需要重点注意,请在这里告诉我们。
+14 -7
View File
@@ -37,16 +37,22 @@ For development dependencies, please see [Dependencies](https://github.com/Carm
- **Theoretically** support ALL MineCraft Versions. - **Theoretically** support ALL MineCraft Versions.
- Reloading the configuration will automatically refresh the prefix of all players. - Reloading the configuration will automatically refresh the prefix of all players.
- Real-time judgment and feedback to the player when permissions are changed. [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/listener/processor/UserNodeUpdateProcessor.java) - Real-time judgment and feedback to the player when permissions are
changed. [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/listener/processor/UserNodeUpdateProcessor.java)
- Configurable sounds and messages. - Configurable sounds and messages.
- The prefix icon can be configured as "Selected", "Has Permission" and “No Permission”. - The prefix icon can be configured as "Selected", "Has Permission" and “No Permission”.
- Item configuration is natively configured through ItemStack, which supports all MC settings! - Item configuration is natively configured through ItemStack, which supports all MC settings!
- TabList is automatically sorted according to the weight of the prefix (if there is a conflict, it can be turned off) - TabList is automatically sorted according to the weight of the prefix (if there is a conflict, it can be turned off)
- The prefix display on the player name (can be turned off if there is a conflict) [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/nametag/UserNameTag.java) - The prefix display on the player name (can be turned off if there is a
- Simple Chat Format Placeholder support. (Not Recommended) [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java) conflict) [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/nametag/UserNameTag.java)
- GUI with automatic sorting and page turning! [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/ui/PrefixSelectGUI.java) - Simple Chat Format Placeholder support. (Not
- Support PlaceholderAPI variables! [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/hooker/UserPrefixExpansion.java) Recommended) [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java)
- Support [Hex Color](https://www.hexcolortool.com/)! (Version 1.16 and above) `&(#Color)` [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/util/ColorParser.java) - GUI with automatic sorting and page
turning! [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/ui/PrefixSelectGUI.java)
- Support PlaceholderAPI
variables! [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/hooker/UserPrefixExpansion.java)
- Support [Hex Color](https://www.hexcolortool.com/)! (Version 1.16 and
above) `&(#Color)` [](https://github.com/CarmJos/UserPrefix/blob/master/src/main/java/cc/carm/plugin/userprefix/util/ColorParser.java)
- Example: LightSlateBlue `&(#8470FF)` 、 DarkSlateBlue `&(#483D8B)` - Example: LightSlateBlue `&(#8470FF)` 、 DarkSlateBlue `&(#483D8B)`
## Notice ## Notice
@@ -112,7 +118,6 @@ the [English Version here](https://github.com/CarmJos/UserPrefix/blob/master/src
<details> <details>
<summary>Click to see plugin configuration</summary> <summary>Click to see plugin configuration</summary>
```yaml ```yaml
version: ${project.version} # DO NOT EDIT IT version: ${project.version} # DO NOT EDIT IT
@@ -212,6 +217,8 @@ selected:
expired: expired:
- "&7Your prefix &f%(oldName) &7has expired," - "&7Your prefix &f%(oldName) &7has expired,"
- "&7Now the prefix is changed to &f%(newName) &7." - "&7Now the prefix is changed to &f%(newName) &7."
removed:
- "&7Your using prefix has been removed, now the prefix is changed to &f%(newName) &7."
reload: reload:
- "&a&lReload completed&7costs &f%(time)ms&7." - "&a&lReload completed&7costs &f%(time)ms&7."
help: help:
+2
View File
@@ -199,6 +199,8 @@ selected:
expired: expired:
- "&7您先前使用的前缀 &f%(oldName) &7已到期。" - "&7您先前使用的前缀 &f%(oldName) &7已到期。"
- "&7现在已为您重新调整为 &f%(newName) &7。" - "&7现在已为您重新调整为 &f%(newName) &7。"
removed:
- "&7您先前使用的前缀已被移除,现在已为您重新调整为 &f%(newName) &7。"
reload: reload:
- "&a&l重载完成!&7共耗时 &f%(time)ms&7。" - "&a&l重载完成!&7共耗时 &f%(time)ms&7。"
help: help:
+8 -8
View File
@@ -4,9 +4,16 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<groupId>cc.carm.plugin</groupId> <groupId>cc.carm.plugin</groupId>
<artifactId>userprefix</artifactId> <artifactId>userprefix</artifactId>
<version>2.2.1</version> <version>2.3.0</version>
<name>UserPrefix</name> <name>UserPrefix</name>
<description>轻便、高效、实时的用户前缀系统。</description> <description>轻便、高效、实时的用户前缀系统。</description>
@@ -46,13 +53,6 @@
</license> </license>
</licenses> </licenses>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<repositories> <repositories>
<repository> <repository>
@@ -2,7 +2,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.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
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;
@@ -30,7 +30,6 @@ import org.jetbrains.annotations.Nullable;
public class Main extends JavaPlugin { public class Main extends JavaPlugin {
private static Main instance; private static Main instance;
private static Metrics metrics;
@Override @Override
public void onEnable() { public void onEnable() {
@@ -60,11 +59,11 @@ public class Main extends JavaPlugin {
log("若您想使用变量进行前缀的显示,请安装PlaceholderAPI"); log("若您想使用变量进行前缀的显示,请安装PlaceholderAPI");
} }
if (PrefixConfig.METRICS.get()) { if (PluginConfig.METRICS.get()) {
log("启用统计数据..."); log("启用统计数据...");
metrics = new Metrics(this, 13776); Metrics metrics = new Metrics(this, 13776);
metrics.addCustomChart(new SingleLineChart("active_prefixes", () -> PrefixManager.getPrefixes().size())); metrics.addCustomChart(new SingleLineChart("active_prefixes", () -> PrefixManager.getPrefixes().size()));
metrics.addCustomChart(new SimplePie("custom_storage", () -> PrefixConfig.CustomStorage.ENABLE.get() ? "ENABLE" : "DISABLE")); metrics.addCustomChart(new SimplePie("custom_storage", () -> PluginConfig.CustomStorage.ENABLE.get() ? "ENABLE" : "DISABLE"));
metrics.addCustomChart(new SimplePie("lp_version", () -> ServiceManager.getService().getPluginMetadata().getVersion())); metrics.addCustomChart(new SimplePie("lp_version", () -> ServiceManager.getService().getPluginMetadata().getVersion()));
metrics.addCustomChart(new SimplePie("papi_version", () -> { metrics.addCustomChart(new SimplePie("papi_version", () -> {
Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI"); Plugin plugin = Bukkit.getPluginManager().getPlugin("PlaceholderAPI");
@@ -113,7 +112,7 @@ public class Main extends JavaPlugin {
} }
public static void debug(String message) { public static void debug(String message) {
if (PrefixConfig.DEBUG.get()) { if (PluginConfig.DEBUG.get()) {
log("[DEBUG] " + message); log("[DEBUG] " + message);
} }
} }
@@ -1,6 +1,6 @@
package cc.carm.plugin.userprefix.command; package cc.carm.plugin.userprefix.command;
import cc.carm.plugin.userprefix.configuration.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import cc.carm.plugin.userprefix.manager.ConfigManager; import cc.carm.plugin.userprefix.manager.ConfigManager;
import cc.carm.plugin.userprefix.manager.PrefixManager; import cc.carm.plugin.userprefix.manager.PrefixManager;
import cc.carm.plugin.userprefix.manager.UserManager; import cc.carm.plugin.userprefix.manager.UserManager;
@@ -22,10 +22,10 @@ public class UserPrefixAdminCommand implements CommandExecutor {
if (args.length == 1) { if (args.length == 1) {
String aim = args[0]; String aim = args[0];
if (aim.equalsIgnoreCase("list")) { if (aim.equalsIgnoreCase("list")) {
MessageUtil.sendWithPlaceholders(sender, PrefixConfig.Messages.LIST_TITLE.get()); MessageUtil.sendWithPlaceholders(sender, PluginConfig.Messages.LIST_TITLE.get());
for (ConfiguredPrefix value : PrefixManager.getPrefixes().values()) { for (ConfiguredPrefix value : PrefixManager.getPrefixes().values()) {
MessageUtil.sendWithPlaceholders( MessageUtil.sendWithPlaceholders(
sender, PrefixConfig.Messages.LIST_VALUE.get(), sender, PluginConfig.Messages.LIST_VALUE.get(),
new String[]{ new String[]{
"%(weight)", "%(identifier)", "%(weight)", "%(identifier)",
"%(name)", "%(permission)", "%(name)", "%(permission)",
@@ -54,7 +54,7 @@ public class UserPrefixAdminCommand implements CommandExecutor {
UserManager.updatePrefixView(onlinePlayer, false); UserManager.updatePrefixView(onlinePlayer, false);
} }
MessageUtil.sendWithPlaceholders( MessageUtil.sendWithPlaceholders(
sender, PrefixConfig.Messages.RELOAD.get(), sender, PluginConfig.Messages.RELOAD.get(),
new String[]{"%(time)"}, new Object[]{(System.currentTimeMillis() - s1)} new String[]{"%(time)"}, new Object[]{(System.currentTimeMillis() - s1)}
); );
return true; return true;
@@ -65,7 +65,7 @@ public class UserPrefixAdminCommand implements CommandExecutor {
} }
public static boolean help(CommandSender sender) { public static boolean help(CommandSender sender) {
MessageUtil.send(sender, PrefixConfig.Messages.HELP.get()); MessageUtil.send(sender, PluginConfig.Messages.HELP.get());
return true; return true;
} }
@@ -7,7 +7,7 @@ import cc.carm.plugin.userprefix.util.ItemStackFactory;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class PrefixConfig { public class PluginConfig {
public static ConfigValue<Boolean> DEBUG = new ConfigValue<>("debug", Boolean.class, false); public static ConfigValue<Boolean> DEBUG = new ConfigValue<>("debug", Boolean.class, false);
@@ -62,12 +62,14 @@ public class PrefixConfig {
public static ConfigMessageList SELECTED = new ConfigMessageList("selected"); public static ConfigMessageList SELECTED = new ConfigMessageList("selected");
public static ConfigMessageList EXPIRED = new ConfigMessageList("expired"); public static ConfigMessageList EXPIRED = new ConfigMessageList("expired");
public static ConfigMessageList REMOVED = new ConfigMessageList("removed");
public static ConfigMessageList RELOAD = new ConfigMessageList("reload"); public static ConfigMessageList RELOAD = new ConfigMessageList("reload");
public static ConfigMessageList HELP = new ConfigMessageList("help"); public static ConfigMessageList HELP = new ConfigMessageList("help");
public static ConfigMessageList LIST_TITLE = new ConfigMessageList("list-title"); public static ConfigMessageList LIST_TITLE = new ConfigMessageList("list-title");
public static ConfigMessageList LIST_VALUE = new ConfigMessageList("list-value"); public static ConfigMessageList LIST_VALUE = new ConfigMessageList("list-value");
} }
public static class Sounds { public static class Sounds {
@@ -0,0 +1,55 @@
package cc.carm.plugin.userprefix.event;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class UserPrefixChangeEvent extends UserPrefixEvent implements Cancellable {
public static HandlerList handler = new HandlerList();
private boolean cancelled;
private final @Nullable ConfiguredPrefix before;
private @NotNull ConfiguredPrefix after;
public UserPrefixChangeEvent(@NotNull Player who,
@Nullable ConfiguredPrefix before,
@NotNull ConfiguredPrefix after) {
super(who);
this.before = before;
this.after = after;
}
public @Nullable ConfiguredPrefix getBefore() {
return before;
}
public @NotNull ConfiguredPrefix getAfter() {
return after;
}
public void setAfter(@NotNull ConfiguredPrefix after) {
this.after = after;
}
@Override
public boolean isCancelled() {
if (before == null) return false; //Could not be cancelled when prefix is null.
else return this.cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handler;
}
}
@@ -0,0 +1,13 @@
package cc.carm.plugin.userprefix.event;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
public abstract class UserPrefixEvent extends PlayerEvent {
public UserPrefixEvent(@NotNull Player who) {
super(who);
}
}
@@ -0,0 +1,30 @@
package cc.carm.plugin.userprefix.event;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class UserPrefixExpireEvent extends UserPrefixEvent {
public static HandlerList handler = new HandlerList();
public final @NotNull ConfiguredPrefix expiredPrefix;
public UserPrefixExpireEvent(@NotNull Player who,
@NotNull ConfiguredPrefix expiredPrefix) {
super(who);
this.expiredPrefix = expiredPrefix;
}
public @NotNull ConfiguredPrefix getExpiredPrefix() {
return expiredPrefix;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handler;
}
}
@@ -1,7 +1,7 @@
package cc.carm.plugin.userprefix.listener; package cc.carm.plugin.userprefix.listener;
import cc.carm.plugin.userprefix.Main; import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.configuration.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import cc.carm.plugin.userprefix.util.MessageUtil; import cc.carm.plugin.userprefix.util.MessageUtil;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -12,8 +12,8 @@ public class ChatListener implements Listener {
@EventHandler @EventHandler
public void onChat(AsyncPlayerChatEvent event) { public void onChat(AsyncPlayerChatEvent event) {
if (!PrefixConfig.Functions.Chat.ENABLE.get()) return; if (!PluginConfig.Functions.Chat.ENABLE.get()) return;
String format = PrefixConfig.Functions.Chat.FORMAT.get(); String format = PluginConfig.Functions.Chat.FORMAT.get();
if (format == null || format.length() < 1) return; if (format == null || format.length() < 1) return;
if (!MessageUtil.hasPlaceholderAPI()) return; if (!MessageUtil.hasPlaceholderAPI()) return;
@@ -1,7 +1,7 @@
package cc.carm.plugin.userprefix.manager; package cc.carm.plugin.userprefix.manager;
import cc.carm.plugin.userprefix.Main; import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.configuration.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix; import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import cc.carm.plugin.userprefix.util.ItemStackFactory; import cc.carm.plugin.userprefix.util.ItemStackFactory;
import org.bukkit.Material; import org.bukkit.Material;
@@ -36,6 +36,7 @@ public class PrefixManager {
loadConfiguredPrefixes(); loadConfiguredPrefixes();
} }
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void loadConfiguredPrefixes() { public static void loadConfiguredPrefixes() {
File prefixDataFolder = getStorageFolder(); File prefixDataFolder = getStorageFolder();
@@ -159,8 +160,8 @@ public class PrefixManager {
} }
private static File getStorageFolder() { private static File getStorageFolder() {
if (PrefixConfig.CustomStorage.ENABLE.get()) { if (PluginConfig.CustomStorage.ENABLE.get()) {
return new File(PrefixConfig.CustomStorage.PATH.get()); return new File(PluginConfig.CustomStorage.PATH.get());
} else { } else {
return new File(Main.getInstance().getDataFolder() + File.separator + FOLDER_NAME); return new File(Main.getInstance().getDataFolder() + File.separator + FOLDER_NAME);
} }
@@ -1,11 +1,12 @@
package cc.carm.plugin.userprefix.manager; package cc.carm.plugin.userprefix.manager;
import cc.carm.plugin.userprefix.Main; import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.configuration.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent;
import cc.carm.plugin.userprefix.event.UserPrefixExpireEvent;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix; import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
import cc.carm.plugin.userprefix.nametag.UserNameTag; import cc.carm.plugin.userprefix.nametag.UserNameTag;
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI; import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
import cc.carm.plugin.userprefix.util.MessageUtil;
import cc.carm.plugin.userprefix.util.gui.GUI; import cc.carm.plugin.userprefix.util.gui.GUI;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import net.luckperms.api.node.NodeType; import net.luckperms.api.node.NodeType;
@@ -26,7 +27,7 @@ public class UserManager {
@Nullable @Nullable
public static UserNameTag getNameTag(Player player) { public static UserNameTag getNameTag(Player player) {
if (PrefixConfig.Functions.NAME_PREFIX.get()) { if (PluginConfig.Functions.NAME_PREFIX.get()) {
if (nameTags.containsKey(player.getUniqueId())) { if (nameTags.containsKey(player.getUniqueId())) {
return nameTags.get(player.getUniqueId()); return nameTags.get(player.getUniqueId());
} else { } else {
@@ -47,7 +48,7 @@ public class UserManager {
public static void initPlayer(Player player) { public static void initPlayer(Player player) {
UserManager.checkPrefix(player, false); UserManager.checkPrefix(player, false);
if (PrefixConfig.Functions.NAME_PREFIX.get()) { if (PluginConfig.Functions.NAME_PREFIX.get()) {
UserManager.createNameTag(player); UserManager.createNameTag(player);
UserManager.updatePrefixView(player, true); UserManager.updatePrefixView(player, true);
} }
@@ -67,10 +68,11 @@ public class UserManager {
* @param loadOthers 是否为玩家更新其他人的前缀(一般用于加入游戏) * @param loadOthers 是否为玩家更新其他人的前缀(一般用于加入游戏)
*/ */
public static void updatePrefixView(Player player, boolean loadOthers) { public static void updatePrefixView(Player player, boolean loadOthers) {
if (!PrefixConfig.Functions.NAME_PREFIX.get()) return; //未启用的情况下,不需要进行任何操作。 if (!PluginConfig.Functions.NAME_PREFIX.get()) return; //未启用的情况下,不需要进行任何操作。
ConfiguredPrefix playerPrefix = UserManager.getPrefix(player);
UserNameTag tag = getNameTag(player); UserNameTag tag = getNameTag(player);
if (tag == null) return; //未启用的情况下,不需要进行任何操作。
ConfiguredPrefix playerPrefix = UserManager.getPrefix(player);
tag.setPrefix(playerPrefix.getContent()); tag.setPrefix(playerPrefix.getContent());
tag.setOrder(playerPrefix.getWeight()); tag.setOrder(playerPrefix.getWeight());
@@ -111,20 +113,42 @@ public class UserManager {
return; return;
} }
checkingPlayers.add(player.getUniqueId()); checkingPlayers.add(player.getUniqueId());
String currentPrefixIdentifier = UserManager.getPrefixData(player); String currentPrefixData = UserManager.getPrefixData(player);
ConfiguredPrefix currentPrefix = PrefixManager.getPrefix(currentPrefixIdentifier);
if (!UserManager.isPrefixUsable(player, currentPrefixIdentifier)) { if (!UserManager.isPrefixUsable(player, currentPrefixData)) {
ConfiguredPrefix currentPrefix = PrefixManager.getPrefix(currentPrefixData);
ConfiguredPrefix newPrefix = UserManager.getHighestPrefix(player); ConfiguredPrefix newPrefix = UserManager.getHighestPrefix(player);
// 更新前缀
UserManager.setPrefix(player, newPrefix, updateView); if (currentPrefix != null) {
//当前前缀不为空,则代表属于前缀过期的情况
Bukkit.getPluginManager().callEvent(new UserPrefixExpireEvent(player, currentPrefix));
// 发送消息 // 发送消息
MessageUtil.sendWithPlaceholders(player, PrefixConfig.Messages.EXPIRED.get(), PluginConfig.Messages.EXPIRED.sendWithPlaceholders(player,
new String[]{"%(newName)", "%(oldName)"}, new String[]{"%(newName)", "%(oldName)"},
new Object[]{newPrefix.getName(), currentPrefix != null ? currentPrefix.getName() : currentPrefixIdentifier} new Object[]{newPrefix.getName(), currentPrefix.getName()}
); );
// 播放声音 // 播放声音
PrefixConfig.Sounds.PREFIX_EXPIRED.play(player); PluginConfig.Sounds.PREFIX_EXPIRED.play(player);
} else {
// 当前前缀为空,则代表是旧的前缀不存在了,
PluginConfig.Messages.REMOVED.sendWithPlaceholders(player,
new String[]{"%(newName)", "%(oldName)"},
new Object[]{newPrefix.getName(), currentPrefixData}
);
} }
UserPrefixChangeEvent event = new UserPrefixChangeEvent(player, currentPrefix, newPrefix);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
// 更新前缀
UserManager.setPrefix(player, event.getAfter(), updateView);
}
}
checkingPlayers.remove(player.getUniqueId()); checkingPlayers.remove(player.getUniqueId());
} }
@@ -186,7 +210,7 @@ public class UserManager {
*/ */
@NotNull @NotNull
public static ConfiguredPrefix getHighestPrefix(Player player) { public static ConfiguredPrefix getHighestPrefix(Player player) {
if (PrefixConfig.Functions.AUTO_USE.get()) { if (PluginConfig.Functions.AUTO_USE.get()) {
// 关闭了自动选择,就直接给默认的前缀,让玩家自己去设置吧~ // 关闭了自动选择,就直接给默认的前缀,让玩家自己去设置吧~
return PrefixManager.getDefaultPrefix(); return PrefixManager.getDefaultPrefix();
} }
@@ -226,7 +250,7 @@ public class UserManager {
* 该方法通过LuckPerms的MetaData实现,因此可以通过指令去操作。 * 该方法通过LuckPerms的MetaData实现,因此可以通过指令去操作。
* *
* @param player 玩家 * @param player 玩家
* @return 正在使用的前缀Identifier(若不存在则返回null) * @return 正在使用的前缀Identifier(若不存在则返回null, 代表未设置前缀)
*/ */
@Nullable @Nullable
public static String getPrefixData(Player player) { public static String getPrefixData(Player player) {
@@ -1,6 +1,6 @@
package cc.carm.plugin.userprefix.ui; package cc.carm.plugin.userprefix.ui;
import cc.carm.plugin.userprefix.configuration.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import cc.carm.plugin.userprefix.manager.PrefixManager; import cc.carm.plugin.userprefix.manager.PrefixManager;
import cc.carm.plugin.userprefix.manager.UserManager; import cc.carm.plugin.userprefix.manager.UserManager;
import cc.carm.plugin.userprefix.model.ConfiguredPrefix; import cc.carm.plugin.userprefix.model.ConfiguredPrefix;
@@ -22,7 +22,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
Player player; Player player;
public PrefixSelectGUI(Player player) { public PrefixSelectGUI(Player player) {
super(GUIType.SIXBYNINE, PrefixConfig.GUI.TITLE.get(), 10, 43); super(GUIType.SIXBYNINE, PluginConfig.GUI.TITLE.get(), 10, 43);
this.player = player; this.player = player;
setPreviousPageSlot(18); setPreviousPageSlot(18);
@@ -54,8 +54,8 @@ public class PrefixSelectGUI extends AutoPagedGUI {
player.closeInventory(); player.closeInventory();
UserManager.setPrefix(player, prefix, true); UserManager.setPrefix(player, prefix, true);
PrefixConfig.Sounds.PREFIX_CHANGE.play(player); PluginConfig.Sounds.PREFIX_CHANGE.play(player);
MessageUtil.sendWithPlaceholders(player, PrefixConfig.Messages.SELECTED.get(), MessageUtil.sendWithPlaceholders(player, PluginConfig.Messages.SELECTED.get(),
new String[]{"%(name)"}, new String[]{"%(name)"},
new Object[]{prefix.getName()}); new Object[]{prefix.getName()});
@@ -87,7 +87,8 @@ public class PrefixSelectGUI extends AutoPagedGUI {
} }
public static void open(Player player) { public static void open(Player player) {
PrefixConfig.Sounds.GUI_OPEN.play(player); player.closeInventory(); // 防止冲突
PluginConfig.Sounds.GUI_OPEN.play(player);
new PrefixSelectGUI(player).openGUI(player); new PrefixSelectGUI(player).openGUI(player);
openingUsers.add(player); openingUsers.add(player);
} }
@@ -1,6 +1,6 @@
package cc.carm.plugin.userprefix.util.gui; package cc.carm.plugin.userprefix.util.gui;
import cc.carm.plugin.userprefix.configuration.PrefixConfig; import cc.carm.plugin.userprefix.configuration.PluginConfig;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -51,7 +51,7 @@ public class AutoPagedGUI extends CommonPagedGUI {
public void openGUI(Player user) { public void openGUI(Player user) {
if (previousPageSlot >= 0) if (previousPageSlot >= 0)
if (hasPreviousPage()) { if (hasPreviousPage()) {
setItem(previousPageSlot, new GUIItem(previousPageUI == null ? PrefixConfig.GUI.Items.PREVIOUS_PAGE.get() : previousPageUI) { setItem(previousPageSlot, new GUIItem(previousPageUI == null ? PluginConfig.GUI.Items.PREVIOUS_PAGE.get() : previousPageUI) {
@Override @Override
public void onClick(ClickType type) { public void onClick(ClickType type) {
if (type == ClickType.RIGHT) { if (type == ClickType.RIGHT) {
@@ -59,7 +59,7 @@ public class AutoPagedGUI extends CommonPagedGUI {
} else { } else {
goPreviousPage(); goPreviousPage();
} }
PrefixConfig.Sounds.GUI_CLICK.play(user); PluginConfig.Sounds.GUI_CLICK.play(user);
openGUI(user); openGUI(user);
} }
}); });
@@ -67,7 +67,7 @@ public class AutoPagedGUI extends CommonPagedGUI {
if (nextPageSlot >= 0) if (nextPageSlot >= 0)
if (hasNextPage()) { if (hasNextPage()) {
setItem(nextPageSlot, new GUIItem(nextPageUI == null ? PrefixConfig.GUI.Items.NEXT_PAGE.get() : nextPageUI) { setItem(nextPageSlot, new GUIItem(nextPageUI == null ? PluginConfig.GUI.Items.NEXT_PAGE.get() : nextPageUI) {
@Override @Override
public void onClick(ClickType type) { public void onClick(ClickType type) {
if (type == ClickType.RIGHT) { if (type == ClickType.RIGHT) {
@@ -75,7 +75,7 @@ public class AutoPagedGUI extends CommonPagedGUI {
} else { } else {
goNextPage(); goNextPage();
} }
PrefixConfig.Sounds.GUI_CLICK.play(user); PluginConfig.Sounds.GUI_CLICK.play(user);
openGUI(user); openGUI(user);
} }
}); });
+2
View File
@@ -3,6 +3,8 @@ selected:
expired: expired:
- "&7Your prefix &f%(oldName) &7has expired," - "&7Your prefix &f%(oldName) &7has expired,"
- "&7Now the prefix is changed to &f%(newName) &7." - "&7Now the prefix is changed to &f%(newName) &7."
removed:
- "&7Your using prefix has been removed, now the prefix is changed to &f%(newName) &7."
reload: reload:
- "&a&lReload completed&7costs &f%(time)ms&7." - "&a&lReload completed&7costs &f%(time)ms&7."
help: help:
+2
View File
@@ -3,6 +3,8 @@ selected:
expired: expired:
- "&7您先前使用的前缀 &f%(oldName) &7已到期。" - "&7您先前使用的前缀 &f%(oldName) &7已到期。"
- "&7现在已为您重新调整为 &f%(newName) &7。" - "&7现在已为您重新调整为 &f%(newName) &7。"
removed:
- "&7您先前使用的前缀已被移除,现在已为您重新调整为 &f%(newName) &7。"
reload: reload:
- "&a&l重载完成!&7共耗时 &f%(time)ms&7。" - "&a&l重载完成!&7共耗时 &f%(time)ms&7。"
help: help: