From 3c1aa996c415e4be5f317fdb36737434605653e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Tue, 13 Feb 2018 00:31:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B3?= =?UTF-8?q?=203.53?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复:JSON 工具的物品展示功能无法显示NBT的问题 --- .../jsonformatter/hover/ShowItemEvent.java | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main/src/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java b/src/main/src/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java index 58f90de75..8df60c70f 100644 --- a/src/main/src/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java +++ b/src/main/src/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java @@ -14,41 +14,57 @@ import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.json.JSONObject; import me.skymc.taboolib.nms.item.DabItemUtils; +import me.skymc.taboolib.nms.item.IDabItemUtils; public class ShowItemEvent extends HoverEvent{ private JSONObject object = new JSONObject(); + public Object getItemTag(ItemStack item) { + try { + return DabItemUtils.getInstance().getTag(DabItemUtils.getInstance().getNMSCopy(item)); + } catch (Exception e) { + return null; + } + } + @SuppressWarnings("deprecation") public ShowItemEvent(ItemStack is){ try{ object.put("action", "show_item"); - ItemMeta im = is.getItemMeta(); - List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); - Map enchants = is.getItemMeta().getEnchants(); StringBuilder tag = new StringBuilder(); - tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "bo" : "f") + ItemUtils.getCustomName(is)); - if (lore.size() > 0) { - tag.append(",Lore:["); - for (String s : lore){ - tag.append("\"" + s + "\","); - } - tag.delete(tag.length() - 1, tag.length()); - tag.append("]"); + Object itemTag = getItemTag(is); + if (itemTag != null) { + tag.append(",tag:" + itemTag); } - tag.append("}"); - if (enchants.size() > 0) { - if(tag.length() > 6) { - tag.append(","); + else { + ItemMeta im = is.getItemMeta(); + List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); + Map enchants = is.getItemMeta().getEnchants(); + tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "bo" : "f") + ItemUtils.getCustomName(is)); + if (lore.size() > 0) { + tag.append(",Lore:["); + for (String s : lore){ + tag.append("\"" + s + "\","); + } + tag.delete(tag.length() - 1, tag.length()); + tag.append("]"); } - tag.append("ench:["); - for (Entry e : enchants.entrySet()) { - tag.append("{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},"); + tag.append("}"); + if (enchants.size() > 0) { + if(tag.length() > 6) { + tag.append(","); + } + tag.append("ench:["); + for (Entry e : enchants.entrySet()) { + tag.append("{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},"); + } + tag.delete(tag.length() - 1, tag.length()); + tag.append("]"); } - tag.delete(tag.length() - 1, tag.length()); - tag.append("]"); + tag.append("}"); } - tag.append("}"); + object.put("value", "{id:" + (TabooLib.getVerint() > 10700 ? DabItemUtils.getMinecraftName(is) : is.getTypeId()) + ",Count:" + is.getAmount() + tag.toString() + "}"); } catch(Exception e) { e.printStackTrace();