Make JsonMessage a ComponentLike

This commit is contained in:
Kieran Wallbanks 2021-03-01 17:39:10 +00:00
parent 838c95828d
commit 9fca53a8d3

View File

@ -4,6 +4,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.jetbrains.annotations.NotNull;
@ -17,7 +18,7 @@ import java.util.Objects;
* @see <a href="https://wiki.vg/Chat">Chat Format</a>
*/
@Deprecated
public abstract class JsonMessage {
public abstract class JsonMessage implements ComponentLike {
// true if the compiled string is up-to-date, false otherwise
private boolean updated;
@ -52,11 +53,8 @@ public abstract class JsonMessage {
return getTextMessage(getJsonObject()).toString();
}
/**
* Gets this JSON message as an Adventure Component.
* @return the component
*/
public Component asComponent() {
@Override
public @NotNull Component asComponent() {
return GsonComponentSerializer.gson().deserialize(this.toString());
}