Solved FireImunity

Discussion in 'Plugin Development' started by L33m4n123, Apr 14, 2013.

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

    L33m4n123

    Hey guys and girls,

    I want to trigger an event that a Player is Imune to Fire.

    Ok. Said - Done

    Code:java
    1. @EventHandler
    2. public void onPlayerBurn(final EntityDamageEvent event) {
    3. Entity entity = event.getEntity();
    4. if (entity instanceof Player) {
    5. Player player = (Player) entity;
    6. if (player.getFireTicks() > 0) {
    7. event.setCancelled(true);
    8. }
    9. }
    10.  
    11. }


    Now the only issue is. If the player gets Attacked with a FireAspect Sword or Flame Bow or gets put on fire he is obviously invincible. But that was not the Idea behind it

    So I thought. Let's check if it it a nonplayer that causes the damage.. But now the player is not imune to fire anymore. Either I misunderstand the Event I used (EntityDamagedByEntityEvent) OR there is a bug within my Code I cannot seem to find OR there is a bug within the Event itself.

    Would be awesome if you could help me. Here's my EntityDamagedByEntityEvent

    Code:java
    1. @EventHandler
    2. public void onPlayerBurn(final EntityDamageByEntityEvent event) {
    3. Entity entity = event.getEntity();
    4. Entity entityDamEntity = event.getDamager();
    5. if (!(entityDamEntity instanceof Player)) {
    6. if (entity instanceof Player) {
    7. Player player = (Player) entity;
    8. if (player.getFireTicks() > 0) {
    9. event.setCancelled(true);
    10. }
    11. }
    12. }
    13.  
    14. }
     
  2. Offline

    ZeusAllMighty11

    You can check if the damager is a player, and if they have a diamond sword with fire aspect
     
  3. Offline

    L33m4n123

    How would I check what enchantment is on the Item?
     
  4. Offline

    L33m4n123

    Ok. Got it working in a different way
    Code:java
    1. @EventHandler
    2. public void onPlayerBurn(final EntityDamageEvent event) {
    3. Entity entity = event.getEntity();
    4. DamageCause damager = event.getCause();
    5. if ((damager == DamageCause.FIRE) || damager == DamageCause.FIRE_TICK) {
    6. if (entity instanceof Player) {
    7. entity.setFireTicks(0);
    8. event.setCancelled(true);
    9. }
    10. }
    11. }
     
Thread Status:
Not open for further replies.

Share This Page