I need ideas to stop linear fly

Discussion in 'Spigot Plugin Development' started by Bart_, May 18, 2016.

  1. Hello guys,
    I need your fantasy!
    I have to prevent people from flying linearly:
    1. Can't check the speed because lots of hack use the walk normal speed (0.2) instead of flyspeed (0.1) while flying, so it will not work.
    2. I can easily stop people from flying with using their coordinates y, but if the guy will only fly linearly it will not work.
    Any ideas?
    Thanks :D
     
  2. No bro, I need ideas to develop myself the code.

    Have you saw where they are? Spigot development xD

    Inviato dal mio SM-G930F utilizzando Tapatalk
     
  3. JamesJ

    Supporter

    Check if they're moving too fast?

    (Time between moving 1 block)

    Remember to incorporate factors such as TPS, server side lag, ping, blocks, etc.
     
  4. Mmm there are several factors at stake...for example what is the normal time it takes from 1 block to another? Maybe the speed 0.2 is 2 blocks in 1 second?

    Inviato dal mio SM-G930F utilizzando Tapatalk
     
  5. JamesJ

    Supporter

    I'm not too sure myself, probably best to do some looking into it :p
     
  6. you only want to prevent them to not flying? all the members including you ? or the people in creative / op can only fly and others cant?
     
    • Sneaking: 1.3 b/ps
    • walking: 4.3 b/ps
    • Running: 5.6 b/ps
    Notice that these are the values for blocks without slipperiness/slow down.
     
  7. Oh really thanks! Tomorrow I will create an algorithm :) !

    Inviato dal mio SM-G930F utilizzando Tapatalk
     
  8. The most reliable way would probably be to check if there's a block below them, and checking if they're going down.
     
  9. JamesJ

    Supporter

    What happens if someone is jumping?
     
  10. Then they'll be moving, and you can set a movement pattern for jumps if you want to.
     
  11. JamesJ

    Supporter

    And if they're flying they'll also be moving..
     
  12. I might have misinterpreted the question. I understood linear as horizontal. Can you rephrase your question a bit for me?
     
  13. Perhaps you're on to something.
    Maybe have a timer that runs every x amount of ticks. Inside save the players y value somewhere each loop and check if the y value has increased by more than 1 block (more than jump height, you will need to account for jump boosts and vector modifications) then you know they're flying.
     
  14. Worked on an anticheat with Alexandeh some time ago. This method works pretty good on a variety of clients, from what we've found. We have even tested it on some of the stronger ghost clients (private ones that are pretty much made with some of the best fly hacks I've seen). Not trying to spoon feed, but just showing a good velocity concept that works. Here ya go:

    Code (Java):
    public class PlayerMove implements Listener
    {
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Player player = e.getPlayer();
            if (!player.isFlying() && !isFalling(player) && !isJumping(player) && !isInBlock(player)) {
                boolean cancelled = configFile.getBoolean("MODULES.FLY.CANCEL");
                new Alert(HackType.FLY, player, 3).sendAlert(); // This player is flying most likely.

                // Config option for sending player back to ground if detected.
                if (cancelled) {
                    player.teleport(getHighestLocation(player.getLocation()));
                }
            }
        }

        private boolean isFalling(Player player) {
            String falling = (player.getFallDistance() / player.getVelocity().getBlockY() * -1) + "";
            return !falling.equals("0.0") && !falling.equals("NaN");
        }

        private boolean isInBlock(Player player) {
            return player.getLocation().getBlock().getType() != Material.AIR || player.getLocation().add(0, -1, 0).getBlock().getType() != Material.AIR;
        }

        private boolean isJumping(Player player) {
            return player.getVelocity().getY() >= (-0.75);
        }

        private Location getHighestLocation(Location location) {
            for (int i = 0; i < 255; i++) {
                Location newLocation = new Location(location.getWorld(), location.getX(), location.getBlockY() - i, location.getZ());
                if (newLocation.getBlock().getType() != Material.AIR) {
                    newLocation.setDirection(location.getDirection());
                    return newLocation.add(0, 1, 0);
                }
            }
            return location;
        }
    }

    P.S. not saying it is perfect so don't criticize me for it, criticize the code.
     
  15. Does this account for vectors that are applied from an external plugin?
     
  16. No, you would have to check for things like that yourself. Many big anti cheats, like CompatNoCheatPlus, are made just for the purpose of hooking into popular plugins that change players' velocity legitimately. The math in the code I showed is completely vanilla
     
  17. Yes I have already did a resource that uses this system (and it has another thing more) but I am want update it with an Antifly linearly, I think today I can finish the new algorithm.

    Inviato dal mio SM-G930F utilizzando Tapatalk
     
  18. @JamesJ @Shadow3097

    Look at this code:
    Code (Text):

        public static boolean AntiSpeed(Player player) {

            Location now = player.getLocation();

            if (player.getAllowFlight() == false && player.isFlying() == false) {

                if (player.isSneaking()) {
                    Main.instance.getServer().getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
                        public void run() {
                            Location after = player.getLocation();
                            double distance = now.distance(after);
                            Log.info("Distance sneaking: " + distance);
                            if (distance > 1.3) {
                                Log.info("Player use sneaking hack");
                            }
                        }
                    }, 20L);// 60 L == 3 sec, 20 ticks == 1 sec
                }

                if (player.isSprinting()) {
                    Main.instance.getServer().getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
                        public void run() {
                            Location after = player.getLocation();
                            double distance = now.distance(after);
                            Log.info("Distance sprinting: " + distance);
                            if (distance > 5.6) {
                                Log.info("Player use sprinting hack");
                            }
                        }
                    }, 20L);// 60 L == 3 sec, 20 ticks == 1 sec
                }

                if (!player.isSprinting() && !player.isSneaking()) {
                    Main.instance.getServer().getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
                        public void run() {
                            Location after = player.getLocation();
                            double distance = now.distance(after);
                            Log.info("Distance normal: " + distance);
                            if (distance > 4.3) {
                                Log.info("Player use walking hack");
                            }
                        }
                    }, 20L);// 60 L == 3 sec, 20 ticks == 1 sec
                }
            }
            return false;
        }

     
    There are lots of problems:
    This code will say "Oh you are a hacker" only because you stop walk or something like, to fix i think to check every tick if he is jumping or falling, if yes, stop the code and exit.

    What do you think about my solution ?

    PS: It's a solution to check if the player has speed hack.