Solved how to detect if damage instanceof Falling

Discussion in 'Plugin Development' started by JarFile, Feb 23, 2015.

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

    JarFile

    So here is my event
    Code:
        @EventHandler
        public void NoFall(EntityDamageEvent e)
        {
           
            if(e instanceof Player)
            {
                Player p = ((Player) e).getPlayer();
               
                if(p.hasPermission("prisonprofessional.adminmenu.nofall"))
                {
                   
                }
            }
           
        }
    
    How would I test if the damage is instance of the player falling?
     
  2. Offline

    Konato_K

  3. Offline

    teej107

  4. Offline

    JarFile

    @Konato_K @teej107 Ok
    Code:
                    if(e.getCause() instanceof FallDamage)
                    {
                       
                    }
    
    Any variahle for FallDamage I can import?
     
  5. Offline

    Konato_K

    @JarFile getCause returns an enum, I'm not sure what you're trying to do.
     
  6. Offline

    JarFile

    @Konato_K Testing if the damage was an instanceof Falling.
     
  7. Offline

    Konato_K

    @JarFile I don't think there is a Falling class anywhere, try checking the link I gave, check the return type, as I said, it's an enum
     
  8. Offline

    JarFile

    @Konato_K I'm new to java, so I don't know a lot. What is an enum? Also, so you are saying that I cannot detect if the damage was from falling?
     
  9. Offline

    caderape

    @JarFile that means you have to check if the cause is equals to the fall damage
    Method: DamageCause
     
  10. Offline

    Konato_K

  11. Offline

    JarFile

    @caderape so
    Code:
                    if(e.getCause() == DamageCause.FALL)
                    {
                       
                    }
    
    @Konato_K @caderape One more thing
    Code:
                        e.setCancelled(true);
    
    
    Seems to still give me damage? I tried e.setDamage(0.0F); didn't work either. I don't want to set the players health to max because it could of not been max before.

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

    teej107

    Maybe you should put this project on hold and gain a good knowledge of Java first. I also recommend you read the plugin tutorial on the Bukkit wiki.
     
  13. Offline

    caderape

    @Konato_K i know.. my english is not really good, i was just saying him to use DamageCause for compare the cause.

    @JarFile try equals and not ==
     
  14. Offline

    teej107

    That's not going to change the outcome.


    @JarFile Are you even sure that code is running? Did you register your event? Put in debug code.
     
  15. Offline

    Konato_K

    @JarFile Cancelling the event works, if it doesn't work for you then you have something else wrong in your code
     
  16. @JarFile I'll give you a hint. ;)
    Code:
    @EventHandler
    public void onEntityDamage(EntityDamageEvent event) {
    if(event.getCause() == EntityDamageEvent.....) {
    event.setCancelled(true);
    }
    }
    Hopefully you will take what everyone else said and use that to figure it out.
     
  17. Offline

    mine-care

    If your thread is Unsolved after what
    @CodePlaysMinecraft said then you should consider taking java basics and bukkit API docs over :- )
     
  18. Offline

    JarFile

    @teej107 Its not running, tested it with sendMessage. heres the register
    Code:
            Bukkit.getPluginManager().registerEvents(new PPModNoFall(this), this);
    
    @CodePlaysMinecraft Bukkit Apidocs website is down... Also Ive alread tried looking for e. I cannot find anything in there, only thing is DamageCause.

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

    Konato_K

    @JarFile Cancelling works, and the link I put before contains the whole documentation.
     
  20. Offline

    JarFile

    @Konato_K The code isn't even running, event before testing for permissions I put sendMessage and nothing hapenned when I got damaged. My registering is above.
     
  21. Offline

    Konato_K

    @JarFile Put all your relevant classes.
     
  22. Offline

    JarFile

  23. @JarFile if(event.getCause() == EntityDamageEvent.DamageCause.FALL) {}
     
  24. Offline

    JarFile

Thread Status:
Not open for further replies.

Share This Page