Paper/patches/server/0520-Create-HoverEvent-from-ItemStack-Entity.patch

52 lines
2.7 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ysl3000 <yannicklamprecht@live.de>
Date: Mon, 6 Jul 2020 22:18:04 +0200
Subject: [PATCH] Create HoverEvent from ItemStack Entity
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
2021-07-07 08:52:40 +02:00
index 8f5d71463616e519c2e183af1c2909fd55a3f93a..1a8ff7339c58a4fffb051a090a7b8c34cb346a61 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
2021-07-07 08:52:40 +02:00
@@ -371,5 +371,40 @@ public final class CraftItemFactory implements ItemFactory {
2021-06-11 14:02:28 +02:00
2021-06-14 16:41:34 +02:00
return nms != null ? net.minecraft.locale.Language.getInstance().getOrDefault(nms.getItem().getDescriptionId()) : null;
2021-06-11 14:02:28 +02:00
}
+
+ @Override
+ public net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(ItemStack itemStack) {
+ net.md_5.bungee.api.chat.ItemTag itemTag = net.md_5.bungee.api.chat.ItemTag.ofNbt(CraftItemStack.asNMSCopy(itemStack).getOrCreateTag().toString());
+ return new net.md_5.bungee.api.chat.hover.content.Item(
+ itemStack.getType().getKey().toString(),
+ itemStack.getAmount(),
+ itemTag);
+ }
+
+ @Override
+ public net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(org.bukkit.entity.Entity entity) {
+ return hoverContentOf(entity, org.apache.commons.lang3.StringUtils.isBlank(entity.getCustomName()) ? null : new net.md_5.bungee.api.chat.TextComponent(entity.getCustomName()));
+ }
+
+ @Override
+ public net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(org.bukkit.entity.Entity entity, String customName) {
+ return hoverContentOf(entity, org.apache.commons.lang3.StringUtils.isBlank(customName) ? null : new net.md_5.bungee.api.chat.TextComponent(customName));
+ }
+
+ @Override
+ public net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(org.bukkit.entity.Entity entity, net.md_5.bungee.api.chat.BaseComponent customName) {
+ return new net.md_5.bungee.api.chat.hover.content.Entity(
+ entity.getType().getKey().toString(),
+ entity.getUniqueId().toString(),
+ customName);
+ }
+
+ @Override
+ public net.md_5.bungee.api.chat.hover.content.Content hoverContentOf(org.bukkit.entity.Entity entity, net.md_5.bungee.api.chat.BaseComponent[] customName) {
+ return new net.md_5.bungee.api.chat.hover.content.Entity(
+ entity.getType().getKey().toString(),
+ entity.getUniqueId().toString(),
+ new net.md_5.bungee.api.chat.TextComponent(customName));
+ }
// Paper end
}