From e14901ac8667ad22b7e865de983ca579b33fb1a3 Mon Sep 17 00:00:00 2001 From: carm Date: Mon, 27 Sep 2021 01:32:17 +0800 Subject: [PATCH] =?UTF-8?q?2.1.0=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=81=8A=E5=A4=A9=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en.md | 9 ++- README.md | 8 +++ pom.xml | 2 +- .../java/cc/carm/plugin/userprefix/Main.java | 2 + .../configuration/PrefixConfig.java | 7 ++ .../userprefix/listener/ChatListener.java | 32 +++++++++ src/main/resources/config.yml | 8 +++ src/main/resources/en_US/config.yml | 7 ++ topic/mcbbs.source | 71 +++---------------- topic/spigot.source | 12 +++- 10 files changed, 91 insertions(+), 67 deletions(-) create mode 100644 src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java diff --git a/README-en.md b/README-en.md index 6d29fbb..8f41a14 100644 --- a/README-en.md +++ b/README-en.md @@ -144,8 +144,15 @@ functions: OnNamePrefix: true # Automatic prefix select. # 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 + 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" Sounds: # Format is [SOUND_NAME:Volume:Pitch] or [SOUND_NAME:Volume] or [SOUND_NAME] diff --git a/README.md b/README.md index c89eb20..6ad177e 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,14 @@ debug: false #debug输出,开发者用的 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| 列表" diff --git a/pom.xml b/pom.xml index 6fe5123..8355843 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cc.carm.plugin UserPrefix - 2.0.0 + 2.1.0 8 diff --git a/src/main/java/cc/carm/plugin/userprefix/Main.java b/src/main/java/cc/carm/plugin/userprefix/Main.java index cc105bc..3e053af 100644 --- a/src/main/java/cc/carm/plugin/userprefix/Main.java +++ b/src/main/java/cc/carm/plugin/userprefix/Main.java @@ -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()) { diff --git a/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java b/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java index cd67a45..ac91608 100644 --- a/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java +++ b/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java @@ -16,6 +16,13 @@ public class PrefixConfig { public static ConfigValue NAME_PREFIX = new ConfigValue<>("functions.OnNamePrefix", Boolean.class, true); public static ConfigValue AUTO_USE = new ConfigValue<>("functions.autoUsePrefix", Boolean.class, true); + public static class Chat { + + public static ConfigValue ENABLE = new ConfigValue<>("functions.chat.enable", Boolean.class, false); + public static ConfigValue FORMAT = new ConfigValue<>("functions.chat.format", String.class, "<%1$s> %2$s"); + + } + } public static class GUI { diff --git a/src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java b/src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java new file mode 100644 index 0000000..c848f93 --- /dev/null +++ b/src/main/java/cc/carm/plugin/userprefix/listener/ChatListener.java @@ -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(); + } + + } + + +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 56df853..1b86137 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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| 列表" diff --git a/src/main/resources/en_US/config.yml b/src/main/resources/en_US/config.yml index 57668e7..13d8cc4 100644 --- a/src/main/resources/en_US/config.yml +++ b/src/main/resources/en_US/config.yml @@ -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" diff --git a/topic/mcbbs.source b/topic/mcbbs.source index abc19e3..50c2def 100644 --- a/topic/mcbbs.source +++ b/topic/mcbbs.source @@ -73,66 +73,7 @@ debug: false #debug输出,开发者用的 functions: OnNamePrefix: true # 是否给头顶上添加前缀,该方法用到了头顶的那个计分板,如有冲突请关掉哦~ - autoUsePrefix: true # 自动前缀显示 当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个 - -GUI: - title: "&f&l我的前缀 &8| 列表" - items: - # 【必须】 GUI中可能存在的其他物品 - next-page: # 下一页物品,如果没有下一页则不显示 - ==: org.bukkit.inventory.ItemStack - type: ARROW - meta: - ==: ItemMeta - meta-type: UNSPECIFIC - display-name: "§f下一页" - lore: - - "" - - "§f右键可前往最后一页哦~" - previous-page: # 上一页物品,如果没有上一页则不显示 - ==: org.bukkit.inventory.ItemStack - type: ARROW - meta: - ==: ItemMeta - meta-type: UNSPECIFIC - display-name: "§f上一页" - lore: - - "" - - "§f右键可前往第一页哦~" - -Sounds: #相关的声音,注释掉则不播放声音 - # 格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】 - openGUI: "BLOCK_NOTE_BLOCK_PLING:1:1" - guiClick: "UI_BUTTON_CLICK" - prefixChange: "ENTITY_VILLAGER_YES" - prefixExpired: "ENTITY_VILLAGER_NO" - -# 默认前缀的配置 -# 默认前缀的权重为0哦 -defaultPrefix: - name: "默认前缀" - content: "&b" - itemNotUsing: - ==: org.bukkit.inventory.ItemStack - type: NAME_TAG - meta: - ==: ItemMeta - meta-type: UNSPECIFIC - display-name: "§f默认玩家前缀 §f(点击切换)" - lore: - - "" - - "§a➥ 点击切换到该前缀" - itemUsing: - ==: org.bukkit.inventory.ItemStack - type: NAME_TAG - meta: - ==: ItemMeta - meta-type: UNSPECIFIC - display-name: "§f默认玩家前缀" - lore: - - "" - - "§a 您正在使用该前缀" -[/code][/spoiler] + autoUsePrefix: true # 自动前缀显示 当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个[/code][/spoiler] [b][size=4][backcolor=transparent]消息配置文件[/backcolor][/size] [/b][size=4](messages.yml)[/size] [spoiler][code]selected: @@ -236,13 +177,17 @@ itemNoPermission: [size=5][b]下载地址[/b][/size] [hr] -[size=3][b]最新版本 [/b][/size][size=3][b] 2.0.0 [/b][/size][attach]1905700[/attach] +[size=3][b]最新版本 2.1.0 [/b][/size][attach]1909962[/attach][quote][b][size=3]更新内容[/size][/b] +1. 添加聊天相关设定,支持聊天前缀。(但不推荐使用哦~)[/quote] + +[spoiler] + +[size=3][b] 2.0.0 [/b][/size][attach]1905700[/attach] [quote][b][size=3]更新内容[/size][/b] 1. 修复低版本可能无法读取物品的bug。 2. 分离配置文件,消息配置文件改为messages.yml,前缀配置文件改 prefixes/*.yml,便于配置和管理。 3. 允许配置GUI中上一页和下一页的物品。 4. 补全帮助文档,在插件首次加载将提供一份英文版的配置,以便使用。[/quote] -[spoiler] [size=3][b] 1.2.5 [/b][/size][attach]1905430[/attach][quote][size=3][b]更新内容[/b] 1. 支持指令的多语言配置。[/size][/quote] [b][size=3] @@ -291,3 +236,5 @@ itemNoPermission: + + diff --git a/topic/spigot.source b/topic/spigot.source index a20817c..02ccc9e 100644 --- a/topic/spigot.source +++ b/topic/spigot.source @@ -59,9 +59,8 @@ Please turn of the [U]functions.OnNamePrefix[/U] in the configuration if there i [SIZE=4][B]3. Item icon configuration problem[/B][/SIZE] Items are read through the ItemStack serialization method provided by Bukkit. For related configuration methods, please refer to [URL='https://www.spigotmc.org/wiki/itemstack-serialization/']ItemStack Serialization[/URL]. -[SIZE=5][B]Commands[/B][/SIZE] -This plugin's Commands are based on Chinese! May support multi-language in the future. - +[SIZE=5][B]Commands[/B] +[/SIZE] [code] /UserPrefix or /prefix #Open prefix GUI /UserPrefixAdmin # View Admin Command Help @@ -128,6 +127,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" Sounds: # Format is [SOUND_NAME:Volume:Pitch] or [SOUND_NAME:Volume] or [SOUND_NAME]