Explosion resistance

Discussion in 'Plugin Development' started by KOLAN_, Sep 28, 2021.

  1. Offline

    KOLAN_

    Hi. I am pretty new to coding plugins to Minecraft. I just want to make Ender Dragon resistant to explosions. I've made something like this, but something doesn't work.

    Code:
    if(event.getEntityType() == EntityType.ENDER_DRAGON) {
                EnderDragon ed = (EnderDragon) event.getEntity();
             
                EntityDamageEvent e = ed.getLastDamageCause();
             
                if(e == DamageCause.BLOCK_EXPLOSION) {
                    e.setDamage(0);
                }
             
                Player player = ed.getKiller();
             
                player.sendMessage("Brawo " + player + ", zabiłeś smoka");
            }
    "e == DamageCause.BLOCK_EXPLOSION" is underscored and it doesn't work. How can I fix this?

    Nevermind, I just found out how to do this

    It went like that:
    Code:
    if(event.getEntityType() == EntityType.ENDER_DRAGON) {
                EnderDragon ed = (EnderDragon) event.getEntity();
               
                EntityDamageEvent e = ed.getLastDamageCause();
               
                if(e.getCause() == DamageCause.BLOCK_EXPLOSION) {
                    e.setDamage(0);
                }
               
                Player player = ed.getKiller();
               
                player.sendMessage("Brawo " + player + ", zabiłeś smoka");
            }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 28, 2021

Share This Page