h31ix

Untitled

Feb 20th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1. CheatProtect: (CheckUtil.java)
  2.  
  3. package me.kevin636.CheatProtect.checks;
  4.  
  5. import java.util.HashSet;
  6. import java.util.Set;
  7. import me.kevin636.CheatProtect.CheatProtectPlayer;
  8. import me.kevin636.CheatProtect.data.PreciseLocation;
  9. import net.minecraft.server.v1_4_R1.Block;
  10. import org.bukkit.Location;
  11. import org.bukkit.World;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.inventory.ItemStack;
  14. import org.bukkit.util.Vector;
  15.  
  16. public class CheckUtil
  17. {
  18. private static final double magic = 0.45D;
  19. private static final double magic2 = 0.55D;
  20. private static final int NONSOLID = 1;
  21. private static final int SOLID = 2;
  22. private static final int LIQUID = 5;
  23. private static final int LADDER = 11;
  24. private static final int FENCE = 19;
  25. private static final int INGROUND = 128;
  26. private static final int ONGROUND = 256;
  27. private static final int[] types;
  28. private static final Set<org.bukkit.Material> foods = new HashSet();
  29.  
  30. static {
  31. types = new int[256];
  32.  
  33. for (int i = 0; i < types.length; i++)
  34. {
  35. types[i] = 3;
  36.  
  37. if (Block.byId[i] != null) {
  38. if (Block.byId[i].material.isSolid())
  39. {
  40. types[i] = 2;
  41. } else if (Block.byId[i].material.isLiquid())
  42. {
  43. types[i] = 5;
  44. }
  45. else {
  46. types[i] = 1;
  47. }
  48.  
  49. }
  50.  
  51. }
  52.  
  53. types[org.bukkit.Material.AIR.getId()] = 1;
  54.  
  55. types[org.bukkit.Material.WEB.getId()] = 3;
  56.  
  57. types[org.bukkit.Material.LADDER.getId()] = 11;
  58. types[org.bukkit.Material.WATER_LILY.getId()] = 11;
  59. types[org.bukkit.Material.VINE.getId()] = 11;
  60.  
  61. types[org.bukkit.Material.FENCE.getId()] = 19;
  62. types[org.bukkit.Material.FENCE_GATE.getId()] = 19;
  63. types[org.bukkit.Material.NETHER_FENCE.getId()] = 19;
  64.  
  65. types[org.bukkit.Material.IRON_FENCE.getId()] = 3;
  66. types[org.bukkit.Material.THIN_GLASS.getId()] = 3;
  67.  
  68. types[org.bukkit.Material.WALL_SIGN.getId()] = 1;
  69. types[org.bukkit.Material.SIGN_POST.getId()] = 1;
  70.  
  71. types[org.bukkit.Material.WOODEN_DOOR.getId()] = 3;
  72. types[org.bukkit.Material.IRON_DOOR_BLOCK.getId()] = 3;
  73. types[org.bukkit.Material.TRAP_DOOR.getId()] = 3;
  74.  
  75. types[org.bukkit.Material.DIODE_BLOCK_OFF.getId()] = 3;
  76. types[org.bukkit.Material.DIODE_BLOCK_ON.getId()] = 3;
  77.  
  78. types[org.bukkit.Material.STONE_PLATE.getId()] = 3;
  79. types[org.bukkit.Material.WOOD_PLATE.getId()] = 3;
  80.  
  81. foods.add(org.bukkit.Material.APPLE);
  82. foods.add(org.bukkit.Material.BREAD);
  83. foods.add(org.bukkit.Material.COOKED_BEEF);
  84. foods.add(org.bukkit.Material.COOKED_CHICKEN);
  85. foods.add(org.bukkit.Material.COOKED_FISH);
  86. foods.add(org.bukkit.Material.COOKIE);
  87. foods.add(org.bukkit.Material.GOLDEN_APPLE);
  88. foods.add(org.bukkit.Material.GRILLED_PORK);
  89. foods.add(org.bukkit.Material.MELON);
  90. foods.add(org.bukkit.Material.MUSHROOM_SOUP);
  91. foods.add(org.bukkit.Material.PORK);
  92. foods.add(org.bukkit.Material.RAW_BEEF);
  93. foods.add(org.bukkit.Material.RAW_CHICKEN);
  94. foods.add(org.bukkit.Material.RAW_FISH);
  95. foods.add(org.bukkit.Material.ROTTEN_FLESH);
  96. foods.add(org.bukkit.Material.SPIDER_EYE);
  97. }
  98.  
  99. public static final double directionCheck(CheatProtectPlayer player, double targetX, double targetY, double targetZ, double targetWidth, double targetHeight, double precision)
  100. {
  101. Location eyes = player.getPlayer().getEyeLocation();
  102.  
  103. 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));
  104.  
  105. Vector direction = eyes.getDirection();
  106.  
  107. double x = targetX - eyes.getX();
  108. double y = targetY - eyes.getY();
  109. double z = targetZ - eyes.getZ();
  110.  
  111. double xPrediction = factor * direction.getX();
  112. double yPrediction = factor * direction.getY();
  113. double zPrediction = factor * direction.getZ();
  114.  
  115. double off = 0.0D;
  116.  
  117. off += Math.max(Math.abs(x - xPrediction) - (targetWidth / 2.0D + precision), 0.0D);
  118. off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2.0D + precision), 0.0D);
  119. off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2.0D + precision), 0.0D);
  120.  
  121. if (off > 1.0D) {
  122. off = Math.sqrt(off);
  123. }
  124.  
  125. return off;
  126. }
  127.  
  128. public static final double reachCheck(CheatProtectPlayer player, double targetX, double targetY, double targetZ, double limit)
  129. {
  130. Location eyes = player.getPlayer().getEyeLocation();
  131.  
  132. 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));
  133.  
  134. return Math.max(distance - limit, 0.0D);
  135. }
  136.  
  137. public static final int evaluateLocation(World world, PreciseLocation location)
  138. {
  139. int lowerX = lowerBorder(location.x);
  140. int upperX = upperBorder(location.x);
  141. int Y = (int)location.y;
  142. int lowerZ = lowerBorder(location.z);
  143. int upperZ = upperBorder(location.z);
  144.  
  145. int result = 0;
  146.  
  147. result |= evaluateSimpleLocation(world, lowerX, Y, lowerZ);
  148. result |= evaluateSimpleLocation(world, upperX, Y, lowerZ);
  149. result |= evaluateSimpleLocation(world, upperX, Y, upperZ);
  150. result |= evaluateSimpleLocation(world, lowerX, Y, upperZ);
  151.  
  152. if (!isInGround(result))
  153. {
  154. if (isSolid(types[world.getBlockTypeIdAt(Location.locToBlock(location.x), Location.locToBlock(location.y), Location.locToBlock(location.z))])) {
  155. result |= 128;
  156. }
  157. }
  158.  
  159. return result;
  160. }
  161.  
  162. private static final int evaluateSimpleLocation(World world, int x, int y, int z)
  163. {
  164. int top = types[world.getBlockTypeIdAt(x, y + 1, z)];
  165. int base = types[world.getBlockTypeIdAt(x, y, z)];
  166. int below = types[world.getBlockTypeIdAt(x, y - 1, z)];
  167.  
  168. int type = 0;
  169.  
  170. if ((below == 19) && (base != 19) && (isNonSolid(top))) {
  171. type = 128;
  172. }
  173. else if ((below != 19) && (isNonSolid(base)) && (types[world.getBlockTypeIdAt(x, y - 2, z)] == 19)) {
  174. type = 256;
  175. }
  176. else if (isNonSolid(top))
  177. {
  178. if ((isSolid(below)) && (isNonSolid(base))) {
  179. type = 256;
  180. }
  181. else if ((isLadder(base)) || (isLadder(top))) {
  182. type = 256;
  183. }
  184. else if (isSolid(base)) {
  185. type = 128;
  186. }
  187.  
  188. }
  189.  
  190. if ((isLiquid(base)) || (isLiquid(top))) {
  191. type |= 133;
  192. }
  193.  
  194. return type;
  195. }
  196.  
  197. public static final boolean isSolid(int value) {
  198. return (value & 0x2) == 2;
  199. }
  200.  
  201. public static final boolean isLiquid(int value) {
  202. return (value & 0x5) == 5;
  203. }
  204.  
  205. private static final boolean isNonSolid(int value) {
  206. return (value & 0x1) == 1;
  207. }
  208.  
  209. private static final boolean isLadder(int value) {
  210. return (value & 0xB) == 11;
  211. }
  212.  
  213. public static final boolean isOnGround(int fromType) {
  214. return (fromType & 0x100) == 256;
  215. }
  216.  
  217. public static final boolean isInGround(int fromType) {
  218. return (fromType & 0x80) == 128;
  219. }
  220.  
  221. private static final int lowerBorder(double d1)
  222. {
  223. double floor = Math.floor(d1);
  224.  
  225. if (floor + 0.45D <= d1) {
  226. return (int)floor;
  227. }
  228. return (int)(floor - 1.0D);
  229. }
  230.  
  231. private static final int upperBorder(double d1)
  232. {
  233. double floor = Math.floor(d1);
  234.  
  235. if (floor + 0.55D < d1) {
  236. return (int)(floor + 1.0D);
  237. }
  238. return (int)floor;
  239. }
  240.  
  241. public static int getType(int typeId) {
  242. return types[typeId];
  243. }
  244.  
  245. public static boolean isFood(ItemStack item) {
  246. if (item == null)
  247. return false;
  248. return foods.contains(item.getType());
  249. }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment