Added spawn position and dimension in condifgration. Added color codes conversion. PlayerInfo packet

This commit is contained in:
Nanit
2020-11-27 00:08:42 +02:00
parent e029336cf0
commit 8da830503a
8 changed files with 206 additions and 73 deletions

View File

@@ -0,0 +1,35 @@
package ru.nanit.limbo.protocol.packets.play;
import ru.nanit.limbo.connection.ClientConnection;
import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PacketOut;
/**
* This packet wrapper used only for ADD_PLAYER action
*/
public class PacketPlayerInfo implements PacketOut {
private int gameMode;
private ClientConnection connection;
public void setConnection(ClientConnection connection) {
this.connection = connection;
}
public void setGameMode(int gameMode) {
this.gameMode = gameMode;
}
@Override
public void encode(ByteMessage msg) {
msg.writeVarInt(0);
msg.writeVarInt(1);
msg.writeUuid(connection.getUuid());
msg.writeString(connection.getUsername());
msg.writeVarInt(0);
msg.writeVarInt(gameMode);
msg.writeVarInt(60);
msg.writeBoolean(false);
}
}

View File

@@ -42,6 +42,7 @@ public enum State {
clientBound.register(0x1F, PacketKeepAlive::new);
clientBound.register(0x0E, PacketChatMessage::new);
clientBound.register(0x0C, PacketBossBar::new);
clientBound.register(0x32, PacketPlayerInfo::new);
}
};
@@ -86,54 +87,4 @@ public enum State {
}
/*
Temporary don't needed
public static class PacketVersionRegistry {
private final Map<Version, PacketIdRegistry<?>> MAPPINGS = new HashMap<>();
public PacketIdRegistry<?> getRegistry(Version version){
PacketIdRegistry<?> registry = MAPPINGS.get(version);
return registry != null ? registry : MAPPINGS.get(version.getClosest(MAPPINGS.keySet()));
}
public <T extends Packet> void register(Version version, int packetId, Supplier<T> supplier){
PacketIdRegistry<T> registry = (PacketIdRegistry<T>) MAPPINGS.computeIfAbsent(version, PacketIdRegistry::new);
registry.register(packetId, supplier);
}
public static class PacketIdRegistry<T extends Packet> {
private final Version version;
private final Map<Integer, Supplier<T>> packetsById = new HashMap<>();
private final Map<Class<?>, Integer> packetIdByClass = new HashMap<>();
public PacketIdRegistry(Version version){
this.version = version;
}
public Version getVersion(){
return version;
}
public Packet getPacket(int packetId){
Supplier<T> supplier = packetsById.get(packetId);
return supplier == null ? null : supplier.get();
}
public int getPacketId(Class<?> packetClass){
return packetIdByClass.getOrDefault(packetClass, -1);
}
public void register(int packetId, Supplier<T> supplier){
packetsById.put(packetId, supplier);
packetIdByClass.put(supplier.get().getClass(), packetId);
}
}
}*/
}