diff --git a/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java b/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java index 57fa78f8..7e576a03 100644 --- a/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java +++ b/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java @@ -9,11 +9,6 @@ import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.ServerLoginHandler; import com.github.steveice10.mc.protocol.data.SubProtocol; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.TextMessage; -import com.github.steveice10.mc.protocol.data.message.style.ChatColor; -import com.github.steveice10.mc.protocol.data.message.style.ChatFormat; -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; import com.github.steveice10.mc.protocol.data.status.PlayerInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo; @@ -43,6 +38,9 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextDecoration; import java.net.Proxy; import java.util.Arrays; @@ -72,7 +70,7 @@ public class MinecraftProtocolTest { return new ServerStatusInfo( new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION), new PlayerInfo(100, 0, new GameProfile[0]), - new TextMessage.Builder().text("Hello world!").build(), + Component.text("Hello world!"), null ); } @@ -119,26 +117,13 @@ public class MinecraftProtocolTest { GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY); System.out.println(profile.getName() + ": " + packet.getMessage()); - MessageStyle green = new MessageStyle.Builder() - .color(ChatColor.GREEN) - .build(); - MessageStyle aquaUnderline = new MessageStyle.Builder() - .color(ChatColor.AQUA) - .formats(ChatFormat.UNDERLINED) - .build(); - - Message msg = new TextMessage.Builder() - .text("Hello, ") - .style(green) - .extra(new TextMessage.Builder() - .text(profile.getName()) - .style(aquaUnderline) - .build()) - .extra(new TextMessage.Builder() - .text("!") - .style(green) - .build()) - .build(); + Component msg = Component.text("Hello, ") + .color(NamedTextColor.GREEN) + .append(Component.text(profile.getName()) + .color(NamedTextColor.AQUA) + .decorate(TextDecoration.UNDERLINED)) + .append(Component.text("!") + .color(NamedTextColor.GREEN)); event.getSession().send(new ServerChatPacket(msg)); } @@ -231,7 +216,7 @@ public class MinecraftProtocolTest { if(event.getPacket() instanceof ServerJoinGamePacket) { event.getSession().send(new ClientChatPacket("Hello, this is a test of MCProtocolLib.")); } else if(event.getPacket() instanceof ServerChatPacket) { - Message message = event.getPacket().getMessage(); + Component message = event.getPacket().getMessage(); System.out.println("Received Message: " + message); event.getSession().disconnect("Finished"); } diff --git a/pom.xml b/pom.xml index b9e14d41..85a4f7bd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.steveice10 mcprotocollib - 1.16.4-1 + 1.16.4-2-SNAPSHOT jar MCProtocolLib @@ -71,6 +71,11 @@ 1.3 compile + + net.kyori + adventure-text-serializer-gson + 4.1.1 + org.projectlombok lombok diff --git a/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java b/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java index 8e228a49..2164e5c4 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java +++ b/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java @@ -30,9 +30,9 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientAdvan import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientClickWindowButtonPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientConfirmTransactionPacket; -import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientDisplayedRecipePacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCraftingBookStatePacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket; +import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientDisplayedRecipePacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientEditBookPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientMoveItemToHotbarPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientPrepareCraftingGridPacket; diff --git a/src/main/java/com/github/steveice10/mc/protocol/ServerListener.java b/src/main/java/com/github/steveice10/mc/protocol/ServerListener.java index 7e9dd8c1..b48d247c 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/ServerListener.java +++ b/src/main/java/com/github/steveice10/mc/protocol/ServerListener.java @@ -4,7 +4,6 @@ import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.auth.service.SessionService; import com.github.steveice10.mc.protocol.data.SubProtocol; -import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.data.status.PlayerInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo; @@ -29,6 +28,7 @@ import com.github.steveice10.packetlib.event.session.DisconnectingEvent; import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; import com.github.steveice10.packetlib.event.session.PacketSentEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; +import net.kyori.adventure.text.Component; import javax.crypto.SecretKey; import java.security.KeyPair; @@ -129,7 +129,7 @@ public class ServerListener extends SessionAdapter { builder = session -> new ServerStatusInfo( VersionInfo.CURRENT, new PlayerInfo(0, 20, new GameProfile[0]), - new TextMessage.Builder().text("A Minecraft Server").build(), + Component.text("A Minecraft Server"), null ); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/PlayerListEntry.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/PlayerListEntry.java index f56614eb..65a324a3 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/PlayerListEntry.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/PlayerListEntry.java @@ -2,10 +2,10 @@ package com.github.steveice10.mc.protocol.data.game; import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; -import com.github.steveice10.mc.protocol.data.message.Message; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import net.kyori.adventure.text.Component; @Data @AllArgsConstructor @@ -13,7 +13,7 @@ public class PlayerListEntry { private final @NonNull GameProfile profile; private final GameMode gameMode; private final int ping; - private final Message displayName; + private final Component displayName; public PlayerListEntry(GameProfile profile) { this(profile, null, 0, null); @@ -27,7 +27,7 @@ public class PlayerListEntry { this(profile, null, ping, null); } - public PlayerListEntry(GameProfile profile, Message displayName) { + public PlayerListEntry(GameProfile profile, Component displayName) { this(profile, null, 0, displayName); } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/advancement/Advancement.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/advancement/Advancement.java index 7edf20d9..dc7a8fd5 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/advancement/Advancement.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/advancement/Advancement.java @@ -1,10 +1,10 @@ package com.github.steveice10.mc.protocol.data.game.advancement; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; -import com.github.steveice10.mc.protocol.data.message.Message; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import net.kyori.adventure.text.Component; import java.util.List; @@ -32,8 +32,8 @@ public class Advancement { @Data @AllArgsConstructor public static class DisplayData { - private final @NonNull Message title; - private final @NonNull Message description; + private final @NonNull Component title; + private final @NonNull Component description; private final ItemStack icon; private final @NonNull FrameType frameType; private final boolean showToast; @@ -42,7 +42,7 @@ public class Advancement { private final float posY; private final String backgroundTexture; - public DisplayData(@NonNull Message title, @NonNull Message description, ItemStack icon, @NonNull FrameType frameType, + public DisplayData(@NonNull Component title, @NonNull Component description, ItemStack icon, @NonNull FrameType frameType, boolean showToast, boolean hidden, float posX, float posY) { this(title, description, icon, frameType, showToast, hidden, posX, posY, null); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java index 76e2d89e..e1d27947 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/Chunk.java @@ -6,7 +6,11 @@ import com.github.steveice10.mc.protocol.data.game.chunk.palette.MapPalette; import com.github.steveice10.mc.protocol.data.game.chunk.palette.Palette; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; -import lombok.*; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NonNull; +import lombok.Setter; import java.io.IOException; diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java index c9e60412..8638e631 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/entity/metadata/EntityMetadata.java @@ -6,14 +6,14 @@ import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; import com.github.steveice10.mc.protocol.data.game.world.particle.Particle; import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleData; import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.ArrayList; @@ -57,7 +57,7 @@ public class EntityMetadata { // Intentional fall-through case CHAT: - value = MessageSerializer.fromString(in.readString()); + value = GsonComponentSerializer.gson().deserialize(in.readString()); break; case ITEM: value = ItemStack.read(in); @@ -140,7 +140,7 @@ public class EntityMetadata { // Intentional fall-through case CHAT: - out.writeString(MessageSerializer.toJsonString((Message) meta.getValue())); + out.writeString(GsonComponentSerializer.gson().serialize((Component) meta.getValue())); break; case ITEM: ItemStack.write(out, (ItemStack) meta.getValue()); diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/world/map/MapIcon.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/world/map/MapIcon.java index eab6ab7e..15c28f64 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/world/map/MapIcon.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/world/map/MapIcon.java @@ -1,9 +1,9 @@ package com.github.steveice10.mc.protocol.data.game.world.map; -import com.github.steveice10.mc.protocol.data.message.Message; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import net.kyori.adventure.text.Component; @Data @AllArgsConstructor @@ -12,5 +12,5 @@ public class MapIcon { private final int centerZ; private final @NonNull MapIconType iconType; private final int iconRotation; - private final Message displayName; + private final Component displayName; } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/BlockNbtMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/BlockNbtMessage.java deleted file mode 100644 index 594dbf69..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/BlockNbtMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class BlockNbtMessage extends NbtMessage { - public static class Builder extends NbtMessage.Builder { - @NonNull - private String pos = ""; - - public Builder pos(@NonNull String pos) { - this.pos = pos; - return this; - } - - @Override - public Builder copy(@NonNull BlockNbtMessage message) { - super.copy(message); - this.pos = message.getPos(); - return this; - } - - @Override - public BlockNbtMessage build() { - return new BlockNbtMessage(this.style, this.extra, this.path, this.interpret, this.pos); - } - } - - private final String pos; - - private BlockNbtMessage(MessageStyle style, List extra, String path, boolean interpret, String pos) { - super(style, extra, path, interpret); - this.pos = pos; - } - - public String getPos() { - return this.pos; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/EntityHoverMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/EntityHoverMessage.java deleted file mode 100644 index aaa69b0c..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/EntityHoverMessage.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class EntityHoverMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String type = ""; - @NonNull - private String id = ""; - private Message name; - - public Builder type(@NonNull String type) { - this.type = type; - return this; - } - - public Builder id(@NonNull String id) { - this.id = id; - return this; - } - - public Builder name(Message name) { - this.name = name; - return this; - } - - @Override - public Builder copy(@NonNull EntityHoverMessage message) { - super.copy(message); - this.type = message.getType(); - this.id = message.getId(); - this.name = message.getName(); - return this; - } - - @Override - public EntityHoverMessage build() { - return new EntityHoverMessage(this.style, this.extra, this.type, this.id, this.name); - } - } - - private final String type; - private final String id; - private final Message name; - - private EntityHoverMessage(MessageStyle style, List extra, String type, String id, Message name) { - super(style, extra); - this.type = type; - this.id = id; - this.name = name; - } - - public String getType() { - return this.type; - } - - public String getId() { - return this.id; - } - - public Message getName() { - return this.name; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/EntityNbtMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/EntityNbtMessage.java deleted file mode 100644 index 051d8c0e..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/EntityNbtMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class EntityNbtMessage extends NbtMessage { - public static class Builder extends NbtMessage.Builder { - @NonNull - private String selector = ""; - - public Builder selector(@NonNull String selector) { - this.selector = selector; - return this; - } - - @Override - public Builder copy(@NonNull EntityNbtMessage message) { - super.copy(message); - this.selector = message.getSelector(); - return this; - } - - @Override - public EntityNbtMessage build() { - return new EntityNbtMessage(this.style, this.extra, this.path, this.interpret, this.selector); - } - } - - private final String selector; - - private EntityNbtMessage(MessageStyle style, List extra, String path, boolean interpret, String selector) { - super(style, extra, path, interpret); - this.selector = selector; - } - - public String getSelector() { - return this.selector; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/ItemHoverMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/ItemHoverMessage.java deleted file mode 100644 index b1f8c233..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/ItemHoverMessage.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.google.gson.JsonElement; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class ItemHoverMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String id = ""; - private int count; - private JsonElement tag; - - public Builder id(@NonNull String id) { - this.id = id; - return this; - } - - public Builder count(int count) { - this.count = count; - return this; - } - - public Builder tag(JsonElement tag) { - this.tag = tag; - return this; - } - - @Override - public Builder copy(@NonNull ItemHoverMessage message) { - super.copy(message); - this.id = message.getId(); - this.count = message.getCount(); - this.tag = message.getTag(); - return this; - } - - @Override - public ItemHoverMessage build() { - return new ItemHoverMessage(this.style, this.extra, this.id, this.count, this.tag); - } - } - - private final String id; - private final int count; - private final JsonElement tag; - - private ItemHoverMessage(MessageStyle style, List extra, String id, int count, JsonElement tag) { - super(style, extra); - this.id = id; - this.count = count; - this.tag = tag; - } - - public String getId() { - return this.id; - } - - public int getCount() { - return this.count; - } - - public JsonElement getTag() { - return this.tag; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/KeybindMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/KeybindMessage.java deleted file mode 100644 index fbedbaa3..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/KeybindMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class KeybindMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String keybind = ""; - - public Builder keybind(@NonNull String keybind) { - this.keybind = keybind; - return this; - } - - @Override - public Builder copy(@NonNull KeybindMessage message) { - super.copy(message); - this.keybind = message.getKeybind(); - return this; - } - - @Override - public KeybindMessage build() { - return new KeybindMessage(this.style, this.extra, this.keybind); - } - } - - private final String keybind; - - private KeybindMessage(MessageStyle style, List extra, String keybind) { - super(style, extra); - this.keybind = keybind; - } - - public String getKeybind() { - return this.keybind; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/Message.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/Message.java deleted file mode 100644 index a0e38b59..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/Message.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -@EqualsAndHashCode -public abstract class Message { - public abstract static class Builder, M extends Message> { - @NonNull - protected MessageStyle style = MessageStyle.DEFAULT; - @NonNull - protected List extra = new ArrayList<>(); - - public B style(@NonNull MessageStyle style) { - this.style = style; - return (B) this; - } - - public B extra(@NonNull Message... extra) { - return this.extra(Arrays.asList(extra)); - } - - public B extra(@NonNull Collection extra) { - this.extra.addAll(extra); - return (B) this; - } - - public B copy(@NonNull M message) { - this.style = message.getStyle(); - this.extra = new ArrayList<>(message.getExtra()); - return (B) this; - } - - public abstract M build(); - } - - private final MessageStyle style; - private final List extra; - - protected Message(MessageStyle style, List extra) { - this.style = style; - this.extra = Collections.unmodifiableList(extra); - } - - public MessageStyle getStyle() { - return this.style; - } - - public List getExtra() { - return this.extra; - } - - public abstract Builder toBuilder(); - - @Override - public String toString() { - return MessageSerializer.toJsonString(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/MessageSerializer.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/MessageSerializer.java deleted file mode 100644 index 9b6ae65f..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/MessageSerializer.java +++ /dev/null @@ -1,286 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.ChatColor; -import com.github.steveice10.mc.protocol.data.message.style.ChatFormat; -import com.github.steveice10.mc.protocol.data.message.style.ClickAction; -import com.github.steveice10.mc.protocol.data.message.style.ClickEvent; -import com.github.steveice10.mc.protocol.data.message.style.HoverAction; -import com.github.steveice10.mc.protocol.data.message.style.HoverEvent; -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import com.github.steveice10.opennbt.conversion.builtin.CompoundTagConverter; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.google.gson.*; - -import java.util.ArrayList; -import java.util.List; - -public class MessageSerializer { - public static Message fromString(String str) { - try { - return fromJson(new JsonParser().parse(str)); - } catch(Exception e) { - return new TextMessage.Builder().text(str).build(); - } - } - - public static Message fromJson(JsonElement e) { - return builderFromJson(e).build(); - } - - private static Message.Builder builderFromJson(JsonElement e) { - if(e.isJsonPrimitive()) { - return new TextMessage.Builder().text(e.getAsString()); - } else if(e.isJsonArray()) { - JsonArray array = e.getAsJsonArray(); - if(array.size() == 0) { - return new TextMessage.Builder().text(""); - } - - Message.Builder msg = builderFromJson(array.get(0)); - for(int index = 1; index < array.size(); index++) { - msg.extra(fromJson(array.get(index))); - } - - return msg; - } else if(e.isJsonObject()) { - JsonObject json = e.getAsJsonObject(); - - Message.Builder msg = dataFromJson(json); - msg.style(styleFromJson(json)); - msg.extra(extraFromJson(json)); - return msg; - } else { - throw new IllegalArgumentException("Cannot convert JSON type " + e.getClass().getSimpleName() + " to a message."); - } - } - - public static String toJsonString(Message message) { - return toJson(message).toString(); - } - - public static JsonElement toJson(Message message) { - if(message instanceof TextMessage && message.getStyle().equals(MessageStyle.DEFAULT) && message.getExtra().isEmpty()) { - return new JsonPrimitive(((TextMessage) message).getText()); - } - - JsonObject json = new JsonObject(); - dataToJson(json, message); - styleToJson(json, message.getStyle()); - extraToJson(json, message.getExtra()); - return json; - } - - private static Message.Builder dataFromJson(JsonObject json) { - if(json.has("text")) { - return new TextMessage.Builder() - .text(json.get("text").getAsString()); - } else if(json.has("translate")) { - List with = new ArrayList<>(); - if(json.has("with")) { - JsonArray withJson = json.get("with").getAsJsonArray(); - for(int index = 0; index < withJson.size(); index++) { - with.add(fromJson(withJson.get(index))); - } - } - - return new TranslationMessage.Builder() - .key(json.get("translate").getAsString()) - .with(with); - } else if(json.has("keybind")) { - return new KeybindMessage.Builder() - .keybind(json.get("keybind").getAsString()); - } else if(json.has("score")) { - JsonObject score = json.get("score").getAsJsonObject(); - return new ScoreMessage.Builder() - .name(score.get("name").getAsString()) - .objective(score.get("objective").getAsString()) - .value(score.has("value") ? score.get("value").getAsString() : null); - } else if(json.has("selector")) { - return new SelectorMessage.Builder() - .selector(json.get("selector").getAsString()); - } else if(json.has("nbt")) { - String path = json.get("nbt").getAsString(); - boolean interpret = json.has("interpret") && json.get("interpret").getAsBoolean(); - if(json.has("block")) { - return new BlockNbtMessage.Builder() - .path(path) - .interpret(interpret) - .pos(json.get("block").getAsString()); - } else if(json.has("entity")) { - return new EntityNbtMessage.Builder() - .path(path) - .interpret(interpret) - .selector(json.get("entity").getAsString()); - } else if(json.has("storage")) { - return new StorageNbtMessage.Builder() - .path(path) - .interpret(interpret) - .id(json.get("storage").getAsString()); - } else { - throw new IllegalArgumentException("Unknown NBT message type in json: " + json); - } - } else if(json.has("type") && json.has("id")) { - EntityHoverMessage.Builder builder = new EntityHoverMessage.Builder(); - builder.type(json.get("type").getAsString()); - builder.id(json.get("id").getAsString()); - - if (json.has("name")) { - builder.name(fromJson(json.get("name"))); - } - - return builder; - } else if(json.has("id")) { - ItemHoverMessage.Builder builder = new ItemHoverMessage.Builder(); - builder.id(json.get("id").getAsString()); - - if (json.has("count")) { - builder.count(json.get("count").getAsInt()); - } - - if (json.has("tag")) { - builder.tag(json.get("tag")); - } - - return builder; - } else { - throw new IllegalArgumentException("Unknown message type in json: " + json); - } - } - - private static void dataToJson(JsonObject json, Message message) { - if(message instanceof TextMessage) { - json.addProperty("text", ((TextMessage) message).getText()); - } else if(message instanceof TranslationMessage) { - TranslationMessage translationMessage = (TranslationMessage) message; - json.addProperty("translate", translationMessage.getKey()); - - List with = translationMessage.getWith(); - if(!with.isEmpty()) { - JsonArray jsonWith = new JsonArray(); - for(Message msg : with) { - jsonWith.add(toJson(msg)); - } - - json.add("with", jsonWith); - } - } else if(message instanceof KeybindMessage) { - json.addProperty("keybind", ((KeybindMessage) message).getKeybind()); - } else if(message instanceof ScoreMessage) { - ScoreMessage scoreMessage = (ScoreMessage) message; - - JsonObject score = new JsonObject(); - score.addProperty("name", scoreMessage.getName()); - score.addProperty("objective", scoreMessage.getObjective()); - if(scoreMessage.getValue() != null) { - score.addProperty("value", scoreMessage.getValue()); - } - - json.add("score", score); - } else if(message instanceof SelectorMessage) { - json.addProperty("selector", ((SelectorMessage) message).getSelector()); - } else if(message instanceof NbtMessage) { - NbtMessage nbtMessage = (NbtMessage) message; - - json.addProperty("nbt", nbtMessage.getPath()); - json.addProperty("interpret", nbtMessage.shouldInterpret()); - - if(message instanceof BlockNbtMessage) { - json.addProperty("block", ((BlockNbtMessage) nbtMessage).getPos()); - } else if(message instanceof EntityNbtMessage) { - json.addProperty("entity", ((EntityNbtMessage) nbtMessage).getSelector()); - } else if(message instanceof StorageNbtMessage) { - json.addProperty("storage", ((StorageNbtMessage) nbtMessage).getId()); - } - } else if(message instanceof EntityHoverMessage) { - EntityHoverMessage entityHoverMessage = (EntityHoverMessage) message; - json.addProperty("type", entityHoverMessage.getType()); - json.addProperty("id", entityHoverMessage.getId()); - json.add("name", toJson(entityHoverMessage.getName())); - } else if(message instanceof ItemHoverMessage) { - ItemHoverMessage entityHoverMessage = (ItemHoverMessage) message; - json.addProperty("id", entityHoverMessage.getId()); - json.addProperty("count", entityHoverMessage.getCount()); - json.add("tag", entityHoverMessage.getTag()); - } - } - - private static MessageStyle styleFromJson(JsonObject json) { - MessageStyle.Builder style = new MessageStyle.Builder(); - if(json.has("color")) { - style.color(json.get("color").getAsString()); - } - - for(ChatFormat format : ChatFormat.values()) { - if(json.has(format.toString()) && json.get(format.toString()).getAsBoolean()) { - style.formats(format); - } - } - - if(json.has("clickEvent")) { - JsonObject click = json.get("clickEvent").getAsJsonObject(); - style.clickEvent(new ClickEvent(ClickAction.byName(click.get("action").getAsString()), click.get("value").getAsString())); - } - - if(json.has("hoverEvent")) { - JsonObject hover = json.get("hoverEvent").getAsJsonObject(); - style.hoverEvent(new HoverEvent(HoverAction.byName(hover.get("action").getAsString()), fromJson(hover.has("value") ? hover.get("value") : hover.get("contents")))); - } - - if(json.has("insertion")) { - style.insertion(json.get("insertion").getAsString()); - } - - return style.build(); - } - - private static void styleToJson(JsonObject json, MessageStyle style) { - if(style.getColor() != ChatColor.NONE) { - json.addProperty("color", style.getColor().toString()); - } - - for(ChatFormat format : style.getFormats()) { - json.addProperty(format.toString(), true); - } - - if(style.getClickEvent() != null) { - JsonObject click = new JsonObject(); - click.addProperty("action", style.getClickEvent().getAction().toString()); - click.addProperty("value", style.getClickEvent().getValue()); - json.add("clickEvent", click); - } - - if(style.getHoverEvent() != null) { - JsonObject hover = new JsonObject(); - hover.addProperty("action", style.getHoverEvent().getAction().toString()); - hover.add("contents", toJson(style.getHoverEvent().getContents())); - json.add("hoverEvent", hover); - } - - if(style.getInsertion() != null) { - json.addProperty("insertion", style.getInsertion()); - } - } - - private static List extraFromJson(JsonObject json) { - List extra = new ArrayList<>(); - if(json.has("extra")) { - JsonArray extraJson = json.get("extra").getAsJsonArray(); - for(int index = 0; index < extraJson.size(); index++) { - extra.add(fromJson(extraJson.get(index))); - } - } - - return extra; - } - - private static void extraToJson(JsonObject json, List extra) { - if(!extra.isEmpty()) { - JsonArray jsonExtra = new JsonArray(); - for(Message msg : extra) { - jsonExtra.add(toJson(msg)); - } - - json.add("extra", jsonExtra); - } - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/NbtMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/NbtMessage.java deleted file mode 100644 index 2ec42232..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/NbtMessage.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public abstract class NbtMessage extends Message { - public abstract static class Builder, M extends NbtMessage> extends Message.Builder { - @NonNull - protected String path = ""; - protected boolean interpret = false; - - public B path(@NonNull String path) { - this.path = path; - return (B) this; - } - - public B interpret(boolean interpret) { - this.interpret = interpret; - return (B) this; - } - - @Override - public B copy(@NonNull M message) { - super.copy(message); - this.path = message.getPath(); - this.interpret = message.shouldInterpret(); - return (B) this; - } - - @Override - public abstract M build(); - } - - private final String path; - private final boolean interpret; - - protected NbtMessage(MessageStyle style, List extra, String path, boolean interpret) { - super(style, extra); - this.path = path; - this.interpret = interpret; - } - - public String getPath() { - return this.path; - } - - public boolean shouldInterpret() { - return this.interpret; - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/ScoreMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/ScoreMessage.java deleted file mode 100644 index 93ae05e9..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/ScoreMessage.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class ScoreMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String name = ""; - @NonNull - private String objective = ""; - private String value = null; - - public Builder name(@NonNull String name) { - this.name = name; - return this; - } - - public Builder objective(@NonNull String objective) { - this.objective = objective; - return this; - } - - public Builder value(String value) { - this.value = value; - return this; - } - - @Override - public Builder copy(@NonNull ScoreMessage message) { - super.copy(message); - this.name = message.getName(); - this.objective = message.getObjective(); - this.value = message.getValue(); - return this; - } - - @Override - public ScoreMessage build() { - return new ScoreMessage(this.style, this.extra, this.name, this.objective, this.value); - } - } - - private final String name; - private final String objective; - private final String value; - - private ScoreMessage(MessageStyle style, List extra, String name, String objective, String value) { - super(style, extra); - this.name = name; - this.objective = objective; - this.value = value; - } - - public String getName() { - return this.name; - } - - public String getObjective() { - return this.objective; - } - - public String getValue() { - return this.value; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/SelectorMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/SelectorMessage.java deleted file mode 100644 index 4f6fcfb0..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/SelectorMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class SelectorMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String selector = ""; - - public Builder selector(@NonNull String selector) { - this.selector = selector; - return this; - } - - @Override - public Builder copy(@NonNull SelectorMessage message) { - super.copy(message); - this.selector = message.getSelector(); - return this; - } - - @Override - public SelectorMessage build() { - return new SelectorMessage(this.style, this.extra, this.selector); - } - } - - private final String selector; - - private SelectorMessage(MessageStyle style, List extra, String selector) { - super(style, extra); - this.selector = selector; - } - - public String getSelector() { - return this.selector; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/StorageNbtMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/StorageNbtMessage.java deleted file mode 100644 index 7379f436..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/StorageNbtMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class StorageNbtMessage extends NbtMessage { - public static class Builder extends NbtMessage.Builder { - @NonNull - private String id = ""; - - public Builder id(@NonNull String id) { - this.id = id; - return this; - } - - @Override - public Builder copy(@NonNull StorageNbtMessage message) { - super.copy(message); - this.id = message.getId(); - return this; - } - - @Override - public StorageNbtMessage build() { - return new StorageNbtMessage(this.style, this.extra, this.path, this.interpret, this.id); - } - } - - private final String id; - - private StorageNbtMessage(MessageStyle style, List extra, String path, boolean interpret, String id) { - super(style, extra, path, interpret); - this.id = id; - } - - public String getId() { - return this.id; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/TextMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/TextMessage.java deleted file mode 100644 index 18bf25f8..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/TextMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class TextMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String text = ""; - - public Builder text(@NonNull String text) { - this.text = text; - return this; - } - - @Override - public Builder copy(@NonNull TextMessage message) { - super.copy(message); - this.text = message.getText(); - return this; - } - - @Override - public TextMessage build() { - return new TextMessage(this.style, this.extra, this.text); - } - } - - private final String text; - - private TextMessage(MessageStyle style, List extra, String text) { - super(style, extra); - this.text = text; - } - - public String getText() { - return this.text; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/TranslationMessage.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/TranslationMessage.java deleted file mode 100644 index 40f85d3d..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/TranslationMessage.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message; - -import com.github.steveice10.mc.protocol.data.message.style.MessageStyle; -import lombok.EqualsAndHashCode; -import lombok.NonNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -@EqualsAndHashCode(callSuper = true) -public class TranslationMessage extends Message { - public static class Builder extends Message.Builder { - @NonNull - private String key = ""; - @NonNull - private List with = new ArrayList<>(); - - public Builder key(@NonNull String key) { - this.key = key; - return this; - } - - public Builder with(@NonNull Message... with) { - return this.with(Arrays.asList(with)); - } - - public Builder with(@NonNull Collection with) { - this.with.addAll(with); - return this; - } - - @Override - public Builder copy(@NonNull TranslationMessage message) { - super.copy(message); - this.key = message.getKey(); - this.with = new ArrayList<>(message.getWith()); - return this; - } - - @Override - public TranslationMessage build() { - return new TranslationMessage(this.style, this.extra, this.key, this.with); - } - } - - private final String key; - private final List with; - - private TranslationMessage(MessageStyle style, List extra, String key, List with) { - super(style, extra); - this.key = key; - this.with = Collections.unmodifiableList(with); - } - - public String getKey() { - return this.key; - } - - public List getWith() { - return this.with; - } - - @Override - public Builder toBuilder() { - return new Builder().copy(this); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ChatColor.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ChatColor.java deleted file mode 100644 index f2560067..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ChatColor.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -public class ChatColor { - public static final String BLACK = "black"; - public static final String DARK_BLUE = "dark_blue"; - public static final String DARK_GREEN = "dark_green"; - public static final String DARK_AQUA = "dark_aqua"; - public static final String DARK_RED = "dark_red"; - public static final String DARK_PURPLE = "dark_purple"; - public static final String GOLD = "gold"; - public static final String GRAY = "gray"; - public static final String DARK_GRAY = "dark_gray"; - public static final String BLUE = "blue"; - public static final String GREEN = "green"; - public static final String AQUA = "aqua"; - public static final String RED = "red"; - public static final String LIGHT_PURPLE = "light_purple"; - public static final String YELLOW = "yellow"; - public static final String WHITE = "white"; - public static final String RESET = "reset"; - public static final String NONE = "none"; -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ChatFormat.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ChatFormat.java deleted file mode 100644 index 770e65ab..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ChatFormat.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -public enum ChatFormat { - BOLD, - UNDERLINED, - STRIKETHROUGH, - ITALIC, - OBFUSCATED; - - public static ChatFormat byName(String name) { - String lowerCase = name.toLowerCase(); - for(ChatFormat format : values()) { - if(format.toString().equals(lowerCase)) { - return format; - } - } - - return null; - } - - @Override - public String toString() { - return this.name().toLowerCase(); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ClickAction.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ClickAction.java deleted file mode 100644 index 53a105bd..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ClickAction.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -public enum ClickAction { - CHANGE_PAGE, - COPY_TO_CLIPBOARD, - OPEN_URL, - RUN_COMMAND, - SUGGEST_COMMAND; - - public static ClickAction byName(String name) { - String lowerCase = name.toLowerCase(); - for(ClickAction action : values()) { - if(action.toString().equals(lowerCase)) { - return action; - } - } - - return null; - } - - @Override - public String toString() { - return this.name().toLowerCase(); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ClickEvent.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ClickEvent.java deleted file mode 100644 index e3de276e..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/ClickEvent.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.ToString; - -@ToString -@EqualsAndHashCode -public class ClickEvent { - @NonNull - private final ClickAction action; - @NonNull - private final String value; - - public ClickEvent(@NonNull ClickAction action, @NonNull String value) { - this.action = action; - this.value = value; - } - - public ClickAction getAction() { - return this.action; - } - - public String getValue() { - return this.value; - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/HoverAction.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/HoverAction.java deleted file mode 100644 index 616a99d4..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/HoverAction.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -public enum HoverAction { - SHOW_TEXT, - SHOW_ITEM, - SHOW_ENTITY; - - public static HoverAction byName(String name) { - String lowerCase = name.toLowerCase(); - for(HoverAction action : values()) { - if(action.toString().equals(lowerCase)) { - return action; - } - } - - return null; - } - - @Override - public String toString() { - return this.name().toLowerCase(); - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/HoverEvent.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/HoverEvent.java deleted file mode 100644 index 7e59e68d..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/HoverEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -import com.github.steveice10.mc.protocol.data.message.Message; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.ToString; - -@ToString -@EqualsAndHashCode -public class HoverEvent { - @NonNull - private final HoverAction action; - - private final Message contents; - - public HoverEvent(@NonNull HoverAction action, @NonNull Message contents) { - this.action = action; - this.contents = contents; - } - - public HoverAction getAction() { - return this.action; - } - - public Message getContents() { - return this.contents; - } -} diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/MessageStyle.java b/src/main/java/com/github/steveice10/mc/protocol/data/message/style/MessageStyle.java deleted file mode 100644 index f4a920bd..00000000 --- a/src/main/java/com/github/steveice10/mc/protocol/data/message/style/MessageStyle.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.github.steveice10.mc.protocol.data.message.style; - -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.ToString; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -@ToString -@EqualsAndHashCode -public class MessageStyle { - public static class Builder { - @NonNull - private String color = ChatColor.NONE; - @NonNull - private List formats = new ArrayList<>(); - private ClickEvent clickEvent; - private HoverEvent hoverEvent; - private String insertion; - - public Builder color(@NonNull String color) { - this.color = color; - return this; - } - - public Builder formats(@NonNull ChatFormat... formats) { - return this.formats(Arrays.asList(formats)); - } - - public Builder formats(@NonNull Collection formats) { - this.formats.addAll(formats); - return this; - } - - public Builder clickEvent(ClickEvent clickEvent) { - this.clickEvent = clickEvent; - return this; - } - - public Builder hoverEvent(HoverEvent hoverEvent) { - this.hoverEvent = hoverEvent; - return this; - } - - public Builder insertion(String insertion) { - this.insertion = insertion; - return this; - } - - public Builder copy(MessageStyle style) { - this.color = style.getColor(); - this.formats = new ArrayList<>(style.getFormats()); - this.clickEvent = style.getClickEvent(); - this.hoverEvent = style.getHoverEvent(); - this.insertion = style.getInsertion(); - return this; - } - - public MessageStyle build() { - return new MessageStyle(this.color, this.formats, this.clickEvent, this.hoverEvent, this.insertion); - } - } - - public static final MessageStyle DEFAULT = new MessageStyle.Builder().build(); - - private final String color; - private final List formats; - private final ClickEvent clickEvent; - private final HoverEvent hoverEvent; - private final String insertion; - - private MessageStyle(String color, List formats, ClickEvent clickEvent, HoverEvent hoverEvent, String insertion) { - this.color = color; - this.formats = Collections.unmodifiableList(formats); - this.clickEvent = clickEvent; - this.hoverEvent = hoverEvent; - this.insertion = insertion; - } - - public String getColor() { - return this.color; - } - - public List getFormats() { - return this.formats; - } - - public ClickEvent getClickEvent() { - return this.clickEvent; - } - - public HoverEvent getHoverEvent() { - return this.hoverEvent; - } - - public String getInsertion() { - return this.insertion; - } - - public Builder toBuilder() { - return new Builder().copy(this); - } -} \ No newline at end of file diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/status/ServerStatusInfo.java b/src/main/java/com/github/steveice10/mc/protocol/data/status/ServerStatusInfo.java index 4291c96c..67872897 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/status/ServerStatusInfo.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/status/ServerStatusInfo.java @@ -1,11 +1,11 @@ package com.github.steveice10.mc.protocol.data.status; -import com.github.steveice10.mc.protocol.data.message.Message; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; @Data @Setter(AccessLevel.NONE) @@ -13,6 +13,6 @@ import lombok.Setter; public class ServerStatusInfo { private @NonNull VersionInfo versionInfo; private @NonNull PlayerInfo playerInfo; - private @NonNull Message description; + private @NonNull Component description; private byte[] iconPng; } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientCraftingBookStatePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientCraftingBookStatePacket.java index dd725cab..3e363f85 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientCraftingBookStatePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientCraftingBookStatePacket.java @@ -5,7 +5,12 @@ import com.github.steveice10.mc.protocol.data.game.window.CraftingBookStateType; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; -import lombok.*; +import lombok.AccessLevel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; import java.io.IOException; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientDisplayedRecipePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientDisplayedRecipePacket.java index 8bf53316..e3907770 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientDisplayedRecipePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/client/window/ClientDisplayedRecipePacket.java @@ -3,7 +3,12 @@ package com.github.steveice10.mc.protocol.packet.ingame.client.window; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; -import lombok.*; +import lombok.AccessLevel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; import java.io.IOException; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java index ddb49650..e9389aef 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerAdvancementsPacket.java @@ -5,8 +5,6 @@ import com.github.steveice10.mc.protocol.data.game.advancement.Advancement; import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData; import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData.FrameType; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -16,6 +14,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.ArrayList; @@ -60,8 +60,8 @@ public class ServerAdvancementsPacket implements Packet { String parentId = in.readBoolean() ? in.readString() : null; DisplayData displayData = null; if(in.readBoolean()) { - Message title = MessageSerializer.fromString(in.readString()); - Message description = MessageSerializer.fromString(in.readString()); + Component title = GsonComponentSerializer.gson().deserialize(in.readString()); + Component description = GsonComponentSerializer.gson().deserialize(in.readString()); ItemStack icon = ItemStack.read(in); FrameType frameType = MagicValues.key(FrameType.class, in.readVarInt()); @@ -137,8 +137,8 @@ public class ServerAdvancementsPacket implements Packet { DisplayData displayData = advancement.getDisplayData(); if(displayData != null) { out.writeBoolean(true); - out.writeString(MessageSerializer.toJsonString(displayData.getTitle())); - out.writeString(MessageSerializer.toJsonString(displayData.getDescription())); + out.writeString(GsonComponentSerializer.gson().serialize(displayData.getTitle())); + out.writeString(GsonComponentSerializer.gson().serialize(displayData.getDescription())); ItemStack.write(out, displayData.getIcon()); out.writeVarInt(MagicValues.value(Integer.class, displayData.getFrameType())); String backgroundTexture = displayData.getBackgroundTexture(); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java index 07cd444c..a70ec526 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerBossBarPacket.java @@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.BossBarAction; import com.github.steveice10.mc.protocol.data.game.BossBarColor; import com.github.steveice10.mc.protocol.data.game.BossBarDivision; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -14,6 +12,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.UUID; @@ -25,7 +25,7 @@ public class ServerBossBarPacket implements Packet { private @NonNull UUID uuid; private @NonNull BossBarAction action; - private Message title; + private Component title; private float health; @@ -41,7 +41,7 @@ public class ServerBossBarPacket implements Packet { this.action = BossBarAction.REMOVE; } - public ServerBossBarPacket(@NonNull UUID uuid, @NonNull Message title) { + public ServerBossBarPacket(@NonNull UUID uuid, @NonNull Component title) { this.uuid = uuid; this.action = BossBarAction.UPDATE_TITLE; @@ -72,7 +72,7 @@ public class ServerBossBarPacket implements Packet { this.showFog = showFog; } - public ServerBossBarPacket(@NonNull UUID uuid, @NonNull Message title, float health, @NonNull BossBarColor color, + public ServerBossBarPacket(@NonNull UUID uuid, @NonNull Component title, float health, @NonNull BossBarColor color, @NonNull BossBarDivision division, boolean darkenSky, boolean playEndMusic, boolean showFog) { this.uuid = uuid; this.action = BossBarAction.ADD; @@ -92,7 +92,7 @@ public class ServerBossBarPacket implements Packet { this.action = MagicValues.key(BossBarAction.class, in.readVarInt()); if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) { - this.title = MessageSerializer.fromString(in.readString()); + this.title = GsonComponentSerializer.gson().deserialize(in.readString()); } if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) { @@ -118,7 +118,7 @@ public class ServerBossBarPacket implements Packet { out.writeVarInt(MagicValues.value(Integer.class, this.action)); if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) { - out.writeString(MessageSerializer.toJsonString(this.title)); + out.writeString(GsonComponentSerializer.gson().serialize(this.title)); } if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java index e2f38082..57f988d4 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerChatPacket.java @@ -2,9 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.server; import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.MessageType; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -14,6 +11,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.UUID; @@ -23,40 +22,40 @@ import java.util.UUID; @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor public class ServerChatPacket implements Packet { - private @NonNull Message message; + private @NonNull Component message; private @NonNull MessageType type; private @NonNull UUID senderUuid; public ServerChatPacket(@NonNull String text) { - this(MessageSerializer.fromString(text)); + this(GsonComponentSerializer.gson().deserialize(text)); } - public ServerChatPacket(@NonNull Message message) { + public ServerChatPacket(@NonNull Component message) { this(message, MessageType.SYSTEM); } public ServerChatPacket(@NonNull String text, @NonNull MessageType type) { - this(MessageSerializer.fromString(text), type, new UUID(0, 0)); + this(GsonComponentSerializer.gson().deserialize(text), type, new UUID(0, 0)); } - public ServerChatPacket(@NonNull Message message, @NonNull MessageType type) { + public ServerChatPacket(@NonNull Component message, @NonNull MessageType type) { this(message, type, new UUID(0, 0)); } public ServerChatPacket(@NonNull String text, @NonNull MessageType type, @NonNull UUID uuid) { - this(MessageSerializer.fromString(text), type, uuid); + this(GsonComponentSerializer.gson().deserialize(text), type, uuid); } @Override public void read(NetInput in) throws IOException { - this.message = MessageSerializer.fromString(in.readString()); + this.message = GsonComponentSerializer.gson().deserialize(in.readString()); this.type = MagicValues.key(MessageType.class, in.readByte()); this.senderUuid = in.readUUID(); } @Override public void write(NetOutput out) throws IOException { - out.writeString(MessageSerializer.toJsonString(this.message)); + out.writeString(GsonComponentSerializer.gson().serialize(this.message)); out.writeByte(MagicValues.value(Integer.class, this.type)); out.writeUUID(this.senderUuid); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java index 5d7ba813..b1e50ef7 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerCombatPacket.java @@ -2,8 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.server; import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.entity.player.CombatState; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -11,6 +9,8 @@ import lombok.AccessLevel; import lombok.Data; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -22,7 +22,7 @@ public class ServerCombatPacket implements Packet { private int entityId; private int duration; private int playerId; - private Message message; + private Component message; public ServerCombatPacket() { this.combatState = CombatState.ENTER_COMBAT; @@ -35,7 +35,7 @@ public class ServerCombatPacket implements Packet { this.duration = duration; } - public ServerCombatPacket(int entityId, int playerId, @NonNull Message message) { + public ServerCombatPacket(int entityId, int playerId, @NonNull Component message) { this.combatState = CombatState.ENTITY_DEAD; this.entityId = entityId; @@ -52,7 +52,7 @@ public class ServerCombatPacket implements Packet { } else if(this.combatState == CombatState.ENTITY_DEAD) { this.playerId = in.readVarInt(); this.entityId = in.readInt(); - this.message = MessageSerializer.fromString(in.readString()); + this.message = GsonComponentSerializer.gson().deserialize(in.readString()); } } @@ -65,7 +65,7 @@ public class ServerCombatPacket implements Packet { } else if(this.combatState == CombatState.ENTITY_DEAD) { out.writeVarInt(this.playerId); out.writeInt(this.entityId); - out.writeString(MessageSerializer.toJsonString(this.message)); + out.writeString(GsonComponentSerializer.gson().serialize(this.message)); } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDeclareRecipesPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDeclareRecipesPacket.java index 5b8141c4..00958657 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDeclareRecipesPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDeclareRecipesPacket.java @@ -6,7 +6,12 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient; import com.github.steveice10.mc.protocol.data.game.recipe.Recipe; import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType; -import com.github.steveice10.mc.protocol.data.game.recipe.data.*; +import com.github.steveice10.mc.protocol.data.game.recipe.data.CookedRecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.RecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapedRecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.SmithingRecipeData; +import com.github.steveice10.mc.protocol.data.game.recipe.data.StoneCuttingRecipeData; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java index 8150eb4c..d22e52f8 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerDisconnectPacket.java @@ -1,7 +1,5 @@ package com.github.steveice10.mc.protocol.packet.ingame.server; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -11,6 +9,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -19,20 +19,20 @@ import java.io.IOException; @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor public class ServerDisconnectPacket implements Packet { - private @NonNull Message reason; + private @NonNull Component reason; public ServerDisconnectPacket(@NonNull String reason) { - this(MessageSerializer.fromString(reason)); + this(GsonComponentSerializer.gson().deserialize(reason)); } @Override public void read(NetInput in) throws IOException { - this.reason = MessageSerializer.fromString(in.readString()); + this.reason = GsonComponentSerializer.gson().deserialize(in.readString()); } @Override public void write(NetOutput out) throws IOException { - out.writeString(MessageSerializer.toJsonString(this.reason)); + out.writeString(GsonComponentSerializer.gson().serialize(this.reason)); } @Override diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java index 93dc7c92..39a72332 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListDataPacket.java @@ -1,7 +1,5 @@ package com.github.steveice10.mc.protocol.packet.ingame.server; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -11,6 +9,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -19,19 +19,19 @@ import java.io.IOException; @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor public class ServerPlayerListDataPacket implements Packet { - private @NonNull Message header; - private @NonNull Message footer; + private @NonNull Component header; + private @NonNull Component footer; @Override public void read(NetInput in) throws IOException { - this.header = MessageSerializer.fromString(in.readString()); - this.footer = MessageSerializer.fromString(in.readString()); + this.header = GsonComponentSerializer.gson().deserialize(in.readString()); + this.footer = GsonComponentSerializer.gson().deserialize(in.readString()); } @Override public void write(NetOutput out) throws IOException { - out.writeString(MessageSerializer.toJsonString(this.header)); - out.writeString(MessageSerializer.toJsonString(this.footer)); + out.writeString(GsonComponentSerializer.gson().serialize(this.header)); + out.writeString(GsonComponentSerializer.gson().serialize(this.footer)); } @Override diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java index 26036bb8..5608876a 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerPlayerListEntryPacket.java @@ -5,8 +5,6 @@ import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.PlayerListEntry; import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -16,6 +14,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.ArrayList; @@ -64,9 +64,9 @@ public class ServerPlayerListEntryPacket implements Packet { int rawGameMode = in.readVarInt(); GameMode gameMode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0)); int ping = in.readVarInt(); - Message displayName = null; + Component displayName = null; if(in.readBoolean()) { - displayName = MessageSerializer.fromString(in.readString()); + displayName = GsonComponentSerializer.gson().deserialize(in.readString()); } entry = new PlayerListEntry(profile, gameMode, ping, displayName); @@ -86,9 +86,9 @@ public class ServerPlayerListEntryPacket implements Packet { break; } case UPDATE_DISPLAY_NAME: { - Message displayName = null; + Component displayName = null; if(in.readBoolean()) { - displayName = MessageSerializer.fromString(in.readString()); + displayName = GsonComponentSerializer.gson().deserialize(in.readString()); } entry = new PlayerListEntry(profile, displayName); @@ -126,7 +126,7 @@ public class ServerPlayerListEntryPacket implements Packet { out.writeVarInt(entry.getPing()); out.writeBoolean(entry.getDisplayName() != null); if(entry.getDisplayName() != null) { - out.writeString(MessageSerializer.toJsonString(entry.getDisplayName())); + out.writeString(GsonComponentSerializer.gson().serialize(entry.getDisplayName())); } break; @@ -139,7 +139,7 @@ public class ServerPlayerListEntryPacket implements Packet { case UPDATE_DISPLAY_NAME: out.writeBoolean(entry.getDisplayName() != null); if(entry.getDisplayName() != null) { - out.writeString(MessageSerializer.toJsonString(entry.getDisplayName())); + out.writeString(GsonComponentSerializer.gson().serialize(entry.getDisplayName())); } break; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java index 73ad255c..b9ce06e6 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTabCompletePacket.java @@ -1,7 +1,5 @@ package com.github.steveice10.mc.protocol.packet.ingame.server; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -10,6 +8,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.Arrays; @@ -22,9 +22,9 @@ public class ServerTabCompletePacket implements Packet { private int start; private int length; private @NonNull String[] matches; - private @NonNull Message[] tooltips; + private @NonNull Component[] tooltips; - public ServerTabCompletePacket(int transactionId, int start, int length, @NonNull String[] matches, @NonNull Message[] tooltips) { + public ServerTabCompletePacket(int transactionId, int start, int length, @NonNull String[] matches, @NonNull Component[] tooltips) { if(tooltips.length != matches.length) { throw new IllegalArgumentException("Length of matches and tooltips must be equal."); } @@ -42,11 +42,11 @@ public class ServerTabCompletePacket implements Packet { this.start = in.readVarInt(); this.length = in.readVarInt(); this.matches = new String[in.readVarInt()]; - this.tooltips = new Message[this.matches.length]; + this.tooltips = new Component[this.matches.length]; for(int index = 0; index < this.matches.length; index++) { this.matches[index] = in.readString(); if (in.readBoolean()) { - this.tooltips[index] = MessageSerializer.fromString(in.readString()); + this.tooltips[index] = GsonComponentSerializer.gson().deserialize(in.readString()); } } } @@ -59,10 +59,10 @@ public class ServerTabCompletePacket implements Packet { out.writeVarInt(this.matches.length); for(int index = 0; index < this.matches.length; index++) { out.writeString(this.matches[index]); - Message tooltip = this.tooltips[index]; + Component tooltip = this.tooltips[index]; if (tooltip != null) { out.writeBoolean(true); - out.writeString(MessageSerializer.toJsonString(tooltip)); + out.writeString(GsonComponentSerializer.gson().serialize(tooltip)); } else { out.writeBoolean(false); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java index c177e334..06517457 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/ServerTitlePacket.java @@ -2,8 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.server; import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.TitleAction; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -12,6 +10,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -21,7 +21,7 @@ import java.io.IOException; public class ServerTitlePacket implements Packet { private @NonNull TitleAction action; - private Message title; + private Component title; private int fadeIn; private int stay; @@ -35,13 +35,12 @@ public class ServerTitlePacket implements Packet { this.action = action; } - public ServerTitlePacket(TitleAction action, Message title) { + public ServerTitlePacket(TitleAction action, Component title) { if(action != TitleAction.TITLE && action != TitleAction.SUBTITLE && action != TitleAction.ACTION_BAR) { throw new IllegalArgumentException("Constructor (action, title) only accepts TITLE, SUBTITLE, and ACTION_BAR."); } this.action = action; - this.title = title; } @@ -60,7 +59,7 @@ public class ServerTitlePacket implements Packet { case TITLE: case SUBTITLE: case ACTION_BAR: - this.title = MessageSerializer.fromString(in.readString()); + this.title = GsonComponentSerializer.gson().deserialize(in.readString()); break; case TIMES: this.fadeIn = in.readInt(); @@ -80,7 +79,7 @@ public class ServerTitlePacket implements Packet { case TITLE: case SUBTITLE: case ACTION_BAR: - out.writeString(MessageSerializer.toJsonString(this.title)); + out.writeString(GsonComponentSerializer.gson().serialize(this.title)); break; case TIMES: out.writeInt(this.fadeIn); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java index 71037380..06026b04 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerScoreboardObjectivePacket.java @@ -3,8 +3,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard; import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction; import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreType; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -13,6 +11,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -23,7 +23,7 @@ public class ServerScoreboardObjectivePacket implements Packet { private @NonNull String name; private @NonNull ObjectiveAction action; - private Message displayName; + private Component displayName; private ScoreType type; public ServerScoreboardObjectivePacket(@NonNull String name) { @@ -31,7 +31,7 @@ public class ServerScoreboardObjectivePacket implements Packet { this.action = ObjectiveAction.REMOVE; } - public ServerScoreboardObjectivePacket(@NonNull String name, @NonNull ObjectiveAction action, @NonNull Message displayName, @NonNull ScoreType type) { + public ServerScoreboardObjectivePacket(@NonNull String name, @NonNull ObjectiveAction action, @NonNull Component displayName, @NonNull ScoreType type) { if(action != ObjectiveAction.ADD && action != ObjectiveAction.UPDATE) { throw new IllegalArgumentException("(name, action, displayName, type) constructor only valid for adding and updating objectives."); } @@ -47,7 +47,7 @@ public class ServerScoreboardObjectivePacket implements Packet { this.name = in.readString(); this.action = MagicValues.key(ObjectiveAction.class, in.readByte()); if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) { - this.displayName = MessageSerializer.fromString(in.readString()); + this.displayName = GsonComponentSerializer.gson().deserialize(in.readString()); this.type = MagicValues.key(ScoreType.class, in.readVarInt()); } } @@ -57,7 +57,7 @@ public class ServerScoreboardObjectivePacket implements Packet { out.writeString(this.name); out.writeByte(MagicValues.value(Integer.class, this.action)); if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) { - out.writeString(MessageSerializer.toJsonString(this.displayName)); + out.writeString(GsonComponentSerializer.gson().serialize(this.displayName)); out.writeVarInt(MagicValues.value(Integer.class, this.type)); } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java index 75d909ce..87f3ea18 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/scoreboard/ServerTeamPacket.java @@ -6,8 +6,6 @@ import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule; import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamAction; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -16,6 +14,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.util.Arrays; @@ -27,9 +27,9 @@ public class ServerTeamPacket implements Packet { private @NonNull String teamName; private @NonNull TeamAction action; - private Message displayName; - private Message prefix; - private Message suffix; + private Component displayName; + private Component prefix; + private Component suffix; private boolean friendlyFire; private boolean seeFriendlyInvisibles; private NameTagVisibility nameTagVisibility; @@ -43,7 +43,7 @@ public class ServerTeamPacket implements Packet { this.action = TeamAction.REMOVE; } - public ServerTeamPacket(@NonNull String teamName, @NonNull Message displayName, @NonNull Message prefix, @NonNull Message suffix, + public ServerTeamPacket(@NonNull String teamName, @NonNull Component displayName, @NonNull Component prefix, @NonNull Component suffix, boolean friendlyFire, boolean seeFriendlyInvisibles, @NonNull NameTagVisibility nameTagVisibility, @NonNull CollisionRule collisionRule, @NonNull TeamColor color) { this.teamName = teamName; @@ -70,7 +70,7 @@ public class ServerTeamPacket implements Packet { this.players = Arrays.copyOf(players, players.length); } - public ServerTeamPacket(@NonNull String teamName, @NonNull Message displayName, @NonNull Message prefix, @NonNull Message suffix, + public ServerTeamPacket(@NonNull String teamName, @NonNull Component displayName, @NonNull Component prefix, @NonNull Component suffix, boolean friendlyFire, boolean seeFriendlyInvisibles, @NonNull NameTagVisibility nameTagVisibility, @NonNull CollisionRule collisionRule, @NonNull TeamColor color, @NonNull String[] players) { this.teamName = teamName; @@ -93,7 +93,7 @@ public class ServerTeamPacket implements Packet { this.teamName = in.readString(); this.action = MagicValues.key(TeamAction.class, in.readByte()); if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { - this.displayName = MessageSerializer.fromString(in.readString()); + this.displayName = GsonComponentSerializer.gson().deserialize(in.readString()); byte flags = in.readByte(); this.friendlyFire = (flags & 0x1) != 0; this.seeFriendlyInvisibles = (flags & 0x2) != 0; @@ -106,8 +106,8 @@ public class ServerTeamPacket implements Packet { this.color = TeamColor.NONE; } - this.prefix = MessageSerializer.fromString(in.readString()); - this.suffix = MessageSerializer.fromString(in.readString()); + this.prefix = GsonComponentSerializer.gson().deserialize(in.readString()); + this.suffix = GsonComponentSerializer.gson().deserialize(in.readString()); } if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) { @@ -123,13 +123,13 @@ public class ServerTeamPacket implements Packet { out.writeString(this.teamName); out.writeByte(MagicValues.value(Integer.class, this.action)); if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { - out.writeString(MessageSerializer.toJsonString(this.displayName)); + out.writeString(GsonComponentSerializer.gson().serialize(this.displayName)); out.writeByte((this.friendlyFire ? 0x1 : 0x0) | (this.seeFriendlyInvisibles ? 0x2 : 0x0)); out.writeString(MagicValues.value(String.class, this.nameTagVisibility)); out.writeString(MagicValues.value(String.class, this.collisionRule)); out.writeVarInt(MagicValues.value(Integer.class, this.color)); - out.writeString(MessageSerializer.toJsonString(this.prefix)); - out.writeString(MessageSerializer.toJsonString(this.suffix)); + out.writeString(GsonComponentSerializer.gson().serialize(this.prefix)); + out.writeString(GsonComponentSerializer.gson().serialize(this.suffix)); } if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java index 742e7967..d7ccba9d 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/server/world/ServerMapDataPacket.java @@ -4,8 +4,6 @@ import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.game.world.map.MapData; import com.github.steveice10.mc.protocol.data.game.world.map.MapIcon; import com.github.steveice10.mc.protocol.data.game.world.map.MapIconType; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -15,6 +13,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -47,9 +47,9 @@ public class ServerMapDataPacket implements Packet { int x = in.readUnsignedByte(); int z = in.readUnsignedByte(); int rotation = in.readUnsignedByte(); - Message displayName = null; + Component displayName = null; if(in.readBoolean()) { - displayName = MessageSerializer.fromString(in.readString()); + displayName = GsonComponentSerializer.gson().deserialize(in.readString()); } this.icons[index] = new MapIcon(x, z, MagicValues.key(MapIconType.class, type), rotation, displayName); @@ -82,7 +82,7 @@ public class ServerMapDataPacket implements Packet { out.writeByte(icon.getIconRotation()); if (icon.getDisplayName() != null) { out.writeBoolean(false); - out.writeString(MessageSerializer.toJsonString(icon.getDisplayName())); + out.writeString(GsonComponentSerializer.gson().serialize(icon.getDisplayName())); } else { out.writeBoolean(true); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java index 4178294d..d4ada071 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacket.java @@ -1,7 +1,5 @@ package com.github.steveice10.mc.protocol.packet.login.server; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.packet.Packet; @@ -11,6 +9,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; @@ -19,20 +19,20 @@ import java.io.IOException; @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor public class LoginDisconnectPacket implements Packet { - private @NonNull Message reason; + private @NonNull Component reason; public LoginDisconnectPacket(String text) { - this(MessageSerializer.fromString(text)); + this(GsonComponentSerializer.gson().deserialize(text)); } @Override public void read(NetInput in) throws IOException { - this.reason = MessageSerializer.fromString(in.readString()); + this.reason = GsonComponentSerializer.gson().deserialize(in.readString()); } @Override public void write(NetOutput out) throws IOException { - out.writeString(MessageSerializer.toJsonString(this.reason)); + out.writeString(GsonComponentSerializer.gson().serialize(this.reason)); } @Override diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java index 3baa24a3..8184bdb8 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacket.java @@ -2,8 +2,6 @@ package com.github.steveice10.mc.protocol.packet.status.server; import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.util.Base64; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.MessageSerializer; import com.github.steveice10.mc.protocol.data.status.PlayerInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo; @@ -20,6 +18,8 @@ import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -51,7 +51,7 @@ public class StatusResponsePacket implements Packet { PlayerInfo players = new PlayerInfo(plrs.get("max").getAsInt(), plrs.get("online").getAsInt(), profiles); JsonElement desc = obj.get("description"); - Message description = MessageSerializer.fromJson(desc); + Component description = GsonComponentSerializer.gson().deserialize(desc.toString()); byte[] icon = null; if(obj.has("favicon")) { icon = this.stringToIcon(obj.get("favicon").getAsString()); @@ -83,7 +83,7 @@ public class StatusResponsePacket implements Packet { obj.add("version", ver); obj.add("players", plrs); - obj.add("description", MessageSerializer.toJson(this.info.getDescription())); + obj.add("description", new Gson().fromJson(GsonComponentSerializer.gson().serialize(this.info.getDescription()), JsonElement.class)); if(this.info.getIconPng() != null) { obj.addProperty("favicon", this.iconToString(this.info.getIconPng())); } diff --git a/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java b/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java index 8cfc0226..512447b1 100644 --- a/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java +++ b/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java @@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol; import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; -import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.data.status.PlayerInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo; @@ -23,6 +22,7 @@ import com.github.steveice10.packetlib.event.session.PacketReceivedEvent; import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpSessionFactory; +import net.kyori.adventure.text.Component; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -47,7 +47,7 @@ public class MinecraftProtocolTest { private static final ServerStatusInfo SERVER_INFO = new ServerStatusInfo( VersionInfo.CURRENT, new PlayerInfo(100, 0, new GameProfile[0]), - new TextMessage.Builder().text("Hello world!").build(), + Component.text("Hello world!"), null ); private static final ServerJoinGamePacket JOIN_GAME_PACKET = new ServerJoinGamePacket(0, false, GameMode.SURVIVAL, GameMode.SURVIVAL, 1, new String[]{"minecraft:world"}, getDimensionTag(), getOverworldTag(), "minecraft:world", 100, 0, 16, false, false, false, false); diff --git a/src/test/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacketTest.java b/src/test/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacketTest.java index 9c6066fc..ace445f2 100644 --- a/src/test/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacketTest.java +++ b/src/test/java/com/github/steveice10/mc/protocol/packet/login/server/LoginDisconnectPacketTest.java @@ -1,13 +1,13 @@ package com.github.steveice10.mc.protocol.packet.login.server; -import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.packet.PacketTest; +import net.kyori.adventure.text.Component; import org.junit.Before; public class LoginDisconnectPacketTest extends PacketTest { @Before public void setup() { this.setPackets(new LoginDisconnectPacket("Message"), - new LoginDisconnectPacket(new TextMessage.Builder().text("Message").build())); + new LoginDisconnectPacket(Component.text("Message"))); } } diff --git a/src/test/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacketTest.java b/src/test/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacketTest.java index f6c81149..412c6472 100644 --- a/src/test/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacketTest.java +++ b/src/test/java/com/github/steveice10/mc/protocol/packet/status/server/StatusResponsePacketTest.java @@ -1,11 +1,11 @@ package com.github.steveice10.mc.protocol.packet.status.server; import com.github.steveice10.mc.auth.data.GameProfile; -import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.github.steveice10.mc.protocol.data.status.PlayerInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo; import com.github.steveice10.mc.protocol.packet.PacketTest; +import net.kyori.adventure.text.Component; import org.junit.Before; import java.util.UUID; @@ -19,7 +19,7 @@ public class StatusResponsePacketTest extends PacketTest { new PlayerInfo(100, 10, new GameProfile[] { new GameProfile(UUID.randomUUID(), "Username") }), - new TextMessage.Builder().text("Description").build(), + Component.text("Description"), null ) ));