feat: add item tip support

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2021-12-18 04:59:53 +00:00
parent 45ec56bebe
commit 80f2a37fc1
5 changed files with 172 additions and 108 deletions

15
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>MiaoChat</artifactId> <artifactId>MiaoChat</artifactId>
<version>1.9.5</version> <version>2.0.0</version>
<parent> <parent>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
@ -13,16 +13,17 @@
</parent> </parent>
<properties> <properties>
<update.description>§a正式版本 §bv1.9.5 §b兼容 1.15 版本</update.description> <update.description>§a正式版本 §bv2.0.0 §b全新版本(号) 配合龙核食用</update.description>
<update.changes> <update.changes>
§621-06-20 §a增强: 兼容 1.18 版本 兼容新版PAPI; §621-12-18 §a增强: 全新版本(号) 新增 itemTip 配合龙核 实现神奇功能;
§621-06-20 §a增强: 兼容 1.17 版本; §621-12-06 §a增强: 兼容 1.18 版本 兼容新版PAPI;
§621-06-20 §a增强: 兼容 1.17 版本
</update.changes>
<update.changelog>
§620-10-10 §c修复: 1.16.3聊天包格式调整的问题; §620-10-10 §c修复: 1.16.3聊天包格式调整的问题;
§620-04-10 §c修复: L10N 本地化组件报错的问题; §620-04-10 §c修复: L10N 本地化组件报错的问题;
§620-04-09 §c修复: 1.13-1.15.2新增物品不兼容的问题; §620-04-09 §c修复: 1.13-1.15.2新增物品不兼容的问题;
§620-02-15 §c修复: 跨服分组分配异常的问题 §620-02-15 §c修复: 跨服分组分配异常的问题;
</update.changes>
<update.changelog>
§619-05-31 §a增强: 跨服聊天压缩数据 增加可传输内容大小; §619-05-31 §a增强: 跨服聊天压缩数据 增加可传输内容大小;
§619-05-29 §c修复: 1.7.10不兼容的问题; §619-05-29 §c修复: 1.7.10不兼容的问题;
§619-02-23 §c修复: BungeeCord 兼容性问题; §619-02-23 §c修复: BungeeCord 兼容性问题;

View File

@ -1,59 +1,62 @@
package pw.yumc.MiaoChat.config; package pw.yumc.MiaoChat.config;
import java.util.List; import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player;
import org.bukkit.entity.Player; import pw.yumc.YumCore.config.annotation.ConfigNode;
import pw.yumc.YumCore.config.annotation.Nullable;
import me.clip.placeholderapi.PlaceholderAPI; import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
import pw.yumc.YumCore.config.annotation.ConfigNode; import pw.yumc.YumCore.tellraw.Tellraw;
import pw.yumc.YumCore.config.annotation.Nullable;
import pw.yumc.YumCore.config.inject.InjectConfigurationSection; import java.util.List;
import pw.yumc.YumCore.tellraw.Tellraw;
public class ChatMessagePart extends InjectConfigurationSection {
public class ChatMessagePart extends InjectConfigurationSection { private String text;
private String text; @Nullable
@Nullable private List<String> tip;
private List<String> tip; @Nullable
@Nullable private ItemTip item;
@ConfigNode("click.type") @Nullable
private String typestring; @ConfigNode("click.type")
@Nullable private String typestring;
@ConfigNode("click.command") @Nullable
private String command; @ConfigNode("click.command")
private transient CLICKTYPE type = CLICKTYPE.SUGGEST; private String command;
private transient CLICKTYPE type = CLICKTYPE.SUGGEST;
public ChatMessagePart(ConfigurationSection config) {
super(config); public ChatMessagePart(ConfigurationSection config) {
if (typestring != null) { super(config);
type = CLICKTYPE.valueOf(typestring); if (typestring != null) {
} type = CLICKTYPE.valueOf(typestring);
} }
}
public Tellraw then(Tellraw tr, Player p) {
tr.then(f(p, text)); public Tellraw then(Tellraw tr, Player p) {
if (tip != null && !tip.isEmpty()) { tr.then(f(p, text));
tr.tip(f(p, tip)); if (item != null) {
} tr.item(item.getItemStack(p, text, tip));
if (command != null && !command.isEmpty()) { } else if (tip != null && !tip.isEmpty()) {
String tc = f(p, command); tr.tip(f(p, tip));
switch (type) { }
case COMMAND: if (command != null && !command.isEmpty()) {
return tr.command(tc); String tc = f(p, command);
case OPENURL: switch (type) {
return tr.openurl(tc); case COMMAND:
case SUGGEST: return tr.command(tc);
return tr.suggest(tc); case OPENURL:
} return tr.openurl(tc);
} case SUGGEST:
return tr; return tr.suggest(tc);
} }
}
private List<String> f(Player player, List<String> text) { return tr;
return PlaceholderAPI.setPlaceholders(player, text); }
}
private List<String> f(Player player, List<String> text) {
private String f(Player player, String text) { return PlaceholderAPI.setPlaceholders(player, text);
return PlaceholderAPI.setPlaceholders(player, text); }
}
} private String f(Player player, String text) {
return PlaceholderAPI.setPlaceholders(player, text);
}
}

