package protocolsupport.protocol.core.initial;

import io.netty.buffer.ByteBuf;
import protocolsupport.api.ProtocolVersion;
import protocolsupport.utils.netty.ChannelUtils;

public class ProtocolUtils {

	protected static ProtocolVersion get16PingVersion(int protocolId) {
		switch (protocolId) {
			case 78: {
				return ProtocolVersion.MINECRAFT_1_6_4;
			}
			case 74: {
				return ProtocolVersion.MINECRAFT_1_6_2;
			}
			case 73: {
				return ProtocolVersion.MINECRAFT_1_6_1;
			}
			default: {
				return ProtocolVersion.MINECRAFT_1_6_4;
			}
		}
	}

	@SuppressWarnings("deprecation")
	protected static ProtocolVersion readOldHandshake(ByteBuf data) {
		ProtocolVersion version = ProtocolVersion.fromId(data.readUnsignedByte());
		return version != ProtocolVersion.UNKNOWN ? version : ProtocolVersion.MINECRAFT_LEGACY;
	}

	@SuppressWarnings("deprecation")
	protected static ProtocolVersion readNettyHandshake(ByteBuf data) {
		if (ChannelUtils.readVarInt(data) == 0x00) {
			ProtocolVersion version = ProtocolVersion.fromId(ChannelUtils.readVarInt(data));
			return version != ProtocolVersion.UNKNOWN ? version : ProtocolVersion.MINECRAFT_FUTURE;
		}
		return null;
	}

}

@@ -73,16 +73,64 @@
 yteBuf;%0A
+import io.netty.handler.codec.DecoderException;%0A
 import p
@@ -980,11 +980,22 @@
 %0A%09%09i
-f (
+nt packetId = 
 Chan
@@ -1019,16 +1019,32 @@
 nt(data)
+;%0A%09%09if (packetId
  == 0x00
@@ -1229,23 +1229,89 @@
 %0A%09%09%7D
-%0A%09%09return null;
+ else %7B%0A%09%09%09throw new DecoderException(packetId + %22is not a valid packet id%22);%0A%09%09%7D
 %0A%09%7D%0A

Throw exception if packet id is wrong