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,21 +1,22 @@
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 me.clip.placeholderapi.PlaceholderAPI;
import pw.yumc.YumCore.config.annotation.ConfigNode; import pw.yumc.YumCore.config.annotation.ConfigNode;
import pw.yumc.YumCore.config.annotation.Nullable; import pw.yumc.YumCore.config.annotation.Nullable;
import pw.yumc.YumCore.config.inject.InjectConfigurationSection; import pw.yumc.YumCore.config.inject.InjectConfigurationSection;
import pw.yumc.YumCore.tellraw.Tellraw; import pw.yumc.YumCore.tellraw.Tellraw;
import java.util.List;
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;
@Nullable
@ConfigNode("click.type") @ConfigNode("click.type")
private String typestring; private String typestring;
@Nullable @Nullable
@ -32,18 +33,20 @@ public class ChatMessagePart extends InjectConfigurationSection {
public Tellraw then(Tellraw tr, Player p) { public Tellraw then(Tellraw tr, Player p) {
tr.then(f(p, text)); tr.then(f(p, text));
if (tip != null && !tip.isEmpty()) { if (item != null) {
tr.item(item.getItemStack(p, text, tip));
} else if (tip != null && !tip.isEmpty()) {
tr.tip(f(p, tip)); tr.tip(f(p, tip));
} }
if (command != null && !command.isEmpty()) { if (command != null && !command.isEmpty()) {
String tc = f(p, command); String tc = f(p, command);
switch (type) { switch (type) {
case COMMAND: case COMMAND:
return tr.command(tc); return tr.command(tc);
case OPENURL: case OPENURL:
return tr.openurl(tc); return tr.openurl(tc);
case SUGGEST: case SUGGEST:
return tr.suggest(tc); return tr.suggest(tc);
} }
} }
return tr; return tr;

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

@ -4,11 +4,11 @@ world:
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]
@ -20,14 +20,22 @@ world:
command: '/tpa %player_name%' command: '/tpa %player_name%'
player: player:
text: '&b%player_name%' text: '&b%player_name%'
# 物品化Tip 可配合龙核/萌芽做ItemTip
item:
# 物品枚举
type: STONE
# 物品子ID
damage: 0
# 物品名称(用于萌芽/龙核匹配) 为空则使用 text
name: '§s§v§i§p'
tip: tip:
- '&6玩家名称: &b%player_name%' - '&6玩家名称: &b%player_name%'
- '&6玩家等级: &a%player_level%' - '&6玩家等级: &a%player_level%'
- '&6玩家血量: &c%player_health%' - '&6玩家血量: &c%player_health%'
- '&6玩家饥饿: &d%player_food_level%' - '&6玩家饥饿: &d%player_food_level%'
- '&6游戏模式: &4%player_gamemode%' - '&6游戏模式: &4%player_gamemode%'
- '' - ''
- '&c点击与我聊天' - '&c点击与我聊天'
click: click:
type: 'SUGGEST' type: 'SUGGEST'
command: '/tell %player_name%' command: '/tell %player_name%'
@ -36,7 +44,7 @@ admin:
help: help:
text: '&4[求助]' text: '&4[求助]'
tip: tip:
- '点击求助OP' - '点击求助OP'
click: click:
type: 'COMMAND' 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