From 95b2984ca931a8d631fb0e1323e67dfa8c2540dd Mon Sep 17 00:00:00 2001 From: asofold Date: Tue, 27 Dec 2016 16:25:44 +0100 Subject: [PATCH] [BLEEDING] Implement isIllegalBounds for cbreflect. --- .../compat/cbreflect/MCAccessCBReflect.java | 52 +++++++++++-------- .../cbreflect/reflect/ReflectHelper.java | 52 +++++++++++++++++++ 2 files changed, 81 insertions(+), 23 deletions(-) diff --git a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/MCAccessCBReflect.java b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/MCAccessCBReflect.java index cc3992ad..e5f829dc 100644 --- a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/MCAccessCBReflect.java +++ b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/MCAccessCBReflect.java @@ -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) ---- diff --git a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/reflect/ReflectHelper.java b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/reflect/ReflectHelper.java index 58f61278..53bee8fe 100644 --- a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/reflect/ReflectHelper.java +++ b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/cbreflect/reflect/ReflectHelper.java @@ -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; + } + }