Skip to content

Commit

Permalink
Fix moving/flying packet interpretation for before 1.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Nov 26, 2015
1 parent 1f33f32 commit 6094bf8
Showing 1 changed file with 39 additions and 37 deletions.
Expand Up @@ -31,13 +31,14 @@
public class MovingFlying extends BaseAdapter {

// Setup for flying packets.
public static final int numBooleans = 3;
public static final int indexOnGround = 0;
public static final int indexhasPos = 1;
public static final int indexhasLook = 2;
public static final int indexX = 0;
public static final int indexY = 1;
public static final int indexZ = 2;
/** 1.7.10 */
public static final int indexStance = 3;
public static final int indexYaw = 0;
public static final int indexPitch = 1;

Expand Down Expand Up @@ -180,54 +181,55 @@ private DataPacketFlying interpretPacket(final PacketEvent event, final long tim

final PacketContainer packet = event.getPacket();
final List<Boolean> booleans = packet.getBooleans().getValues();
if (booleans.size() != MovingFlying.numBooleans) {
if (booleans.size() != 3) {
packetMismatch();
return null;
}
final boolean onGround = booleans.get(MovingFlying.indexOnGround).booleanValue();
final boolean hasPos = booleans.get(MovingFlying.indexhasPos).booleanValue();
final boolean hasLook = booleans.get(MovingFlying.indexhasLook).booleanValue();
final boolean onGround = booleans.get(MovingFlying.indexOnGround).booleanValue();

if (!hasPos && !hasLook) {
return new DataPacketFlying(onGround, time);
} else {
final List<Double> doubles;
final List<Float> floats;

if (hasPos) {
doubles = packet.getDoubles().getValues();
if (doubles.size() != 3) {
packetMismatch();
return null;
}
}
else {
doubles = null;
}
final List<Double> doubles;
final List<Float> floats;

if (hasPos) {
doubles = packet.getDoubles().getValues();
if (doubles.size() != 3 && doubles.size() != 4) {
// 3: 1.8, 4: 1.7.10 and before (stance).
packetMismatch();
return null;
}
// TODO: before 1.8: stance (should make possible to reject in isInvalidContent).
}
else {
doubles = null;
}

if (hasLook) {
floats = packet.getFloat().getValues();
if (floats.size() != 2) {
packetMismatch();
return null;
}
}
else {
floats = null;
}
if (hasPos && hasLook) {
return new DataPacketFlying(onGround, doubles.get(indexX), doubles.get(indexY), doubles.get(indexZ), floats.get(indexYaw), floats.get(indexPitch), time);
}
else if (hasLook) {
return new DataPacketFlying(onGround, floats.get(indexYaw), floats.get(indexPitch), time);
}
else if (hasPos) {
return new DataPacketFlying(onGround, doubles.get(indexX), doubles.get(indexY), doubles.get(indexZ), time);
}
else {
throw new IllegalStateException("Can't be, it can't be!");
if (hasLook) {
floats = packet.getFloat().getValues();
if (floats.size() != 2) {
packetMismatch();
return null;
}
}
else {
floats = null;
}
if (hasPos && hasLook) {
return new DataPacketFlying(onGround, doubles.get(indexX), doubles.get(indexY), doubles.get(indexZ), floats.get(indexYaw), floats.get(indexPitch), time);
}
else if (hasLook) {
return new DataPacketFlying(onGround, floats.get(indexYaw), floats.get(indexPitch), time);
}
else if (hasPos) {
return new DataPacketFlying(onGround, doubles.get(indexX), doubles.get(indexY), doubles.get(indexZ), time);
}
else {
throw new IllegalStateException("Can't be, it can't be!");
}
}

/**
Expand Down

0 comments on commit 6094bf8

Please sign in to comment.