Merge branch 'master' of https://github.com/Steveice10/MCProtocolLib into feature/1.17

This commit is contained in:
DoctorMacc 2020-12-04 18:02:46 -05:00
commit 5e526ff01a
No known key found for this signature in database
GPG key ID: 6D6E7E059F186DB4
56 changed files with 201 additions and 1408 deletions

View file

@ -9,11 +9,6 @@ import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.mc.protocol.ServerLoginHandler; import com.github.steveice10.mc.protocol.ServerLoginHandler;
import com.github.steveice10.mc.protocol.data.SubProtocol; 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.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.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo; 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.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.tcp.TcpSessionFactory; 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.net.Proxy;
import java.util.Arrays; import java.util.Arrays;
@ -72,7 +70,7 @@ public class MinecraftProtocolTest {
return new ServerStatusInfo( return new ServerStatusInfo(
new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION), new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION),
new PlayerInfo(100, 0, new GameProfile[0]), new PlayerInfo(100, 0, new GameProfile[0]),
new TextMessage.Builder().text("Hello world!").build(), Component.text("Hello world!"),
null null
); );
} }
@ -119,26 +117,13 @@ public class MinecraftProtocolTest {
GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY); GameProfile profile = event.getSession().getFlag(MinecraftConstants.PROFILE_KEY);
System.out.println(profile.getName() + ": " + packet.getMessage()); System.out.println(profile.getName() + ": " + packet.getMessage());
MessageStyle green = new MessageStyle.Builder() Component msg = Component.text("Hello, ")
.color(ChatColor.GREEN) .color(NamedTextColor.GREEN)
.build(); .append(Component.text(profile.getName())
MessageStyle aquaUnderline = new MessageStyle.Builder() .color(NamedTextColor.AQUA)
.color(ChatColor.AQUA) .decorate(TextDecoration.UNDERLINED))
.formats(ChatFormat.UNDERLINED) .append(Component.text("!")
.build(); .color(NamedTextColor.GREEN));
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();
event.getSession().send(new ServerChatPacket(msg)); event.getSession().send(new ServerChatPacket(msg));
} }
@ -231,7 +216,7 @@ public class MinecraftProtocolTest {
if(event.getPacket() instanceof ServerJoinGamePacket) { if(event.getPacket() instanceof ServerJoinGamePacket) {
event.getSession().send(new ClientChatPacket("Hello, this is a test of MCProtocolLib.")); event.getSession().send(new ClientChatPacket("Hello, this is a test of MCProtocolLib."));
} else if(event.getPacket() instanceof ServerChatPacket) { } else if(event.getPacket() instanceof ServerChatPacket) {
Message message = event.<ServerChatPacket>getPacket().getMessage(); Component message = event.<ServerChatPacket>getPacket().getMessage();
System.out.println("Received Message: " + message); System.out.println("Received Message: " + message);
event.getSession().disconnect("Finished"); event.getSession().disconnect("Finished");
} }

View file

@ -71,6 +71,11 @@
<version>1.3</version> <version>1.3</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>4.2.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>

View file

@ -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.ClientClickWindowButtonPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; 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.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.ClientCraftingBookStatePacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket; 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.ClientEditBookPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientMoveItemToHotbarPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientMoveItemToHotbarPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientPrepareCraftingGridPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientPrepareCraftingGridPacket;

View file

@ -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.exception.request.RequestException;
import com.github.steveice10.mc.auth.service.SessionService; import com.github.steveice10.mc.auth.service.SessionService;
import com.github.steveice10.mc.protocol.data.SubProtocol; 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.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo; 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.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.PacketSentEvent; import com.github.steveice10.packetlib.event.session.PacketSentEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
import net.kyori.adventure.text.Component;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import java.security.KeyPair; import java.security.KeyPair;
@ -129,7 +129,7 @@ public class ServerListener extends SessionAdapter {
builder = session -> new ServerStatusInfo( builder = session -> new ServerStatusInfo(
VersionInfo.CURRENT, VersionInfo.CURRENT,
new PlayerInfo(0, 20, new GameProfile[0]), new PlayerInfo(0, 20, new GameProfile[0]),
new TextMessage.Builder().text("A Minecraft Server").build(), Component.text("A Minecraft Server"),
null null
); );
} }

View file

@ -0,0 +1,18 @@
package com.github.steveice10.mc.protocol.data;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
public final class DefaultComponentSerializer {
private static GsonComponentSerializer serializer = GsonComponentSerializer.gson();
public static GsonComponentSerializer get() {
return serializer;
}
public static void set(GsonComponentSerializer serializer) {
DefaultComponentSerializer.serializer = serializer;
}
private DefaultComponentSerializer() {
}
}

View file

@ -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.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; 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.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import net.kyori.adventure.text.Component;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -13,7 +13,7 @@ public class PlayerListEntry {
private final @NonNull GameProfile profile; private final @NonNull GameProfile profile;
private final GameMode gameMode; private final GameMode gameMode;
private final int ping; private final int ping;
private final Message displayName; private final Component displayName;
public PlayerListEntry(GameProfile profile) { public PlayerListEntry(GameProfile profile) {
this(profile, null, 0, null); this(profile, null, 0, null);
@ -27,7 +27,7 @@ public class PlayerListEntry {
this(profile, null, ping, null); this(profile, null, ping, null);
} }
public PlayerListEntry(GameProfile profile, Message displayName) { public PlayerListEntry(GameProfile profile, Component displayName) {
this(profile, null, 0, displayName); this(profile, null, 0, displayName);
} }
} }

