Custom OnGround variable problem

Discussion in 'Spigot Plugin Development' started by HyperPlay, May 23, 2015.

  1. I made this util so I can see if the player is really on the ground or not (useful for a custom anticheat plugin), but it doesn't seem to work if the player stands on the edge of a block. I've been trying to get this working all day.

    Code: http://paste.md-5.net/pavanuleva.coffee

    Code (Text):
    package net.hyperplay.hypercheat.util;

    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.material.Gate;

    public class AccurateOnGround {

        public static boolean isActuallyOnGround(Location location) {
            return a(location)
                    || a(location.add(0D, 0D, -0.3D))
                    || a(location.add(0D, 0D, 0.3D))
                    || a(location.add(0.3D, 0D, -0.3D))
                    || a(location.add(0.3D, 0D, 0D))
                    || a(location.add(0.3D, 0D, 0.3D))
                    || a(location.add(-1.3D, 0D, 0D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(-1.3D, 0D, 0.3D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(-1.3D, 0D, -0.3D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(0.3D, 0D, -1.3D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(-1.3D, 0D, -1.3D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(-0.3D, 0D, -1.3D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(0D, 0D, -1.3D)) //Needed due to the way Minecraft puts the points at the edge of the blocks. :/
                    || a(location.add(-0.3D, 0D, 0D))
                    || a(location.add(-0.3D, 0D, 0.3D))
                    || a(location.add(-0.3D, 0D, -0.3D));
        }

        private static boolean a(Location location) {
            Block block = location.getWorld().getBlockAt((int) location.getX(), (int) location.getY(), (int) location.getZ());
            if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER || block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA)
                return false;
            if (location.getY() % 1 == 0) { //Normal Blocks
                if (location.clone().subtract(0, 1, 0).getBlock().getType().isOccluding()
                        || location.clone().subtract(0, 1, 0).getBlock().getType() == Material.HOPPER
                        || location.clone().subtract(0, 1, 0).getBlock().getType().toString().contains("STAIRS"))
                    return true;
                return false;
            }
            if (location.getY() % 0.5 == 0) { //snow:4, fences, walls & slabs.
                Material m = block.getType();
                if (m == Material.STEP || m == Material.WOOD_STEP || m == Material.SKULL || m == Material.CAKE_BLOCK || m == Material.CAKE)
                    return true;
                if (m == Material.SNOW && block.getData() == (byte) 4) return true;
                m = location.clone().subtract(0, 1, 0).getBlock().getType();
                if (m == Material.COBBLE_WALL || m.toString().contains("FENCE")) {
                    Block b = location.clone().subtract(0, 1, 0).getBlock();
                    if (b.getState().getData() instanceof Gate) {
                        Gate gate = (Gate) b.getState().getData();
                        if (gate.isOpen()) return false;
                    }
                    return true;
                }
            }

            if (location.getY() % 0.125 == 0) {
                Material m = block.getType();
                if (location.getY() - (int) location.getY() == 0.125) {
                    if (m == Material.SNOW && block.getData() == (byte) 1) return true;
                    if (m == Material.DIODE || m == Material.DIODE_BLOCK_ON || m == Material.DIODE_BLOCK_OFF || m == Material.REDSTONE_COMPARATOR || m == Material.REDSTONE_COMPARATOR_ON || m == Material.REDSTONE_COMPARATOR_OFF)
                        return true;
                }
                if (location.getY() - (int) location.getY() == 0.25) {
                    if (m == Material.SNOW && block.getData() == (byte) 2) return true;
                }
                if (location.getY() - (int) location.getY() == 0.375) {
                    if (m == Material.SNOW && block.getData() == (byte) 3) return true;
                }
                if (location.getY() - (int) location.getY() == 0.625) {
                    if (m == Material.SNOW && block.getData() == (byte) 5) return true;
                    if (m == Material.HOPPER) return true;
                }
                if (location.getY() - (int) location.getY() == 0.75) {
                    if (m == Material.SNOW && block.getData() == (byte) 6) return true;
                    if (m == Material.ENCHANTMENT_TABLE) return true;
                }
                if (location.getY() - (int) location.getY() == 0.875) {
                    if (m == Material.SNOW && block.getData() == (byte) 7) return true;
                    if (m == Material.CHEST || m == Material.ENDER_CHEST || m == Material.TRAPPED_CHEST || m == Material.LOCKED_CHEST || m == Material.SOUL_SAND)
                        return true;
                }
            }
            if (location.getY() - (int) location.getY() == 0.015625) {
                if (block.getType() == Material.WATER_LILY) return true;
            }
            if (location.getY() - (int) location.getY() == 0.5625) {
                if (block.getType() == Material.BED || block.getType() == Material.BED_BLOCK)
                    return true;
            }
            if (location.getY() - (int) location.getY() == 0.8125) {
                if (block.getType() == Material.ENDER_PORTAL_FRAME) return true;
            }
            return false;
        }

    }