#2905: HoverEvent getValue compat method

This commit is contained in:
Mystiflow 2020-07-15 09:05:05 +10:00 committed by md_5
parent 94c4fcbad7
commit 0af4bfdbdf
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 22 additions and 0 deletions

View File

@ -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.
*

View File

@ -59,6 +59,11 @@ public class ComponentSerializer implements JsonDeserializer<BaseComponent>
}
}
public static String toString(Object object)
{
return gson.toJson( object );
}
public static String toString(BaseComponent component)
{
return gson.toJson( component );