From 0af4bfdbdf8c51f9db7e465900a8751218743e4f Mon Sep 17 00:00:00 2001 From: Mystiflow Date: Wed, 15 Jul 2020 09:05:05 +1000 Subject: [PATCH] #2905: HoverEvent getValue compat method --- .../net/md_5/bungee/api/chat/HoverEvent.java | 17 +++++++++++++++++ .../md_5/bungee/chat/ComponentSerializer.java | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java b/chat/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java index 1d0d7240..02da5ac5 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java @@ -13,6 +13,7 @@ import net.md_5.bungee.api.chat.hover.content.Content; import net.md_5.bungee.api.chat.hover.content.Entity; import net.md_5.bungee.api.chat.hover.content.Item; import net.md_5.bungee.api.chat.hover.content.Text; +import net.md_5.bungee.chat.ComponentSerializer; @Getter @ToString @@ -70,6 +71,22 @@ public final class HoverEvent this.legacy = true; } + @Deprecated + public BaseComponent[] getValue() + { + Content content = contents.get( 0 ); + if ( content instanceof Text && ( (Text) content ).getValue() instanceof BaseComponent[] ) + { + return (BaseComponent[]) ( (Text) content ).getValue(); + } + + TextComponent component = new TextComponent( ComponentSerializer.toString( content ) ); + return new BaseComponent[] + { + component + }; + } + /** * Adds a content to this hover event. * diff --git a/chat/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java b/chat/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java index 34b6e3a3..f1a38151 100644 --- a/chat/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java +++ b/chat/src/main/java/net/md_5/bungee/chat/ComponentSerializer.java @@ -59,6 +59,11 @@ public class ComponentSerializer implements JsonDeserializer } } + public static String toString(Object object) + { + return gson.toJson( object ); + } + public static String toString(BaseComponent component) { return gson.toJson( component );