版本更新至 3.53
修复:JSON 工具的物品展示功能无法显示NBT的问题
This commit is contained in:
parent
819e3e4cf4
commit
a41d43b080
@ -14,41 +14,57 @@ import me.skymc.taboolib.TabooLib;
|
|||||||
import me.skymc.taboolib.inventory.ItemUtils;
|
import me.skymc.taboolib.inventory.ItemUtils;
|
||||||
import me.skymc.taboolib.json.JSONObject;
|
import me.skymc.taboolib.json.JSONObject;
|
||||||
import me.skymc.taboolib.nms.item.DabItemUtils;
|
import me.skymc.taboolib.nms.item.DabItemUtils;
|
||||||
|
import me.skymc.taboolib.nms.item.IDabItemUtils;
|
||||||
|
|
||||||
public class ShowItemEvent extends HoverEvent{
|
public class ShowItemEvent extends HoverEvent{
|
||||||
|
|
||||||
private JSONObject object = new JSONObject();
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
public ShowItemEvent(ItemStack is){
|
public ShowItemEvent(ItemStack is){
|
||||||
try{
|
try{
|
||||||
object.put("action", "show_item");
|
object.put("action", "show_item");
|
||||||
ItemMeta im = is.getItemMeta();
|
|
||||||
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
|
|
||||||
Map<Enchantment, Integer> enchants = is.getItemMeta().getEnchants();
|
|
||||||
StringBuilder tag = new StringBuilder();
|
StringBuilder tag = new StringBuilder();
|
||||||
tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "¡ìb¡ìo" : "¡ìf") + ItemUtils.getCustomName(is));
|
Object itemTag = getItemTag(is);
|
||||||
if (lore.size() > 0) {
|
if (itemTag != null) {
|
||||||
tag.append(",Lore:[");
|
tag.append(",tag:" + itemTag);
|
||||||
for (String s : lore){
|
|
||||||
tag.append("\"" + s + "\",");
|
|
||||||
}
|
|
||||||
tag.delete(tag.length() - 1, tag.length());
|
|
||||||
tag.append("]");
|
|
||||||
}
|
}
|
||||||
tag.append("}");
|
else {
|
||||||
if (enchants.size() > 0) {
|
ItemMeta im = is.getItemMeta();
|
||||||
if(tag.length() > 6) {
|
List<String> lore = im.hasLore() ? im.getLore() : new ArrayList<>();
|
||||||
tag.append(",");
|
Map<Enchantment, Integer> enchants = is.getItemMeta().getEnchants();
|
||||||
|
tag.append(",tag:{display:{Name:" + (enchants.size() > 0 ? "¡ìb¡ìo" : "¡ì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:[");
|
tag.append("}");
|
||||||
for (Entry<Enchantment, Integer> e : enchants.entrySet()) {
|
if (enchants.size() > 0) {
|
||||||
tag.append("{id:" + e.getKey().getId() + ",lvl:" + e.getValue() + "},");
|
if(tag.length() > 6) {
|
||||||
|
tag.append(",");
|
||||||
|
}
|
||||||
|
tag.append("ench:[");
|
||||||
|
for (Entry<Enchantment, Integer> 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() + "}");
|
object.put("value", "{id:" + (TabooLib.getVerint() > 10700 ? DabItemUtils.getMinecraftName(is) : is.getTypeId()) + ",Count:" + is.getAmount() + tag.toString() + "}");
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user