Solved Stop player death & fall damage

Discussion in 'Plugin Development' started by Astrophylite, Mar 10, 2016.

Thread Status:
Not open for further replies.
  1. Hey guys!

    I just wanted to know, how do you stop player's from dying and taking fall damage? For some reason, I've coded it and it just won't work...

    CODE:
    Code:java
    1.  
    2. @EventHandler
    3. public void onEntityDamage(EntityDamageEvent e) {
    4. if(e.getEntityType() == EntityType.PLAYER) {
    5. Player p = Bukkit.getPlayer(e.getEntity().getUniqueId());
    6. if(p.getName().equals(certainPlayerHere)) {
    7. p.setHealth((float) 20);
    8. }
    9. } else {
    10. return;
    11. }
    12. }
    13.  

    Code:java
    1.  
    2. Bukkit.getServer().getPluginManager().registerEvents(new EVENTEntityDamageEvent(), this);
    3.  


    Any help will be appreciated,
    _zircon_.
     
  2. Offline

    HoeMC

    Use e.setCancelled(), not p.setHealth(). You can also use e.getCause() to check if the damage is from falling.
     
  3. Offline

    Zombie_Striker

    @_zircon_
    Instead of this:
    Use:
    Code:
    Player p = (Player)e.getEntity();
    I'm assuming "certainPlayerHere" is a string, correct? If so, unless the name is exactly the same, it will not always work. Instead, try equalsIgnoreCase.

    This just sets the health back to 20. The player will still be damaged, you have to cancel the event.

    This does nothing. Remove it.
     
  4. Offline

    Gonmarte

    Why u dont check the cause and then u cancel the event?
    Code:
    if(e.getCause()==DamageCause.FALL){
    event.setCancelled(true);
    }
    
     
  5. Offline

    Zombie_Striker

    @Gonmarte
    1. Spoonfeeding is bad.
    2. He wants to limit it to only certain players, not every single entity. If he were to use what you posted, he would also need to add a check for the player.
     
  6. Offline

    Gonmarte

    Sorry ;/ So he can check the players' name that he want, and then cancell it.
     
  7. I hate it when people spoon-feed but thanks anyway. Thank you all for your help ;)

    Thanks,
    _zircon_.

    EDIT: I am checking the name of the player (which is correct) and the damage cause (DamageCause.FALL) and it just doesn't seem to work...
     
    Last edited: Mar 19, 2016
  8. Offline

    Gonmarte

    u
    Canyou post your code?
     
  9. Code:java
    1.  
    2. @EventHandler(priority = EventPriority.HIGHEST)
    3. public void onEntityDamage(EntityDamageEvent e) {
    4. if(e.getEntityType() == EntityType.PLAYER) {
    5. Player p = (Player)e.getEntity();
    6. if((e.getCause() == DamageCause.FALL) && (p.getName().equalsIgnoreCase("playername"))) {
    7. e.setCancelled(true);
    8. p.setHealth((float) 20);
    9. }
    10.  


    EDIT: OMG... I am soooo stupid... I was exporting the plugin to the wrong place and uploading one that hadn't even changed.

    Thanks everyone for their help but it's fixed now,
    _zircon_.
     
    Last edited: Mar 19, 2016
Thread Status:
Not open for further replies.

Share This Page