Solved Fly Hack Detection not works?

Discussion in 'Plugin Development' started by ProStriker123, Dec 6, 2014.

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

    ProStriker123

    Its not works for me when i trying to fly up its not works and when i speed its works????
    Code:java
    1. @EventHandler
    2. public void onFlyHackChecker(PlayerMoveEvent e) {
    3. Player p = e.getPlayer();
    4. Location from = e.getFrom().clone();
    5. Location to = e.getTo().clone();
    6. if (from.distance(to) > .48) {
    7. if(p.isSprinting()) return;
    8. p.teleport(e.getFrom());
    9. for(Player pOP : Bukkit.getOnlinePlayers()) {
    10. if(pOP.isOp()) {
    11. pOP.sendMessage("Fly Hack Detected on: "+ e.getPlayer().getName());
    12. }
    13. }
    14. }
    15. }
     
  2. Offline

    mrCookieSlime

  3. Offline

    ProStriker123

    yes i registered its works but not how i want it for
    when you trying to fly only up its not works but when you fly staright its works

    mrCookieSlime, also do you have any tutorial thats will help me or anything? its would be wonderful also thanks for your help

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
  4. Offline

    xize

    Hmm what does that dot do there?

    this:
    > .48

    I thought for a double value this is invalid?

    anyways try to print out your results also the distances.
     
  5. ProStriker123
    Try printing out the distance between from and to, and see if it matches what you've got there (.48).

    edit: ninja'd by xize
     
    xize likes this.
  6. Offline

    mrCookieSlime

    ProStriker123
    Nope, I don't have a Tutorial handy.
    However the distance between two Locations are doubles.
    Doubles cannot be compared using >/< when also listening for the decimal values.
    You need to use if (Double.compare(distance, 0.48) > 0)
    That means that the distance is greater than 0.48

    Also, when flying straight up you are a bit slower than if you fly towards a direction.
    You need to keep that in mind when comparing the Values.
     
  7. Offline

    ProStriker123

    mrCookieSlime, how can i do tha "Double" a little example please.
    i also appreciate your help!!
     
  8. Offline

    mrCookieSlime

    I gave you an Example.
    And a double is a sort of Number.
    http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html
    But doubles also store decimal Values (unlike Integers for example), this means that a Double can be 2.33 for example.
    However the operators >/</=/etc. only listen for the first number.
    So, if the distance is 0.93 and you are checking if it is > 0.46
    it will end up like 0 > 0 and it will return false since 0 is not greater than 0.
    That is why you need to use Double.compare()
    because this one does actually listen for decimal Values.
     
  9. Offline

    ProStriker123

    mrCookieSlime, like this? cause its shows me red if(Double.compare(e.getFrom(), 0.48) > 0) {

    }
     
  10. Offline

    mrCookieSlime

    Nope, you don't want to compare the Location he was coming from with a Double. You need to compare the distance between from and to with 0.48
     
  11. Offline

    Avygeil

    mrCookieSlime Where did you get that from? Just use D to tell the compiler it's a double.

    ProStriker123 Also note that you should use distanceSquared instead, especially in PlayerMoveEvent. And the vector cloning is not necessary here. You probably don't want to return if sprinting too, but more like change the threshold value.
     
    ProStriker123 likes this.
  12. Offline

    ProStriker123

    Avygeil mrCookieSlime, i only dont know how to do the double distance =, its not works for me in the ways i did
     
  13. Offline

    mrCookieSlime

    ProStriker123
    ? You already have the distance...
    from.distance(to)
     
    ProStriker123 likes this.
  14. Offline

    ProStriker123

    yes?

    mrCookieSlime its works but now when i jumping or falling its sends me the message "check"

    @EventHandler
    public void onFlyHackChecker(PlayerMoveEvent e) {
    Player p = e.getPlayer();
    Location from = e.getFrom();
    Location to = e.getTo();
    double distance = from.distance(to);
    if(Double.compare(distance, .48) > 0) {
    e.getPlayer().sendMessage("Check");
    }
    }

    <Edit by mrCookieSlime: Merged posts.>
     
  15. Offline

    Avygeil

    ProStriker123 First, like others said, you have to find a good threshold. In your event, just print e.getFrom().distanceSquared(e.getTo()), move around and see what values you get. Only then compare the value, just like you did in your first post, but adding "D" at the end of the number (though the compiler might do it alone, just do it). If flying up gets you less than 0.48, that's probably where the mistake is (seems high to me).

    But now that I think about it, you are probably going to detect a lot of things with the same threshold... What if the player just jumps normally, has jump boost or is falling? Your method, as it is, won't simply detect if a player is flying, but simply if his speed in any direction is too high.

    What you could do is use the algebraic distance, so you could see if he's actually flying and not falling, check potion effects (maybe the potion strength could be a factor for the threshold), and check if he's like 10 blocks higher than the highest block at his position. But those are costy operations in a PlayerMoveEvent, and even with all that, there might still be flaws. So you see it's not as simple as it seems. :)
     
    ProStriker123 likes this.
  16. Offline

    ProStriker123

    Avygeil, wow works very nicely but when he falls how can i do it? its wont send message
     
  17. Offline

    Avygeil

    ProStriker123
    If to.getY() - from.getY() < 0D, the player is falling.
     
    ProStriker123 likes this.
  18. Offline

    ProStriker123

    Thanks very much!!!!! its works perfectly!!! Avygeil

    Fixed

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
    Avygeil likes this.
  19. Offline

    Gingerbreadman

    I actually found out an exploit
    I tested it on lots of servers and it always works
     
Thread Status:
Not open for further replies.

Share This Page