From 4334733c52ab5f13235d6e6216e9d56c1f7a7436 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Sat, 1 Aug 2020 01:05:11 +0200 Subject: [PATCH] Cleanup ChatHoverEvent --- .../minestom/server/chat/ChatHoverEvent.java | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/minestom/server/chat/ChatHoverEvent.java b/src/main/java/net/minestom/server/chat/ChatHoverEvent.java index 2cf45cb3c..0a437f3ac 100644 --- a/src/main/java/net/minestom/server/chat/ChatHoverEvent.java +++ b/src/main/java/net/minestom/server/chat/ChatHoverEvent.java @@ -2,8 +2,8 @@ package net.minestom.server.chat; import com.google.gson.JsonObject; import net.minestom.server.entity.Entity; -import net.minestom.server.entity.EntityType; import net.minestom.server.item.ItemStack; +import net.minestom.server.item.metadata.*; /** * Represent a hover event for a specific portion of the message @@ -69,6 +69,9 @@ public class ChatHoverEvent { * @return the chat hover event */ public static ChatHoverEvent showItem(ItemStack itemStack) { + final ItemMeta itemMeta = itemStack.getItemMeta(); + final boolean hasMeta = itemMeta != null; + JsonObject itemJson = new JsonObject(); // Basic Item structure itemJson.addProperty("id", itemStack.getMaterial().getName()); @@ -102,13 +105,23 @@ public class ChatHoverEvent { // TODO: Attribute modifiers // Potion Effects - // TODO: CustomPotionEffects - // TODO: Potion - // TODO: CustomPotionColor + { + if (hasMeta && itemMeta instanceof PotionMeta) { + final PotionMeta potionMeta = (PotionMeta) itemMeta; + // TODO: CustomPotionEffects + // TODO: Potion + // TODO: CustomPotionColor + } + } // Crossbows - // TODO: ChargedProjectiles - // TODO: Charged + { + if (hasMeta && itemMeta instanceof CrossbowMeta) { + final CrossbowMeta crossbowMeta = (CrossbowMeta) itemMeta; + // TODO: ChargedProjectiles + // TODO: Charged + } + } // Display JsonObject displayJson = null; @@ -157,7 +170,12 @@ public class ChatHoverEvent { // TODO: ENtityTag // Maps - // TODO: Alot check https://minecraft.gamepedia.com/Player.dat_format#Item_structure#Maps + { + if (hasMeta && itemMeta instanceof MapMeta) { + final MapMeta mapMeta = (MapMeta) itemMeta; + // TODO: Alot check https://minecraft.gamepedia.com/Player.dat_format#Item_structure#Maps + } + } // Suspicious Stew // TODO: Effects @@ -166,9 +184,14 @@ public class ChatHoverEvent { // TODO: DebugProperty // Compasses - // TODO: LodestoneTracked - // TODO: LodestoneDimension - // TODO: LodestonePos + { + if (hasMeta && itemMeta instanceof CompassMeta) { + final CompassMeta compassMeta = (CompassMeta) itemMeta; + // TODO: LodestoneTracked + // TODO: LodestoneDimension + // TODO: LodestonePos + } + } if (displayJson != null) { @@ -196,14 +219,15 @@ public class ChatHoverEvent { * @return the chat hover event */ public static ChatHoverEvent showEntity(Entity entity) { - final String id = entity.getUuid().toString(); + // TODO + /*final String id = entity.getUuid().toString(); final String type = EntityType.fromId(entity.getEntityType()) .getNamespaceID().replace("minecraft:", ""); - // TODO name JsonObject object = new JsonObject(); object.addProperty("id", id); object.addProperty("type", type); - return new ChatHoverEvent("show_entity", object); + return new ChatHoverEvent("show_entity", object);*/ + throw new UnsupportedOperationException("Entity hover isn't implemented yet"); } }