View file

@ -1,10 +1,10 @@
package com.github.steveice10.mc.protocol.data.game.advancement; 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.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.message.Message;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import net.kyori.adventure.text.Component;
import java.util.List; import java.util.List;
@ -32,8 +32,8 @@ public class Advancement {
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public static class DisplayData { public static class DisplayData {
private final @NonNull Message title; private final @NonNull Component title;
private final @NonNull Message description; private final @NonNull Component description;
private final ItemStack icon; private final ItemStack icon;
private final @NonNull FrameType frameType; private final @NonNull FrameType frameType;
private final boolean showToast; private final boolean showToast;
@ -42,7 +42,7 @@ public class Advancement {
private final float posY; private final float posY;
private final String backgroundTexture; 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) { boolean showToast, boolean hidden, float posX, float posY) {
this(title, description, icon, frameType, showToast, hidden, posX, posY, null); this(title, description, icon, frameType, showToast, hidden, posX, posY, null);
} }

View file

@ -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.mc.protocol.data.game.chunk.palette.Palette;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; 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; import java.io.IOException;

View file

@ -1,19 +1,19 @@
package com.github.steveice10.mc.protocol.data.game.entity.metadata; package com.github.steveice10.mc.protocol.data.game.entity.metadata;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.NBT; import com.github.steveice10.mc.protocol.data.game.NBT;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; 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.Particle;
import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleData; 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.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.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -57,7 +57,7 @@ public class EntityMetadata {
// Intentional fall-through // Intentional fall-through
case CHAT: case CHAT:
value = MessageSerializer.fromString(in.readString()); value = DefaultComponentSerializer.get().deserialize(in.readString());
break; break;
case ITEM: case ITEM:
value = ItemStack.read(in); value = ItemStack.read(in);
@ -140,7 +140,7 @@ public class EntityMetadata {
// Intentional fall-through // Intentional fall-through
case CHAT: case CHAT:
out.writeString(MessageSerializer.toJsonString((Message) meta.getValue())); out.writeString(DefaultComponentSerializer.get().serialize((Component) meta.getValue()));
break; break;
case ITEM: case ITEM:
ItemStack.write(out, (ItemStack) meta.getValue()); ItemStack.write(out, (ItemStack) meta.getValue());

View file

@ -11,7 +11,7 @@ import lombok.NonNull;
public class CookedRecipeData implements RecipeData { public class CookedRecipeData implements RecipeData {
private final @NonNull String group; private final @NonNull String group;
private final @NonNull Ingredient ingredient; private final @NonNull Ingredient ingredient;
private final @NonNull ItemStack result; private final ItemStack result;
private final float experience; private final float experience;
private final int cookingTime; private final int cookingTime;
} }

View file

@ -13,5 +13,5 @@ public class ShapedRecipeData implements RecipeData {
private final int height; private final int height;
private final @NonNull String group; private final @NonNull String group;
private final @NonNull Ingredient[] ingredients; private final @NonNull Ingredient[] ingredients;
private final @NonNull ItemStack result; private final ItemStack result;
} }

View file

@ -11,5 +11,5 @@ import lombok.NonNull;
public class ShapelessRecipeData implements RecipeData { public class ShapelessRecipeData implements RecipeData {
private final @NonNull String group; private final @NonNull String group;
private final @NonNull Ingredient[] ingredients; private final @NonNull Ingredient[] ingredients;
private final @NonNull ItemStack result; private final ItemStack result;
} }

View file

@ -11,5 +11,5 @@ import lombok.NonNull;
public class SmithingRecipeData implements RecipeData { public class SmithingRecipeData implements RecipeData {
private final @NonNull Ingredient base; private final @NonNull Ingredient base;
private final @NonNull Ingredient addition; private final @NonNull Ingredient addition;
private final @NonNull ItemStack result; private final ItemStack result;
} }

View file

@ -11,5 +11,5 @@ import lombok.NonNull;
public class StoneCuttingRecipeData implements RecipeData { public class StoneCuttingRecipeData implements RecipeData {
private final @NonNull String group; private final @NonNull String group;
private final @NonNull Ingredient ingredient; private final @NonNull Ingredient ingredient;
private final @NonNull ItemStack result; private final ItemStack result;
} }

View file

@ -1,9 +1,9 @@
package com.github.steveice10.mc.protocol.data.game.world.map; package com.github.steveice10.mc.protocol.data.game.world.map;
import com.github.steveice10.mc.protocol.data.message.Message;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import net.kyori.adventure.text.Component;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@ -12,5 +12,5 @@ public class MapIcon {
private final int centerZ; private final int centerZ;
private final @NonNull MapIconType iconType; private final @NonNull MapIconType iconType;
private final int iconRotation; private final int iconRotation;
private final Message displayName; private final Component displayName;
} }

View file

@ -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<Builder, BlockNbtMessage> {
@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<Message> 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);
}
}

View file

@ -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<Builder, EntityHoverMessage> {
@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<Message> 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);
}
}

View file

@ -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<Builder, EntityNbtMessage> {
@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<Message> 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);
}
}

View file

@ -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<Builder, ItemHoverMessage> {
@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<Message> 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);
}
}

View file

@ -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<Builder, KeybindMessage> {
@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<Message> extra, String keybind) {
super(style, extra);
this.keybind = keybind;
}
public String getKeybind() {
return this.keybind;
}
@Override
public Builder toBuilder() {
return new Builder().copy(this);
}
}

