Don't use MagicValues for MessageType and fix player chat decoding

This commit is contained in:
Camotoy 2022-05-25 19:34:32 -04:00
parent 0a733c7139
commit 9255986c37
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
4 changed files with 7 additions and 15 deletions

View file

@ -4,7 +4,6 @@ import com.github.steveice10.mc.protocol.data.game.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
import com.github.steveice10.mc.protocol.data.game.ClientCommand;
import com.github.steveice10.mc.protocol.data.game.MessageType;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
import com.github.steveice10.mc.protocol.data.game.ResourcePackStatus;
import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
@ -161,15 +160,6 @@ public class MagicValues {
register(FillStackAction.FILL, 0);
register(MessageType.CHAT, 0);
register(MessageType.SYSTEM, 1);
register(MessageType.GAME_INFO, 2);
register(MessageType.SAY_COMMAND, 3);
register(MessageType.MSG_COMMAND, 4);
register(MessageType.TEAM_MSG_COMMAND, 5);
register(MessageType.EMOTE_COMMAND, 6);
register(MessageType.TELLRAW_COMMAND, 7);
register(GameMode.UNKNOWN, 255); // https://bugs.mojang.com/browse/MC-189885 - should be -1
register(GameMode.SURVIVAL, 0);
register(GameMode.CREATIVE, 1);

View file

@ -9,4 +9,6 @@ public enum MessageType {
TEAM_MSG_COMMAND,
EMOTE_COMMAND,
TELLRAW_COMMAND;
public static final MessageType[] VALUES = values();
}

View file

@ -37,7 +37,7 @@ public class ClientboundPlayerChatPacket implements Packet {
this.unsignedContent = null;
}
this.type = MagicValues.key(MessageType.class, in.readVarInt());
this.type = in.readEnum(MessageType.VALUES);
this.senderUUID = in.readUUID();
this.senderName = DefaultComponentSerializer.get().deserialize(in.readString());
if (in.readBoolean()) {
@ -46,9 +46,9 @@ public class ClientboundPlayerChatPacket implements Packet {
this.senderTeamName = null;
}
this.timeStamp = in.readLong();
this.salt = in.readLong();
this.signature = in.readBytes(in.readVarInt());
this.timeStamp = in.readLong();
}
@Override
@ -58,7 +58,7 @@ public class ClientboundPlayerChatPacket implements Packet {
DefaultComponentSerializer.get().serialize(this.unsignedContent);
}
out.writeVarInt(MagicValues.value(Integer.class, this.type));
out.writeEnum(this.type);
out.writeUUID(this.senderUUID);
DefaultComponentSerializer.get().serialize(this.senderName);
if (this.senderTeamName != null) {

View file

@ -22,12 +22,12 @@ public class ClientboundSystemChatPacket implements Packet {
public ClientboundSystemChatPacket(NetInput in) throws IOException {
this.content = DefaultComponentSerializer.get().deserialize(in.readString());
this.type = MagicValues.key(MessageType.class, in.readVarInt());
this.type = in.readEnum(MessageType.VALUES);
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(DefaultComponentSerializer.get().serialize(this.content));
out.writeVarInt(MagicValues.value(Integer.class, this.type));
out.writeEnum(this.type);
}
}