Merge pull request #284 from CharlesVaneenoo/remove_useless_if

Remove useless if in GamePacketencoder
This commit is contained in:
Major
2016-03-17 20:39:13 +00:00
@@ -31,14 +31,11 @@ public final class GamePacketEncoder extends MessageToByteEncoder<GamePacket> {
protected void encode(ChannelHandlerContext ctx, GamePacket packet, ByteBuf out) throws Exception {
PacketType type = packet.getType();
int payloadLength = packet.getLength();
if (type == PacketType.VARIABLE_BYTE) {
if (payloadLength >= 256) {
throw new Exception("Payload too long for variable byte packet.");
}
} else if (type == PacketType.VARIABLE_SHORT) {
if (payloadLength >= 65_536) {
throw new Exception("Payload too long for variable short packet.");
}
if (type == PacketType.VARIABLE_BYTE && payloadLength >= 256) {
throw new Exception("Payload too long for variable byte packet.");
} else if (type == PacketType.VARIABLE_SHORT && payloadLength >= 65_536) {
throw new Exception("Payload too long for variable short packet.");
}
out.writeByte(packet.getOpcode() + random.nextInt() & 0xFF);