Cleanup ChatHoverEvent

This commit is contained in:
Felix Cravic 2020-08-01 01:05:11 +02:00
parent f95feeaaf1
commit 4334733c52

View File

@ -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");
}
}