From 80f2a37fc14b4868a06e4e0b021db8155147cfa6 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 18 Dec 2021 04:59:53 +0000 Subject: [PATCH] feat: add item tip support Signed-off-by: MiaoWoo --- pom.xml | 15 ++- .../yumc/MiaoChat/config/ChatMessagePart.java | 121 +++++++++--------- .../java/pw/yumc/MiaoChat/config/ItemTip.java | 52 ++++++++ src/main/resources/format.yml | 90 +++++++------ src/main/resources/plugin.yml | 2 +- 5 files changed, 172 insertions(+), 108 deletions(-) create mode 100644 src/main/java/pw/yumc/MiaoChat/config/ItemTip.java diff --git a/pom.xml b/pom.xml index 6fcb1dc..4f182b8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 MiaoChat - 1.9.5 + 2.0.0 pw.yumc @@ -13,16 +13,17 @@ - §a正式版本 §bv1.9.5 §b兼容 1.15 版本 + §a正式版本 §bv2.0.0 §b全新版本(号) 配合龙核食用 - §621-06-20 §a增强: 兼容 1.18 版本 兼容新版PAPI; - §621-06-20 §a增强: 兼容 1.17 版本; + §621-12-18 §a增强: 全新版本(号) 新增 itemTip 配合龙核 实现神奇功能; + §621-12-06 §a增强: 兼容 1.18 版本 兼容新版PAPI; + §621-06-20 §a增强: 兼容 1.17 版本 + + §620-10-10 §c修复: 1.16.3聊天包格式调整的问题; §620-04-10 §c修复: L10N 本地化组件报错的问题; §620-04-09 §c修复: 1.13-1.15.2新增物品不兼容的问题; - §620-02-15 §c修复: 跨服分组分配异常的问题 - - + §620-02-15 §c修复: 跨服分组分配异常的问题; §619-05-31 §a增强: 跨服聊天压缩数据 增加可传输内容大小; §619-05-29 §c修复: 1.7.10不兼容的问题; §619-02-23 §c修复: BungeeCord 兼容性问题; diff --git a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java index b2afc33..f02f67d 100644 --- a/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java +++ b/src/main/java/pw/yumc/MiaoChat/config/ChatMessagePart.java @@ -1,59 +1,62 @@ -package pw.yumc.MiaoChat.config; - -import java.util.List; - -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Player; - -import me.clip.placeholderapi.PlaceholderAPI; -import pw.yumc.YumCore.config.annotation.ConfigNode; -import pw.yumc.YumCore.config.annotation.Nullable; -import pw.yumc.YumCore.config.inject.InjectConfigurationSection; -import pw.yumc.YumCore.tellraw.Tellraw; - -public class ChatMessagePart extends InjectConfigurationSection { - private String text; - @Nullable - private List tip; - @Nullable - @ConfigNode("click.type") - private String typestring; - @Nullable - @ConfigNode("click.command") - private String command; - private transient CLICKTYPE type = CLICKTYPE.SUGGEST; - - public ChatMessagePart(ConfigurationSection config) { - super(config); - if (typestring != null) { - type = CLICKTYPE.valueOf(typestring); - } - } - - public Tellraw then(Tellraw tr, Player p) { - tr.then(f(p, text)); - if (tip != null && !tip.isEmpty()) { - tr.tip(f(p, tip)); - } - if (command != null && !command.isEmpty()) { - String tc = f(p, command); - switch (type) { - case COMMAND: - return tr.command(tc); - case OPENURL: - return tr.openurl(tc); - case SUGGEST: - return tr.suggest(tc); - } - } - return tr; - } - - private List f(Player player, List text) { - return PlaceholderAPI.setPlaceholders(player, text); - } - - private String f(Player player, String text) { - return PlaceholderAPI.setPlaceholders(player, text); - } -} +package pw.yumc.MiaoChat.config; + +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import pw.yumc.YumCore.config.annotation.ConfigNode; +import pw.yumc.YumCore.config.annotation.Nullable; +import pw.yumc.YumCore.config.inject.InjectConfigurationSection; +import pw.yumc.YumCore.tellraw.Tellraw; + +import java.util.List; + +public class ChatMessagePart extends InjectConfigurationSection { + private String text; + @Nullable + private List tip; + @Nullable + private ItemTip item; + @Nullable + @ConfigNode("click.type") + private String typestring; + @Nullable + @ConfigNode("click.command") + private String command; + private transient CLICKTYPE type = CLICKTYPE.SUGGEST; + + public ChatMessagePart(ConfigurationSection config) { + super(config); + if (typestring != null) { + type = CLICKTYPE.valueOf(typestring); + } + } + + public Tellraw then(Tellraw tr, Player p) { + tr.then(f(p, text)); + if (item != null) { + tr.item(item.getItemStack(p, text, tip)); + } else if (tip != null && !tip.isEmpty()) { + tr.tip(f(p, tip)); + } + if (command != null && !command.isEmpty()) { + String tc = f(p, command); + switch (type) { + case COMMAND: + return tr.command(tc); + case OPENURL: + return tr.openurl(tc); + case SUGGEST: + return tr.suggest(tc); + } + } + return tr; + } + + private List f(Player player, List text) { + return PlaceholderAPI.setPlaceholders(player, text); + } + + private String f(Player player, String text) { + return PlaceholderAPI.setPlaceholders(player, text); + } +} diff --git a/src/main/java/pw/yumc/MiaoChat/config/ItemTip.java b/src/main/java/pw/yumc/MiaoChat/config/ItemTip.java new file mode 100644 index 0000000..814c3d8 --- /dev/null +++ b/src/main/java/pw/yumc/MiaoChat/config/ItemTip.java @@ -0,0 +1,52 @@ +package pw.yumc.MiaoChat.config; + +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import pw.yumc.MiaoChat.bungee.Log; +import pw.yumc.YumCore.config.annotation.Default; +import pw.yumc.YumCore.config.annotation.Nullable; +import pw.yumc.YumCore.config.inject.InjectConfigurationSection; + +import java.util.List; + +public class ItemTip extends InjectConfigurationSection { + private String type; + @Default("0") + private Short damage; + @Nullable + private String name; + + private transient ItemStack itemStack; + private transient ItemMeta itemMeta; + + public ItemTip(ConfigurationSection config) { + super(config); + } + + @Override + protected void init() { + super.init(); + try { + Material material = Material.valueOf(type); + this.itemStack = new ItemStack(material, 1, damage); + this.itemMeta = Bukkit.getItemFactory().getItemMeta(material); + } catch (Throwable ex) { + this.itemStack = new ItemStack(Material.STONE, 1); + Log.w("物品 %s 解析失败 将使用默认值 STONE...", type); + } + } + + public ItemStack getItemStack(Player p, String name, List tip) { + ItemStack itemStack = this.itemStack.clone(); + ItemMeta itemMeta = this.itemMeta.clone(); + itemMeta.setDisplayName(PlaceholderAPI.setPlaceholders(p, this.name == null ? name : this.name)); + itemMeta.setLore(PlaceholderAPI.setPlaceholders(p, tip)); + itemStack.setItemMeta(itemMeta); + return itemStack; + } +} diff --git a/src/main/resources/format.yml b/src/main/resources/format.yml index 31446cc..2fe6921 100644 --- a/src/main/resources/format.yml +++ b/src/main/resources/format.yml @@ -1,42 +1,50 @@ -#当前文件为定义格式的基础文件 -world: - #文本 支持PAPI变量 - text: '&6[&a%player_world%&6]' - #悬浮提示 支持PAPI - tip: - - '&6当前所在位置:' - - '&6世界: &d%player_world%' - - '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%' - - '' - - '&c点击即可TP我!' - #点击操作 - click: - #操作类型: [COMMAND,SUGGEST,OPENURL] - #COMMAND代表执行命令 - #SUGGEST代表命令补全 - #OPENURL代表打开网址 - type: 'COMMAND' - #命令或网址 支持PAPI - command: '/tpa %player_name%' -player: - text: '&b%player_name%' - tip: - - '&6玩家名称: &b%player_name%' - - '&6玩家等级: &a%player_level%' - - '&6玩家血量: &c%player_health%' - - '&6玩家饥饿: &d%player_food_level%' - - '&6游戏模式: &4%player_gamemode%' - - '' - - '&c点击与我聊天' - click: - type: 'SUGGEST' - command: '/tell %player_name%' -admin: - text: '&6[&c管理员&6]' -help: - text: '&4[求助]' - tip: - - '点击求助OP' - click: - type: 'COMMAND' +#当前文件为定义格式的基础文件 +world: + #文本 支持PAPI变量 + text: '&6[&a%player_world%&6]' + #悬浮提示 支持PAPI + tip: + - '&6当前所在位置:' + - '&6世界: &d%player_world%' + - '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%' + - '' + - '&c点击即可TP我!' + #点击操作 + click: + #操作类型: [COMMAND,SUGGEST,OPENURL] + #COMMAND代表执行命令 + #SUGGEST代表命令补全 + #OPENURL代表打开网址 + type: 'COMMAND' + #命令或网址 支持PAPI + command: '/tpa %player_name%' +player: + text: '&b%player_name%' + # 物品化Tip 可配合龙核/萌芽做ItemTip + item: + # 物品枚举 + type: STONE + # 物品子ID + damage: 0 + # 物品名称(用于萌芽/龙核匹配) 为空则使用 text + name: '§s§v§i§p' + tip: + - '&6玩家名称: &b%player_name%' + - '&6玩家等级: &a%player_level%' + - '&6玩家血量: &c%player_health%' + - '&6玩家饥饿: &d%player_food_level%' + - '&6游戏模式: &4%player_gamemode%' + - '' + - '&c点击与我聊天' + click: + type: 'SUGGEST' + command: '/tell %player_name%' +admin: + text: '&6[&c管理员&6]' +help: + text: '&4[求助]' + tip: + - '点击求助OP' + click: + type: 'COMMAND' command: '管理员@%player_name% 我需要你的帮助!' \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e76095b..3c2c0fa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,7 +25,7 @@ permissions: default: true ${project.artifactId}.color: description: 彩字聊天权限! - default: true + default: op ${project.artifactId}.admin: description: 管理员格式权限! default: op