版本更新至 5.12
调整:指令 “/tlib iteminfo” 提示信息 调整:JSON 工具的物品显示功能算法优化 修复:JSON 工具的物品显示功能在 1.7.10 版本失效的问题
This commit is contained in:
parent
6742a915c0
commit
819e3e4cf4
@ -11,6 +11,7 @@ import me.skymc.taboolib.inventory.ItemUtils;
|
|||||||
import me.skymc.taboolib.itemnbtapi.NBTItem;
|
import me.skymc.taboolib.itemnbtapi.NBTItem;
|
||||||
import me.skymc.taboolib.jsonformatter.JSONFormatter;
|
import me.skymc.taboolib.jsonformatter.JSONFormatter;
|
||||||
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
|
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
|
||||||
|
import me.skymc.taboolib.jsonformatter.hover.ShowItemEvent;
|
||||||
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
|
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
|
||||||
import me.skymc.taboolib.message.MsgUtils;
|
import me.skymc.taboolib.message.MsgUtils;
|
||||||
|
|
||||||
@ -36,6 +37,8 @@ public class InfoCommand extends SubCommand {
|
|||||||
json.append("§7 - 物品名称: §f"); json.appendHoverClick("§f" + ItemUtils.getCustomName(player.getItemInHand()), new ShowTextEvent("§f点击复制"), new SuggestCommandEvent(ItemUtils.getCustomName(player.getItemInHand()).replace("§", "&")));
|
json.append("§7 - 物品名称: §f"); json.appendHoverClick("§f" + ItemUtils.getCustomName(player.getItemInHand()), new ShowTextEvent("§f点击复制"), new SuggestCommandEvent(ItemUtils.getCustomName(player.getItemInHand()).replace("§", "&")));
|
||||||
json.newLine();
|
json.newLine();
|
||||||
json.append("§7 - 物品序号: §f" + player.getItemInHand().getTypeId() + ":" + player.getItemInHand().getDurability());
|
json.append("§7 - 物品序号: §f" + player.getItemInHand().getTypeId() + ":" + player.getItemInHand().getDurability());
|
||||||
|
json.newLine();
|
||||||
|
json.append("¡ì7 - ÎïƷչʾ: ¡ìf"); json.appendHover(ItemUtils.getCustomName(player.getItemInHand()), new ShowItemEvent(player.getItemInHand()));
|
||||||
json.send(player);
|
json.send(player);
|
||||||
|
|
||||||
NBTItem nbt = new NBTItem(((Player) sender).getItemInHand());
|
NBTItem nbt = new NBTItem(((Player) sender).getItemInHand());
|
||||||
|
@ -5,12 +5,14 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import me.skymc.taboolib.TabooLib;
|
||||||
|
import me.skymc.taboolib.inventory.ItemUtils;
|
||||||
import me.skymc.taboolib.json.JSONObject;
|
import me.skymc.taboolib.json.JSONObject;
|
||||||
import me.skymc.taboolib.nms.NMSUtil19;
|
|
||||||
import me.skymc.taboolib.nms.item.DabItemUtils;
|
import me.skymc.taboolib.nms.item.DabItemUtils;
|
||||||
|
|
||||||
public class ShowItemEvent extends HoverEvent{
|
public class ShowItemEvent extends HoverEvent{
|
||||||
@ -21,51 +23,33 @@ public class ShowItemEvent extends HoverEvent{
|
|||||||
public ShowItemEvent(ItemStack is){
|
public ShowItemEvent(ItemStack is){
|
||||||
try{
|
try{
|
||||||
object.put("action", "show_item");
|
object.put("action", "show_item");
|
||||||
String display = DabItemUtils.getName(is);
|
|
||||||
String raw = DabItemUtils.getRawName(is);
|
|
||||||
ItemMeta im = is.getItemMeta();
|
ItemMeta im = is.getItemMeta();
|
||||||
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<String>();
|
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
|
||||||
Map<Enchantment, Integer> enchants = is.getItemMeta().getEnchants();
|
Map<Enchantment, Integer> enchants = is.getItemMeta().getEnchants();
|
||||||
boolean utag = !display.equals(raw) || lore.size() > 0 || enchants.size() > 0;
|
StringBuilder tag = new StringBuilder();
|
||||||
String tag = "";
|
tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "¡ìb¡ìo" : "¡ìf") + ItemUtils.getCustomName(is));
|
||||||
if(utag){
|
|
||||||
tag = ",tag:{";
|
|
||||||
if(!display.equals(raw)){
|
|
||||||
tag = tag + "display:{Name:" + display;
|
|
||||||
if (lore.size() > 0) {
|
if (lore.size() > 0) {
|
||||||
tag = tag + ",Lore:[";
|
tag.append(",Lore:[");
|
||||||
for (String s : lore){
|
for (String s : lore){
|
||||||
tag = tag + "\"" + s + "\",";
|
tag.append("\"" + s + "\",");
|
||||||
}
|
|
||||||
tag = tag.substring(0, tag.length() - 1);
|
|
||||||
tag = tag + "]";
|
|
||||||
}
|
|
||||||
tag = tag + "}";
|
|
||||||
}else{
|
|
||||||
if(lore.size() > 0){
|
|
||||||
tag = tag + "display:{Lore:[";
|
|
||||||
for(String s : lore){
|
|
||||||
tag = tag + "\"" + s + "\",";
|
|
||||||
}
|
|
||||||
tag = tag.substring(0, tag.length() - 1);
|
|
||||||
tag = tag + "]}";
|
|
||||||
}
|
}
|
||||||
|
tag.delete(tag.length() - 1, tag.length());
|
||||||
|
tag.append("]");
|
||||||
}
|
}
|
||||||
|
tag.append("}");
|
||||||
if (enchants.size() > 0) {
|
if (enchants.size() > 0) {
|
||||||
if(tag.length() > 6) {
|
if(tag.length() > 6) {
|
||||||
tag = tag + ",";
|
tag.append(",");
|
||||||
}
|
}
|
||||||
tag = tag + "ench:[";
|
tag.append("ench:[");
|
||||||
for (Entry<Enchantment, Integer> e : enchants.entrySet()) {
|
for (Entry<Enchantment, Integer> e : enchants.entrySet()) {
|
||||||
tag = tag + "{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},";
|
tag.append("{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},");
|
||||||
}
|
}
|
||||||
tag = tag.substring(0, tag.length() - 1);
|
tag.delete(tag.length() - 1, tag.length());
|
||||||
tag = tag + "]";
|
tag.append("]");
|
||||||
}
|
}
|
||||||
tag = tag + "}";
|
tag.append("}");
|
||||||
}
|
object.put("value", "{id:" + (TabooLib.getVerint() > 10700 ? DabItemUtils.getMinecraftName(is) : is.getTypeId()) + ",Count:" + is.getAmount() + tag.toString() + "}");
|
||||||
String name = DabItemUtils.getMinecraftName(is);
|
|
||||||
object.put("value", "{id:" + name + ",Count:" + is.getAmount() + tag + "}");
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user