From 819e3e4cf4fced9c5fdaba7050765c599b9324dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 12 Feb 2018 23:36:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B3?= =?UTF-8?q?=205.12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整:指令 “/tlib iteminfo” 提示信息 调整:JSON 工具的物品显示功能算法优化 修复:JSON 工具的物品显示功能在 1.7.10 版本失效的问题 --- .../taboolib/commands/sub/InfoCommand.java | 3 + .../jsonformatter/hover/ShowItemEvent.java | 70 +++++++------------ 2 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/main/src/me/skymc/taboolib/commands/sub/InfoCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/InfoCommand.java index 9a2ee47..0d1b0e3 100644 --- a/src/main/src/me/skymc/taboolib/commands/sub/InfoCommand.java +++ b/src/main/src/me/skymc/taboolib/commands/sub/InfoCommand.java @@ -11,6 +11,7 @@ import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.itemnbtapi.NBTItem; import me.skymc.taboolib.jsonformatter.JSONFormatter; 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.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.newLine(); 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); NBTItem nbt = new NBTItem(((Player) sender).getItemInHand()); 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 cd388c1..58f90de 100644 --- a/src/main/src/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java +++ b/src/main/src/me/skymc/taboolib/jsonformatter/hover/ShowItemEvent.java @@ -5,12 +5,14 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.bukkit.Bukkit; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; 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.nms.NMSUtil19; import me.skymc.taboolib.nms.item.DabItemUtils; public class ShowItemEvent extends HoverEvent{ @@ -21,52 +23,34 @@ public class ShowItemEvent extends HoverEvent{ public ShowItemEvent(ItemStack is){ try{ object.put("action", "show_item"); - String display = DabItemUtils.getName(is); - String raw = DabItemUtils.getRawName(is); ItemMeta im = is.getItemMeta(); - List lore = im.hasLore() ? im.getLore() : new ArrayList(); + List lore = im.hasLore() ? im.getLore() : new ArrayList<>(); Map enchants = is.getItemMeta().getEnchants(); - boolean utag = !display.equals(raw) || lore.size() > 0 || enchants.size() > 0; - String tag = ""; - if(utag){ - tag = ",tag:{"; - if(!display.equals(raw)){ - tag = tag + "display:{Name:" + display; - if(lore.size() > 0){ - tag = tag + ",Lore:["; - for(String s : lore){ - tag = tag + "\"" + 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 + "]}"; - } + 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 + "\","); } - if(enchants.size() > 0){ - if(tag.length() > 6){ - tag = tag + ","; - } - tag = tag + "ench:["; - for(Entry e : enchants.entrySet()){ - tag = tag + "{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},"; - } - tag = tag.substring(0, tag.length() - 1); - tag = tag + "]"; - } - tag = tag + "}"; + tag.delete(tag.length() - 1, tag.length()); + tag.append("]"); } - String name = DabItemUtils.getMinecraftName(is); - object.put("value", "{id:" + name + ",Count:" + is.getAmount() + tag + "}"); - }catch(Exception e){ + 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.append("}"); + object.put("value", "{id:" + (TabooLib.getVerint() > 10700 ? DabItemUtils.getMinecraftName(is) : is.getTypeId()) + ",Count:" + is.getAmount() + tag.toString() + "}"); + } catch(Exception e) { e.printStackTrace(); } }