Solved How to prevent fall damage

Discussion in 'Plugin Development' started by Ytry, Nov 8, 2013.

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

    Ytry

    So I am making a simple plugin that allows users to fly but takes away flight on damage. My problem is I would like to prevent them from taking fall damage after they are knocked out of fly but I can't seem to figure it out. Any suggestions?
     
  2. Offline

    The_Doctor_123

    With the Player object, you can call the setFallDistance method. Set it to negative five hundred or whatever.
     
  3. Offline

    Tss1410

    @EventHandler
    public void onPlayerDamage(final EntityDamageEvent e){
    if(e.getCause() == DamageCause.FALL){
    e.setCancelled(true);
    }
    }
     
  4. Offline

    The_Doctor_123

    Tss1410
    He would have to make some List of falling players and check if the List contains that player, then cancel the event. My way is probably easier.
     
  5. Offline

    MrSparkzz

    The_Doctor_123
    Why would he have to do that?

    The EntityDamageEvent is called per entity when they take damage, check if the entity is an instance of a Player then cast that entity to a Player and you should be all set to cancel the Fall Damage. I've done it this way before and it worked.
     
  6. Offline

    The_Doctor_123

    MrSparkzz
    Did you read what he asked?

    He wants to stop flying when the player gets damaged but doesn't want them to take damage when they hit the ground.
     
  7. Offline

    MrSparkzz

  8. Offline

    Ytry

    Thanks for the quick reply The_Doctor_123 I tried the set fall distance thing but I was setting to 1 or 0 and it didn't stop the fall damage. Here is the code if you see that I am doing something wrong please let me know.
    Code:java
    1. @EventHandler
    2. public void onPlayerDamage(EntityDamageEvent e) {
    3. if (e.getEntity() instanceof Player) {
    4. Player player = (Player) e.getEntity();
    5. if (player.isFlying() || player.getAllowFlight()) {
    6. player.setFlying(false);
    7. player.setAllowFlight(false);
    8. player.setFallDistance(0);
    9. player.sendMessage(ChatColor.RED
    10. + "Flying forced off by damage");
    11. }


    I just tried setting it to -5 instead of 0 just to see and it didn't fix it either.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  9. Offline

    The_Doctor_123

    Ytry
    Set it to -500.
     
  10. Offline

    Ytry

    The_Doctor_123 Tried that still taking fall damage

    Anyone have any other suggestions?

    I am still unable to figure this out : /

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  11. Offline

    drtshock

  12. Offline

    Ytry

    drtshock Hmm thanks for the link. I would like to play around with this but it seems I can't even connect to my local server atm because my account can't authenticate or something. I tried setting it to online mode to false but it just reset to true when I run the server?
     
  13. Offline

    AoH_Ruthless

    Ytry
    Could you post your updated code? Thank you
     
Thread Status:
Not open for further replies.

Share This Page