Solved Checking if something happens to quickly

Discussion in 'Spigot Plugin Development' started by AllinoneGamer, Sep 26, 2016.

  1. Trying to stop players to bhop, so to stop them if there z goes greater than one up within a timestamp, e.g 1sec,.
    Code (Text):

            int z =p.getLocation().getBlockZ();
            int zp = p.getLocation().getBlockZ() + 1;
            int time = 2;
            if(z > zp);
  2. Why Z? The Y axis is the vertical direction in Minecraft.
    You can check if the difference in a PlayerMoveEvent between event.getTo().getY() and event.getFrom().getY() is too big.
  3. I'm using the z, since bhop is still jumping, but jumping further and faster.
    Also, i just need to know if it happens to quickly, e.g in a spam plugin
  4. Then you can save System.currentTimeMillis() in a HashMap for a player, and in the next PlayerMoveEvent you get the value from the HashMap.
    velocity = distance / time
    • Agree Agree x 1
  5. Why use z? If he turns 90° your plugin will do nothing because he is now moving towards ±x.
    PS: What happens to quickly? "bhop" is no word, "hop" may be one, although one unfamiliar, so please use "jump" if you mean "hop".
  6. bhop = bunnyhop, a type of speedhack which became pretty popular in the last few months.
  7. If i get the z down im sure i can quickly do the x aswell.
    What he said, bhop is a speedhack
  8. So when making the hashmap how would i use the millis:
    Code (Text):
    HashMap<Player, ?> = new HashMap<Player, ?>();
  9. Instead of the ? use Long (the boxed class, not the primitive type).
  10. I'd do Map<UUID, Long> lastMoveEvent = new HashMap<UUID, Long>()
    You shouldn't store the Player object to prevent memory leaks.
  11. Alright.
  12. ( sorry for double post ), How am i going to use the hashmap. Since what im trying is if the z || x goes +1 in a second,
  13. At the end of every PlayerMoveEvent store the System.currentTimeMillis() in the HashMap, at the beginning check if the players UUID is in the HashMap and then get the difference between System.currentTimeMillis() and the value in the HashMap.
    But to be honest, a more reliable way would be to use the value of event.getTo().distance(event.getFrom()). The problem with that is that this also contains the vertical distance, so make sure to exclude the Y axis. Not going to tell you how though, you can probably figure it out.