mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Rename MessageType; use Object2IntMap for Statistics
This commit is contained in:
parent
94b07ea44a
commit
54fc9f0750
8 changed files with 28 additions and 21 deletions
|
@ -10,7 +10,7 @@ import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
|||
import com.github.steveice10.mc.protocol.ServerLoginHandler;
|
||||
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||
import com.github.steveice10.mc.protocol.data.game.BuiltinChatType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
|
||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||
|
@ -125,7 +125,7 @@ public class MinecraftProtocolTest {
|
|||
.append(Component.text("!")
|
||||
.color(NamedTextColor.GREEN));
|
||||
|
||||
session.send(new ClientboundSystemChatPacket(msg, MessageType.SYSTEM.ordinal()));
|
||||
session.send(new ClientboundSystemChatPacket(msg, BuiltinChatType.SYSTEM.ordinal()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -123,6 +123,12 @@
|
|||
<version>1.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nukkitx.fastutil</groupId>
|
||||
<artifactId>fastutil-object-int-maps</artifactId>
|
||||
<version>8.5.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.codec;
|
|||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.BitStorage;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.ChunkSection;
|
||||
import com.github.steveice10.mc.protocol.data.game.chunk.DataPalette;
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.HashMap;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum MessageType {
|
||||
public enum BuiltinChatType {
|
||||
CHAT,
|
||||
SYSTEM,
|
||||
GAME_INFO,
|
||||
|
@ -16,24 +16,24 @@ public enum MessageType {
|
|||
|
||||
private final String resourceLocation;
|
||||
|
||||
MessageType() {
|
||||
BuiltinChatType() {
|
||||
this.resourceLocation = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public String getResourceLocation() {
|
||||
return resourceLocation;
|
||||
}
|
||||
private static final Map<String, MessageType> BY_RESOURCE_LOCATION;
|
||||
private static final Map<String, BuiltinChatType> BY_RESOURCE_LOCATION;
|
||||
|
||||
static {
|
||||
MessageType[] values = values();
|
||||
BuiltinChatType[] values = values();
|
||||
BY_RESOURCE_LOCATION = new HashMap<>(values.length);
|
||||
for (MessageType type : values) {
|
||||
for (BuiltinChatType type : values) {
|
||||
BY_RESOURCE_LOCATION.put(type.getResourceLocation(), type);
|
||||
}
|
||||
}
|
||||
|
||||
public static MessageType from(String resourceLocation) {
|
||||
public static BuiltinChatType from(String resourceLocation) {
|
||||
return BY_RESOURCE_LOCATION.get(resourceLocation);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
|||
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
||||
import com.github.steveice10.mc.protocol.data.game.statistic.*;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
|
@ -18,9 +20,9 @@ import java.util.Map;
|
|||
@With
|
||||
@AllArgsConstructor
|
||||
public class ClientboundAwardStatsPacket implements MinecraftPacket {
|
||||
private final @NonNull Map<Statistic, Integer> statistics = new HashMap<>(); //TODO Fastutil
|
||||
private final @NonNull Object2IntMap<Statistic> statistics = new Object2IntOpenHashMap<>();
|
||||
|
||||
public ClientboundAwardStatsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundAwardStatsPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
int length = helper.readVarInt(in);
|
||||
for (int index = 0; index < length; index++) {
|
||||
StatisticCategory category = helper.readStatisticCategory(in);
|
||||
|
@ -64,7 +66,7 @@ public class ClientboundAwardStatsPacket implements MinecraftPacket {
|
|||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
helper.writeVarInt(out, this.statistics.size());
|
||||
for (Map.Entry<Statistic, Integer> entry : statistics.entrySet()) {
|
||||
for (Object2IntMap.Entry<Statistic> entry : statistics.object2IntEntrySet()) {
|
||||
Statistic statistic = entry.getKey();
|
||||
|
||||
StatisticCategory category;
|
||||
|
@ -101,7 +103,7 @@ public class ClientboundAwardStatsPacket implements MinecraftPacket {
|
|||
}
|
||||
helper.writeStatisticCategory(out, category);
|
||||
helper.writeVarInt(out, statisticId);
|
||||
helper.writeVarInt(out, entry.getValue());
|
||||
helper.writeVarInt(out, entry.getIntValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
|||
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||
import com.github.steveice10.mc.protocol.data.game.BuiltinChatType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -22,7 +22,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
|
|||
private final Component signedContent;
|
||||
private final @Nullable Component unsignedContent;
|
||||
/**
|
||||
* Is {@link MessageType} defined in the order sent by the server in the login packet.
|
||||
* Is {@link BuiltinChatType} defined in the order sent by the server in the login packet.
|
||||
*/
|
||||
private final int typeId;
|
||||
private final UUID senderUUID;
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
|||
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||
import com.github.steveice10.mc.protocol.data.game.BuiltinChatType;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
@ -18,7 +18,7 @@ import java.io.IOException;
|
|||
public class ClientboundSystemChatPacket implements MinecraftPacket {
|
||||
private final Component content;
|
||||
/**
|
||||
* Is {@link MessageType} defined in the order sent by the server in the login packet.
|
||||
* Is {@link BuiltinChatType} defined in the order sent by the server in the login packet.
|
||||
*/
|
||||
private final int typeId;
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import lombok.With;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -14,13 +14,13 @@ import java.io.IOException;
|
|||
@With
|
||||
@AllArgsConstructor
|
||||
public class ServerboundChatPacket implements MinecraftPacket {
|
||||
private final @NonNull String message;
|
||||
private final @NotNull String message;
|
||||
private final long timeStamp;
|
||||
private final long salt;
|
||||
private final byte[] signature;
|
||||
private final byte @NotNull[] signature;
|
||||
private final boolean signedPreview;
|
||||
|
||||
public ServerboundChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ServerboundChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.message = helper.readString(in);
|
||||
this.timeStamp = in.readLong();
|
||||
this.salt = in.readLong();
|
||||
|
|
Loading…
Reference in a new issue