View File

@ -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<String> 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;
}
}

View File

@ -1,42 +1,50 @@
#当前文件为定义格式的基础文件 #当前文件为定义格式的基础文件
world: world:
#文本 支持PAPI变量 #文本 支持PAPI变量
text: '&6[&a%player_world%&6]' text: '&6[&a%player_world%&6]'
#悬浮提示 支持PAPI #悬浮提示 支持PAPI
tip: tip:
- '&6当前所在位置:' - '&6当前所在位置:'
- '&6世界: &d%player_world%' - '&6世界: &d%player_world%'
- '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%' - '&6坐标: &aX:%player_x% Y: %player_y% Z: %player_z%'
- '' - ''
- '&c点击即可TP我!' - '&c点击即可TP我!'
#点击操作 #点击操作
click: click:
#操作类型: [COMMAND,SUGGEST,OPENURL] #操作类型: [COMMAND,SUGGEST,OPENURL]
#COMMAND代表执行命令 #COMMAND代表执行命令
#SUGGEST代表命令补全 #SUGGEST代表命令补全
#OPENURL代表打开网址 #OPENURL代表打开网址
type: 'COMMAND' type: 'COMMAND'
#命令或网址 支持PAPI #命令或网址 支持PAPI
command: '/tpa %player_name%' command: '/tpa %player_name%'
player: player:
text: '&b%player_name%' text: '&b%player_name%'
tip: # 物品化Tip 可配合龙核/萌芽做ItemTip
- '&6玩家名称: &b%player_name%' item:
- '&6玩家等级: &a%player_level%' # 物品枚举
- '&6玩家血量: &c%player_health%' type: STONE
- '&6玩家饥饿: &d%player_food_level%' # 物品子ID
- '&6游戏模式: &4%player_gamemode%' damage: 0
- '' # 物品名称(用于萌芽/龙核匹配) 为空则使用 text
- '&c点击与我聊天' name: '§s§v§i§p'
click: tip:
type: 'SUGGEST' - '&6玩家名称: &b%player_name%'
command: '/tell %player_name%' - '&6玩家等级: &a%player_level%'
admin: - '&6玩家血量: &c%player_health%'
text: '&6[&c管理员&6]' - '&6玩家饥饿: &d%player_food_level%'
help: - '&6游戏模式: &4%player_gamemode%'
text: '&4[求助]' - ''
tip: - '&c点击与我聊天'
- '点击求助OP' click:
click: type: 'SUGGEST'
type: 'COMMAND' command: '/tell %player_name%'
admin:
text: '&6[&c管理员&6]'
help:
text: '&4[求助]'
tip:
- '点击求助OP'
click:
type: 'COMMAND'
command: '管理员@%player_name% 我需要你的帮助!' command: '管理员@%player_name% 我需要你的帮助!'

View File

@ -25,7 +25,7 @@ permissions:
default: true default: true
${project.artifactId}.color: ${project.artifactId}.color:
description: 彩字聊天权限! description: 彩字聊天权限!
default: true default: op
${project.artifactId}.admin: ${project.artifactId}.admin:
description: 管理员格式权限! description: 管理员格式权限!
default: op default: op