View file

@ -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<B extends Builder<?, M>, M extends Message> {
@NonNull
protected MessageStyle style = MessageStyle.DEFAULT;
@NonNull
protected List<Message> 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<Message> 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<Message> extra;
protected Message(MessageStyle style, List<Message> extra) {
this.style = style;
this.extra = Collections.unmodifiableList(extra);
}
public MessageStyle getStyle() {
return this.style;
}
public List<Message> getExtra() {
return this.extra;
}
public abstract Builder<?, ?> toBuilder();
@Override
public String toString() {
return MessageSerializer.toJsonString(this);
}
}

View file

@ -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<Message> 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<Message> 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<Message> extraFromJson(JsonObject json) {
List<Message> 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<Message> extra) {
if(!extra.isEmpty()) {
JsonArray jsonExtra = new JsonArray();
for(Message msg : extra) {
jsonExtra.add(toJson(msg));
}
json.add("extra", jsonExtra);
}
}
}

View file

@ -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<B extends Builder<?, M>, M extends NbtMessage> extends Message.Builder<B, M> {
@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<Message> 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;
}
}

View file

@ -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<Builder, ScoreMessage> {
@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<Message> 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);
}
}

View file

@ -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<Builder, SelectorMessage> {
@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<Message> extra, String selector) {
super(style, extra);
this.selector = selector;
}
public String getSelector() {
return this.selector;
}
@Override
public Builder toBuilder() {
return new Builder().copy(this);
}
}

View file

@ -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<Builder, StorageNbtMessage> {
@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<Message> 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);
}
}

View file

@ -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<Builder, TextMessage> {
@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<Message> extra, String text) {
super(style, extra);
this.text = text;
}
public String getText() {
return this.text;
}
@Override
public Builder toBuilder() {
return new Builder().copy(this);
}
}

View file

@ -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<Builder, TranslationMessage> {
@NonNull
private String key = "";
@NonNull
private List<Message> 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<Message> 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<Message> with;
private TranslationMessage(MessageStyle style, List<Message> extra, String key, List<Message> with) {
super(style, extra);
this.key = key;
this.with = Collections.unmodifiableList(with);
}
public String getKey() {
return this.key;
}
public List<Message> getWith() {
return this.with;
}
@Override
public Builder toBuilder() {
return new Builder().copy(this);
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<ChatFormat> 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<ChatFormat> 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<ChatFormat> formats;
private final ClickEvent clickEvent;
private final HoverEvent hoverEvent;
private final String insertion;
private MessageStyle(String color, List<ChatFormat> 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<ChatFormat> 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);
}
}

View file

@ -1,11 +1,11 @@
package com.github.steveice10.mc.protocol.data.status; package com.github.steveice10.mc.protocol.data.status;
import com.github.steveice10.mc.protocol.data.message.Message;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
@Data @Data
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
@ -13,6 +13,6 @@ import lombok.Setter;
public class ServerStatusInfo { public class ServerStatusInfo {
private @NonNull VersionInfo versionInfo; private @NonNull VersionInfo versionInfo;
private @NonNull PlayerInfo playerInfo; private @NonNull PlayerInfo playerInfo;
private @NonNull Message description; private @NonNull Component description;
private byte[] iconPng; private byte[] iconPng;
} }

View file

@ -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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; 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; import java.io.IOException;

View file

@ -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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; 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; import java.io.IOException;

View file

