Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CheatProtect: (CheckUtil.java)
- package me.kevin636.CheatProtect.checks;
- import java.util.HashSet;
- import java.util.Set;
- import me.kevin636.CheatProtect.CheatProtectPlayer;
- import me.kevin636.CheatProtect.data.PreciseLocation;
- import net.minecraft.server.v1_4_R1.Block;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.util.Vector;
- public class CheckUtil
- {
- private static final double magic = 0.45D;
- private static final double magic2 = 0.55D;
- private static final int NONSOLID = 1;
- private static final int SOLID = 2;
- private static final int LIQUID = 5;
- private static final int LADDER = 11;
- private static final int FENCE = 19;
- private static final int INGROUND = 128;
- private static final int ONGROUND = 256;
- private static final int[] types;
- private static final Set<org.bukkit.Material> foods = new HashSet();
- static {
- types = new int[256];
- for (int i = 0; i < types.length; i++)
- {
- types[i] = 3;
- if (Block.byId[i] != null) {
- if (Block.byId[i].material.isSolid())
- {
- types[i] = 2;
- } else if (Block.byId[i].material.isLiquid())
- {
- types[i] = 5;
- }
- else {
- types[i] = 1;
- }
- }
- }
- types[org.bukkit.Material.AIR.getId()] = 1;
- types[org.bukkit.Material.WEB.getId()] = 3;
- types[org.bukkit.Material.LADDER.getId()] = 11;
- types[org.bukkit.Material.WATER_LILY.getId()] = 11;
- types[org.bukkit.Material.VINE.getId()] = 11;
- types[org.bukkit.Material.FENCE.getId()] = 19;
- types[org.bukkit.Material.FENCE_GATE.getId()] = 19;
- types[org.bukkit.Material.NETHER_FENCE.getId()] = 19;
- types[org.bukkit.Material.IRON_FENCE.getId()] = 3;
- types[org.bukkit.Material.THIN_GLASS.getId()] = 3;
- types[org.bukkit.Material.WALL_SIGN.getId()] = 1;
- types[org.bukkit.Material.SIGN_POST.getId()] = 1;
- types[org.bukkit.Material.WOODEN_DOOR.getId()] = 3;
- types[org.bukkit.Material.IRON_DOOR_BLOCK.getId()] = 3;
- types[org.bukkit.Material.TRAP_DOOR.getId()] = 3;
- types[org.bukkit.Material.DIODE_BLOCK_OFF.getId()] = 3;
- types[org.bukkit.Material.DIODE_BLOCK_ON.getId()] = 3;
- types[org.bukkit.Material.STONE_PLATE.getId()] = 3;
- types[org.bukkit.Material.WOOD_PLATE.getId()] = 3;
- foods.add(org.bukkit.Material.APPLE);
- foods.add(org.bukkit.Material.BREAD);
- foods.add(org.bukkit.Material.COOKED_BEEF);
- foods.add(org.bukkit.Material.COOKED_CHICKEN);
- foods.add(org.bukkit.Material.COOKED_FISH);
- foods.add(org.bukkit.Material.COOKIE);
- foods.add(org.bukkit.Material.GOLDEN_APPLE);
- foods.add(org.bukkit.Material.GRILLED_PORK);
- foods.add(org.bukkit.Material.MELON);
- foods.add(org.bukkit.Material.MUSHROOM_SOUP);
- foods.add(org.bukkit.Material.PORK);
- foods.add(org.bukkit.Material.RAW_BEEF);
- foods.add(org.bukkit.Material.RAW_CHICKEN);
- foods.add(org.bukkit.Material.RAW_FISH);
- foods.add(org.bukkit.Material.ROTTEN_FLESH);
- foods.add(org.bukkit.Material.SPIDER_EYE);
- }
- public static final double directionCheck(CheatProtectPlayer player, double targetX, double targetY, double targetZ, double targetWidth, double targetHeight, double precision)
- {
- Location eyes = player.getPlayer().getEyeLocation();
- double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2.0D) + Math.pow(eyes.getY() - targetY, 2.0D) + Math.pow(eyes.getZ() - targetZ, 2.0D));
- Vector direction = eyes.getDirection();
- double x = targetX - eyes.getX();
- double y = targetY - eyes.getY();
- double z = targetZ - eyes.getZ();
- double xPrediction = factor * direction.getX();
- double yPrediction = factor * direction.getY();
- double zPrediction = factor * direction.getZ();
- double off = 0.0D;
- off += Math.max(Math.abs(x - xPrediction) - (targetWidth / 2.0D + precision), 0.0D);
- off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2.0D + precision), 0.0D);
- off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2.0D + precision), 0.0D);
- if (off > 1.0D) {
- off = Math.sqrt(off);
- }
- return off;
- }
- public static final double reachCheck(CheatProtectPlayer player, double targetX, double targetY, double targetZ, double limit)
- {
- Location eyes = player.getPlayer().getEyeLocation();
- double distance = Math.sqrt(Math.pow(eyes.getX() - targetX, 2.0D) + Math.pow(eyes.getY() - targetY, 2.0D) + Math.pow(eyes.getZ() - targetZ, 2.0D));
- return Math.max(distance - limit, 0.0D);
- }
- public static final int evaluateLocation(World world, PreciseLocation location)
- {
- int lowerX = lowerBorder(location.x);
- int upperX = upperBorder(location.x);
- int Y = (int)location.y;
- int lowerZ = lowerBorder(location.z);
- int upperZ = upperBorder(location.z);
- int result = 0;
- result |= evaluateSimpleLocation(world, lowerX, Y, lowerZ);
- result |= evaluateSimpleLocation(world, upperX, Y, lowerZ);
- result |= evaluateSimpleLocation(world, upperX, Y, upperZ);
- result |= evaluateSimpleLocation(world, lowerX, Y, upperZ);
- if (!isInGround(result))
- {
- if (isSolid(types[world.getBlockTypeIdAt(Location.locToBlock(location.x), Location.locToBlock(location.y), Location.locToBlock(location.z))])) {
- result |= 128;
- }
- }
- return result;
- }
- private static final int evaluateSimpleLocation(World world, int x, int y, int z)
- {
- int top = types[world.getBlockTypeIdAt(x, y + 1, z)];
- int base = types[world.getBlockTypeIdAt(x, y, z)];
- int below = types[world.getBlockTypeIdAt(x, y - 1, z)];
- int type = 0;
- if ((below == 19) && (base != 19) && (isNonSolid(top))) {
- type = 128;
- }
- else if ((below != 19) && (isNonSolid(base)) && (types[world.getBlockTypeIdAt(x, y - 2, z)] == 19)) {
- type = 256;
- }
- else if (isNonSolid(top))
- {
- if ((isSolid(below)) && (isNonSolid(base))) {
- type = 256;
- }
- else if ((isLadder(base)) || (isLadder(top))) {
- type = 256;
- }
- else if (isSolid(base)) {
- type = 128;
- }
- }
- if ((isLiquid(base)) || (isLiquid(top))) {
- type |= 133;
- }
- return type;
- }
- public static final boolean isSolid(int value) {
- return (value & 0x2) == 2;
- }
- public static final boolean isLiquid(int value) {
- return (value & 0x5) == 5;
- }
- private static final boolean isNonSolid(int value) {
- return (value & 0x1) == 1;
- }
- private static final boolean isLadder(int value) {
- return (value & 0xB) == 11;
- }
- public static final boolean isOnGround(int fromType) {
- return (fromType & 0x100) == 256;
- }
- public static final boolean isInGround(int fromType) {
- return (fromType & 0x80) == 128;
- }
- private static final int lowerBorder(double d1)
- {
- double floor = Math.floor(d1);
- if (floor + 0.45D <= d1) {
- return (int)floor;
- }
- return (int)(floor - 1.0D);
- }
- private static final int upperBorder(double d1)
- {
- double floor = Math.floor(d1);
- if (floor + 0.55D < d1) {
- return (int)(floor + 1.0D);
- }
- return (int)floor;
- }
- public static int getType(int typeId) {
- return types[typeId];
- }
- public static boolean isFood(ItemStack item) {
- if (item == null)
- return false;
- return foods.contains(item.getType());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment