Deny fall damage for a set amount of time.

Discussion in 'Plugin Development' started by Telmovieira, Aug 9, 2015.

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


    Hello everyone!
    My question today is simple. I know how to deny fall damage. I personaly use the following way:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void EntityDamagebyfall(EntityDamageEvent event) {
            Player player = (Player) event.getEntity();
    if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
    This has been proven to work multiple times.

    Now how do i do it so it only lasts for a couple of seconds, and then enables fall damage again?

    Any help is apreciated.
    Thank you.
  2. Add the player(s uuid) to a List, then create a new delayed task that removes the player(s uuid) from the list after x ticks.
    In the even check if the cause is fall (as you already have) AND if the player(s uuid) is in the list. Then cancel
  3. Offline


    @Telmovieira @FisheyLP , Instead of creating a list and a task, just make a map<UUID, Integer> with the int being like System.currentTimeMillis() + 10000 (10 seconds from now), and in the event handler check if System.currentTimeMillis is greater than or equal to the value in the map, if so remove the entry and allow fall damage otherwise cancel fall damage!

    This way is slightly less hard on the server, because you dont have a task checking if it is almost time to cancel yet, you just check the time whenever the event happens!
  4. Actually it isn't even noticeable. Because the task is only created when the player isn't in the cooldown and stops and he removes the player from the list after the delay. If the player is in the list (simple list.contains check) cancel the event which isn't lagging the server at all
  5. Offline


    @FisheyLP I feel like @Chiller's method is a lot more simple disregarding the fact that a task is completely unnecessary. However System.currentTimeMillis returns a long rather than an int.
Thread Status:
Not open for further replies.

Share This Page