use of com.github.dirtpowered.dirtmv.data.protocol.BaseProtocol in project DirtMultiversion by DirtPowered.
the class PacketUtil method readModernPacket.
public static PacketData readModernPacket(MinecraftVersion ver, ProtocolState state, PacketInput buf, PacketDirection dir, int id) throws IOException {
BaseProtocol protocol = ProtocolRegistry.getProtocolFromVersion(ver);
DataType[] parts = protocol.getStateDependedProtocol().getInstruction(id, state, dir);
if (parts == null) {
Logger.warn("Unknown packet id {} ({}), state: {}, direction: {}", StringUtils.intToHexStr(id), id, state, dir);
return new PacketData(0);
}
TypeHolder[] typeHolders = new TypeHolder[parts.length];
int i = 0;
while (i < parts.length) {
DataType dataType = parts[i];
typeHolders[i] = new TypeHolder(dataType.getType(), dataType.read(buf));
i++;
}
return new PacketData(id, typeHolders);
}
use of com.github.dirtpowered.dirtmv.data.protocol.BaseProtocol in project DirtMultiversion by DirtPowered.
the class PacketUtil method readPacket.
public static PacketData readPacket(MinecraftVersion version, PacketInput buffer) throws IOException {
Preconditions.checkNotNull(version, "Version not provided");
short packetId = buffer.readUnsignedByte();
BaseProtocol protocol = ProtocolRegistry.getProtocolFromVersion(version);
Preconditions.checkNotNull(protocol, "Protocol %s is not registered", version);
DataType[] parts = protocol.dataTypes[packetId];
String packetMapping = PreNettyPacketNames.getPacketName(packetId);
String protocolName = protocol.getClass().getSimpleName();
Preconditions.checkNotNull(parts, "Unknown packet id %s (%s) in protocol %s", packetId, packetMapping, protocolName);
TypeHolder[] typeHolders = new TypeHolder[parts.length];
int i = 0;
while (i < parts.length) {
DataType dataType = parts[i];
typeHolders[i] = new TypeHolder(dataType.getType(), dataType.read(buffer));
i++;
}
return new PacketData(packetId, typeHolders);
}
Aggregations