Efficiently Detecting Speed Hacks

Discussion in 'Spigot Plugin Development' started by Technerder, May 27, 2017.

  1. i have been trying to think of an efficient way of detecting speed hacks. My current code is something like this

    Public void Move(PlayerMoveEvent event) {

    Player player = event.getPlayer();

    Get player position and save location

    Wait a second

    Get location again

    Get distance traveled

    If player moved more than x blocks

    Player is cheating


    However this doesent seem efficient, any ideas on what i could to better to make this more efficient, or should i just redo my whole code with a new method?
  2. ScarabCoder

    ScarabCoder Retired Resource Staff

    You could try checking if e.getFrom() is more than a certain distance from e.getTo()
  3. Well first of all, the PlayerMoveEvent is fired anytime a player moves, including pitch & yaw. Therefore I believe it is more efficiento to check and compare player location via timer (runnable or whatever its called)
  4. So something along the lines on:

    New runnable
    Player player = randomplayer
    Get player location
    Wait 20 ticks
    Get location again
    Subtract old location from new location
    If distance is higher than x player ischeating

    Ps- sorry about writing like this, im on my phone and i dont feel like typing full events out. :p
  5. Also how would i check if player was hit ordamaged, so if someone hits the player and boosts them, it wont give false positives.
  6. electronicboy

    IRC Staff

    hardly, because then you remove the overall accuracy of such checks, especially in cases where the server starts lagging and other issues like that. You'd also be caring about players who haven't moved.

    The general case for PME is pretty much "escape fast", e.g. if the players X, Y, Z hasn't changed, you don't need to do anything else so just remove it.
  7. Mas


    Listen for PME.
    Get the distance the player travelled.
    Find the exact distance the player can move when walking/sprinting.
    Factor in everything that can change speed.
    Account for ping and TPS so lag doesn't cause as many false positives.