mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-06-05 00:35:02 +08:00
2.1.0版本更新 支持聊天前缀
This commit is contained in:
@@ -4,6 +4,7 @@ import cc.carm.plugin.userprefix.command.UserPrefixAdminCommand;
|
||||
import cc.carm.plugin.userprefix.command.UserPrefixCommand;
|
||||
import cc.carm.plugin.userprefix.configuration.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.hooker.UserPrefixExpansion;
|
||||
import cc.carm.plugin.userprefix.listener.ChatListener;
|
||||
import cc.carm.plugin.userprefix.listener.UserListener;
|
||||
import cc.carm.plugin.userprefix.listener.processor.UserNodeUpdateProcessor;
|
||||
import cc.carm.plugin.userprefix.manager.ConfigManager;
|
||||
@@ -38,6 +39,7 @@ public class Main extends JavaPlugin {
|
||||
|
||||
log("注册监听器...");
|
||||
regListener(new UserListener());
|
||||
regListener(new ChatListener());
|
||||
ServiceManager.getService().getEventBus().subscribe(this, UserDataRecalculateEvent.class, UserNodeUpdateProcessor::process);
|
||||
|
||||
if (MessageUtil.hasPlaceholderAPI()) {
|
||||
|
||||
@@ -16,6 +16,13 @@ public class PrefixConfig {
|
||||
public static ConfigValue<Boolean> NAME_PREFIX = new ConfigValue<>("functions.OnNamePrefix", Boolean.class, true);
|
||||
public static ConfigValue<Boolean> AUTO_USE = new ConfigValue<>("functions.autoUsePrefix", Boolean.class, true);
|
||||
|
||||
public static class Chat {
|
||||
|
||||
public static ConfigValue<Boolean> ENABLE = new ConfigValue<>("functions.chat.enable", Boolean.class, false);
|
||||
public static ConfigValue<String> FORMAT = new ConfigValue<>("functions.chat.format", String.class, "<%1$s> %2$s");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GUI {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package cc.carm.plugin.userprefix.listener;
|
||||
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.configuration.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.util.MessageUtil;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
if (!PrefixConfig.Functions.Chat.ENABLE.get()) return;
|
||||
String format = PrefixConfig.Functions.Chat.FORMAT.get();
|
||||
if (format == null || format.length() < 1) return;
|
||||
|
||||
if (!MessageUtil.hasPlaceholderAPI()) return;
|
||||
|
||||
try {
|
||||
event.setFormat(PlaceholderAPI.setPlaceholders(event.getPlayer(), format));
|
||||
} catch (Exception exception) {
|
||||
Main.log("Please check the chat configuration.");
|
||||
Main.log("请检查配置文件中聊天相关是否配置正确。");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,6 +5,14 @@ debug: false
|
||||
functions:
|
||||
OnNamePrefix: true # 是否给头顶上添加前缀,该方法用到了头顶的那个计分板,如有冲突请关掉哦~
|
||||
autoUsePrefix: true # 自动前缀显示 当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个
|
||||
chat:
|
||||
# 聊天功能
|
||||
# - 我不推荐使用本插件的聊天功能,而是建议使用其他的聊天插件。
|
||||
# - 本插件仅仅提供了**最基本**的格式变量支持,不包含其他任何功能。
|
||||
# - 注意聊天格式需要遵守Bukkit原格式,即不得缺失 “%1$s” 和 “%2$s” 。
|
||||
# - 本插件的聊天功能不影响其他插件对聊天事件的操作。
|
||||
enable: false # 是否启用
|
||||
format: "<%UserPrefix_prefix%%1$s> %2$s" #聊天的格式,注意 “%1$s” 和 “%2$s” 不可缺少,分别代表 玩家名 与 消息内容 。
|
||||
|
||||
GUI:
|
||||
title: "&f&l我的前缀 &8| 列表"
|
||||
|
||||
@@ -35,6 +35,13 @@ functions:
|
||||
# When the player does not choose a prefix by himself,
|
||||
# the prefix with the highest weight will be used automatically
|
||||
autoUsePrefix: true
|
||||
chat:
|
||||
# Chat Function
|
||||
# - I recommend using other chat plugins instead of using this plugin,
|
||||
# - this plugin only provides very basic chat format placeholders.
|
||||
# - Notice that: format must has “%1$s” and “%2$s” for PlayerName and Message (Bukkit Chat Event)
|
||||
enable: false
|
||||
format: "<%UserPrefix_prefix%%1$s> %2$s"
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user