From 3eab23ae928d590401bd0ceb9a22b288b116c36f Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 10 Dec 2014 00:45:08 +0100 Subject: [PATCH] [BLEEDING] First attempt to make slime blocks work. --- .../compat/bukkit/MCAccessBukkit.java | 5 + .../compat/cb2512/MCAccessCB2512.java | 249 +-- .../compat/cb2545/MCAccessCB2545.java | 249 +-- .../compat/cb2602/MCAccessCB2602.java | 251 +-- .../compat/cb2645/MCAccessCB2645.java | 253 +-- .../compat/cb2691/MCAccessCB2691.java | 257 +-- .../compat/cb2763/MCAccessCB2763.java | 255 +-- .../compat/cb2794/MCAccessCB2794.java | 243 +-- .../compat/cb2808/MCAccessCB2808.java | 245 +-- .../compat/cb2882/MCAccessCB2882.java | 247 +-- .../compat/cb2922/MCAccessCB2922.java | 247 +-- .../compat/cb3026/MCAccessCB3026.java | 247 +-- .../compat/cb3043/MCAccessCB3043.java | 285 +-- .../compat/cb3100/MCAccessCB3100.java | 289 +-- .../compat/cbdev/MCAccessCBDev.java | 5 + .../compat/glowstone/MCAccessGlowstone.java | 6 + .../nocheatplus/checks/fight/Critical.java | 6 +- .../checks/fight/FightListener.java | 6 +- .../nocheatplus/checks/moving/MovingData.java | 83 +- .../checks/moving/MovingListener.java | 171 +- .../nocheatplus/checks/moving/MovingUtil.java | 92 + .../nocheatplus/checks/moving/NoFall.java | 20 +- .../checks/moving/SurvivalFly.java | 10 + .../nocheatplus/compat/MCAccess.java | 224 ++- .../blocks/init/vanilla/BlocksMC1_8.java | 3 + .../utilities/BlockProperties.java | 14 +- .../nocheatplus/utilities/PlayerLocation.java | 1782 ++++++++--------- 27 files changed, 2957 insertions(+), 2787 deletions(-) create mode 100644 NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingUtil.java diff --git a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/bukkit/MCAccessBukkit.java b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/bukkit/MCAccessBukkit.java index b20cb245..dbee9555 100644 --- a/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/bukkit/MCAccessBukkit.java +++ b/NCPCompatBukkit/src/main/java/fr/neatmonster/nocheatplus/compat/bukkit/MCAccessBukkit.java @@ -324,6 +324,11 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{ } } + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.NO; // Assumption. + } + // @Override // public void correctDirection(Player player) { // // TODO: Consider using reflection (detect CraftPlayer, access EntityPlayer + check if possible (!), use flags for if valid or invalid.) diff --git a/NCPCompatCB2512/src/main/java/fr/neatmonster/nocheatplus/compat/cb2512/MCAccessCB2512.java b/NCPCompatCB2512/src/main/java/fr/neatmonster/nocheatplus/compat/cb2512/MCAccessCB2512.java index 872d9352..864565a9 100644 --- a/NCPCompatCB2512/src/main/java/fr/neatmonster/nocheatplus/compat/cb2512/MCAccessCB2512.java +++ b/NCPCompatCB2512/src/main/java/fr/neatmonster/nocheatplus/compat/cb2512/MCAccessCB2512.java @@ -24,145 +24,150 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2512 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2512(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_4_5.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_4_5.Block.class, - new String[]{"v", "w", "x", "y", "z", "A"}, double.class); - } - @Override - public String getMCVersion() { - return "1.4.5"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2512(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_4_5.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_4_5.Block.class, + new String[]{"v", "w", "x", "y", "z", "A"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2512"; - } + @Override + public String getMCVersion() { + return "1.4.5"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2512"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2512(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_4_5.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2512(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_4_5.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @Override - public AlmostBoolean isIllegalBounds(final Player player) { - final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - if (entityPlayer.dead) return AlmostBoolean.NO; - final AxisAlignedBB box = entityPlayer.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public AlmostBoolean isIllegalBounds(final Player player) { + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + if (entityPlayer.dead) return AlmostBoolean.NO; + final AxisAlignedBB box = entityPlayer.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - switch(mat){ - case SAND: - case GRAVEL: - return true; - default: - return false; - } - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + switch(mat){ + case SAND: + case GRAVEL: + return true; + default: + return false; + } + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2545/src/main/java/fr/neatmonster/nocheatplus/compat/cb2545/MCAccessCB2545.java b/NCPCompatCB2545/src/main/java/fr/neatmonster/nocheatplus/compat/cb2545/MCAccessCB2545.java index 4b8a0c8f..15f22bf0 100644 --- a/NCPCompatCB2545/src/main/java/fr/neatmonster/nocheatplus/compat/cb2545/MCAccessCB2545.java +++ b/NCPCompatCB2545/src/main/java/fr/neatmonster/nocheatplus/compat/cb2545/MCAccessCB2545.java @@ -24,145 +24,150 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2545 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2545(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_4_6.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_4_6.Block.class, - new String[]{"v", "w", "x", "y", "z", "A"}, double.class); - } - @Override - public String getMCVersion() { - return "1.4.6"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2545(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_4_6.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_4_6.Block.class, + new String[]{"v", "w", "x", "y", "z", "A"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2545"; - } + @Override + public String getMCVersion() { + return "1.4.6"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2545"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2545(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_4_6.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2545(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_4_6.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @Override - public AlmostBoolean isIllegalBounds(final Player player) { - final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - if (entityPlayer.dead) return AlmostBoolean.NO; - final AxisAlignedBB box = entityPlayer.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public AlmostBoolean isIllegalBounds(final Player player) { + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + if (entityPlayer.dead) return AlmostBoolean.NO; + final AxisAlignedBB box = entityPlayer.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - switch(mat){ - case SAND: - case GRAVEL: - return true; - default: - return false; - } - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + switch(mat){ + case SAND: + case GRAVEL: + return true; + default: + return false; + } + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2602/src/main/java/fr/neatmonster/nocheatplus/compat/cb2602/MCAccessCB2602.java b/NCPCompatCB2602/src/main/java/fr/neatmonster/nocheatplus/compat/cb2602/MCAccessCB2602.java index 80566230..36f242f7 100644 --- a/NCPCompatCB2602/src/main/java/fr/neatmonster/nocheatplus/compat/cb2602/MCAccessCB2602.java +++ b/NCPCompatCB2602/src/main/java/fr/neatmonster/nocheatplus/compat/cb2602/MCAccessCB2602.java @@ -24,146 +24,151 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2602 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2602(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_4_R1.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_4_R1.Block.class, - new String[]{"v", "w", "x", "y", "z", "A"}, double.class); - } - @Override - public String getMCVersion() { - // 1_4_R1 - return "1.4.7"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2602(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_4_R1.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_4_R1.Block.class, + new String[]{"v", "w", "x", "y", "z", "A"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2602"; - } + @Override + public String getMCVersion() { + // 1_4_R1 + return "1.4.7"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2602"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2602(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_4_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2602(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_4_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @Override - public AlmostBoolean isIllegalBounds(final Player player) { - final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); - if (entityPlayer.dead) return AlmostBoolean.NO; - final AxisAlignedBB box = entityPlayer.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public AlmostBoolean isIllegalBounds(final Player player) { + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + if (entityPlayer.dead) return AlmostBoolean.NO; + final AxisAlignedBB box = entityPlayer.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - switch(mat){ - case SAND: - case GRAVEL: - return true; - default: - return false; - } - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + switch(mat){ + case SAND: + case GRAVEL: + return true; + default: + return false; + } + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2645/src/main/java/fr/neatmonster/nocheatplus/compat/cb2645/MCAccessCB2645.java b/NCPCompatCB2645/src/main/java/fr/neatmonster/nocheatplus/compat/cb2645/MCAccessCB2645.java index 52e87ac1..a946a770 100644 --- a/NCPCompatCB2645/src/main/java/fr/neatmonster/nocheatplus/compat/cb2645/MCAccessCB2645.java +++ b/NCPCompatCB2645/src/main/java/fr/neatmonster/nocheatplus/compat/cb2645/MCAccessCB2645.java @@ -24,147 +24,152 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2645 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2645(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R1.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_5_R1.Block.class, - new String[]{"u", "v", "w", "x", "y", "z"}, double.class); - } - @Override - public String getMCVersion() { - // 1_5_R1 - return "1.5"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2645(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R1.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_5_R1.Block.class, + new String[]{"u", "v", "w", "x", "y", "z"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2645"; - } + @Override + public String getMCVersion() { + // 1_5_R1 + return "1.5"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2645"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2645(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_5_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2645(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_5_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - switch(mat){ - case SAND: - case GRAVEL: - return true; - default: - return false; - } - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + switch(mat){ + case SAND: + case GRAVEL: + return true; + default: + return false; + } + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java b/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java index b23f176d..eb0a979a 100644 --- a/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java +++ b/NCPCompatCB2691/src/main/java/fr/neatmonster/nocheatplus/compat/cb2691/MCAccessCB2691.java @@ -24,149 +24,154 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2691 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2691(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R2.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_5_R2.Block.class, - new String[]{"u", "v", "w", "x", "y", "z"}, double.class); - } - @Override - public String getMCVersion() { - // 1_5_R2 - return "1.5.1"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2691(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R2.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_5_R2.Block.class, + new String[]{"u", "v", "w", "x", "y", "z"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2691"; - } + @Override + public String getMCVersion() { + // 1_5_R2 + return "1.5.1"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2691"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2691(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_5_R2.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else { - return entityHeight; - } - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2691(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_5_R2.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else { + return entityHeight; + } + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - switch(mat){ - case SAND: - case GRAVEL: - return true; - default: - return false; - } - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + switch(mat){ + case SAND: + case GRAVEL: + return true; + default: + return false; + } + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2763/src/main/java/fr/neatmonster/nocheatplus/compat/cb2763/MCAccessCB2763.java b/NCPCompatCB2763/src/main/java/fr/neatmonster/nocheatplus/compat/cb2763/MCAccessCB2763.java index 0663ede7..7566ac7b 100644 --- a/NCPCompatCB2763/src/main/java/fr/neatmonster/nocheatplus/compat/cb2763/MCAccessCB2763.java +++ b/NCPCompatCB2763/src/main/java/fr/neatmonster/nocheatplus/compat/cb2763/MCAccessCB2763.java @@ -24,148 +24,153 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2763 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2763(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R3.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_5_R3.Block.class, - new String[]{"u", "v", "w", "x", "y", "z"}, double.class); - } - @Override - public String getMCVersion() { - // 1_5_R3 - return "1.5.2"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2763(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_5_R3.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_5_R3.Block.class, + new String[]{"u", "v", "w", "x", "y", "z"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2763"; - } + @Override + public String getMCVersion() { + // 1_5_R3 + return "1.5.2"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2763"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2763(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_5_R3.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2763(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_5_R3.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage)); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: TEST: return mat.hasGravity(); - switch(mat){ - case SAND: - case GRAVEL: - return true; - default: - return false; - } - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: TEST: return mat.hasGravity(); + switch(mat){ + case SAND: + case GRAVEL: + return true; + default: + return false; + } + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2794/src/main/java/fr/neatmonster/nocheatplus/compat/cb2794/MCAccessCB2794.java b/NCPCompatCB2794/src/main/java/fr/neatmonster/nocheatplus/compat/cb2794/MCAccessCB2794.java index 3f3a6cbd..6dfa05df 100644 --- a/NCPCompatCB2794/src/main/java/fr/neatmonster/nocheatplus/compat/cb2794/MCAccessCB2794.java +++ b/NCPCompatCB2794/src/main/java/fr/neatmonster/nocheatplus/compat/cb2794/MCAccessCB2794.java @@ -24,142 +24,147 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2794 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2794(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_6_R1.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_6_R1.Block.class, - new String[]{"u", "v", "w", "x", "y", "z"}, double.class); - } - @Override - public String getMCVersion() { - // 1_6_R1 - return "1.6.1"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2794(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_6_R1.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_6_R1.Block.class, + new String[]{"u", "v", "w", "x", "y", "z"}, double.class); + } - @Override - public String getServerVersionTag() { - return "CB2794"; - } + @Override + public String getMCVersion() { + // 1_6_R1 + return "1.6.1"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2794"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2794(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_6_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2794(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_6_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2808/src/main/java/fr/neatmonster/nocheatplus/compat/cb2808/MCAccessCB2808.java b/NCPCompatCB2808/src/main/java/fr/neatmonster/nocheatplus/compat/cb2808/MCAccessCB2808.java index df47b905..1a06aab7 100644 --- a/NCPCompatCB2808/src/main/java/fr/neatmonster/nocheatplus/compat/cb2808/MCAccessCB2808.java +++ b/NCPCompatCB2808/src/main/java/fr/neatmonster/nocheatplus/compat/cb2808/MCAccessCB2808.java @@ -24,143 +24,148 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2808 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2808(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_6_R2.", new String[]{"Entity" , "dead"}); - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_6_R2.Block.class, - new String[]{"u", "v", "w", "x", "y", "z"}, double.class); - // TODO: Nail it down further. - } - @Override - public String getMCVersion() { - // 1_6_R2 - return "1.6.2"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2808(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_6_R2.", new String[]{"Entity" , "dead"}); + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_6_R2.Block.class, + new String[]{"u", "v", "w", "x", "y", "z"}, double.class); + // TODO: Nail it down further. + } - @Override - public String getServerVersionTag() { - return "CB2808"; - } + @Override + public String getMCVersion() { + // 1_6_R2 + return "1.6.2"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2808"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2808(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_6_R2.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2808(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_6_R2.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2882/src/main/java/fr/neatmonster/nocheatplus/compat/cb2882/MCAccessCB2882.java b/NCPCompatCB2882/src/main/java/fr/neatmonster/nocheatplus/compat/cb2882/MCAccessCB2882.java index 6976ef56..22b0baa3 100644 --- a/NCPCompatCB2882/src/main/java/fr/neatmonster/nocheatplus/compat/cb2882/MCAccessCB2882.java +++ b/NCPCompatCB2882/src/main/java/fr/neatmonster/nocheatplus/compat/cb2882/MCAccessCB2882.java @@ -24,144 +24,149 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2882 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2882(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_6_R3.", new String[]{"Entity" , "dead"}); - // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_6_R3.Block.class, - new String[]{"u", "v", "w", "x", "y", "z"}, double.class); - // TODO: Nail it down further. - } - @Override - public String getMCVersion() { - // 1_6_R3 - return "1.6.4"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2882(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_6_R3.", new String[]{"Entity" , "dead"}); + // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_6_R3.Block.class, + new String[]{"u", "v", "w", "x", "y", "z"}, double.class); + // TODO: Nail it down further. + } - @Override - public String getServerVersionTag() { - return "CB2882"; - } + @Override + public String getMCVersion() { + // 1_6_R3 + return "1.6.4"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2882"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2882(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_6_R3.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2882(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_6_R3.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.byId[id]; - if (block == null || block.material == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.material.isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.byId[id]; + if (block == null || block.material == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.material.isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB2922/src/main/java/fr/neatmonster/nocheatplus/compat/cb2922/MCAccessCB2922.java b/NCPCompatCB2922/src/main/java/fr/neatmonster/nocheatplus/compat/cb2922/MCAccessCB2922.java index b70c4538..1799b3c2 100644 --- a/NCPCompatCB2922/src/main/java/fr/neatmonster/nocheatplus/compat/cb2922/MCAccessCB2922.java +++ b/NCPCompatCB2922/src/main/java/fr/neatmonster/nocheatplus/compat/cb2922/MCAccessCB2922.java @@ -24,144 +24,149 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB2922 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB2922(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R1.", new String[]{"Entity" , "dead"}); - // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R1.Block.class, - new String[]{"x", "y", "z", "A", "B", "C"}, double.class); - // TODO: Nail it down further. - } - @Override - public String getMCVersion() { - // 1_7_R1 - return "1.7.2"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB2922(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R1.", new String[]{"Entity" , "dead"}); + // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R1.Block.class, + new String[]{"x", "y", "z", "A", "B", "C"}, double.class); + // TODO: Nail it down further. + } - @Override - public String getServerVersionTag() { - return "CB2922"; - } + @Override + public String getMCVersion() { + // 1_7_R1 + return "1.7.2"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB2922"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB2922(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_7_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB2922(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.e(id); - if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.getMaterial().isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_7_R1.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.e(id); - if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.getMaterial().isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.e(id); + if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.getMaterial().isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.e(id); + if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.getMaterial().isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB3026/src/main/java/fr/neatmonster/nocheatplus/compat/cb3026/MCAccessCB3026.java b/NCPCompatCB3026/src/main/java/fr/neatmonster/nocheatplus/compat/cb3026/MCAccessCB3026.java index be87b08a..07f8c094 100644 --- a/NCPCompatCB3026/src/main/java/fr/neatmonster/nocheatplus/compat/cb3026/MCAccessCB3026.java +++ b/NCPCompatCB3026/src/main/java/fr/neatmonster/nocheatplus/compat/cb3026/MCAccessCB3026.java @@ -24,144 +24,149 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB3026 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB3026(){ - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R2.", new String[]{"Entity" , "dead"}); - // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R2.Block.class, - new String[]{"x", "y", "z", "A", "B", "C"}, double.class); - // TODO: Nail it down further. - } - @Override - public String getMCVersion() { - // 1_7_R2 - return "1.7.5"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB3026(){ + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R2.", new String[]{"Entity" , "dead"}); + // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R2.Block.class, + new String[]{"x", "y", "z", "A", "B", "C"}, double.class); + // TODO: Nail it down further. + } - @Override - public String getServerVersionTag() { - return "CB3026"; - } + @Override + public String getMCVersion() { + // 1_7_R2 + return "1.7.5"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB3026"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB3026(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_7_R2.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB3026(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.e(id); - if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.getMaterial().isSolid()); - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_7_R2.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.e(id); - if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; - else return AlmostBoolean.match(block.getMaterial().isLiquid()); - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.e(id); + if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.getMaterial().isSolid()); + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.e(id); + if (block == null || block.getMaterial() == null) return AlmostBoolean.MAYBE; + else return AlmostBoolean.match(block.getMaterial().isLiquid()); + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - - if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - else return Double.NEGATIVE_INFINITY; - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + if (mcPlayer.hasEffect(MobEffectList.JUMP)) return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + else return Double.NEGATIVE_INFINITY; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } + + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB3043/src/main/java/fr/neatmonster/nocheatplus/compat/cb3043/MCAccessCB3043.java b/NCPCompatCB3043/src/main/java/fr/neatmonster/nocheatplus/compat/cb3043/MCAccessCB3043.java index ad7114b8..b8844620 100644 --- a/NCPCompatCB3043/src/main/java/fr/neatmonster/nocheatplus/compat/cb3043/MCAccessCB3043.java +++ b/NCPCompatCB3043/src/main/java/fr/neatmonster/nocheatplus/compat/cb3043/MCAccessCB3043.java @@ -24,163 +24,168 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB3043 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB3043() { - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R3.", new String[] {"Entity" , "dead"}); - // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R3.Block.class, - new String[]{"x", "y", "z", "A", "B", "C"}, double.class); - // TODO: Nail it down further. - } - @Override - public String getMCVersion() { - // 1_7_R3 - return "1.7.8|1.7.9"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB3043() { + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R3.", new String[] {"Entity" , "dead"}); + // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R3.Block.class, + new String[]{"x", "y", "z", "A", "B", "C"}, double.class); + // TODO: Nail it down further. + } - @Override - public String getServerVersionTag() { - return "CB3043"; - } + @Override + public String getMCVersion() { + // 1_7_R3 + return "1.7.8|1.7.9"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB3043"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB3043(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_7_R3.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB3043(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.e(id); - if (block == null || block.getMaterial() == null) { - return AlmostBoolean.MAYBE; - } - else { - return AlmostBoolean.match(block.getMaterial().isSolid()); - } - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_7_R3.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.e(id); - if (block == null || block.getMaterial() == null) { - return AlmostBoolean.MAYBE; - } - else { - return AlmostBoolean.match(block.getMaterial().isLiquid()); - } - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.e(id); + if (block == null || block.getMaterial() == null) { + return AlmostBoolean.MAYBE; + } + else { + return AlmostBoolean.match(block.getMaterial().isSolid()); + } + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.e(id); + if (block == null || block.getMaterial() == null) { + return AlmostBoolean.MAYBE; + } + else { + return AlmostBoolean.match(block.getMaterial().isLiquid()); + } + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.JUMP)) { - return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - } - else { - return Double.NEGATIVE_INFINITY; - } - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) { - return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - } - else { - return Double.NEGATIVE_INFINITY; - } - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.JUMP)) { + return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + } + else { + return Double.NEGATIVE_INFINITY; + } + } - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) { + return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + } + else { + return Double.NEGATIVE_INFINITY; + } + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCB3100/src/main/java/fr/neatmonster/nocheatplus/compat/cb3100/MCAccessCB3100.java b/NCPCompatCB3100/src/main/java/fr/neatmonster/nocheatplus/compat/cb3100/MCAccessCB3100.java index b5ad18d7..2eec83bd 100644 --- a/NCPCompatCB3100/src/main/java/fr/neatmonster/nocheatplus/compat/cb3100/MCAccessCB3100.java +++ b/NCPCompatCB3100/src/main/java/fr/neatmonster/nocheatplus/compat/cb3100/MCAccessCB3100.java @@ -24,165 +24,170 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.ReflectionUtil; public class MCAccessCB3100 implements MCAccess{ - - /** - * Constructor to let it fail. - */ - public MCAccessCB3100() { - getCommandMap(); - ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R4.", new String[] {"Entity" , "dead"}); - // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ - ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R4.Block.class, - new String[]{"x", "y", "z", "A", "B", "C"}, double.class); - // TODO: Nail it down further. - } - @Override - public String getMCVersion() { - // 1_7_R4 - return "1.7.10"; - } + /** + * Constructor to let it fail. + */ + public MCAccessCB3100() { + getCommandMap(); + ReflectionUtil.checkMembers("net.minecraft.server.v1_7_R4.", new String[] {"Entity" , "dead"}); + // block bounds, original: minX, maxX, minY, maxY, minZ, maxZ + ReflectionUtil.checkMethodReturnTypesNoArgs(net.minecraft.server.v1_7_R4.Block.class, + new String[]{"x", "y", "z", "A", "B", "C"}, double.class); + // TODO: Nail it down further. + } - @Override - public String getServerVersionTag() { - return "CB3100"; - } + @Override + public String getMCVersion() { + // 1_7_R4 + return "1.7.10"; + } - @Override - public CommandMap getCommandMap() { - return ((CraftServer) Bukkit.getServer()).getCommandMap(); - } + @Override + public String getServerVersionTag() { + return "CB3100"; + } - @Override - public BlockCache getBlockCache(final World world) { - return new BlockCacheCB3100(world); - } + @Override + public CommandMap getCommandMap() { + return ((CraftServer) Bukkit.getServer()).getCommandMap(); + } - @Override - public double getHeight(final Entity entity) { - final net.minecraft.server.v1_7_R4.Entity mcEntity = ((CraftEntity) entity).getHandle(); - final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); - if (entity instanceof LivingEntity) { - return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); - } else return entityHeight; - } + @Override + public BlockCache getBlockCache(final World world) { + return new BlockCacheCB3100(world); + } - @Override - public AlmostBoolean isBlockSolid(final int id) { - final Block block = Block.getById(id); - if (block == null || block.getMaterial() == null) { - return AlmostBoolean.MAYBE; - } - else { - return AlmostBoolean.match(block.getMaterial().isSolid()); - } - } + @Override + public double getHeight(final Entity entity) { + final net.minecraft.server.v1_7_R4.Entity mcEntity = ((CraftEntity) entity).getHandle(); + final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.height, mcEntity.boundingBox.e - mcEntity.boundingBox.b)); + if (entity instanceof LivingEntity) { + return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); + } else return entityHeight; + } - @Override - public AlmostBoolean isBlockLiquid(final int id) { - final Block block = Block.getById(id); - if (block == null || block.getMaterial() == null) { - return AlmostBoolean.MAYBE; - } - else { - return AlmostBoolean.match(block.getMaterial().isLiquid()); - } - } + @Override + public AlmostBoolean isBlockSolid(final int id) { + final Block block = Block.getById(id); + if (block == null || block.getMaterial() == null) { + return AlmostBoolean.MAYBE; + } + else { + return AlmostBoolean.match(block.getMaterial().isSolid()); + } + } - @Override - public double getWidth(final Entity entity) { - return ((CraftEntity) entity).getHandle().width; - } + @Override + public AlmostBoolean isBlockLiquid(final int id) { + final Block block = Block.getById(id); + if (block == null || block.getMaterial() == null) { + return AlmostBoolean.MAYBE; + } + else { + return AlmostBoolean.match(block.getMaterial().isLiquid()); + } + } - @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.boundingBox; - 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 double getWidth(final Entity entity) { + return ((CraftEntity) entity).getHandle().width; + } - @Override - public double getJumpAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.JUMP)) { - return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); - } - else { - return Double.NEGATIVE_INFINITY; - } - } + @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.boundingBox; + 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 double getFasterMovementAmplifier(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) { - return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); - } - else { - return Double.NEGATIVE_INFINITY; - } - } + @Override + public double getJumpAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.JUMP)) { + return mcPlayer.getEffect(MobEffectList.JUMP).getAmplifier(); + } + else { + return Double.NEGATIVE_INFINITY; + } + } - @Override - public int getInvulnerableTicks(final Player player) { - return ((CraftPlayer) player).getHandle().invulnerableTicks; - } + @Override + public double getFasterMovementAmplifier(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + if (mcPlayer.hasEffect(MobEffectList.FASTER_MOVEMENT)) { + return mcPlayer.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier(); + } + else { + return Double.NEGATIVE_INFINITY; + } + } - @Override - public void setInvulnerableTicks(final Player player, final int ticks) { - ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; - } + @Override + public int getInvulnerableTicks(final Player player) { + return ((CraftPlayer) player).getHandle().invulnerableTicks; + } - @Override - public void dealFallDamage(final Player player, final double damage) { - ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); - } + @Override + public void setInvulnerableTicks(final Player player, final int ticks) { + ((CraftPlayer) player).getHandle().invulnerableTicks = ticks; + } - @Override - public boolean isComplexPart(final Entity entity) { - return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; - } + @Override + public void dealFallDamage(final Player player, final double damage) { + ((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage); + } - @Override - public boolean shouldBeZombie(final Player player) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); - return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; - } + @Override + public boolean isComplexPart(final Entity entity) { + return ((CraftEntity) entity).getHandle() instanceof EntityComplexPart; + } - @Override - public void setDead(final Player player, final int deathTicks) { - final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + @Override + public boolean shouldBeZombie(final Player player) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ; + } + + @Override + public void setDead(final Player player, final int deathTicks) { + final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); mcPlayer.deathTicks = deathTicks; mcPlayer.dead = true; - } - - @Override - public boolean hasGravity(final Material mat) { - // TODO: Test/check. - return mat.hasGravity(); - } - -// @Override -// public void correctDirection(final Player player) { -// final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); -// // Main direction. -// mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); -// mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); -// // Consider setting the lastYaw here too. -// } - + } + + @Override + public boolean hasGravity(final Material mat) { + // TODO: Test/check. + return mat.hasGravity(); + } + + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.MAYBE; + } + + // @Override + // public void correctDirection(final Player player) { + // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); + // // Main direction. + // mcPlayer.yaw = LocUtil.correctYaw(mcPlayer.yaw); + // mcPlayer.pitch = LocUtil.correctPitch(mcPlayer.pitch); + // // Consider setting the lastYaw here too. + // } + } diff --git a/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/MCAccessCBDev.java b/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/MCAccessCBDev.java index 5a614bcb..87bd1e5f 100644 --- a/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/MCAccessCBDev.java +++ b/NCPCompatCBDev/src/main/java/fr/neatmonster/nocheatplus/compat/cbdev/MCAccessCBDev.java @@ -176,6 +176,11 @@ public class MCAccessCBDev implements MCAccess{ return mat.hasGravity(); } + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.YES; + } + // @Override // public void correctDirection(final Player player) { // final EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle(); diff --git a/NCPCompatGlowstone/src/main/java/fr/neatmonster/nocheatplus/compat/glowstone/MCAccessGlowstone.java b/NCPCompatGlowstone/src/main/java/fr/neatmonster/nocheatplus/compat/glowstone/MCAccessGlowstone.java index 3b9c937a..f491f329 100644 --- a/NCPCompatGlowstone/src/main/java/fr/neatmonster/nocheatplus/compat/glowstone/MCAccessGlowstone.java +++ b/NCPCompatGlowstone/src/main/java/fr/neatmonster/nocheatplus/compat/glowstone/MCAccessGlowstone.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandMap; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import fr.neatmonster.nocheatplus.compat.AlmostBoolean; import fr.neatmonster.nocheatplus.compat.bukkit.MCAccessBukkit; import fr.neatmonster.nocheatplus.utilities.BlockCache; @@ -53,4 +54,9 @@ public class MCAccessGlowstone extends MCAccessBukkit{ ((GlowPlayer) player).damage(damage, DamageCause.FALL); } + @Override + public AlmostBoolean dealFallDamageFiresAnEvent() { + return AlmostBoolean.YES; // Assumption (it's native access). + } + } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java index 65b63d44..fe5f4991 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java @@ -13,7 +13,7 @@ import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.checks.moving.MovingConfig; import fr.neatmonster.nocheatplus.checks.moving.MovingData; -import fr.neatmonster.nocheatplus.checks.moving.MovingListener; +import fr.neatmonster.nocheatplus.checks.moving.MovingUtil; import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.StringUtil; @@ -46,7 +46,7 @@ public class Critical extends Check { if (mcFallDistance > 0.0 && data.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)) { final MovingData mData = MovingData.getData(player); - if (MovingListener.shouldCheckSurvivalFly(player, mData, mCc) && CheckType.MOVING_NOFALL.isEnabled(player)) { + if (MovingUtil.shouldCheckSurvivalFly(player, mData, mCc) && CheckType.MOVING_NOFALL.isEnabled(player)) { // TODO: Set max y in MovingListener, to be independent of sf/nofall! player.sendMessage("Critical: fd=" + mcFallDistance + "(" + mData.noFallFallDistance +") y=" + loc.getY() + ((mData.hasSetBack() && mData.getSetBackY() < mData.noFallMaxY) ? (" jumped=" + StringUtil.fdec3.format(mData.noFallMaxY - mData.getSetBackY())): "")); } @@ -61,7 +61,7 @@ public class Critical extends Check { // TODO: Skip near the highest jump height (needs check if head collided with something solid, which also detects low jump). if (dataM.sfLowJump || mcFallDistance < cc.criticalFallDistance && !BlockProperties.isResetCond(player, loc, mCc.yOnGround)) { final MovingConfig ccM = MovingConfig.getConfig(player); - if (MovingListener.shouldCheckSurvivalFly(player, dataM, ccM)) { + if (MovingUtil.shouldCheckSurvivalFly(player, dataM, ccM)) { data.criticalVL += 1.0; // Execute whatever actions are associated with this check and // the violation level and find out if we should cancel the event. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java index 31b436d3..87023303 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java @@ -35,7 +35,7 @@ import fr.neatmonster.nocheatplus.checks.moving.LocationTrace.TraceEntry; import fr.neatmonster.nocheatplus.checks.moving.MediumLiftOff; import fr.neatmonster.nocheatplus.checks.moving.MovingConfig; import fr.neatmonster.nocheatplus.checks.moving.MovingData; -import fr.neatmonster.nocheatplus.checks.moving.MovingListener; +import fr.neatmonster.nocheatplus.checks.moving.MovingUtil; import fr.neatmonster.nocheatplus.compat.BridgeHealth; import fr.neatmonster.nocheatplus.components.JoinLeaveListener; import fr.neatmonster.nocheatplus.logging.Streams; @@ -297,7 +297,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{ if (hDist >= 0.23) { // TODO: Might need to check hDist relative to speed / modifiers. final MovingConfig mc = MovingConfig.getConfig(player); - if (now <= mData.timeSprinting + mc.sprintingGrace && MovingListener.shouldCheckSurvivalFly(player, mData, mc)){ + if (now <= mData.timeSprinting + mc.sprintingGrace && MovingUtil.shouldCheckSurvivalFly(player, mData, mc)){ // Judge as "lost sprint" problem. // TODO: What would mData.lostSprintCount > 0 mean here? mData.lostSprintCount = 7; @@ -566,7 +566,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{ if (damagedData.debug || mdata.debug) { NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, damagedPlayer.getName() + " received knockback level: " + level); } - MovingListener.addVelocity(damagedPlayer, mdata, mcc, dir.getX(), vy, dir.getZ()); + mdata.addVelocity(damagedPlayer, mcc, dir.getX(), vy, dir.getZ()); } /** diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java index 377ca7f5..d95590f3 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingData.java @@ -7,12 +7,15 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import fr.neatmonster.nocheatplus.NCPAPIProvider; import fr.neatmonster.nocheatplus.checks.access.ACheckData; import fr.neatmonster.nocheatplus.checks.access.CheckDataFactory; import fr.neatmonster.nocheatplus.checks.access.ICheckData; +import fr.neatmonster.nocheatplus.logging.Streams; import fr.neatmonster.nocheatplus.utilities.ActionAccumulator; import fr.neatmonster.nocheatplus.utilities.ActionFrequency; import fr.neatmonster.nocheatplus.utilities.PlayerLocation; +import fr.neatmonster.nocheatplus.utilities.TickTask; /** * Player specific data for the moving checks. @@ -119,7 +122,7 @@ public class MovingData extends ACheckData { public double verticalFreedom; public double verticalVelocity; public int verticalVelocityUsed = 0; - + /** Horizontal velocity modeled as an axis (always positive) */ private final AxisVelocity horVel = new AxisVelocity(); @@ -522,21 +525,13 @@ public class MovingData extends ACheckData { public void addHorizontalVelocity(final Velocity vel) { horVel.add(vel); } - - /** - * Add vertical velocity (distance).
- * @param vel - */ - public void addVerticalVelocity(final Velocity vel) { - horVel.add(vel); - } /** * Remove all vertical and horizontal velocity. */ public void removeAllVelocity() { horVel.clear(); -// verVel.clear(); + // verVel.clear(); } /** @@ -546,7 +541,7 @@ public class MovingData extends ACheckData { */ public void removeInvalidVelocity(final int tick) { horVel.removeInvalid(tick); -// verVel.removeInvalid(tick); + // verVel.removeInvalid(tick); } /** @@ -555,7 +550,7 @@ public class MovingData extends ACheckData { public void clearActiveHorVel() { horVel.clearActive(); } - + /** * Clear only active horizontal velocity. */ @@ -570,14 +565,14 @@ public class MovingData extends ACheckData { public boolean hasQueuedHorVel() { return horVel.hasQueued(); } - -// public boolean hasActiveVerVel() { -// return verVel.hasActive(); -// } -// public boolean hasQueuedVerVel() { -// return verVel.hasQueued(); -// } + // public boolean hasActiveVerVel() { + // return verVel.hasActive(); + // } + + // public boolean hasQueuedVerVel() { + // return verVel.hasQueued(); + // } /** * Called for moving events, increase age of velocity, decrease amounts, check which entries are invalid. Both horizontal and vertical. @@ -585,9 +580,9 @@ public class MovingData extends ACheckData { public void velocityTick() { // Horizontal velocity (intermediate concept). horVel.tick(); - + // Vertical velocity (new concept). -// verVel.tick(); + // verVel.tick(); if (verticalVelocity <= 0.09D) { verticalVelocityUsed ++; verticalVelocityCounter--; @@ -779,4 +774,50 @@ public class MovingData extends ACheckData { trace = null; } + /** + * Add velocity to internal book-keeping. + * @param player + * @param data + * @param cc + * @param vx + * @param vy + * @param vz + */ + public void addVelocity(final Player player, final MovingConfig cc, final double vx, final double vy, final double vz) { + + final int tick = TickTask.getTick(); + removeInvalidVelocity(tick - cc.velocityActivationTicks); + + if (debug) { + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " new velocity: " + vx + ", " + vy + ", " + vz); + } + + boolean used = false; + if (vy > 0D) { + used = true; + if (verticalFreedom <= 0.001 && verticalVelocityCounter >= 0) { + verticalVelocity = 0; + } + verticalVelocity += vy; + verticalFreedom += verticalVelocity; + verticalVelocityCounter = Math.min(100, Math.max(verticalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(vy * 10.0)); // 50; + verticalVelocityUsed = 0; + } + + + if (vx != 0.0 && vz != 0.0) { + final double newVal = Math.sqrt(vx * vx + vz * vz); + used = true; + final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, Math.max(20, 1 + (int) Math.round(newVal * 10.0))); + addHorizontalVelocity(vel); + } + + // Set dirty flag here. + if (used) { + sfDirty = true; // TODO: Only needed for vertical velocity? Get rid anyway :p. + sfNoLowJump = true; + } + // TODO: clear accounting here ? + } + } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 8c9c8b2e..71869c06 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -83,65 +83,6 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters; */ public class MovingListener extends CheckListener implements TickListener, IRemoveData, IHaveCheckType, INotifyReload, INeedConfig, JoinLeaveListener{ - /** - * Check if the player is to be checked by the survivalfly check. - * @param player - * @param data - * @param cc - * @return - */ - public static final boolean shouldCheckSurvivalFly(final Player player, final MovingData data, final MovingConfig cc) { - return cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY) && - (cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && !player.isFlying() && (cc.ignoreAllowFlight || !player.getAllowFlight()); - } - - /** - * Handle an illegal move by a player, attempt to restore a valid location. - * @param event - * @param player - * @param data - */ - public static void handleIllegalMove(final PlayerMoveEvent event, final Player player, final MovingData data) - { - // This might get extended to a check-like thing. - boolean restored = false; - final PlayerLocation pLoc = new PlayerLocation(NCPAPIProvider.getNoCheatPlusAPI().getMCAccess(), null); - // (Mind that we don't set the block cache here). - final Location loc = player.getLocation(); - if (!restored && data.hasSetBack()) { - final Location setBack = data.getSetBack(loc); - pLoc.set(setBack, player); - if (!pLoc.isIllegal()) { - event.setFrom(setBack); - event.setTo(setBack); - restored = true; - } - else { - data.resetSetBack(); - } - } - if (!restored) { - pLoc.set(loc, player); - if (!pLoc.isIllegal()) { - event.setFrom(loc); - event.setTo(loc); - restored = true; - } - } - pLoc.cleanup(); - if (!restored) { - // TODO: reset the bounding box of the player ? - if (MovingConfig.getConfig(player).tempKickIllegal) { - NCPAPIProvider.getNoCheatPlusAPI().denyLogin(player.getName(), 24L * 60L * 60L * 1000L); - StaticLog.logSevere("[NCP] could not restore location for " + player.getName() + ", kicking them and deny login for 24 hours"); - } else { - StaticLog.logSevere("[NCP] could not restore location for " + player.getName() + ", kicking them."); - } - CheckUtils.kickIllegalMove(player); - } - } - - /** The instance of NoCheatPlus. */ private final Plugin plugin = Bukkit.getPluginManager().getPlugin("NoCheatPlus"); // TODO @@ -238,7 +179,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo if (Math.abs(loc.getX() - 0.5 - block.getX()) <= 1D && Math.abs(loc.getZ() - 0.5 - block.getZ()) <= 1D && loc.getY() - blockY > 0D && loc.getY() - blockY < 2D - && (canJumpOffTop(mat) || BlockProperties.isLiquid(mat))) { + && (MovingUtil.canJumpOffTop(mat) || BlockProperties.isLiquid(mat))) { // The creative fly and/or survival fly check is enabled, the // block was placed below the player and is // solid, so do what we have to do. @@ -248,16 +189,6 @@ public class MovingListener extends CheckListener implements TickListener, IRemo useLoc.setWorld(null); } - /** - * Used for a workaround that resets the set-back for the case of jumping on just placed blocks. - * @param id - * @return - */ - private static boolean canJumpOffTop(final Material blockType) { - // TODO: Test if this can be removed! - return BlockProperties.isGround(blockType) || BlockProperties.isSolid(blockType); - } - /** * We listen to this event to prevent player from flying by sending bed leaving packets. * @@ -288,7 +219,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo final MovingData data = MovingData.getData(player); final MovingConfig cc = MovingConfig.getConfig(player); Location target = null; - final boolean sfCheck = shouldCheckSurvivalFly(player, data, cc); + final boolean sfCheck = MovingUtil.shouldCheckSurvivalFly(player, data, cc); if (sfCheck) { target = data.getSetBack(loc); } @@ -452,7 +383,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo } // Check for illegal move and bounding box etc. if (moveInfo.from.isIllegal() || moveInfo.to.isIllegal()) { - handleIllegalMove(event, player, data); + MovingUtil.handleIllegalMove(event, player, data); moveInfo.cleanup(); parkedInfo.add(moveInfo); return; @@ -548,7 +479,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Check which fly check to use. final boolean checkCf; final boolean checkSf; - if (shouldCheckSurvivalFly(player, data, cc)) { + if (MovingUtil.shouldCheckSurvivalFly(player, data, cc)) { checkCf = false; checkSf = true; data.adjustWalkSpeed(player.getWalkSpeed(), tick, cc.speedGrace); @@ -563,6 +494,17 @@ public class MovingListener extends CheckListener implements TickListener, IRemo else{ checkCf = checkSf = false; } + + boolean checkNf = true; + if (checkSf || checkCf) { + // Check jumping on things like slime blocks. + if (to.getY() < from.getY() && player.getFallDistance() > 1f && (BlockProperties.getBlockFlags(pTo.getTypeIdBelow()) & BlockProperties.F_BOUNCE25) != 0L) { + // Apply changes to NoFall and other. + processTrampoline(player, pFrom, pTo, data, cc); + // Skip NoFall. + checkNf = false; + } + } // Flying checks. if (checkSf) { @@ -587,7 +529,10 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Only check if passable has not already set back. newTo = survivalFly.check(player, pFrom, pTo, data, cc, time); } - final boolean checkNf = cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL); + // Only check NoFall, if not already vetoed. + if (checkNf) { + checkNf = cc.noFallCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_NOFALL) && !player.hasPermission(Permissions.MOVING_NOFALL); + } if (newTo == null) { // Hover. // TODO: Could reset for from-on-ground as well, for not too big moves. @@ -669,6 +614,32 @@ public class MovingListener extends CheckListener implements TickListener, IRemo parkedInfo.add(moveInfo); } + private void processTrampoline(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) { + // TODO: Where to put... + // TODO: Other side conditions (fluids, web) + // TODO: Fake fall distance exploit (to bounce off slime blocks :p). + // TODO: Confine further (depends on which checks are enabled, if possible to check, e.g. noFallMaxY). + // Check for slime block below explicitly. + // The center of the player must be above the block. + if (cc.debug) { + NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " Trampoline effect..."); + } + // TODO: Consider making this just a checking method (use result for applying effects). + // CHEATING: Add velocity. + // TODO: 1. Confine for direct use (no latency here). 2. Hard set velocity? 3.. Switch to friction based. + if (!survivalFly.isReallySneaking(player)) { + data.addVelocity(player, cc, 0.0, (double) player.getFallDistance() / 30.0, 0.0); + } + // CHEATING: Remove fall distance: + // TODO: Test under which conditions the player would still take fall damage. + // TODO: Depends on NoFall being enabled as well. + player.setFallDistance(0f); + data.noFallFallDistance = 0f; + data.noFallMaxY = 0.0; + data.noFallSkipAirCheck = true; + // (Skipping the NoFall check is necessary, because THIS move can be big.) + } + /** * * @param player @@ -1022,53 +993,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo // Process velocity. final Vector velocity = event.getVelocity(); final MovingConfig cc = MovingConfig.getConfig(player); - addVelocity(player, data, cc, velocity.getX(), velocity.getY(), velocity.getZ()); - } - - /** - * Add velocity to internal book-keeping. - * @param player - * @param data - * @param cc - * @param vx - * @param vy - * @param vz - */ - public static void addVelocity(final Player player, final MovingData data, final MovingConfig cc, final double vx, final double vy, final double vz) { - - final int tick = TickTask.getTick(); - data.removeInvalidVelocity(tick - cc.velocityActivationTicks); - - if (data.debug) { - NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, player.getName() + " new velocity: " + vx + ", " + vy + ", " + vz); - } - - boolean used = false; - if (vy > 0D) { - used = true; - if (data.verticalFreedom <= 0.001 && data.verticalVelocityCounter >= 0) { - data.verticalVelocity = 0; - } - data.verticalVelocity += vy; - data.verticalFreedom += data.verticalVelocity; - data.verticalVelocityCounter = Math.min(100, Math.max(data.verticalVelocityCounter, cc.velocityGraceTicks ) + 1 + (int) Math.round(vy * 10.0)); // 50; - data.verticalVelocityUsed = 0; - } - - - if (vx != 0.0 && vz != 0.0) { - final double newVal = Math.sqrt(vx * vx + vz * vz); - used = true; - final Velocity vel = new Velocity(tick, newVal, cc.velocityActivationCounter, Math.max(20, 1 + (int) Math.round(newVal * 10.0))); - data.addHorizontalVelocity(vel); - } - - // Set dirty flag here. - if (used) { - data.sfDirty = true; // TODO: Only needed for vertical velocity? Get rid anyway :p. - data.sfNoLowJump = true; - } - // TODO: clear accounting here ? + data.addVelocity(player, cc, velocity.getX(), velocity.getY(), velocity.getZ()); } /** @@ -1178,7 +1103,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo return; } final MovingConfig cc = MovingConfig.getConfig(player); - if (event.isCancelled() || !shouldCheckSurvivalFly(player, data, cc) || !noFall.isEnabled(player)) { + if (event.isCancelled() || !MovingUtil.shouldCheckSurvivalFly(player, data, cc) || !noFall.isEnabled(player)) { data.clearNoFallData(); return; } @@ -1659,7 +1584,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo else{ if (data.sfHoverTicks > cc.sfHoverTicks) { // Re-Check if survivalfly can apply at all. - if (shouldCheckSurvivalFly(player, data, cc)) { + if (MovingUtil.shouldCheckSurvivalFly(player, data, cc)) { handleHoverViolation(player, loc, cc, data); // Assume the player might still be hovering. res = false; diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingUtil.java new file mode 100644 index 00000000..c9c303c5 --- /dev/null +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/MovingUtil.java @@ -0,0 +1,92 @@ +package fr.neatmonster.nocheatplus.checks.moving; + +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerMoveEvent; + +import fr.neatmonster.nocheatplus.NCPAPIProvider; +import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; +import fr.neatmonster.nocheatplus.logging.StaticLog; +import fr.neatmonster.nocheatplus.permissions.Permissions; +import fr.neatmonster.nocheatplus.utilities.BlockProperties; +import fr.neatmonster.nocheatplus.utilities.CheckUtils; +import fr.neatmonster.nocheatplus.utilities.PlayerLocation; + +/** + * Static utility methods. + * @author dev1mc + * + */ +public class MovingUtil { + + /** + * Check if the player is to be checked by the survivalfly check. + * @param player + * @param data + * @param cc + * @return + */ + public static final boolean shouldCheckSurvivalFly(final Player player, final MovingData data, final MovingConfig cc) { + return cc.survivalFlyCheck && !NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) && !player.hasPermission(Permissions.MOVING_SURVIVALFLY) && + (cc.ignoreCreative || player.getGameMode() != GameMode.CREATIVE) && !player.isFlying() && (cc.ignoreAllowFlight || !player.getAllowFlight()); + } + + /** + * Handle an illegal move by a player, attempt to restore a valid location. + * @param event + * @param player + * @param data + */ + public static void handleIllegalMove(final PlayerMoveEvent event, final Player player, final MovingData data) + { + // This might get extended to a check-like thing. + boolean restored = false; + final PlayerLocation pLoc = new PlayerLocation(NCPAPIProvider.getNoCheatPlusAPI().getMCAccess(), null); + // (Mind that we don't set the block cache here). + final Location loc = player.getLocation(); + if (!restored && data.hasSetBack()) { + final Location setBack = data.getSetBack(loc); + pLoc.set(setBack, player); + if (!pLoc.isIllegal()) { + event.setFrom(setBack); + event.setTo(setBack); + restored = true; + } + else { + data.resetSetBack(); + } + } + if (!restored) { + pLoc.set(loc, player); + if (!pLoc.isIllegal()) { + event.setFrom(loc); + event.setTo(loc); + restored = true; + } + } + pLoc.cleanup(); + if (!restored) { + // TODO: reset the bounding box of the player ? + if (MovingConfig.getConfig(player).tempKickIllegal) { + NCPAPIProvider.getNoCheatPlusAPI().denyLogin(player.getName(), 24L * 60L * 60L * 1000L); + StaticLog.logSevere("[NCP] could not restore location for " + player.getName() + ", kicking them and deny login for 24 hours"); + } else { + StaticLog.logSevere("[NCP] could not restore location for " + player.getName() + ", kicking them."); + } + CheckUtils.kickIllegalMove(player); + } + } + + /** + * Used for a workaround that resets the set-back for the case of jumping on just placed blocks. + * @param id + * @return + */ + public static boolean canJumpOffTop(final Material blockType) { + return BlockProperties.isGround(blockType) || BlockProperties.isSolid(blockType); + } + +} diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java index 6baba6d7..9dd899af 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/NoFall.java @@ -76,14 +76,20 @@ public class NoFall extends Check { private void dealFallDamage(final Player player, final double damage) { - // TODO: Byte code compatibility ? - final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage); - Bukkit.getPluginManager().callEvent(event); - if (!event.isCancelled()){ - // TODO: account for no damage ticks etc. - player.setLastDamageCause(event); - mcAccess.dealFallDamage(player, BridgeHealth.getDamage(event)); + if (mcAccess.dealFallDamageFiresAnEvent().decide()) { + // TODO: Better decideOptimistically? + mcAccess.dealFallDamage(player, damage); } + else { + final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage); + Bukkit.getPluginManager().callEvent(event); + if (!event.isCancelled()){ + // TODO: account for no damage ticks etc. + player.setLastDamageCause(event); + mcAccess.dealFallDamage(player, BridgeHealth.getDamage(event)); + } + } + // TODO: let this be done by the damage event (!). // data.clearNoFallData(); // -> currently done in the damage eventhandling method. player.setFallDistance(0); diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 6e5b8f75..0961f000 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -589,6 +589,15 @@ public class SurvivalFly extends Check { return hAllowedDistance; } + /** + * Access method from outside. + * @param player + * @return + */ + public boolean isReallySneaking(final Player player) { + return reallySneaking.contains(player.getName()); + } + /** * Check if touching the ground was lost (client did not send, or server did not put it through). * @param player @@ -1140,6 +1149,7 @@ public class SurvivalFly extends Check { double yMargin = cc.yOnGround; // TODO: Might set margin higher depending on distance to 0 of block and last y distance etc. // TODO: check with iY + 0.25 removed. + // TODO: Slime blocks ? if (BlockProperties.isOnGround(from.getBlockCache(), Math.min(data.fromX, from.getX()) - r, iY - yMargin, Math.min(data.fromZ, from.getZ()) - r, Math.max(data.fromX, from.getX()) + r, iY + 0.25, Math.max(data.fromZ, from.getZ()) + r, 0L)) { return applyLostGround(player, from, true, data, "interpolate"); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccess.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccess.java index 72fe71d8..b17a9445 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccess.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccess.java @@ -20,120 +20,126 @@ import fr.neatmonster.nocheatplus.utilities.BlockCache; * */ public interface MCAccess { - - /** - * Simple version identifiers, if several must be separated by '|' like "1.4.2|1.4.4|1.4.5", to indicate multiple sub-versions supported use "1.5.x", use "?" to indicate general future support. - * @return - */ - public String getMCVersion(); - - /** - * Server version tag, like CB 2511. - * @return - */ - public String getServerVersionTag(); - - /** - * Get the servers command map. - * @return May return null if not supported. - */ - public CommandMap getCommandMap(); - - /** - * Get a BlockCache implementation. - * @param world May be null to store an instance of BlockCache for future use. - * @return - */ - public BlockCache getBlockCache(World world); - - /** - * Get height of an entity (attack relevant, the maximal "thing" found). - */ - public double getHeight(Entity entity); - - /** - * Return some width. - * @param entity - * @return - */ - public double getWidth(Entity entity); - - /** - * NMS Block static. - * @param id - * @return MAYBE if undecided, YES or NO if decided. - */ - public AlmostBoolean isBlockSolid(int id); - - /** - * NMS Block static.. - * @param id - * @return MAYBE if undecided, YES or NO if decided. - */ - public AlmostBoolean isBlockLiquid(int id); - /** - * Does only check y bounds, returns false if dead. this is half a check as auxiliary means for PlayerLocation.isIllegal. - * @param player - * @return MAYBE if undecided, YES or NO if decided. - */ - public AlmostBoolean isIllegalBounds(Player player); - - /** - * - * @param player - * @return Double.NEGATIVE_INFINITY if not present. - */ - public double getJumpAmplifier(Player player); - - /** - * - * @return Double.NEGATIVE_INFINITY if not present. - */ - public double getFasterMovementAmplifier(Player player); + /** + * Simple version identifiers, if several must be separated by '|' like "1.4.2|1.4.4|1.4.5", to indicate multiple sub-versions supported use "1.5.x", use "?" to indicate general future support. + * @return + */ + public String getMCVersion(); - public int getInvulnerableTicks(Player player); + /** + * Server version tag, like CB 2511. + * @return + */ + public String getServerVersionTag(); - public void setInvulnerableTicks(Player player, int ticks); + /** + * Get the servers command map. + * @return May return null if not supported. + */ + public CommandMap getCommandMap(); - public void dealFallDamage(Player player, double damage); + /** + * Get a BlockCache implementation. + * @param world May be null to store an instance of BlockCache for future use. + * @return + */ + public BlockCache getBlockCache(World world); - /** - * This may well be removed, if possible to check with Bukkit. - * @param damaged - * @return - */ - public boolean isComplexPart(Entity damaged); + /** + * Get height of an entity (attack relevant, the maximal "thing" found). + */ + public double getHeight(Entity entity); + + /** + * Return some width. + * @param entity + * @return + */ + public double getWidth(Entity entity); + + /** + * NMS Block static. + * @param id + * @return MAYBE if undecided, YES or NO if decided. + */ + public AlmostBoolean isBlockSolid(int id); + + /** + * NMS Block static.. + * @param id + * @return MAYBE if undecided, YES or NO if decided. + */ + public AlmostBoolean isBlockLiquid(int id); + + /** + * Does only check y bounds, returns false if dead. this is half a check as auxiliary means for PlayerLocation.isIllegal. + * @param player + * @return MAYBE if undecided, YES or NO if decided. + */ + public AlmostBoolean isIllegalBounds(Player player); + + /** + * + * @param player + * @return Double.NEGATIVE_INFINITY if not present. + */ + public double getJumpAmplifier(Player player); + + /** + * + * @return Double.NEGATIVE_INFINITY if not present. + */ + public double getFasterMovementAmplifier(Player player); + + public int getInvulnerableTicks(Player player); + + public void setInvulnerableTicks(Player player, int ticks); + + public void dealFallDamage(Player player, double damage); + + /** + * If dealFallDamage(Player, double) will fire a damage event. + * @return + */ + public AlmostBoolean dealFallDamageFiresAnEvent(); + + /** + * This may well be removed, if possible to check with Bukkit. + * @param damaged + * @return + */ + public boolean isComplexPart(Entity damaged); + + /** + * Tests if player is not set to dead but has no health. + * @param player + * @return + */ + public boolean shouldBeZombie(Player player); + + /** + * Ensure the player is really taken out: Set flag + death ticks. + * + * TODO: Check if still necessary + make knowledge-base entries for what to check. + * + * @param player + * @param deathTicks + */ + public void setDead(Player player, int deathTicks); + + /** + * Usually sand and gravel. Not for fastest access. + * @param type + * @return + */ + public boolean hasGravity(Material type); + + // /** + // * Correct the direction (yaw + pitch). If this can't be done lightly it should just do nothing. Check pitch and yaw before calling, use auxiliary methods from LocUtil. + // * @param player + // */ + // public void correctDirection(Player player); - /** - * Tests if player is not set to dead but has no health. - * @param player - * @return - */ - public boolean shouldBeZombie(Player player); - /** - * Ensure the player is really taken out: Set flag + death ticks. - * - * TODO: Check if still necessary + make knowledge-base entries for what to check. - * - * @param player - * @param deathTicks - */ - public void setDead(Player player, int deathTicks); - - /** - * Usually sand and gravel. Not for fastest access. - * @param type - * @return - */ - public boolean hasGravity(Material type); - -// /** -// * Correct the direction (yaw + pitch). If this can't be done lightly it should just do nothing. Check pitch and yaw before calling, use auxiliary methods from LocUtil. -// * @param player -// */ -// public void correctDirection(Player player); - - } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/init/vanilla/BlocksMC1_8.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/init/vanilla/BlocksMC1_8.java index beef36e9..2fc6b13d 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/init/vanilla/BlocksMC1_8.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/blocks/init/vanilla/BlocksMC1_8.java @@ -7,6 +7,7 @@ import fr.neatmonster.nocheatplus.compat.blocks.init.BlockInit; import fr.neatmonster.nocheatplus.config.WorldConfigProvider; import fr.neatmonster.nocheatplus.logging.StaticLog; import fr.neatmonster.nocheatplus.utilities.BlockFlags; +import fr.neatmonster.nocheatplus.utilities.BlockProperties; public class BlocksMC1_8 implements BlockPropertiesSetup { @@ -22,6 +23,8 @@ public class BlocksMC1_8 implements BlockPropertiesSetup { public void setupBlockProperties(WorldConfigProvider worldConfigProvider) { // 165(SLIME_BLOCK BlockInit.setAs(165, Material.TNT); // Full block, instant break. + // Add the bouncing flag. + BlockProperties.setBlockFlags(165, BlockProperties.getBlockFlags(165) | BlockProperties.F_BOUNCE25); // 166(BARRIER BlockInit.setAs(166, Material.BEDROCK); // Full block, unbreakable. diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java index e4e02265..18e29284 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/BlockProperties.java @@ -367,13 +367,19 @@ public class BlockProperties { /** Meta-flag to indicate that the (max.-) edges should mean a collision, can be passed to collidesBlock. */ public static final long F_COLLIDE_EDGES = 0x100000; - + /** Thick fence (default wooden fence). */ public static final long F_THICK_FENCE = 0x200000; - + /** Fence gate style with 0x04 being fully passable. */ public static final long F_PASSABLE_X4 = 0x200000; + + // TODO: Separate no fall damage flag ? [-> on ground could return "dominating" flags, or extra flags] + /** Like slime block: bounce back 25% of fall height without taking fall damage [TODO: Check/adjust]. */ + public static final long F_BOUNCE25 = 0x400000; + // TODO: When flags are out, switch to per-block classes :p. + /** * Map flag to names. */ @@ -601,7 +607,7 @@ public class BlockProperties { }) { blockFlags[mat.getId()] |= F_HEIGHT150 | F_VARIABLE | F_THICK_FENCE; } - + // Fence gate(s). for (final Material mat : new Material[]{ Material.FENCE_GATE, @@ -1334,7 +1340,7 @@ public class BlockProperties { pLoc.cleanup(); return res; } - + /** * Simple checking method, heavy. No isIllegal check. * @param player diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java index 83460040..875ebc5e 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/PlayerLocation.java @@ -1,891 +1,891 @@ -package fr.neatmonster.nocheatplus.utilities; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import fr.neatmonster.nocheatplus.compat.AlmostBoolean; -import fr.neatmonster.nocheatplus.compat.MCAccess; - -/** - * An utility class used to know a lot of things for a player and a location - * given. - */ -public class PlayerLocation { - - // Final members // - private final MCAccess mcAccess; - - // Simple members // - - /** Y parameter for growing the bounding box with the isOnGround check. */ - private double yOnGround = 0.001; - - /** The block coordinates. */ - private int blockX, blockY, blockZ; - - /** The exact coordinates. */ - private double x, y, z; - - private float yaw, pitch; - - private double width; - - /** Bounding box of the player. */ - private double minX, maxX, minY, maxY, minZ, maxZ; - - // TODO: Check if onGround can be completely replaced by onGroundMinY and notOnGroundMaxY. - /** Minimal yOnGround for which the player is on ground. No extra xz/y margin.*/ - private double onGroundMinY = Double.MAX_VALUE; - /** Maximal yOnGround for which the player is not on ground. No extra xz/y margin.*/ - private double notOnGroundMaxY = Double.MIN_VALUE; - - // "Light" object members (reset to null) // - - // TODO: The following should be changed to primitive types, add one long for "checked"-flags. Booleans can be compressed into a long. - // TODO: All properties that can be set should have a "checked" flag, thus resetting the flag suffices. - - /** Type id of the block at the position. */ - private Integer typeId = null; - - /** Type id of the block below. */ - private Integer typeIdBelow = null; - - /** Data value of the block this position is on. */ - private Integer data = null; - - /** All block flags collected for maximum used bounds. */ - private Long blockFlags = null; - - /** Is the player on ice? */ - private Boolean onIce = null; - - /** Is the player on ladder? */ - private Boolean onClimbable = null; - - /** Simple test if the exact position is passable. */ - private Boolean passable = null; - - /** Is the player above stairs? */ - private Boolean aboveStairs = null; - - /** Is the player in lava? */ - private Boolean inLava = null; - - /** Is the player in water? */ - private Boolean inWater = null; - - /** Is the player is web? */ - private Boolean inWeb = null; - - /** Is the player on the ground? */ - private Boolean onGround = null; - - // "Heavy" object members (reset to null for cleanup). // - - /** The player ! */ - private Player player = null; - - /** Bukkit world. */ - private World world = null; - - // "Heavy" object members (further cleanup call needed + set to null for cleanup) // - - /** Optional block property cache. */ - private BlockCache blockCache = null; - - - public PlayerLocation(final MCAccess mcAccess, final BlockCache blockCache) { - this.mcAccess = mcAccess; - this.blockCache = blockCache; - } - - public Player getPlayer() { - return player; - } - - /** - * Gets the location. - * - * @return the location - * @throws NullPointerException, if the world stored internally is null. - */ - public Location getLocation() { - if (this.world == null) { - throw new NullPointerException("World is null."); - } - return new Location(world, x, y, z); - } - - /** - * Get the world! - * @return - */ - public World getWorld() { - return world; - } - - /** - * Gets the blockX. - * - * @return the blockX - */ - public double getX() { - return x; - } - - /** - * Gets the boundY. - * - * @return the boundY - */ - public double getY() { - return y; - } - - /** - * Gets the blockZ. - * - * @return the blockZ - */ - public double getZ() { - return z; - } - - /** - * Gets the yaw. - * - * @return the yaw - */ - public float getYaw() { - return yaw; - } - - /** - * Gets the pitch. - * - * @return the pitch - */ - public float getPitch() { - return pitch; - } - - public Vector getVector() { - return new Vector(x, y, z); - } - - public double getWidth() { - return width; - } - - public int getBlockX() { - return blockX; - } - - public int getBlockY() { - return blockY; - } - - public int getBlockZ() { - return blockZ; - } - - /** - * Compares block coordinates (not the world). - * - * @param other - * @return - */ - public final boolean isSameBlock(final PlayerLocation other) { - return blockX == other.getBlockX() && blockZ == other.getBlockZ() && blockY == other.getBlockY(); - } - - /** - * Block coordinate comparison. - * @param x - * @param y - * @param z - * @return - */ - public final boolean isSameBlock(final int x, final int y, final int z) { - return blockX == x && blockZ == z && blockY == y; - } - - /** - * Compares block coordinates (not the world). - * @param loc - * @return - */ - public final boolean isSameBlock(final Location loc) { - return blockX == loc.getBlockX() && blockZ == loc.getBlockZ() && blockY == loc.getBlockY(); - } - - /** - * Check if this location is above the given one (blockY + 1). - * @param loc - * @return - */ - public boolean isBlockAbove(final PlayerLocation loc) { - return blockY == loc.getBlockY() + 1 && blockX == loc.getBlockX() && blockZ == loc.getBlockZ(); - } - - /** - * Check if this location is above the given one (blockY + 1). - * @param loc - * @return - */ - public boolean isBlockAbove(final Location loc) { - return blockY == loc.getBlockY() + 1 && blockX == loc.getBlockX() && blockZ == loc.getBlockZ(); - } - - /** - * Compares exact coordinates (not the world). - * - * @param loc - * @return - */ - public boolean isSamePos(final PlayerLocation loc) { - return x == loc.getX() && z == loc.getZ() && y == loc.getY(); - } - - /** - * Compares exact coordinates (not the world). - * - * @param loc - * @return - */ - public boolean isSamePos(final Location loc) { - return x == loc.getX() && z == loc.getZ() && y == loc.getY(); - } - - /** - * Manhattan distance, see Trigutil. - * @param other - * @return - */ - public int manhattan(final PlayerLocation other) { - // TODO: Consider using direct field access from other methods as well. - return TrigUtil.manhattan(this.blockX, this.blockY, this.blockZ, other.blockX, other.blockY, other.blockZ); - } - - /** - * Maximum block distance comparing dx, dy, dz. - * @param other - * @return - */ - public int maxBlockDist(final PlayerLocation other) { - // TODO: Consider using direct field access from other methods as well. - return TrigUtil.maxDistance(this.blockX, this.blockY, this.blockZ, other.blockX, other.blockY, other.blockZ); - } - - /** - * Checks if the player is above stairs. - * - * @return true, if the player above on stairs - */ - public boolean isAboveStairs() { - if (aboveStairs == null) { - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_STAIRS) == 0 ) { - aboveStairs = false; - return false; - } - // TODO: Distinguish based on actual height off .0 ? - // TODO: diff still needed ? - final double diff = 0; // 0.001; - aboveStairs = BlockProperties.collides(blockCache, minX - diff, minY - 1.0, minZ - diff, maxX + diff, minY + 0.25, maxZ + diff, BlockProperties.F_STAIRS); - } - return aboveStairs; - } - - /** - * Checks if the player is in lava. - * - * @return true, if the player is in lava - */ - public boolean isInLava() { - if (inLava == null) { - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_LAVA) == 0 ) { - inLava = false; - return false; - } - // TODO: ... -// final double dX = -0.10000000149011612D; -// final double dY = -0.40000000596046448D; -// final double dZ = dX; -// inLava = BlockProperties.collides(blockCache, minX - dX, minY - dY, minZ - dZ, maxX + dX, maxY + dY, maxZ + dZ, BlockProperties.F_LAVA); - inLava = BlockProperties.collides(blockCache, minX, minY, minZ, maxX, maxY, maxZ, BlockProperties.F_LAVA); - } - return inLava; - } - - /** - * Checks if the player is in water. - * - * @return true, if the player is in water - */ - public boolean isInWater() { - if (inWater == null) { - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_WATER) == 0 ) { - inWater = false; - return false; - } - // TODO: ... -// final double dX = -0.001D; -// final double dY = -0.40000000596046448D - 0.001D; -// final double dZ = dX; -// inWater = BlockProperties.collides(blockCache, minX - dX, minY - dY, minZ - dZ, maxX + dX, maxY + dY, maxZ + dZ, BlockProperties.F_WATER); - inWater = BlockProperties.collides(blockCache, minX, minY, minZ, maxX, maxY, maxZ, BlockProperties.F_WATER); - - } - return inWater; - } - - /** - * Checks if the player is in a liquid. - * - * @return true, if the player is in a liquid - */ - public boolean isInLiquid() { - // TODO: optimize (check liquid first and only if liquid check further) - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_LIQUID) == 0 ) return false; - // TODO: This should check for F_LIQUID too, Use a method that returns all found flags (!). - return isInWater() || isInLava(); - } - - /** - * Checks if the player is on ice. - * - * @return true, if the player is on ice - */ - public boolean isOnIce() { - if (onIce == null) { - // TODO: Use a box here too ? - // TODO: check if player is really sneaking (refactor from survivalfly to static access in Combined ?)! - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_ICE) == 0) { - // TODO: check onGroundMinY !? - onIce = false; - } else { - final int id; - if (player.isSneaking() || player.isBlocking()) { - id = getTypeId(blockX, Location.locToBlock(minY - 0.1D), blockZ); - } - else { - id = getTypeIdBelow().intValue(); - } - onIce = BlockProperties.isIce(id); - } - } - return onIce; - } - - /** - * Checks if the player is on a ladder or vine. - * - * @return If so. - */ - public boolean isOnClimbable() { - if (onClimbable == null) { - // Climbable blocks. - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_CLIMBABLE) == 0 ) { - onClimbable = false; - return false; - } - onClimbable = (BlockProperties.getBlockFlags(getTypeId()) & BlockProperties.F_CLIMBABLE) != 0; - // TODO: maybe use specialized bounding box. -// final double d = 0.1d; -// onClimbable = BlockProperties.collides(getBlockAccess(), minX - d, minY - d, minZ - d, maxX + d, minY + 1.0, maxZ + d, BlockProperties.F_CLIMBABLE); - } - return onClimbable; - } - - /** - * Check if a player may climb upwards (isOnClimbable returned true, player does not move from/to ground).
- * Having checked the other stuff is prerequisite for calling this (!). - * @param jumpHeigth Height the player is allowed to have jumped. - * @return - */ - public boolean canClimbUp(double jumpHeigth) { - // TODO: distinguish vines. - if (BlockProperties.isAttachedClimbable(getTypeId())) { - // Check if vine is attached to something solid - if (BlockProperties.canClimbUp(blockCache, blockX, blockY, blockZ)) { - return true; - } - // Check the block at head height. - final int headY = Location.locToBlock(y + player.getEyeHeight()); - if (headY > blockY) { - for (int cy = blockY + 1; cy <= headY; cy ++) { - if (BlockProperties.canClimbUp(blockCache, blockX, cy, blockZ)) { - return true; - } - } - } - // Finally check possible jump height. - // TODO: This too is inaccurate. - if (isOnGround(jumpHeigth)) { - // Here ladders are ok. - return true; - } - return false; - } - return true; - } - - /** - * Checks if the player is above a ladder or vine.
- * Does not save back value to field. - * - * @return If so. - */ - public boolean isAboveLadder() { - if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_CLIMBABLE) == 0 ) return false; - // TODO: bounding box ? - return (BlockProperties.getBlockFlags(getTypeIdBelow()) & BlockProperties.F_CLIMBABLE) != 0; - } - - /** - * Checks if the player is in web. - * - * @return true, if the player is in web - */ - public boolean isInWeb() { - if (inWeb == null) { - // TODO: inset still needed ? - final double inset = 0.001d; - inWeb = BlockProperties.collidesId(blockCache, minX + inset, minY + inset, minZ + inset, maxX - inset, maxY - inset, maxZ - inset, Material.WEB); - } - return inWeb; - } - - /** - * Checks if the player is on ground, including entities such as Minecart, Boat. - * - * @return true, if the player is on ground - */ - public boolean isOnGround() { - if (onGround != null) { - return onGround; - } - // Check cached values and simplifications. - if (notOnGroundMaxY >= yOnGround) onGround = false; - else if (onGroundMinY <= yOnGround) onGround = true; - else { - // Shortcut check (currently needed for being stuck + sf). - if (blockFlags == null || (blockFlags.longValue() & BlockProperties.F_GROUND) != 0) { - // TODO: Consider dropping this shortcut. - final int bY = Location.locToBlock(y - yOnGround); - final int id = bY == blockY ? getTypeId() : (bY == blockY -1 ? getTypeIdBelow() : blockCache.getTypeId(blockX, bY, blockZ)); - final long flags = BlockProperties.getBlockFlags(id); - // TODO: Might remove check for variable ? - if ((flags & BlockProperties.F_GROUND) != 0 && (flags & BlockProperties.F_VARIABLE) == 0) { - final double[] bounds = blockCache.getBounds(blockX, bY, blockZ); - // Check collision if not inside of the block. [Might be a problem for cauldron or similar + something solid above.] - // TODO: Might need more refinement. - if (bounds != null && y - bY >= bounds[4] && BlockProperties.collidesBlock(blockCache, x, minY - yOnGround, z, x, minY, z, blockX, bY, blockZ, id, bounds, flags)) { - // TODO: BlockHeight is needed for fences, use right away (above)? - if (!BlockProperties.isPassableWorkaround(blockCache, blockX, bY, blockZ, minX - blockX, minY - yOnGround - bY, minZ - blockZ, id, maxX - minX, yOnGround, maxZ - minZ, 1.0) - || (flags & BlockProperties.F_GROUND_HEIGHT) != 0 && BlockProperties.getGroundMinHeight(blockCache, blockX, bY, blockZ, id, bounds, flags) <= y - bY) { -// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** onground SHORTCUT"); - onGround = true; - } - } - } - if (onGround == null) { -// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** fetch onground std"); - // Full on-ground check (blocks). - // Note: Might check for half-block height too (getTypeId), but that is much more seldom. - onGround = BlockProperties.isOnGround(blockCache, minX, minY - yOnGround, minZ, maxX, minY, maxZ, 0L); - } - } - else onGround = false; - } - if (onGround) onGroundMinY = Math.min(onGroundMinY, yOnGround); - else { -// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** onground check entities"); - // TODO: further confine this ? - notOnGroundMaxY = Math.max(notOnGroundMaxY, yOnGround); - final double d1 = 0.25D; - onGround = blockCache.standsOnEntity(player, minX - d1, minY - yOnGround - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1); - } - return onGround; - } - - /** - * Simple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. - * @param yOnGround Margin below the player. - * @return - */ - public boolean isOnGround(final double yOnGround) { - if (notOnGroundMaxY >= yOnGround) return false; - else if (onGroundMinY <= yOnGround) return true; - return isOnGround(yOnGround, 0D, 0D, 0L); - } - - /** - * SSimple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. - * @param yOnGround - * @param ignoreFlags Flags to not regard as ground. - * @return - */ - public boolean isOnGround(final double yOnGround, final long ignoreFlags) { - if (ignoreFlags == 0) { - if (notOnGroundMaxY >= yOnGround) return false; - else if (onGroundMinY <= yOnGround) return true; - } - return isOnGround(yOnGround, 0D, 0D, ignoreFlags); - } - - - /** - * Simple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. - * @param yOnGround Margin below the player. - * @param xzMargin - * @param yMargin Extra margin added below and above. - * @return - */ - public boolean isOnGround(final double yOnGround, final double xzMargin, final double yMargin) { - if (xzMargin >= 0 && onGroundMinY <= yOnGround) return true; - if (xzMargin <= 0 && yMargin == 0) { - if (notOnGroundMaxY >= yOnGround) return false; - } - return isOnGround(yOnGround, xzMargin, yMargin, 0); - } - - /** - * Simple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. - * @param yOnGround Margin below the player. - * @param xzMargin - * @param yMargin Extra margin added below and above. - * @param ignoreFlags Flags to not regard as ground. - * @return - */ - public boolean isOnGround(final double yOnGround, final double xzMargin, final double yMargin, final long ignoreFlags) { - if (ignoreFlags == 0) { - if (xzMargin >= 0 && onGroundMinY <= yOnGround) return true; - if (xzMargin <= 0 && yMargin == 0) { - if (notOnGroundMaxY >= yOnGround) return false; - } - } -// NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** Fetch on-ground: yOnGround=" + yOnGround + " xzM=" + xzMargin + " yM=" + yMargin + " ign=" + ignoreFlags); - final boolean onGround = BlockProperties.isOnGround(blockCache, minX - xzMargin, minY - yOnGround - yMargin, minZ - xzMargin, maxX + xzMargin, minY + yMargin, maxZ + xzMargin, ignoreFlags); - if (ignoreFlags == 0) { - if (onGround) { - if (xzMargin <= 0 && yMargin == 0) { - onGroundMinY = Math.min(onGroundMinY, yOnGround); - } - } - else { - if (xzMargin >= 0) { - notOnGroundMaxY = Math.max(notOnGroundMaxY, yOnGround); - } - } - } - return onGround; - } - - /** - * Simple check with custom margins (Boat, Minecart). - * @param yOnGround Margin below the player. - * @param xzMargin - * @param yMargin Extra margin added below and above. - * @return - */ - public boolean standsOnEntity(final double yOnGround, final double xzMargin, final double yMargin) { - return blockCache.standsOnEntity(player, minX - xzMargin, minY - yOnGround - yMargin, minZ - xzMargin, maxX + xzMargin, minY + yMargin, maxZ + xzMargin); - } - - /** - * Check if solid blocks hit the box. - * @param xzMargin - * @param yMargin - * @return - */ - public boolean isNextToSolid(final double xzMargin, final double yMargin) { - // TODO: Adjust to check block flags ? - return BlockProperties.collides(blockCache, minX - xzMargin, minY - yMargin, minZ - xzMargin, maxX + xzMargin, maxY + yMargin, maxZ + xzMargin, BlockProperties.F_SOLID); - } - - /** - * Check if solid blocks hit the box. - * @param xzMargin - * @param yMargin - * @return - */ - public boolean isNextToGround(final double xzMargin, final double yMargin) { - // TODO: Adjust to check block flags ? - return BlockProperties.collides(blockCache, minX - xzMargin, minY - yMargin, minZ - xzMargin, maxX + xzMargin, maxY + yMargin, maxZ + xzMargin, BlockProperties.F_GROUND); - } - - /** - * Reset condition for flying checks (sf + nofall): liquids, web, ladder (not on-ground, though). - * @return - */ - public boolean isResetCond() { - // NOTE: if optimizing, setYOnGround has to be kept in mind. - return isInLiquid() || isOnClimbable() || isInWeb(); - } - - public double getyOnGround() { - return yOnGround; - } - - /** - * This resets onGround and blockFlags. - * @param yOnGround - */ - public void setyOnGround(final double yOnGround) { - this.yOnGround = yOnGround; - this.onGround = null; - blockFlags = null; - } - - /** - * Test if the foot location is passable (not the bounding box). - *
The result is cached. - * @return - */ - public boolean isPassable() { - if (passable == null) { - passable = BlockProperties.isPassable(blockCache, x, y, z, getTypeId()); -// passable = BlockProperties.isPassableExact(blockCache, x, y, z, getTypeId()); - } - return passable; - } - - /** - * Convenience method: delegate to BlockProperties.isDoppwnStream . - * - * @param xDistance - * @param zDistance - * @return - */ - public boolean isDownStream(final double xDistance, final double zDistance) - { - return BlockProperties.isDownStream(blockCache, blockX, blockY, blockZ, getData(), xDistance, zDistance); - } - - public Integer getTypeId() { - if (typeId == null) typeId = getTypeId(blockX, blockY, blockZ); - return typeId; - } - - public Integer getTypeIdBelow() { - if (typeIdBelow == null) typeIdBelow = getTypeId(blockX, blockY - 1, blockZ); - return typeIdBelow; - } - - public Integer getData() { - if (data == null) data = getData(blockX, blockY, blockZ); - return data; - } - - /** - * Uses id cache if present. - * - * @param x - * @param y - * @param z - * @return - */ - public final int getTypeId(final int x, final int y, final int z) { - return blockCache.getTypeId(x, y, z); - } - - /** - * Uses id cache if present. - * - * @param x - * @param y - * @param z - * @return - */ - public final int getData(final int x, final int y, final int z) { - return blockCache.getData(x, y, z); - } - - /** - * Set the id cache for faster id getting. - * - * @param cache - */ - public void setBlockCache(final BlockCache cache) { - this.blockCache = cache; - } - - /** - * Get the underlying BLockCache. - * @return - */ - public final BlockCache getBlockCache() { - return blockCache; - } - - /** - * Sets the player location object. - * - * @param location - * the location - * @param player - * the player - * @throws NullPointerException, if player.getLocation.getWorld() returns null. - */ - public void set(final Location location, final Player player) { - set(location, player, 0.001); - } - - /** - * Sets the player location object. Does not set or reset blockCache. - * - * @param location - * the location - * @param player - * the player - * @throws NullPointerException, if Location.getWorld() returns null. - */ - public void set(final Location location, final Player player, final double yOnGround) - { - - // Entity reference. - this.player = player; - - // Set coordinates. - blockX = location.getBlockX(); - blockY = location.getBlockY(); - blockZ = location.getBlockZ(); - x = location.getX(); - y = location.getY(); - z = location.getZ(); - yaw = location.getYaw(); - pitch = location.getPitch(); - - // Set bounding box. - this.width = mcAccess.getWidth(player); - final double dxz = Math.round(this.width * 500.0) / 1000.0; // this.width / 2; // 0.3; - minX = x - dxz; - minY = y; - minZ = z - dxz; - maxX = x + dxz; - maxY = y + player.getEyeHeight(); - maxZ = z + dxz; - // TODO: With current bounding box the stance is never checked. - - // Set world / block access. - world = location.getWorld(); - - if (world == null) { - throw new NullPointerException("World is null."); - } - - // Reset cached values. - typeId = typeIdBelow = data = null; - aboveStairs = inLava = inWater = inWeb = onGround = onIce = onClimbable = passable = null; - onGroundMinY = Double.MAX_VALUE; - notOnGroundMaxY = Double.MIN_VALUE; - blockFlags = null; - - this.yOnGround = yOnGround; - } - - /** - * Check the maximally used bounds for the block checking, - * to have flags ready for faster denial. - * @param maxYonGround - */ - public void collectBlockFlags(double maxYonGround) { - maxYonGround = Math.max(yOnGround, maxYonGround); - // TODO: Clearly refine this for 1.5 high blocks. - // TODO: Check which checks need blocks below. - final double yExtra = 0.6; // y - blockY - maxYonGround > 0.5 ? 0.5 : 1.0; - // TODO: xz margin still needed ? - final double xzM = 0; //0.001; - blockFlags = BlockProperties.collectFlagsSimple(blockCache, minX - xzM, minY - yExtra - maxYonGround, minZ - xzM, maxX + xzM, Math.max(maxY, minY + 1.5), maxZ + xzM); - } - - /** - * Check chunks within 1 block distance for if they are loaded and load unloaded chunks. - * @return Number of chunks loaded. - */ - public int ensureChunksLoaded() { - return ensureChunksLoaded(1.0); - } - - /** - * Check chunks within xzMargin radius for if they are loaded and load unloaded chunks. - * @param xzMargin - * @return Number of chunks loaded. - */ - public int ensureChunksLoaded(final double xzMargin) { - return BlockCache.ensureChunksLoaded(world, x, z, xzMargin); - } - - /** - * Set some references to null. - */ - public void cleanup() { - player = null; - world = null; - blockCache = null; // No reset here. - } - - /** - * Attempt to check for some exploits (!). - * - * @return - */ - public boolean isIllegal() { - final AlmostBoolean spec = mcAccess.isIllegalBounds(player); - if (spec != AlmostBoolean.MAYBE) { - return spec.decide(); - } - else if (Math.abs(minX) > 3.2E7D || Math.abs(maxX) > 3.2E7D || Math.abs(minY) > 3.2E7D || Math.abs(maxY) > 3.2E7D || Math.abs(minZ) > 3.2E7D || Math.abs(maxZ) > 3.2E7D) return true; - // if (Math.abs(box.a) > 3.2E7D || Math.abs(box.b) > 3.2E7D || Math.abs(box.c) > 3.2E7D || Math.abs(box.d) > 3.2E7D || Math.abs(box.e) > 3.2E7D || Math.abs(box.f) > 3.2E7D) return true; - else return false; - } - - /** - * Get the collected block-flags. This will return null if collectBlockFlags has not been called. - * @return - */ - public Long getBlockFlags() { - return blockFlags; - } - - /** - * Set the block flags which are usually collected on base of bounding box, yOnGround and other considerations, such as 1.5 high blocks. - * @param blockFlags - */ - public void setBlockFlags(Long blockFlags) { - this.blockFlags = blockFlags; - } - - /** - * Not cached. - * @return - */ - public int getTypeIdAbove() { - return blockCache.getTypeId(blockX, blockY + 1, blockZ); - } - - /** - * Set cached info according to other.
- * Minimal optimizations: take block flags directly, on-ground max/min bounds, only set stairs if not on ground and not reset-condition. - * @param other - */ - public void prepare(final PlayerLocation other) { - this.onGround = other.isOnGround(); - this.inWater = other.isInWater(); - this.inLava = other.isInLava(); - this.inWeb = other.isInWeb(); - this.onClimbable = other.isOnClimbable(); - if (!onGround && !isResetCond()) this.aboveStairs = other.isAboveStairs(); - this.onIce = other.isOnIce(); - this.typeId = other.getTypeId(); - this.typeIdBelow = other.getTypeIdBelow(); - this.notOnGroundMaxY = other.notOnGroundMaxY; - this.onGroundMinY = other.onGroundMinY; - this.blockFlags = other.blockFlags; // Assume set. - } - -} +package fr.neatmonster.nocheatplus.utilities; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import fr.neatmonster.nocheatplus.compat.AlmostBoolean; +import fr.neatmonster.nocheatplus.compat.MCAccess; + +/** + * An utility class used to know a lot of things for a player and a location + * given. + */ +public class PlayerLocation { + + // Final members // + private final MCAccess mcAccess; + + // Simple members // + + /** Y parameter for growing the bounding box with the isOnGround check. */ + private double yOnGround = 0.001; + + /** The block coordinates. */ + private int blockX, blockY, blockZ; + + /** The exact coordinates. */ + private double x, y, z; + + private float yaw, pitch; + + private double width; + + /** Bounding box of the player. */ + private double minX, maxX, minY, maxY, minZ, maxZ; + + // TODO: Check if onGround can be completely replaced by onGroundMinY and notOnGroundMaxY. + /** Minimal yOnGround for which the player is on ground. No extra xz/y margin.*/ + private double onGroundMinY = Double.MAX_VALUE; + /** Maximal yOnGround for which the player is not on ground. No extra xz/y margin.*/ + private double notOnGroundMaxY = Double.MIN_VALUE; + + // "Light" object members (reset to null) // + + // TODO: The following should be changed to primitive types, add one long for "checked"-flags. Booleans can be compressed into a long. + // TODO: All properties that can be set should have a "checked" flag, thus resetting the flag suffices. + + /** Type id of the block at the position. */ + private Integer typeId = null; + + /** Type id of the block below. */ + private Integer typeIdBelow = null; + + /** Data value of the block this position is on. */ + private Integer data = null; + + /** All block flags collected for maximum used bounds. */ + private Long blockFlags = null; + + /** Is the player on ice? */ + private Boolean onIce = null; + + /** Is the player on ladder? */ + private Boolean onClimbable = null; + + /** Simple test if the exact position is passable. */ + private Boolean passable = null; + + /** Is the player above stairs? */ + private Boolean aboveStairs = null; + + /** Is the player in lava? */ + private Boolean inLava = null; + + /** Is the player in water? */ + private Boolean inWater = null; + + /** Is the player is web? */ + private Boolean inWeb = null; + + /** Is the player on the ground? */ + private Boolean onGround = null; + + // "Heavy" object members (reset to null for cleanup). // + + /** The player ! */ + private Player player = null; + + /** Bukkit world. */ + private World world = null; + + // "Heavy" object members (further cleanup call needed + set to null for cleanup) // + + /** Optional block property cache. */ + private BlockCache blockCache = null; + + + public PlayerLocation(final MCAccess mcAccess, final BlockCache blockCache) { + this.mcAccess = mcAccess; + this.blockCache = blockCache; + } + + public Player getPlayer() { + return player; + } + + /** + * Gets the location. + * + * @return the location + * @throws NullPointerException, if the world stored internally is null. + */ + public Location getLocation() { + if (this.world == null) { + throw new NullPointerException("World is null."); + } + return new Location(world, x, y, z); + } + + /** + * Get the world! + * @return + */ + public World getWorld() { + return world; + } + + /** + * Gets the blockX. + * + * @return the blockX + */ + public double getX() { + return x; + } + + /** + * Gets the boundY. + * + * @return the boundY + */ + public double getY() { + return y; + } + + /** + * Gets the blockZ. + * + * @return the blockZ + */ + public double getZ() { + return z; + } + + /** + * Gets the yaw. + * + * @return the yaw + */ + public float getYaw() { + return yaw; + } + + /** + * Gets the pitch. + * + * @return the pitch + */ + public float getPitch() { + return pitch; + } + + public Vector getVector() { + return new Vector(x, y, z); + } + + public double getWidth() { + return width; + } + + public int getBlockX() { + return blockX; + } + + public int getBlockY() { + return blockY; + } + + public int getBlockZ() { + return blockZ; + } + + /** + * Compares block coordinates (not the world). + * + * @param other + * @return + */ + public final boolean isSameBlock(final PlayerLocation other) { + return blockX == other.getBlockX() && blockZ == other.getBlockZ() && blockY == other.getBlockY(); + } + + /** + * Block coordinate comparison. + * @param x + * @param y + * @param z + * @return + */ + public final boolean isSameBlock(final int x, final int y, final int z) { + return blockX == x && blockZ == z && blockY == y; + } + + /** + * Compares block coordinates (not the world). + * @param loc + * @return + */ + public final boolean isSameBlock(final Location loc) { + return blockX == loc.getBlockX() && blockZ == loc.getBlockZ() && blockY == loc.getBlockY(); + } + + /** + * Check if this location is above the given one (blockY + 1). + * @param loc + * @return + */ + public boolean isBlockAbove(final PlayerLocation loc) { + return blockY == loc.getBlockY() + 1 && blockX == loc.getBlockX() && blockZ == loc.getBlockZ(); + } + + /** + * Check if this location is above the given one (blockY + 1). + * @param loc + * @return + */ + public boolean isBlockAbove(final Location loc) { + return blockY == loc.getBlockY() + 1 && blockX == loc.getBlockX() && blockZ == loc.getBlockZ(); + } + + /** + * Compares exact coordinates (not the world). + * + * @param loc + * @return + */ + public boolean isSamePos(final PlayerLocation loc) { + return x == loc.getX() && z == loc.getZ() && y == loc.getY(); + } + + /** + * Compares exact coordinates (not the world). + * + * @param loc + * @return + */ + public boolean isSamePos(final Location loc) { + return x == loc.getX() && z == loc.getZ() && y == loc.getY(); + } + + /** + * Manhattan distance, see Trigutil. + * @param other + * @return + */ + public int manhattan(final PlayerLocation other) { + // TODO: Consider using direct field access from other methods as well. + return TrigUtil.manhattan(this.blockX, this.blockY, this.blockZ, other.blockX, other.blockY, other.blockZ); + } + + /** + * Maximum block distance comparing dx, dy, dz. + * @param other + * @return + */ + public int maxBlockDist(final PlayerLocation other) { + // TODO: Consider using direct field access from other methods as well. + return TrigUtil.maxDistance(this.blockX, this.blockY, this.blockZ, other.blockX, other.blockY, other.blockZ); + } + + /** + * Checks if the player is above stairs. + * + * @return true, if the player above on stairs + */ + public boolean isAboveStairs() { + if (aboveStairs == null) { + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_STAIRS) == 0 ) { + aboveStairs = false; + return false; + } + // TODO: Distinguish based on actual height off .0 ? + // TODO: diff still needed ? + final double diff = 0; // 0.001; + aboveStairs = BlockProperties.collides(blockCache, minX - diff, minY - 1.0, minZ - diff, maxX + diff, minY + 0.25, maxZ + diff, BlockProperties.F_STAIRS); + } + return aboveStairs; + } + + /** + * Checks if the player is in lava. + * + * @return true, if the player is in lava + */ + public boolean isInLava() { + if (inLava == null) { + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_LAVA) == 0 ) { + inLava = false; + return false; + } + // TODO: ... + // final double dX = -0.10000000149011612D; + // final double dY = -0.40000000596046448D; + // final double dZ = dX; + // inLava = BlockProperties.collides(blockCache, minX - dX, minY - dY, minZ - dZ, maxX + dX, maxY + dY, maxZ + dZ, BlockProperties.F_LAVA); + inLava = BlockProperties.collides(blockCache, minX, minY, minZ, maxX, maxY, maxZ, BlockProperties.F_LAVA); + } + return inLava; + } + + /** + * Checks if the player is in water. + * + * @return true, if the player is in water + */ + public boolean isInWater() { + if (inWater == null) { + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_WATER) == 0 ) { + inWater = false; + return false; + } + // TODO: ... + // final double dX = -0.001D; + // final double dY = -0.40000000596046448D - 0.001D; + // final double dZ = dX; + // inWater = BlockProperties.collides(blockCache, minX - dX, minY - dY, minZ - dZ, maxX + dX, maxY + dY, maxZ + dZ, BlockProperties.F_WATER); + inWater = BlockProperties.collides(blockCache, minX, minY, minZ, maxX, maxY, maxZ, BlockProperties.F_WATER); + + } + return inWater; + } + + /** + * Checks if the player is in a liquid. + * + * @return true, if the player is in a liquid + */ + public boolean isInLiquid() { + // TODO: optimize (check liquid first and only if liquid check further) + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_LIQUID) == 0 ) return false; + // TODO: This should check for F_LIQUID too, Use a method that returns all found flags (!). + return isInWater() || isInLava(); + } + + /** + * Checks if the player is on ice. + * + * @return true, if the player is on ice + */ + public boolean isOnIce() { + if (onIce == null) { + // TODO: Use a box here too ? + // TODO: check if player is really sneaking (refactor from survivalfly to static access in Combined ?)! + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_ICE) == 0) { + // TODO: check onGroundMinY !? + onIce = false; + } else { + final int id; + if (player.isSneaking() || player.isBlocking()) { + id = getTypeId(blockX, Location.locToBlock(minY - 0.1D), blockZ); + } + else { + id = getTypeIdBelow().intValue(); + } + onIce = BlockProperties.isIce(id); + } + } + return onIce; + } + + /** + * Checks if the player is on a ladder or vine. + * + * @return If so. + */ + public boolean isOnClimbable() { + if (onClimbable == null) { + // Climbable blocks. + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_CLIMBABLE) == 0 ) { + onClimbable = false; + return false; + } + onClimbable = (BlockProperties.getBlockFlags(getTypeId()) & BlockProperties.F_CLIMBABLE) != 0; + // TODO: maybe use specialized bounding box. + // final double d = 0.1d; + // onClimbable = BlockProperties.collides(getBlockAccess(), minX - d, minY - d, minZ - d, maxX + d, minY + 1.0, maxZ + d, BlockProperties.F_CLIMBABLE); + } + return onClimbable; + } + + /** + * Check if a player may climb upwards (isOnClimbable returned true, player does not move from/to ground).
+ * Having checked the other stuff is prerequisite for calling this (!). + * @param jumpHeigth Height the player is allowed to have jumped. + * @return + */ + public boolean canClimbUp(double jumpHeigth) { + // TODO: distinguish vines. + if (BlockProperties.isAttachedClimbable(getTypeId())) { + // Check if vine is attached to something solid + if (BlockProperties.canClimbUp(blockCache, blockX, blockY, blockZ)) { + return true; + } + // Check the block at head height. + final int headY = Location.locToBlock(y + player.getEyeHeight()); + if (headY > blockY) { + for (int cy = blockY + 1; cy <= headY; cy ++) { + if (BlockProperties.canClimbUp(blockCache, blockX, cy, blockZ)) { + return true; + } + } + } + // Finally check possible jump height. + // TODO: This too is inaccurate. + if (isOnGround(jumpHeigth)) { + // Here ladders are ok. + return true; + } + return false; + } + return true; + } + + /** + * Checks if the player is above a ladder or vine.
+ * Does not save back value to field. + * + * @return If so. + */ + public boolean isAboveLadder() { + if (blockFlags != null && (blockFlags.longValue() & BlockProperties.F_CLIMBABLE) == 0 ) return false; + // TODO: bounding box ? + return (BlockProperties.getBlockFlags(getTypeIdBelow()) & BlockProperties.F_CLIMBABLE) != 0; + } + + /** + * Checks if the player is in web. + * + * @return true, if the player is in web + */ + public boolean isInWeb() { + if (inWeb == null) { + // TODO: inset still needed ? + final double inset = 0.001d; + inWeb = BlockProperties.collidesId(blockCache, minX + inset, minY + inset, minZ + inset, maxX - inset, maxY - inset, maxZ - inset, Material.WEB); + } + return inWeb; + } + + /** + * Checks if the player is on ground, including entities such as Minecart, Boat. + * + * @return true, if the player is on ground + */ + public boolean isOnGround() { + if (onGround != null) { + return onGround; + } + // Check cached values and simplifications. + if (notOnGroundMaxY >= yOnGround) onGround = false; + else if (onGroundMinY <= yOnGround) onGround = true; + else { + // Shortcut check (currently needed for being stuck + sf). + if (blockFlags == null || (blockFlags.longValue() & BlockProperties.F_GROUND) != 0) { + // TODO: Consider dropping this shortcut. + final int bY = Location.locToBlock(y - yOnGround); + final int id = bY == blockY ? getTypeId() : (bY == blockY -1 ? getTypeIdBelow() : blockCache.getTypeId(blockX, bY, blockZ)); + final long flags = BlockProperties.getBlockFlags(id); + // TODO: Might remove check for variable ? + if ((flags & BlockProperties.F_GROUND) != 0 && (flags & BlockProperties.F_VARIABLE) == 0) { + final double[] bounds = blockCache.getBounds(blockX, bY, blockZ); + // Check collision if not inside of the block. [Might be a problem for cauldron or similar + something solid above.] + // TODO: Might need more refinement. + if (bounds != null && y - bY >= bounds[4] && BlockProperties.collidesBlock(blockCache, x, minY - yOnGround, z, x, minY, z, blockX, bY, blockZ, id, bounds, flags)) { + // TODO: BlockHeight is needed for fences, use right away (above)? + if (!BlockProperties.isPassableWorkaround(blockCache, blockX, bY, blockZ, minX - blockX, minY - yOnGround - bY, minZ - blockZ, id, maxX - minX, yOnGround, maxZ - minZ, 1.0) + || (flags & BlockProperties.F_GROUND_HEIGHT) != 0 && BlockProperties.getGroundMinHeight(blockCache, blockX, bY, blockZ, id, bounds, flags) <= y - bY) { + // NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** onground SHORTCUT"); + onGround = true; + } + } + } + if (onGround == null) { + // NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** fetch onground std"); + // Full on-ground check (blocks). + // Note: Might check for half-block height too (getTypeId), but that is much more seldom. + onGround = BlockProperties.isOnGround(blockCache, minX, minY - yOnGround, minZ, maxX, minY, maxZ, 0L); + } + } + else onGround = false; + } + if (onGround) onGroundMinY = Math.min(onGroundMinY, yOnGround); + else { + // NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** onground check entities"); + // TODO: further confine this ? + notOnGroundMaxY = Math.max(notOnGroundMaxY, yOnGround); + final double d1 = 0.25D; + onGround = blockCache.standsOnEntity(player, minX - d1, minY - yOnGround - d1, minZ - d1, maxX + d1, minY + 0.25 + d1, maxZ + d1); + } + return onGround; + } + + /** + * Simple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. + * @param yOnGround Margin below the player. + * @return + */ + public boolean isOnGround(final double yOnGround) { + if (notOnGroundMaxY >= yOnGround) return false; + else if (onGroundMinY <= yOnGround) return true; + return isOnGround(yOnGround, 0D, 0D, 0L); + } + + /** + * SSimple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. + * @param yOnGround + * @param ignoreFlags Flags to not regard as ground. + * @return + */ + public boolean isOnGround(final double yOnGround, final long ignoreFlags) { + if (ignoreFlags == 0) { + if (notOnGroundMaxY >= yOnGround) return false; + else if (onGroundMinY <= yOnGround) return true; + } + return isOnGround(yOnGround, 0D, 0D, ignoreFlags); + } + + + /** + * Simple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. + * @param yOnGround Margin below the player. + * @param xzMargin + * @param yMargin Extra margin added below and above. + * @return + */ + public boolean isOnGround(final double yOnGround, final double xzMargin, final double yMargin) { + if (xzMargin >= 0 && onGroundMinY <= yOnGround) return true; + if (xzMargin <= 0 && yMargin == 0) { + if (notOnGroundMaxY >= yOnGround) return false; + } + return isOnGround(yOnGround, xzMargin, yMargin, 0); + } + + /** + * Simple block-on-ground check for given margin (no entities). Meant for checking bigger margin than the normal yOnGround. + * @param yOnGround Margin below the player. + * @param xzMargin + * @param yMargin Extra margin added below and above. + * @param ignoreFlags Flags to not regard as ground. + * @return + */ + public boolean isOnGround(final double yOnGround, final double xzMargin, final double yMargin, final long ignoreFlags) { + if (ignoreFlags == 0) { + if (xzMargin >= 0 && onGroundMinY <= yOnGround) return true; + if (xzMargin <= 0 && yMargin == 0) { + if (notOnGroundMaxY >= yOnGround) return false; + } + } + // NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, "*** Fetch on-ground: yOnGround=" + yOnGround + " xzM=" + xzMargin + " yM=" + yMargin + " ign=" + ignoreFlags); + final boolean onGround = BlockProperties.isOnGround(blockCache, minX - xzMargin, minY - yOnGround - yMargin, minZ - xzMargin, maxX + xzMargin, minY + yMargin, maxZ + xzMargin, ignoreFlags); + if (ignoreFlags == 0) { + if (onGround) { + if (xzMargin <= 0 && yMargin == 0) { + onGroundMinY = Math.min(onGroundMinY, yOnGround); + } + } + else { + if (xzMargin >= 0) { + notOnGroundMaxY = Math.max(notOnGroundMaxY, yOnGround); + } + } + } + return onGround; + } + + /** + * Simple check with custom margins (Boat, Minecart). + * @param yOnGround Margin below the player. + * @param xzMargin + * @param yMargin Extra margin added below and above. + * @return + */ + public boolean standsOnEntity(final double yOnGround, final double xzMargin, final double yMargin) { + return blockCache.standsOnEntity(player, minX - xzMargin, minY - yOnGround - yMargin, minZ - xzMargin, maxX + xzMargin, minY + yMargin, maxZ + xzMargin); + } + + /** + * Check if solid blocks hit the box. + * @param xzMargin + * @param yMargin + * @return + */ + public boolean isNextToSolid(final double xzMargin, final double yMargin) { + // TODO: Adjust to check block flags ? + return BlockProperties.collides(blockCache, minX - xzMargin, minY - yMargin, minZ - xzMargin, maxX + xzMargin, maxY + yMargin, maxZ + xzMargin, BlockProperties.F_SOLID); + } + + /** + * Check if solid blocks hit the box. + * @param xzMargin + * @param yMargin + * @return + */ + public boolean isNextToGround(final double xzMargin, final double yMargin) { + // TODO: Adjust to check block flags ? + return BlockProperties.collides(blockCache, minX - xzMargin, minY - yMargin, minZ - xzMargin, maxX + xzMargin, maxY + yMargin, maxZ + xzMargin, BlockProperties.F_GROUND); + } + + /** + * Reset condition for flying checks (sf + nofall): liquids, web, ladder (not on-ground, though). + * @return + */ + public boolean isResetCond() { + // NOTE: if optimizing, setYOnGround has to be kept in mind. + return isInLiquid() || isOnClimbable() || isInWeb(); + } + + public double getyOnGround() { + return yOnGround; + } + + /** + * This resets onGround and blockFlags. + * @param yOnGround + */ + public void setyOnGround(final double yOnGround) { + this.yOnGround = yOnGround; + this.onGround = null; + blockFlags = null; + } + + /** + * Test if the foot location is passable (not the bounding box). + *
The result is cached. + * @return + */ + public boolean isPassable() { + if (passable == null) { + passable = BlockProperties.isPassable(blockCache, x, y, z, getTypeId()); + // passable = BlockProperties.isPassableExact(blockCache, x, y, z, getTypeId()); + } + return passable; + } + + /** + * Convenience method: delegate to BlockProperties.isDoppwnStream . + * + * @param xDistance + * @param zDistance + * @return + */ + public boolean isDownStream(final double xDistance, final double zDistance) + { + return BlockProperties.isDownStream(blockCache, blockX, blockY, blockZ, getData(), xDistance, zDistance); + } + + public Integer getTypeId() { + if (typeId == null) typeId = getTypeId(blockX, blockY, blockZ); + return typeId; + } + + public Integer getTypeIdBelow() { + if (typeIdBelow == null) typeIdBelow = getTypeId(blockX, blockY - 1, blockZ); + return typeIdBelow; + } + + public Integer getData() { + if (data == null) data = getData(blockX, blockY, blockZ); + return data; + } + + /** + * Uses id cache if present. + * + * @param x + * @param y + * @param z + * @return + */ + public final int getTypeId(final int x, final int y, final int z) { + return blockCache.getTypeId(x, y, z); + } + + /** + * Uses id cache if present. + * + * @param x + * @param y + * @param z + * @return + */ + public final int getData(final int x, final int y, final int z) { + return blockCache.getData(x, y, z); + } + + /** + * Set the id cache for faster id getting. + * + * @param cache + */ + public void setBlockCache(final BlockCache cache) { + this.blockCache = cache; + } + + /** + * Get the underlying BLockCache. + * @return + */ + public final BlockCache getBlockCache() { + return blockCache; + } + + /** + * Sets the player location object. + * + * @param location + * the location + * @param player + * the player + * @throws NullPointerException, if player.getLocation.getWorld() returns null. + */ + public void set(final Location location, final Player player) { + set(location, player, 0.001); + } + + /** + * Sets the player location object. Does not set or reset blockCache. + * + * @param location + * the location + * @param player + * the player + * @throws NullPointerException, if Location.getWorld() returns null. + */ + public void set(final Location location, final Player player, final double yOnGround) + { + + // Entity reference. + this.player = player; + + // Set coordinates. + blockX = location.getBlockX(); + blockY = location.getBlockY(); + blockZ = location.getBlockZ(); + x = location.getX(); + y = location.getY(); + z = location.getZ(); + yaw = location.getYaw(); + pitch = location.getPitch(); + + // Set bounding box. + this.width = mcAccess.getWidth(player); + final double dxz = Math.round(this.width * 500.0) / 1000.0; // this.width / 2; // 0.3; + minX = x - dxz; + minY = y; + minZ = z - dxz; + maxX = x + dxz; + maxY = y + player.getEyeHeight(); + maxZ = z + dxz; + // TODO: With current bounding box the stance is never checked. + + // Set world / block access. + world = location.getWorld(); + + if (world == null) { + throw new NullPointerException("World is null."); + } + + // Reset cached values. + typeId = typeIdBelow = data = null; + aboveStairs = inLava = inWater = inWeb = onGround = onIce = onClimbable = passable = null; + onGroundMinY = Double.MAX_VALUE; + notOnGroundMaxY = Double.MIN_VALUE; + blockFlags = null; + + this.yOnGround = yOnGround; + } + + /** + * Check the maximally used bounds for the block checking, + * to have flags ready for faster denial. + * @param maxYonGround + */ + public void collectBlockFlags(double maxYonGround) { + maxYonGround = Math.max(yOnGround, maxYonGround); + // TODO: Clearly refine this for 1.5 high blocks. + // TODO: Check which checks need blocks below. + final double yExtra = 0.6; // y - blockY - maxYonGround > 0.5 ? 0.5 : 1.0; + // TODO: xz margin still needed ? + final double xzM = 0; //0.001; + blockFlags = BlockProperties.collectFlagsSimple(blockCache, minX - xzM, minY - yExtra - maxYonGround, minZ - xzM, maxX + xzM, Math.max(maxY, minY + 1.5), maxZ + xzM); + } + + /** + * Check chunks within 1 block distance for if they are loaded and load unloaded chunks. + * @return Number of chunks loaded. + */ + public int ensureChunksLoaded() { + return ensureChunksLoaded(1.0); + } + + /** + * Check chunks within xzMargin radius for if they are loaded and load unloaded chunks. + * @param xzMargin + * @return Number of chunks loaded. + */ + public int ensureChunksLoaded(final double xzMargin) { + return BlockCache.ensureChunksLoaded(world, x, z, xzMargin); + } + + /** + * Set some references to null. + */ + public void cleanup() { + player = null; + world = null; + blockCache = null; // No reset here. + } + + /** + * Attempt to check for some exploits (!). + * + * @return + */ + public boolean isIllegal() { + final AlmostBoolean spec = mcAccess.isIllegalBounds(player); + if (spec != AlmostBoolean.MAYBE) { + return spec.decide(); + } + else if (Math.abs(minX) > 3.2E7D || Math.abs(maxX) > 3.2E7D || Math.abs(minY) > 3.2E7D || Math.abs(maxY) > 3.2E7D || Math.abs(minZ) > 3.2E7D || Math.abs(maxZ) > 3.2E7D) return true; + // if (Math.abs(box.a) > 3.2E7D || Math.abs(box.b) > 3.2E7D || Math.abs(box.c) > 3.2E7D || Math.abs(box.d) > 3.2E7D || Math.abs(box.e) > 3.2E7D || Math.abs(box.f) > 3.2E7D) return true; + else return false; + } + + /** + * Get the collected block-flags. This will return null if collectBlockFlags has not been called. + * @return + */ + public Long getBlockFlags() { + return blockFlags; + } + + /** + * Set the block flags which are usually collected on base of bounding box, yOnGround and other considerations, such as 1.5 high blocks. + * @param blockFlags + */ + public void setBlockFlags(Long blockFlags) { + this.blockFlags = blockFlags; + } + + /** + * Not cached. + * @return + */ + public int getTypeIdAbove() { + return blockCache.getTypeId(blockX, blockY + 1, blockZ); + } + + /** + * Set cached info according to other.
+ * Minimal optimizations: take block flags directly, on-ground max/min bounds, only set stairs if not on ground and not reset-condition. + * @param other + */ + public void prepare(final PlayerLocation other) { + this.onGround = other.isOnGround(); + this.inWater = other.isInWater(); + this.inLava = other.isInLava(); + this.inWeb = other.isInWeb(); + this.onClimbable = other.isOnClimbable(); + if (!onGround && !isResetCond()) this.aboveStairs = other.isAboveStairs(); + this.onIce = other.isOnIce(); + this.typeId = other.getTypeId(); + this.typeIdBelow = other.getTypeIdBelow(); + this.notOnGroundMaxY = other.notOnGroundMaxY; + this.onGroundMinY = other.onGroundMinY; + this.blockFlags = other.blockFlags; // Assume set. + } + +}