From 61ab8c124a5d664b68be629c41a6adb71d438782 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 16 Nov 2012 17:37:31 +0100 Subject: [PATCH] Add some safe guards for MC API access. --- .../utilities/BlockProperties.java | 12 +++++- .../nocheatplus/utilities/PlayerLocation.java | 37 +++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index 8d755a2e..d4b322cf 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/src/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -884,12 +884,20 @@ public class BlockProperties { /** * Hiding the API access here.
- * TODO: Find description of this and use block properties from here, as well as a speaking method name. + * TODO: Find description of this and use block properties from here, as well as a speaking method name.
+ * Assumption: This is something like "can stand on this type of block". * @param id * @return */ public static final boolean i(final int id) { - return Block.i(id); + // TODO: Replace by independent method. + try{ + return Block.i(id); + } + catch(Throwable t){ + // Minecraft default value. + return true; + } } public static final long getBLockFlags(final int id){ diff --git a/src/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java b/src/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java index 959310d2..d5beeb4b 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java +++ b/src/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java @@ -331,24 +331,29 @@ public class PlayerLocation { final double d0 = 0; //0.001D; onGround = BlockProperties.isOnGround(getBlockAccess(), minX - d0, minY - yOnGround, minZ - d0, maxX + d0, minY + 0.25, maxZ + d0); if (!onGround) { - // TODO: Probably check other ids too before doing this ? - final double d1 = 0.25D; - final AxisAlignedBB box = useBox.b(minX - d1, minY - getyOnGround() - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1); - @SuppressWarnings("rawtypes") - final List list = worldServer.getEntities(entityPlayer, box); - @SuppressWarnings("rawtypes") - Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - final Entity entity = (Entity) iterator.next(); - final EntityType type = entity.getBukkitEntity().getType(); - if (type != EntityType.BOAT && type != EntityType.MINECART) continue; - final AxisAlignedBB otherBox = entity.boundingBox; - if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c) continue; - else { - onGround = true; - break; + try{ + // TODO: Probably check other ids too before doing this ? + final double d1 = 0.25D; + final AxisAlignedBB box = useBox.b(minX - d1, minY - getyOnGround() - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1); + @SuppressWarnings("rawtypes") + final List list = worldServer.getEntities(entityPlayer, box); + @SuppressWarnings("rawtypes") + Iterator iterator = list.iterator(); + while (iterator.hasNext()) { + final Entity entity = (Entity) iterator.next(); + final EntityType type = entity.getBukkitEntity().getType(); + if (type != EntityType.BOAT && type != EntityType.MINECART) continue; + final AxisAlignedBB otherBox = entity.boundingBox; + if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c) continue; + else { + onGround = true; + break; + } } } + catch (Throwable t){ + // Ignore exceptions (Context: DisguiseCraft). + } } } return onGround;