[BLEEDING] Implement isIllegalBounds for cbreflect.

This commit is contained in:
asofold 2016-12-27 16:25:44 +01:00
parent 1ba300f3af
commit 95b2984ca9
2 changed files with 81 additions and 23 deletions

View File

@ -27,6 +27,7 @@ import fr.neatmonster.nocheatplus.compat.cbreflect.reflect.ReflectHelper.Reflect
import fr.neatmonster.nocheatplus.compat.versions.GenericVersion;
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
import fr.neatmonster.nocheatplus.logging.Streams;
import fr.neatmonster.nocheatplus.utilities.location.LocUtil;
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
public class MCAccessCBReflect extends MCAccessBukkitBase {
@ -190,29 +191,34 @@ public class MCAccessCBReflect extends MCAccessBukkitBase {
}
}
// TODO: ---- Missing (better to implement these) ----
// @Override
// public AlmostBoolean isIllegalBounds(final Player player) {
// final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
// if (entityPlayer.dead) {
// return AlmostBoolean.NO;
// }
// // TODO: Does this need a method call for the "real" box? Might be no problem during moving events, though.
// final AxisAlignedBB box = entityPlayer.getBoundingBox();
// if (!entityPlayer.isSleeping()) {
// // This can not really test stance but height of bounding box.
// final double dY = Math.abs(box.e - box.b);
// if (dY > 1.8) {
// return AlmostBoolean.YES; // dY > 1.65D ||
// }
// if (dY < 0.1D && entityPlayer.length >= 0.1) {
// return AlmostBoolean.YES;
// }
// }
// return AlmostBoolean.MAYBE;
// }
@Override
public AlmostBoolean isIllegalBounds(final Player player) {
if (player.isDead()) {
return AlmostBoolean.NO;
}
try {
final double[] bounds = helper.getBoundsTemp(player);
if (LocUtil.isBadCoordinate(bounds)) {
return AlmostBoolean.YES;
}
if (!player.isSleeping()) {
final double dY = Math.abs(bounds[4] - bounds[1]);
if (dY > 1.8) {
return AlmostBoolean.YES; // dY > 1.65D ||
}
if (dY < 0.1D && getHeight(player) >= 0.1) { // TODO: Not strictly the height parameter.
return AlmostBoolean.YES;
}
}
}
catch (ReflectFailureException e) {
// Ignore.
}
catch (NullPointerException ne) {
// Ignore.
}
return AlmostBoolean.MAYBE;
}
// ---- Missing (probably ok with Bukkit only) ----

View File

@ -74,6 +74,8 @@ public class ReflectHelper {
protected final ReflectEntity reflectLivingEntity;
protected final ReflectPlayer reflectPlayer;
private final double[] tempBounds = new double[6];
public ReflectHelper() throws ReflectFailureException {
// TODO: Store one instance of ReflectFailureException?
// TODO: Allow some more to not work?
@ -407,4 +409,54 @@ public class ReflectHelper {
return height;
}
/**
* Fetch the bounding box.
*
* @param entity
* @return A new double array {minX, minY, minZ, maxX, maxY, maxZ}. Not to
* be stored etc.
* @throws ReflectFailureException
* On failure to fetch bounds.
*/
public double[] getBounds(final Entity entity) {
return getBounds(entity, new double[6]);
}
/**
* Fetch the bounding box.
*
* @param entity
* @return The internally stored double array for bounds {minX, minY, minZ,
* maxX, maxY, maxZ}. Not to be stored etc.
* @throws ReflectFailureException
* On failure to fetch bounds.
*/
public double[] getBoundsTemp(final Entity entity) {
return getBounds(entity, tempBounds);
}
/**
* Fetch the bounding box.
*
* @param entity
* @param bounds
* The double[6+] array, which to fill values in to.
* @return The passed bounds array filled with {minX, minY, minZ, maxX,
* maxY, maxZ}.
* @throws ReflectFailureException
* On failure to fetch bounds.
*/
public double[] getBounds(final Entity entity, final double[] bounds) {
// TODO: Also fetch for legacy versions?
if (reflectAxisAlignedBB == null || reflectEntity == null) {
fail();
}
final Object aabb = ReflectionUtil.invokeMethodNoArgs(reflectEntity.nmsGetBoundingBox, reflectEntity.getHandle(entity));
if (aabb == null) {
fail();
}
reflectAxisAlignedBB.fillInValues(aabb, bounds);
return bounds;
}
}