Let DataLocation extend IGetPositionWithLook.

(+Implement DataLocation.hashCode.)
This commit is contained in:
asofold 2016-06-24 19:08:58 +02:00
parent 3bdb5414ae
commit a38e63d4a9
5 changed files with 67 additions and 26 deletions

View File

@ -168,10 +168,10 @@ public class MovingFlying extends BaseAdapter {
}
private boolean isInvalidContent(final DataPacketFlying packetData) {
if (packetData.hasPos && CheckUtils.isBadCoordinate(packetData.x, packetData.y, packetData.z)) {
if (packetData.hasPos && CheckUtils.isBadCoordinate(packetData.getX(), packetData.getY(), packetData.getZ())) {
return true;
}
if (packetData.hasLook && CheckUtils.isBadCoordinate(packetData.yaw, packetData.pitch)) {
if (packetData.hasLook && CheckUtils.isBadCoordinate(packetData.getYaw(), packetData.getPitch())) {
return true;
}
return false;

View File

@ -106,7 +106,7 @@ public class Visible extends Check {
continue;
}
// TODO: Might skip last pitch+yaw as well.
if (packetData.pitch == oldPitch && packetData.yaw == oldYaw) {
if (packetData.getPitch() == oldPitch && packetData.getYaw() == oldYaw) {
if (count == 0) {
count = 1;
}
@ -118,8 +118,8 @@ public class Visible extends Check {
count ++;
}
// Run ray-tracing again with updated pitch and yaw.
useLoc.setPitch(packetData.pitch);
useLoc.setYaw(packetData.yaw);
useLoc.setPitch(packetData.getPitch());
useLoc.setYaw(packetData.getYaw());
direction = useLoc.getDirection(); // TODO: Better.
tags.clear();
tags.add("flying(" + i + ")"); // Interesting if this gets through.

View File

@ -37,15 +37,15 @@ public class CountableLocation extends DataLocation {
final StringBuilder builder = new StringBuilder(256);
builder.append("CountableLocation(");
builder.append("x=");
builder.append(x);
builder.append(getX());
builder.append(",y=");
builder.append(y);
builder.append(getY());
builder.append(",z=");
builder.append(z);
builder.append(getZ());
builder.append(",pitch=");
builder.append(pitch);
builder.append(getPitch());
builder.append(",yaw=");
builder.append(yaw);
builder.append(getYaw());
builder.append(",count=");
builder.append(count);
// Skip time for now.

View File

@ -14,18 +14,29 @@
*/
package fr.neatmonster.nocheatplus.checks.net.model;
import fr.neatmonster.nocheatplus.checks.moving.location.LocUtil;
import fr.neatmonster.nocheatplus.components.location.IGetPositionWithLook;
/**
* An immutable location data object with coordinates and pitch and yaw.
*
* @author asofold
*
*/
public class DataLocation {
public class DataLocation implements IGetPositionWithLook {
// TODO: hashCode + equals.
// TODO: equals.
// TODO: hashCode won't help much if sub classes will override it anyway.
public final double x, y, z;
public final float yaw, pitch;
private final double x;
private final double y;
private final double z;
private final float yaw;
private final float pitch;
public DataLocation(double x, double y, double z, float yaw, float pitch) {
this.x = x;
@ -42,7 +53,7 @@ public class DataLocation {
* @return
*/
public boolean isSameLocation(final DataLocation other) {
return y == other.y && x == other.x && z == other.z && pitch == other.pitch && yaw == other.yaw;
return getY() == other.getY() && getX() == other.getX() && getZ() == other.getZ() && getPitch() == other.getPitch() && getYaw() == other.getYaw();
}
/**
@ -56,7 +67,7 @@ public class DataLocation {
* @return
*/
public boolean isSameLocation(final double x, final double y, final double z, final float yaw, final float pitch) {
return x == this.x && y == this.y && z == this.z && yaw == this.yaw && pitch == this.pitch;
return x == this.getX() && y == this.getY() && z == this.getZ() && yaw == this.getYaw() && pitch == this.getPitch();
}
@Override
@ -64,17 +75,47 @@ public class DataLocation {
final StringBuilder builder = new StringBuilder(256);
builder.append("Location(");
builder.append("x=");
builder.append(x);
builder.append(getX());
builder.append(",y=");
builder.append(y);
builder.append(getY());
builder.append(",z=");
builder.append(z);
builder.append(getZ());
builder.append(",pitch=");
builder.append(pitch);
builder.append(getPitch());
builder.append(",yaw=");
builder.append(yaw);
builder.append(getYaw());
builder.append(")");
return builder.toString();
}
@Override
public double getX() {
return x;
}
@Override
public double getY() {
return y;
}
@Override
public double getZ() {
return z;
}
@Override
public float getYaw() {
return yaw;
}
@Override
public float getPitch() {
return pitch;
}
@Override
public int hashCode() {
return LocUtil.hashCode(this);
}
}

View File

@ -100,17 +100,17 @@ public class DataPacketFlying extends DataLocation {
builder.append(onGround);
if (hasPos) {
builder.append(",x=");
builder.append(x);
builder.append(getX());
builder.append(",y=");
builder.append(y);
builder.append(getY());
builder.append(",z=");
builder.append(z);
builder.append(getZ());
}
if (hasLook) {
builder.append(",pitch=");
builder.append(pitch);
builder.append(getPitch());
builder.append(",yaw=");
builder.append(yaw);
builder.append(getYaw());
}
// Skip time for now.
builder.append(")");