@ -1,12 +1,11 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement; 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;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData.FrameType; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -16,6 +15,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -60,8 +60,8 @@ public class ServerAdvancementsPacket implements Packet {
String parentId = in.readBoolean() ? in.readString() : null; String parentId = in.readBoolean() ? in.readString() : null;
DisplayData displayData = null; DisplayData displayData = null;
if(in.readBoolean()) { if(in.readBoolean()) {
Message title = MessageSerializer.fromString(in.readString()); Component title = DefaultComponentSerializer.get().deserialize(in.readString());
Message description = MessageSerializer.fromString(in.readString()); Component description = DefaultComponentSerializer.get().deserialize(in.readString());
ItemStack icon = ItemStack.read(in); ItemStack icon = ItemStack.read(in);
FrameType frameType = MagicValues.key(FrameType.class, in.readVarInt()); FrameType frameType = MagicValues.key(FrameType.class, in.readVarInt());
@ -137,8 +137,8 @@ public class ServerAdvancementsPacket implements Packet {
DisplayData displayData = advancement.getDisplayData(); DisplayData displayData = advancement.getDisplayData();
if(displayData != null) { if(displayData != null) {
out.writeBoolean(true); out.writeBoolean(true);
out.writeString(MessageSerializer.toJsonString(displayData.getTitle())); out.writeString(DefaultComponentSerializer.get().serialize(displayData.getTitle()));
out.writeString(MessageSerializer.toJsonString(displayData.getDescription())); out.writeString(DefaultComponentSerializer.get().serialize(displayData.getDescription()));
ItemStack.write(out, displayData.getIcon()); ItemStack.write(out, displayData.getIcon());
out.writeVarInt(MagicValues.value(Integer.class, displayData.getFrameType())); out.writeVarInt(MagicValues.value(Integer.class, displayData.getFrameType()));
String backgroundTexture = displayData.getBackgroundTexture(); String backgroundTexture = displayData.getBackgroundTexture();

View file

@ -1,11 +1,10 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; 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.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -14,6 +13,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
@ -25,7 +25,7 @@ public class ServerBossBarPacket implements Packet {
private @NonNull UUID uuid; private @NonNull UUID uuid;
private @NonNull BossBarAction action; private @NonNull BossBarAction action;
private Message title; private Component title;
private float health; private float health;
@ -41,7 +41,7 @@ public class ServerBossBarPacket implements Packet {
this.action = BossBarAction.REMOVE; this.action = BossBarAction.REMOVE;
} }
public ServerBossBarPacket(@NonNull UUID uuid, @NonNull Message title) { public ServerBossBarPacket(@NonNull UUID uuid, @NonNull Component title) {
this.uuid = uuid; this.uuid = uuid;
this.action = BossBarAction.UPDATE_TITLE; this.action = BossBarAction.UPDATE_TITLE;
@ -72,7 +72,7 @@ public class ServerBossBarPacket implements Packet {
this.showFog = showFog; 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) { @NonNull BossBarDivision division, boolean darkenSky, boolean playEndMusic, boolean showFog) {
this.uuid = uuid; this.uuid = uuid;
this.action = BossBarAction.ADD; this.action = BossBarAction.ADD;
@ -92,7 +92,7 @@ public class ServerBossBarPacket implements Packet {
this.action = MagicValues.key(BossBarAction.class, in.readVarInt()); this.action = MagicValues.key(BossBarAction.class, in.readVarInt());
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) { if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
this.title = MessageSerializer.fromString(in.readString()); this.title = DefaultComponentSerializer.get().deserialize(in.readString());
} }
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) { 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)); out.writeVarInt(MagicValues.value(Integer.class, this.action));
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) { if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
out.writeString(MessageSerializer.toJsonString(this.title)); out.writeString(DefaultComponentSerializer.get().serialize(this.title));
} }
if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) { if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {

View file

@ -1,10 +1,8 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.MessageType; 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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -14,6 +12,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.UUID; import java.util.UUID;
@ -23,40 +22,40 @@ import java.util.UUID;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor @AllArgsConstructor
public class ServerChatPacket implements Packet { public class ServerChatPacket implements Packet {
private @NonNull Message message; private @NonNull Component message;
private @NonNull MessageType type; private @NonNull MessageType type;
private @NonNull UUID senderUuid; private @NonNull UUID senderUuid;
public ServerChatPacket(@NonNull String text) { public ServerChatPacket(@NonNull String text) {
this(MessageSerializer.fromString(text)); this(DefaultComponentSerializer.get().deserialize(text));
} }
public ServerChatPacket(@NonNull Message message) { public ServerChatPacket(@NonNull Component message) {
this(message, MessageType.SYSTEM); this(message, MessageType.SYSTEM);
} }
public ServerChatPacket(@NonNull String text, @NonNull MessageType type) { public ServerChatPacket(@NonNull String text, @NonNull MessageType type) {
this(MessageSerializer.fromString(text), type, new UUID(0, 0)); this(DefaultComponentSerializer.get().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)); this(message, type, new UUID(0, 0));
} }
public ServerChatPacket(@NonNull String text, @NonNull MessageType type, @NonNull UUID uuid) { public ServerChatPacket(@NonNull String text, @NonNull MessageType type, @NonNull UUID uuid) {
this(MessageSerializer.fromString(text), type, uuid); this(DefaultComponentSerializer.get().deserialize(text), type, uuid);
} }
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.message = MessageSerializer.fromString(in.readString()); this.message = DefaultComponentSerializer.get().deserialize(in.readString());
this.type = MagicValues.key(MessageType.class, in.readByte()); this.type = MagicValues.key(MessageType.class, in.readByte());
this.senderUuid = in.readUUID(); this.senderUuid = in.readUUID();
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
out.writeString(MessageSerializer.toJsonString(this.message)); out.writeString(DefaultComponentSerializer.get().serialize(this.message));
out.writeByte(MagicValues.value(Integer.class, this.type)); out.writeByte(MagicValues.value(Integer.class, this.type));
out.writeUUID(this.senderUuid); out.writeUUID(this.senderUuid);
} }

View file

@ -1,9 +1,8 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -11,6 +10,7 @@ import lombok.AccessLevel;
import lombok.Data; import lombok.Data;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -22,7 +22,7 @@ public class ServerCombatPacket implements Packet {
private int entityId; private int entityId;
private int duration; private int duration;
private int playerId; private int playerId;
private Message message; private Component message;
public ServerCombatPacket() { public ServerCombatPacket() {
this.combatState = CombatState.ENTER_COMBAT; this.combatState = CombatState.ENTER_COMBAT;
@ -35,7 +35,7 @@ public class ServerCombatPacket implements Packet {
this.duration = duration; 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.combatState = CombatState.ENTITY_DEAD;
this.entityId = entityId; this.entityId = entityId;
@ -52,7 +52,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.combatState == CombatState.ENTITY_DEAD) { } else if(this.combatState == CombatState.ENTITY_DEAD) {
this.playerId = in.readVarInt(); this.playerId = in.readVarInt();
this.entityId = in.readInt(); this.entityId = in.readInt();
this.message = MessageSerializer.fromString(in.readString()); this.message = DefaultComponentSerializer.get().deserialize(in.readString());
} }
} }
@ -65,7 +65,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.combatState == CombatState.ENTITY_DEAD) { } else if(this.combatState == CombatState.ENTITY_DEAD) {
out.writeVarInt(this.playerId); out.writeVarInt(this.playerId);
out.writeInt(this.entityId); out.writeInt(this.entityId);
out.writeString(MessageSerializer.toJsonString(this.message)); out.writeString(DefaultComponentSerializer.get().serialize(this.message));
} }
} }

