Need Help Fly/Speed Hack Detection

Discussion in 'Plugin Development' started by Mang0eZPvP, Sep 6, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Mang0eZPvP

    Why can't i have to variables with the same name? i am going to show you the relevant code:

    Code:java
    1. @SuppressWarnings("unchecked")
    2. public static ArrayList<Jump> GetJumps(ArrayList<MoveLog> moves) {
    3. int inc = 1;
    4.  
    5. ArrayList jumps = new ArrayList();
    6.  
    7. while (inc < moves.size()) {
    8. if (((MoveLog) moves.get(inc)).isInVehicle) {
    9. return new ArrayList();
    10. }
    11.  
    12. int startInc = inc;
    13.  
    14. while ((inc < moves.size()) && (!((MoveLog) moves.get(inc)).isAir))
    15. inc++;
    16.  
    17. if (inc > startInc + 5) {
    18. MoveCheck tmp79_76 = Instance;
    19. tmp79_76.getClass();
    20. Jump jump = new Jump((MoveLog) moves.get(startInc), (MoveLog) moves.get((inc + startInc - 1) / 2), (MoveLog) moves.get(inc - 1));
    21. jump.isOnGround = true;
    22. jumps.add(jump);
    23. MoveLog end;
    24. }
    25.  
    26. if (inc >= moves.size()) {
    27. break;
    28. }
    29. MoveLog start = (MoveLog) moves.get(inc - 1);
    30.  
    31. while ((inc < moves.size()) && (((MoveLog) moves.get(inc)).isAir) && (((MoveLog) moves.get(inc)).location.getY() > ((MoveLog) moves.get(inc - 1)).location.getY()))
    32. inc++;
    33.  
    34. if (inc >= moves.size()) {
    35. MoveCheck tmp235_232 = Instance;
    36. tmp235_232.getClass();
    37. jumps.add(new Jump(start, (MoveLog) moves.get(inc - 1), (MoveLog) moves.get(inc - 1)));
    38. break;
    39. }
    40.  
    41. MoveLog apex = (MoveLog) moves.get(inc - 1);
    42. boolean isFloating = false;
    43. boolean isOnFire = false;
    44. int floatCount = 0;
    45.  
    46. while ((inc < moves.size()) && (((MoveLog) moves.get(inc)).isAir)) {
    47. if (((MoveLog) moves.get(inc - 1)).location.getY() <= ((MoveLog) moves.get(inc)).location.getY()) {
    48. floatCount++;
    49.  
    50. if (floatCount > 3)
    51. isFloating = true;
    52. } else {
    53. floatCount = 0;
    54. }
    55.  
    56. if (((MoveLog) moves.get(inc)).isOnFire) {
    57. isOnFire = true;
    58. }
    59. inc++;
    60. }
    61. MoveLog end;
    62. MoveLog end;
    63. if (inc >= moves.size())
    64. end = (MoveLog) moves.get(moves.size() - 1);
    65. else
    66. end = (MoveLog) moves.get(inc);
    67. MoveCheck tmp433_430 = Instance;
    68. tmp433_430.getClass();
    69. Jump jump = new Jump(start, apex, end);
    70. jump.isFloating = isFloating;
    71. jump.isOnFire = isOnFire;
    72. jumps.add(jump);
    73. }
    74.  
    75. return jumps;
    76. }
    77.  
    78. public class Jump {
    79. public MoveCheck.MoveLog start;
    80. public MoveCheck.MoveLog apex;
    81. public MoveCheck.MoveLog end;
    82. public double height;
    83. public double fallDistance;
    84. public double length;
    85. public double time;
    86. public double jumpTime;
    87. public double fallTime;
    88. public double verticalSpeed;
    89. public double jumpSpeed;
    90. public double fallSpeed;
    91. public double horizontalSpeed;
    92. public boolean isFloating = false;
    93. public boolean isOnGround = false;
    94. public boolean isOnFire = false;
    95.  
    96. public Jump(MoveCheck.MoveLog start, MoveCheck.MoveLog apex, MoveCheck.MoveLog end) {
    97. this.start = start;
    98. this.apex = apex;
    99. this.end = end;
    100.  
    101. if ((start.location.getY() == apex.location.getY()) && (apex.location.getY() == end.location.getY()) && (!start.isAir) && (!apex.isAir) && (!end.isAir)) {
    102. this.isOnGround = true;
    103. }
    104. this.height = (apex.location.getY() - start.location.getY());
    105. this.fallDistance = (apex.location.getY() - end.location.getY());
    106. this.length = (GetHorzDistance(start.location, apex.location) + GetHorzDistance(apex.location, end.location));
    107.  
    108. this.time = ((end.time - start.time) / 1000.0D);
    109. this.jumpTime = ((apex.time - start.time) / 1000.0D);
    110. this.fallTime = ((end.time - apex.time) / 1000.0D);
    111.  
    112. this.jumpSpeed = (this.height / this.jumpTime);
    113. this.fallSpeed = (this.fallDistance / this.fallTime);
    114. this.verticalSpeed = ((this.height + this.fallDistance) / this.time);
    115.  
    116. this.horizontalSpeed = (this.length / this.time);
    117. }
    118.  
    119. private double GetHorzDistance(Location a, Location b) {
    120. double x = Math.abs(a.getX() - b.getX());
    121. double z = Math.abs(a.getZ() - b.getZ());
    122.  
    123. return Math.sqrt(x * x + z * z);
    124. }
    125. }
    126.  
    127. public class MoveLog {
    128. public Player player;
    129. public long time;
    130. public Location location;
    131. public Vector velocity;
    132. public boolean isSprinting;
    133. public boolean isSneaking;
    134. public boolean isAir;
    135. public boolean isOnFire;
    136. public boolean isInVehicle;
    137.  
    138. public MoveLog(Player p, Location l) {
    139. this.player = p;
    140. this.location = l.clone();
    141. this.time = System.currentTimeMillis();
    142. this.velocity = p.getVelocity();
    143. this.isSprinting = p.isSprinting();
    144. this.isSneaking = p.isSneaking();
    145. this.isInVehicle = p.isInsideVehicle();
    146. this.isOnFire = (p.getFireTicks() > 0);
    147.  
    148. if (Math.abs(this.velocity.getX()) < 0.001D)
    149. this.velocity.setX(0);
    150. if (Math.abs(this.velocity.getY()) < 0.001D)
    151. this.velocity.setY(0);
    152. if (Math.abs(this.velocity.getZ()) < 0.001D) {
    153. this.velocity.setZ(0);
    154. }
    155. this.isAir = isBlockAir(this.location);
    156. }
    157.  
    158. public double Speed(MoveLog other) {
    159. if (other == null) {
    160. return 0.0D;
    161. }
    162. long time = Math.abs(this.time - other.time);
    163. double distance = this.location.distance(other.location);
    164.  
    165. return distance / time;
    166. }
    167.  
    168. private boolean isMaterialAir(Material type) {
    169. return (type == Material.AIR) || (type == Material.TORCH) || (type == Material.REDSTONE_TORCH_OFF) || (type == Material.REDSTONE_TORCH_ON);
    170. }
    171.  
    172. private boolean isBlockAir(Location location) {
    173. Location l = location.clone();
    174. double x = l.getX();
    175. double y = l.getY();
    176. double z = l.getZ();
    177.  
    178. y = Math.floor(y) - 0.001D;
    179.  
    180. Material type = new Location(l.getWorld(), x, y, z).getBlock().getType();
    181.  
    182. if (!isMaterialAir(type)) {
    183. return false;
    184. }
    185. boolean xup = false;
    186. boolean xdwn = false;
    187. boolean zup = false;
    188. boolean zdwn = false;
    189.  
    190. if ((int) x != (int) (x + 0.32D)) {
    191. xup = true;
    192. type = new Location(l.getWorld(), x + 0.32D, y, z).getBlock().getType();
    193.  
    194. if (!isMaterialAir(type)) {
    195. return false;
    196. }
    197. }
    198. if ((int) x != (int) (x - 0.32D)) {
    199. xdwn = true;
    200. type = new Location(l.getWorld(), x - 0.32D, y, z).getBlock().getType();
    201.  
    202. if (!isMaterialAir(type)) {
    203. return false;
    204. }
    205. }
    206. if ((int) z != (int) (z + 0.32D)) {
    207. zup = true;
    208. type = new Location(l.getWorld(), x, y, z + 0.32D).getBlock().getType();
    209.  
    210. if (!isMaterialAir(type)) {
    211. return false;
    212. }
    213. }
    214. if ((int) z != (int) (z - 0.32D)) {
    215. zdwn = true;
    216. type = new Location(l.getWorld(), x, y, z - 0.32D).getBlock().getType();
    217.  
    218. if (!isMaterialAir(type)) {
    219. return false;
    220. }
    221. }
    222. if ((xup) && (zup)) {
    223. type = new Location(l.getWorld(), x + 0.32D, y, z + 0.32D).getBlock().getType();
    224.  
    225. if (!isMaterialAir(type)) {
    226. return false;
    227. }
    228. }
    229. if ((xup) && (zdwn)) {
    230. type = new Location(l.getWorld(), x + 0.32D, y, z - 0.32D).getBlock().getType();
    231.  
    232. if (!isMaterialAir(type)) {
    233. return false;
    234. }
    235. }
    236. if ((xdwn) && (zup)) {
    237. type = new Location(l.getWorld(), x - 0.32D, y, z + 0.32D).getBlock().getType();
    238.  
    239. if (!isMaterialAir(type)) {
    240. return false;
    241. }
    242. }
    243. if ((xdwn) && (zdwn)) {
    244. type = new Location(l.getWorld(), x - 0.32D, y, z - 0.32D).getBlock().getType();
    245.  
    246. if (!isMaterialAir(type)) {
    247. return false;
    248. }
    249. }
    250. return true;
    251. }
    252. }



    it says it at MoveLog end; line 61 and 62
     
  2. Offline

    CakePvP

    Just remove one of them o.o

    (ps, isn't that code from the public kNoHax?)
     
  3. Offline

    GaaTavares

    Yes, it is :confused:, this code isn't working, i already tried.
     
  4. Offline

    Mang0eZPvP

    then line 20 will do an error
     
  5. Offline

    Cirno

    https://forums.bukkit.org/threads/code-error.152098/

    Oh the irony...
    Anyways, I'll be blunt: I would suggest you go back and learn a little more if you're asking why can't variables declared within the same block have the same name.

    To be serious:
    You can't have 2 variables with the same name because how will the plugin work at runtime if you change try to change one of the two variables?
     
  6. Offline

    Mang0eZPvP

    well then why is line 20 doing an error???
     
  7. Offline

    Cirno

    It would help if you posted a stack trace and/or the error; we can't read your mind :p
     
  8. Offline

    Mang0eZPvP

    k here is the dupicate error one:
    Code:
    15:52:45 [WARNING] [Squeez] Task #53 for Squeez v1.0 generated an exception
    java.lang.Error: Unresolved compilation problem:
            Duplicate local variable end
     
            at com.fruitspvp.utils.MoveCheck.GetJumps(MoveCheck.java:199)
            at com.fruitspvp.utils.MoveCheck.run(MoveCheck.java:95)
            at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java
    :53)
            at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHea
    rtbeat(CraftScheduler.java:345)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    22)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    and the one at line 20:
    Code:
    15:54:03 [WARNING] [Squeez] Task #69 for Squeez v1.0 generated an exception
    java.lang.Error: Unresolved compilation problem:
            No enclosing instance of type MoveCheck is accessible. Must qualify the
    allocation with an enclosing instance of type MoveCheck (e.g. x.new A() where x
    is an instance of MoveCheck).
     
            at com.fruitspvp.utils.MoveCheck.GetJumps(MoveCheck.java:157)
            at com.fruitspvp.utils.MoveCheck.run(MoveCheck.java:95)
            at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java
    :53)
            at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHea
    rtbeat(CraftScheduler.java:345)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    22)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
     
  9. Offline

    GaaTavares

    mmm, i dont recommend to use kNoHax, there are a lot of better anti cheats, like ncp, and they have more checks >.>
     
  10. Offline

    Mang0eZPvP

    i only need speed and fly hck detection thats the thing...

    Ok then can someone give me a peace of sample code to check packets being sent from the server and detecting if it is illegal or not?

    Yes it is... Got a problem? I only copied the event listener class and movecheck

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  11. Offline

    Axe2760

    I hope you gave them credit...?
     
  12. Offline

    Mang0eZPvP

    The code has not been supported since 1.1 so why plus he is so rich. The code is from the server mcpvp.com
     
  13. Offline

    Axe2760

    Copying someone else's work and putting it as your own is completely wrong.
     
    mattrick16 likes this.
  14. Offline

    Mang0eZPvP

    Did you read the comment before that? I asked is there away to get packets sent by the client and refuse them? Dw bout kNoHax it is way outdated and won't work anyway since hacks have been updated so much...
     
  15. Offline

    Axe2760

    This might just be me, but how can you expect people to give you "sample code" when you just copied/pasted from someone's plugin? I don't see how it being outdated gives you any right to use it as your own without asking the author/crediting them. (Depending on the license.)
     
  16. Offline

    Mang0eZPvP

    i have since removed it any way. and as i said he does not care about his old code...
     
  17. Offline

    Mang0eZPvP

    hmmmmm. Is there away to get packets sent by the client and refuse them? as i stated before???
     
  18. Offline

    xTrollxDudex

    Mang0eZPvP
    You need ProtocolLib to "refuse" packets I believe
     
  19. Offline

    5thblock

    Does that mean that because your brother doesn't care about his old essay you can use it? No.

    Don't make a big deal over it, always attribute code.
     
  20. Offline

    The_Doctor_123

    Between the stupid question at the top and the copying of code, I must ask: Do you know the least bit of Java?
     
  21. Offline

    Mang0eZPvP

    not with the BukkitAPI but Java yea

    k...

    will try

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  22. Offline

    The_Doctor_123

    Mang0eZPvP
    You know Java? So you should easily be able to know that you cannot declare the same variable name in a block more than once?
     
    mattrick16 likes this.
  23. Offline

    mattrick

    Is it time to give up hope on this thread yet?
     
  24. Offline

    Mang0eZPvP

    i know that... i have abbonaded the top part of this thread
     
  25. Offline

    The_Doctor_123

    Mang0eZPvP
    One does not simply learn Java in a few days.
     
  26. Offline

    Mang0eZPvP

    i have know it for more then 6 months... i simply forgot one of the simplest rules...
     
  27. Offline

    The_Doctor_123

    Mang0eZPvP
    Nor does one programmer simply forget an unforgettable rule to all of programming.
     
  28. Offline

    xTrollxDudex

    kevinspl2000 likes this.
  29. Offline

    Mang0eZPvP

    I would love if one moderator closes this thread... please
     
    Axe2760 likes this.
  30. Offline

    The_Doctor_123

    • Trolling
    xTrollxDudex
    Did you accidentally forget how to walk today?
     
    Zarko likes this.
Thread Status:
Not open for further replies.

Share This Page