View file

@ -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.Ingredient;
import com.github.steveice10.mc.protocol.data.game.recipe.Recipe; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;

View file

@ -1,7 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; 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.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -11,6 +10,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -19,20 +19,20 @@ import java.io.IOException;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor @AllArgsConstructor
public class ServerDisconnectPacket implements Packet { public class ServerDisconnectPacket implements Packet {
private @NonNull Message reason; private @NonNull Component reason;
public ServerDisconnectPacket(@NonNull String reason) { public ServerDisconnectPacket(@NonNull String reason) {
this(MessageSerializer.fromString(reason)); this(DefaultComponentSerializer.get().deserialize(reason));
} }
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.reason = MessageSerializer.fromString(in.readString()); this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
out.writeString(MessageSerializer.toJsonString(this.reason)); out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
} }
@Override @Override

View file

@ -1,7 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; 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.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -11,6 +10,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -19,19 +19,19 @@ import java.io.IOException;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor @AllArgsConstructor
public class ServerPlayerListDataPacket implements Packet { public class ServerPlayerListDataPacket implements Packet {
private @NonNull Message header; private @NonNull Component header;
private @NonNull Message footer; private @NonNull Component footer;
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.header = MessageSerializer.fromString(in.readString()); this.header = DefaultComponentSerializer.get().deserialize(in.readString());
this.footer = MessageSerializer.fromString(in.readString()); this.footer = DefaultComponentSerializer.get().deserialize(in.readString());
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
out.writeString(MessageSerializer.toJsonString(this.header)); out.writeString(DefaultComponentSerializer.get().serialize(this.header));
out.writeString(MessageSerializer.toJsonString(this.footer)); out.writeString(DefaultComponentSerializer.get().serialize(this.footer));
} }
@Override @Override

View file

@ -1,12 +1,11 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; 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.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -16,6 +15,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -64,9 +64,9 @@ public class ServerPlayerListEntryPacket implements Packet {
int rawGameMode = in.readVarInt(); int rawGameMode = in.readVarInt();
GameMode gameMode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0)); GameMode gameMode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0));
int ping = in.readVarInt(); int ping = in.readVarInt();
Message displayName = null; Component displayName = null;
if(in.readBoolean()) { if(in.readBoolean()) {
displayName = MessageSerializer.fromString(in.readString()); displayName = DefaultComponentSerializer.get().deserialize(in.readString());
} }
entry = new PlayerListEntry(profile, gameMode, ping, displayName); entry = new PlayerListEntry(profile, gameMode, ping, displayName);
@ -86,9 +86,9 @@ public class ServerPlayerListEntryPacket implements Packet {
break; break;
} }
case UPDATE_DISPLAY_NAME: { case UPDATE_DISPLAY_NAME: {
Message displayName = null; Component displayName = null;
if(in.readBoolean()) { if(in.readBoolean()) {
displayName = MessageSerializer.fromString(in.readString()); displayName = DefaultComponentSerializer.get().deserialize(in.readString());
} }
entry = new PlayerListEntry(profile, displayName); entry = new PlayerListEntry(profile, displayName);
@ -126,7 +126,7 @@ public class ServerPlayerListEntryPacket implements Packet {
out.writeVarInt(entry.getPing()); out.writeVarInt(entry.getPing());
out.writeBoolean(entry.getDisplayName() != null); out.writeBoolean(entry.getDisplayName() != null);
if(entry.getDisplayName() != null) { if(entry.getDisplayName() != null) {
out.writeString(MessageSerializer.toJsonString(entry.getDisplayName())); out.writeString(DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
} }
break; break;
@ -139,7 +139,7 @@ public class ServerPlayerListEntryPacket implements Packet {
case UPDATE_DISPLAY_NAME: case UPDATE_DISPLAY_NAME:
out.writeBoolean(entry.getDisplayName() != null); out.writeBoolean(entry.getDisplayName() != null);
if(entry.getDisplayName() != null) { if(entry.getDisplayName() != null) {
out.writeString(MessageSerializer.toJsonString(entry.getDisplayName())); out.writeString(DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
} }
break; break;

View file

@ -1,7 +1,6 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; 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.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -10,6 +9,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -22,9 +22,9 @@ public class ServerTabCompletePacket implements Packet {
private int start; private int start;
private int length; private int length;
private @NonNull String[] matches; 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) { if(tooltips.length != matches.length) {
throw new IllegalArgumentException("Length of matches and tooltips must be equal."); 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.start = in.readVarInt();
this.length = in.readVarInt(); this.length = in.readVarInt();
this.matches = new String[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++) { for(int index = 0; index < this.matches.length; index++) {
this.matches[index] = in.readString(); this.matches[index] = in.readString();
if (in.readBoolean()) { if (in.readBoolean()) {
this.tooltips[index] = MessageSerializer.fromString(in.readString()); this.tooltips[index] = DefaultComponentSerializer.get().deserialize(in.readString());
} }
} }
} }
@ -59,10 +59,10 @@ public class ServerTabCompletePacket implements Packet {
out.writeVarInt(this.matches.length); out.writeVarInt(this.matches.length);
for(int index = 0; index < this.matches.length; index++) { for(int index = 0; index < this.matches.length; index++) {
out.writeString(this.matches[index]); out.writeString(this.matches[index]);
Message tooltip = this.tooltips[index]; Component tooltip = this.tooltips[index];
if (tooltip != null) { if (tooltip != null) {
out.writeBoolean(true); out.writeBoolean(true);
out.writeString(MessageSerializer.toJsonString(tooltip)); out.writeString(DefaultComponentSerializer.get().serialize(tooltip));
} else { } else {
out.writeBoolean(false); out.writeBoolean(false);
} }

View file

@ -1,9 +1,8 @@
package com.github.steveice10.mc.protocol.packet.ingame.server; package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.TitleAction; 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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -12,6 +11,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -21,7 +21,7 @@ import java.io.IOException;
public class ServerTitlePacket implements Packet { public class ServerTitlePacket implements Packet {
private @NonNull TitleAction action; private @NonNull TitleAction action;
private Message title; private Component title;
private int fadeIn; private int fadeIn;
private int stay; private int stay;
@ -35,13 +35,12 @@ public class ServerTitlePacket implements Packet {
this.action = action; 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) { if(action != TitleAction.TITLE && action != TitleAction.SUBTITLE && action != TitleAction.ACTION_BAR) {
throw new IllegalArgumentException("Constructor (action, title) only accepts TITLE, SUBTITLE, and ACTION_BAR."); throw new IllegalArgumentException("Constructor (action, title) only accepts TITLE, SUBTITLE, and ACTION_BAR.");
} }
this.action = action; this.action = action;
this.title = title; this.title = title;
} }
@ -60,7 +59,7 @@ public class ServerTitlePacket implements Packet {
case TITLE: case TITLE:
case SUBTITLE: case SUBTITLE:
case ACTION_BAR: case ACTION_BAR:
this.title = MessageSerializer.fromString(in.readString()); this.title = DefaultComponentSerializer.get().deserialize(in.readString());
break; break;
case TIMES: case TIMES:
this.fadeIn = in.readInt(); this.fadeIn = in.readInt();
@ -80,7 +79,7 @@ public class ServerTitlePacket implements Packet {
case TITLE: case TITLE:
case SUBTITLE: case SUBTITLE:
case ACTION_BAR: case ACTION_BAR:
out.writeString(MessageSerializer.toJsonString(this.title)); out.writeString(DefaultComponentSerializer.get().serialize(this.title));
break; break;
case TIMES: case TIMES:
out.writeInt(this.fadeIn); out.writeInt(this.fadeIn);

View file

@ -1,10 +1,9 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard; package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; 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.ObjectiveAction;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreType; 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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -13,6 +12,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -23,7 +23,7 @@ public class ServerScoreboardObjectivePacket implements Packet {
private @NonNull String name; private @NonNull String name;
private @NonNull ObjectiveAction action; private @NonNull ObjectiveAction action;
private Message displayName; private Component displayName;
private ScoreType type; private ScoreType type;
public ServerScoreboardObjectivePacket(@NonNull String name) { public ServerScoreboardObjectivePacket(@NonNull String name) {
@ -31,7 +31,7 @@ public class ServerScoreboardObjectivePacket implements Packet {
this.action = ObjectiveAction.REMOVE; 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) { if(action != ObjectiveAction.ADD && action != ObjectiveAction.UPDATE) {
throw new IllegalArgumentException("(name, action, displayName, type) constructor only valid for adding and updating objectives."); 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.name = in.readString();
this.action = MagicValues.key(ObjectiveAction.class, in.readByte()); this.action = MagicValues.key(ObjectiveAction.class, in.readByte());
if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) { if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
this.displayName = MessageSerializer.fromString(in.readString()); this.displayName = DefaultComponentSerializer.get().deserialize(in.readString());
this.type = MagicValues.key(ScoreType.class, in.readVarInt()); this.type = MagicValues.key(ScoreType.class, in.readVarInt());
} }
} }
@ -57,7 +57,7 @@ public class ServerScoreboardObjectivePacket implements Packet {
out.writeString(this.name); out.writeString(this.name);
out.writeByte(MagicValues.value(Integer.class, this.action)); out.writeByte(MagicValues.value(Integer.class, this.action));
if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) { if(this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
out.writeString(MessageSerializer.toJsonString(this.displayName)); out.writeString(DefaultComponentSerializer.get().serialize(this.displayName));
out.writeVarInt(MagicValues.value(Integer.class, this.type)); out.writeVarInt(MagicValues.value(Integer.class, this.type));
} }
} }

View file

@ -1,13 +1,12 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard; package com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.UnmappedValueException; import com.github.steveice10.mc.protocol.data.UnmappedValueException;
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule; 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.NameTagVisibility;
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamAction; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -16,6 +15,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -27,9 +27,9 @@ public class ServerTeamPacket implements Packet {
private @NonNull String teamName; private @NonNull String teamName;
private @NonNull TeamAction action; private @NonNull TeamAction action;
private Message displayName; private Component displayName;
private Message prefix; private Component prefix;
private Message suffix; private Component suffix;
private boolean friendlyFire; private boolean friendlyFire;
private boolean seeFriendlyInvisibles; private boolean seeFriendlyInvisibles;
private NameTagVisibility nameTagVisibility; private NameTagVisibility nameTagVisibility;
@ -43,7 +43,7 @@ public class ServerTeamPacket implements Packet {
this.action = TeamAction.REMOVE; 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, boolean friendlyFire, boolean seeFriendlyInvisibles, @NonNull NameTagVisibility nameTagVisibility,
@NonNull CollisionRule collisionRule, @NonNull TeamColor color) { @NonNull CollisionRule collisionRule, @NonNull TeamColor color) {
this.teamName = teamName; this.teamName = teamName;
@ -70,7 +70,7 @@ public class ServerTeamPacket implements Packet {
this.players = Arrays.copyOf(players, players.length); 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, boolean friendlyFire, boolean seeFriendlyInvisibles, @NonNull NameTagVisibility nameTagVisibility,
@NonNull CollisionRule collisionRule, @NonNull TeamColor color, @NonNull String[] players) { @NonNull CollisionRule collisionRule, @NonNull TeamColor color, @NonNull String[] players) {
this.teamName = teamName; this.teamName = teamName;
@ -93,7 +93,7 @@ public class ServerTeamPacket implements Packet {
this.teamName = in.readString(); this.teamName = in.readString();
this.action = MagicValues.key(TeamAction.class, in.readByte()); this.action = MagicValues.key(TeamAction.class, in.readByte());
if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
this.displayName = MessageSerializer.fromString(in.readString()); this.displayName = DefaultComponentSerializer.get().deserialize(in.readString());
byte flags = in.readByte(); byte flags = in.readByte();
this.friendlyFire = (flags & 0x1) != 0; this.friendlyFire = (flags & 0x1) != 0;
this.seeFriendlyInvisibles = (flags & 0x2) != 0; this.seeFriendlyInvisibles = (flags & 0x2) != 0;
@ -106,8 +106,8 @@ public class ServerTeamPacket implements Packet {
this.color = TeamColor.NONE; this.color = TeamColor.NONE;
} }
this.prefix = MessageSerializer.fromString(in.readString()); this.prefix = DefaultComponentSerializer.get().deserialize(in.readString());
this.suffix = MessageSerializer.fromString(in.readString()); this.suffix = DefaultComponentSerializer.get().deserialize(in.readString());
} }
if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) { 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.writeString(this.teamName);
out.writeByte(MagicValues.value(Integer.class, this.action)); out.writeByte(MagicValues.value(Integer.class, this.action));
if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { if(this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
out.writeString(MessageSerializer.toJsonString(this.displayName)); out.writeString(DefaultComponentSerializer.get().serialize(this.displayName));
out.writeByte((this.friendlyFire ? 0x1 : 0x0) | (this.seeFriendlyInvisibles ? 0x2 : 0x0)); 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.nameTagVisibility));
out.writeString(MagicValues.value(String.class, this.collisionRule)); out.writeString(MagicValues.value(String.class, this.collisionRule));
out.writeVarInt(MagicValues.value(Integer.class, this.color)); out.writeVarInt(MagicValues.value(Integer.class, this.color));
out.writeString(MessageSerializer.toJsonString(this.prefix)); out.writeString(DefaultComponentSerializer.get().serialize(this.prefix));
out.writeString(MessageSerializer.toJsonString(this.suffix)); out.writeString(DefaultComponentSerializer.get().serialize(this.suffix));
} }
if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) { if(this.action == TeamAction.CREATE || this.action == TeamAction.ADD_PLAYER || this.action == TeamAction.REMOVE_PLAYER) {

View file

@ -1,11 +1,10 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.world; package com.github.steveice10.mc.protocol.packet.ingame.server.world;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues; 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.MapData;
import com.github.steveice10.mc.protocol.data.game.world.map.MapIcon; 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.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.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -15,6 +14,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -47,9 +47,9 @@ public class ServerMapDataPacket implements Packet {
int x = in.readUnsignedByte(); int x = in.readUnsignedByte();
int z = in.readUnsignedByte(); int z = in.readUnsignedByte();
int rotation = in.readUnsignedByte(); int rotation = in.readUnsignedByte();
Message displayName = null; Component displayName = null;
if(in.readBoolean()) { if(in.readBoolean()) {
displayName = MessageSerializer.fromString(in.readString()); displayName = DefaultComponentSerializer.get().deserialize(in.readString());
} }
this.icons[index] = new MapIcon(x, z, MagicValues.key(MapIconType.class, type), rotation, displayName); this.icons[index] = new MapIcon(x, z, MagicValues.key(MapIconType.class, type), rotation, displayName);
@ -75,6 +75,7 @@ public class ServerMapDataPacket implements Packet {
out.writeByte(this.scale); out.writeByte(this.scale);
out.writeBoolean(this.trackingPosition); out.writeBoolean(this.trackingPosition);
out.writeBoolean(this.locked); out.writeBoolean(this.locked);
<<<<<<< HEAD
if(this.trackingPosition) { if(this.trackingPosition) {
out.writeVarInt(this.icons.length); out.writeVarInt(this.icons.length);
for(int index = 0; index < this.icons.length; index++) { for(int index = 0; index < this.icons.length; index++) {
@ -90,6 +91,21 @@ public class ServerMapDataPacket implements Packet {
} else { } else {
out.writeBoolean(true); out.writeBoolean(true);
} }
=======
out.writeVarInt(this.icons.length);
for(int index = 0; index < this.icons.length; index++) {
MapIcon icon = this.icons[index];
int type = MagicValues.value(Integer.class, icon.getIconType());
out.writeVarInt(type);
out.writeByte(icon.getCenterX());
out.writeByte(icon.getCenterZ());
out.writeByte(icon.getIconRotation());
if (icon.getDisplayName() != null) {
out.writeBoolean(false);
out.writeString(DefaultComponentSerializer.get().serialize(icon.getDisplayName()));
} else {
out.writeBoolean(true);
>>>>>>> fa0aaccb611429a19e5df66016b3d99a95304888
} }
} }

View file

@ -1,7 +1,6 @@
package com.github.steveice10.mc.protocol.packet.login.server; 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.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.message.MessageSerializer;
import com.github.steveice10.packetlib.io.NetInput; import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput; import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
@ -11,6 +10,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
@ -19,20 +19,20 @@ import java.io.IOException;
@NoArgsConstructor(access = AccessLevel.PRIVATE) @NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor @AllArgsConstructor
public class LoginDisconnectPacket implements Packet { public class LoginDisconnectPacket implements Packet {
private @NonNull Message reason; private @NonNull Component reason;
public LoginDisconnectPacket(String text) { public LoginDisconnectPacket(String text) {
this(MessageSerializer.fromString(text)); this(DefaultComponentSerializer.get().deserialize(text));
} }
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.reason = MessageSerializer.fromString(in.readString()); this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
out.writeString(MessageSerializer.toJsonString(this.reason)); out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
} }
@Override @Override

View file

@ -2,8 +2,7 @@ package com.github.steveice10.mc.protocol.packet.status.server;
import com.github.steveice10.mc.auth.data.GameProfile; import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.auth.util.Base64; import com.github.steveice10.mc.auth.util.Base64;
import com.github.steveice10.mc.protocol.data.message.Message; import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
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.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo;
@ -20,6 +19,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import net.kyori.adventure.text.Component;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; 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); PlayerInfo players = new PlayerInfo(plrs.get("max").getAsInt(), plrs.get("online").getAsInt(), profiles);
JsonElement desc = obj.get("description"); JsonElement desc = obj.get("description");
Message description = MessageSerializer.fromJson(desc); Component description = DefaultComponentSerializer.get().deserialize(desc.toString());
byte[] icon = null; byte[] icon = null;
if(obj.has("favicon")) { if(obj.has("favicon")) {
icon = this.stringToIcon(obj.get("favicon").getAsString()); icon = this.stringToIcon(obj.get("favicon").getAsString());
@ -83,7 +83,7 @@ public class StatusResponsePacket implements Packet {
obj.add("version", ver); obj.add("version", ver);
obj.add("players", plrs); obj.add("players", plrs);
obj.add("description", MessageSerializer.toJson(this.info.getDescription())); obj.add("description", new Gson().fromJson(DefaultComponentSerializer.get().serialize(this.info.getDescription()), JsonElement.class));
if(this.info.getIconPng() != null) { if(this.info.getIconPng() != null) {
obj.addProperty("favicon", this.iconToString(this.info.getIconPng())); obj.addProperty("favicon", this.iconToString(this.info.getIconPng()));
} }

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol;
import com.github.steveice10.mc.auth.data.GameProfile; 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.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.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo; 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.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
import net.kyori.adventure.text.Component;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -47,7 +47,7 @@ public class MinecraftProtocolTest {
private static final ServerStatusInfo SERVER_INFO = new ServerStatusInfo( private static final ServerStatusInfo SERVER_INFO = new ServerStatusInfo(
VersionInfo.CURRENT, VersionInfo.CURRENT,
new PlayerInfo(100, 0, new GameProfile[0]), new PlayerInfo(100, 0, new GameProfile[0]),
new TextMessage.Builder().text("Hello world!").build(), Component.text("Hello world!"),
null 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); 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);

View file

@ -1,13 +1,13 @@
package com.github.steveice10.mc.protocol.packet.login.server; 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 com.github.steveice10.mc.protocol.packet.PacketTest;
import net.kyori.adventure.text.Component;
import org.junit.Before; import org.junit.Before;
public class LoginDisconnectPacketTest extends PacketTest { public class LoginDisconnectPacketTest extends PacketTest {
@Before @Before
public void setup() { public void setup() {
this.setPackets(new LoginDisconnectPacket("Message"), this.setPackets(new LoginDisconnectPacket("Message"),
new LoginDisconnectPacket(new TextMessage.Builder().text("Message").build())); new LoginDisconnectPacket(Component.text("Message")));
} }
} }

View file

@ -1,11 +1,11 @@
package com.github.steveice10.mc.protocol.packet.status.server; package com.github.steveice10.mc.protocol.packet.status.server;
import com.github.steveice10.mc.auth.data.GameProfile; 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.PlayerInfo;
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo; import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.github.steveice10.mc.protocol.data.status.VersionInfo; import com.github.steveice10.mc.protocol.data.status.VersionInfo;
import com.github.steveice10.mc.protocol.packet.PacketTest; import com.github.steveice10.mc.protocol.packet.PacketTest;
import net.kyori.adventure.text.Component;
import org.junit.Before; import org.junit.Before;
import java.util.UUID; import java.util.UUID;
@ -19,7 +19,7 @@ public class StatusResponsePacketTest extends PacketTest {
new PlayerInfo(100, 10, new GameProfile[] { new PlayerInfo(100, 10, new GameProfile[] {
new GameProfile(UUID.randomUUID(), "Username") new GameProfile(UUID.randomUUID(), "Username")
}), }),
new TextMessage.Builder().text("Description").build(), Component.text("Description"),
null null
) )
)); ));