Java Code Examples for org.bukkit.event.entity.EntityDamageEvent#DamageCause

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent#DamageCause . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PotionDamageResolver.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public @Nullable PotionInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    // If potion is already resolved (i.e. as a splash potion), leave it alone
    if(damager instanceof PotionInfo ||
       damager instanceof ProjectileInfo && ((ProjectileInfo) damager).getProjectile() instanceof PotionInfo) {
        return null;
    }

    final PotionEffectType effect;
    switch(damageType) {
        case POISON: effect = PotionEffectType.POISON; break;
        case WITHER: effect = PotionEffectType.WITHER; break;
        case MAGIC: effect = PotionEffectType.HARM; break;
        default: return null;
    }

    return new GenericPotionInfo(effect);
}
 
Example 2
Source File: ListenerDamage.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onDamage(EntityDamageEvent e) {
    Entity entity = e.getEntity();
    if(!(entity instanceof Player)) return;
    if(checkDamageByEntity(e)) return;

    Player player = (Player) entity;
    EntityDamageEvent.DamageCause cause = e.getCause();
    if(doesNotTagPlayer(cause)) return;

    ICombatManager combatManager = this.plugin.getCombatManager();
    boolean wasInCombat = combatManager.isInCombat(player);

    boolean tagged = combatManager.tag(player, null, PlayerPreTagEvent.TagType.UNKNOWN, PlayerPreTagEvent.TagReason.UNKNOWN);
    if(!wasInCombat && tagged) {
        String message = getTagMessage(cause);
        this.plugin.sendMessage(player, message);
    }
}
 
Example 3
Source File: ExplosionDamageResolver.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable ExplosionInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    switch(damageType) {
        case ENTITY_EXPLOSION:
        case BLOCK_EXPLOSION:
            // Bukkit fires block explosion events with a null damager in rare situations
            return damager == null ? null : new ExplosionInfo(damager);

        default:
            return null;
    }
}
 
Example 4
Source File: MasterResolver.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    // Filter out observers immediately
    if(!players.canInteract(victim)) return new NullDamageInfo();

    for(DamageResolver resolver : damageResolvers) {
        DamageInfo resolvedInfo = resolver.resolveDamage(damageType, victim, damager);
        if(resolvedInfo != null) {
            return resolvedInfo;
        }
    }

    // This should never happen
    return new NullDamageInfo();
}
 
Example 5
Source File: TitleRespawn.java    From CardinalPGM with MIT License 5 votes vote down vote up
private void killPlayer(final Player player, Player killer, EntityDamageEvent.DamageCause cause) {
    if (deadPlayers.containsKey(player.getUniqueId())) return;
    this.deadPlayers.put(player.getUniqueId(), System.currentTimeMillis());

    CardinalDeathEvent cardinalDeathEvent = new CardinalDeathEvent(player, killer, cause);
    Bukkit.getServer().getPluginManager().callEvent(cardinalDeathEvent);

    dropInventory(player, true);

    PlayerDeathEvent deathEvent = new PlayerDeathEvent(player, new ArrayList<ItemStack>(), player.getExpToLevel(), 0, 0, 0, null);
    deathEvent.setDeathMessage(null);
    Bukkit.getServer().getPluginManager().callEvent(deathEvent);

    if (!isDeadUUID(player.getUniqueId())) return;

    Players.setObserver(player);

    PlayerNameUpdateEvent nameUpdateEvent = new PlayerNameUpdateEvent(player);
    Bukkit.getServer().getPluginManager().callEvent(nameUpdateEvent);

    sendTitle(player);

    player.setGameMode(GameMode.CREATIVE);

    setBlood(player, true);
    playDeathAnimation(player);

    if (!this.spectate) sendArmorStandPacket(player);

    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0, true, false), false);
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, this.blackout ? Integer.MAX_VALUE : 20, 0, true, false), false);

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Cardinal.getInstance(), new Runnable() {
        public void run() {
            GameHandler.getGameHandler().getMatch().getModules().getModule(Visibility.class).showOrHide(player);
        }
    }, 15L);
    if (this.auto) hasLeftClicked.add(player.getUniqueId());
}
 
Example 6
Source File: TrackerMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private DamageInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  // Filter out observers immediately
  if (match.getParticipant(victim) == null) return new NullDamageInfo();

  for (DamageResolver resolver : damageResolvers) {
    DamageInfo resolvedInfo = resolver.resolveDamage(damageType, victim, damager);
    if (resolvedInfo != null) {
      return resolvedInfo;
    }
  }

  // This should never happen
  return new NullDamageInfo();
}
 
Example 7
Source File: ListenerDamage.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private boolean doesNotTagPlayer(EntityDamageEvent.DamageCause cause) {
    if(cause == null) return true;

    FileConfiguration config = this.expansion.getConfig("damage-tagger.yml");
    boolean allDamage = config.getBoolean("all-damage");
    if(allDamage) return false;

    String causeName = cause.name().toLowerCase().replace("_", "-");
    String configPath = "damage-type." + causeName;
    return !config.getBoolean(configPath, false);
}
 
Example 8
Source File: ExplosionDamageResolver.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable ExplosionInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  switch (damageType) {
    case ENTITY_EXPLOSION:
    case BLOCK_EXPLOSION:
      // Bukkit fires block explosion events with a null damager in rare situations
      return damager == null ? null : new ExplosionInfo(damager);

    default:
      return null;
  }
}
 
Example 9
Source File: FallingBlockDamageResolver.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable FallingBlockInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    if(damageType == EntityDamageEvent.DamageCause.FALLING_BLOCK && damager instanceof FallingBlockInfo) {
        return (FallingBlockInfo) damager;
    }
    return null;
}
 
Example 10
Source File: GenericDamageInfo.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public GenericDamageInfo(EntityDamageEvent.DamageCause damageType, @Nullable PhysicalInfo damager) {
    this.damageType = checkNotNull(damageType);
    this.damager = damager;
}
 
Example 11
Source File: EventResolver.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
default DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim) {
    return resolveDamage(damageType, victim, (PhysicalInfo) null);
}
 
Example 12
Source File: TrackerMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim) {
  return resolveDamage(damageType, victim, (PhysicalInfo) null);
}
 
Example 13
Source File: TrackerMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public DamageInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable Block damager) {
  if (damager == null) return resolveDamage(damageType, victim);
  return resolveDamage(damageType, victim, blockTracker.resolveBlock(damager));
}
 
Example 14
Source File: CauseFilter.java    From CardinalPGM with MIT License 4 votes vote down vote up
private Boolean evaluate(Event event) {
    if (!(event instanceof EntityDamageEvent)) {
        switch (cause) {
            case WORLD:
                return event instanceof WorldEvent;
            case LIVING:
                return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof LivingEntity;
            case MOB:
                return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof Creature;
            case PLAYER:
                return event instanceof PlayerEvent || event instanceof BlockPlaceEvent || event instanceof BlockBreakEvent;

            case PUNCH:
                return event instanceof PlayerInteractEvent
                        && ((PlayerInteractEvent) event).getAction().equals(Action.LEFT_CLICK_BLOCK);
            case TRAMPLE:
                return event instanceof PlayerMoveEvent;
            case MINE:
                return event instanceof BlockBreakEvent;

            case EXPLOSION:
                return event instanceof EntityExplodeEvent;
        }
    } else {
        EntityDamageEvent.DamageCause damageCause = ((EntityDamageEvent) event).getCause();
        switch (cause) {
            case MELEE:
                return damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK);
            case PROJECTILE:
                return damageCause.equals(EntityDamageEvent.DamageCause.PROJECTILE);
            case POTION:
                return damageCause.equals(EntityDamageEvent.DamageCause.MAGIC)
                        || damageCause.equals(EntityDamageEvent.DamageCause.POISON)
                        || damageCause.equals(EntityDamageEvent.DamageCause.WITHER)
                        || damageCause.equals(EntityDamageEvent.DamageCause.DRAGON_BREATH);
            case EXPLOSION:
                return damageCause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
                        || damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            case COMBUSTION:
                return damageCause.equals(EntityDamageEvent.DamageCause.FIRE)
                        || damageCause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)
                        || damageCause.equals(EntityDamageEvent.DamageCause.MELTING)
                        || damageCause.equals(EntityDamageEvent.DamageCause.LAVA)
                        || damageCause.equals(EntityDamageEvent.DamageCause.HOT_FLOOR);
            case FALL:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALL);
            case GRAVITY:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALL)
                        || damageCause.equals(EntityDamageEvent.DamageCause.VOID);
            case VOID:
                return damageCause.equals(EntityDamageEvent.DamageCause.VOID);
            case SQUASH:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALLING_BLOCK);
            case SUFFOCATION:
                return damageCause.equals(EntityDamageEvent.DamageCause.SUFFOCATION);
            case DROWNING:
                return damageCause.equals(EntityDamageEvent.DamageCause.DROWNING);
            case STARVATION:
                return damageCause.equals(EntityDamageEvent.DamageCause.STARVATION);
            case LIGHTNING:
                return damageCause.equals(EntityDamageEvent.DamageCause.LIGHTNING);
            case CACTUS:
                return damageCause.equals(EntityDamageEvent.DamageCause.CONTACT);
            case THORNS:
                return damageCause.equals(EntityDamageEvent.DamageCause.THORNS);
        }
    }
    return null;
}
 
Example 15
Source File: CardinalDeathEvent.java    From CardinalPGM with MIT License 4 votes vote down vote up
public EntityDamageEvent.DamageCause getCause() {
    return cause;
}
 
Example 16
Source File: GenericDamageInfo.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public GenericDamageInfo(EntityDamageEvent.DamageCause damageType) {
    this(damageType, null);
}
 
Example 17
Source File: DamageResolver.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Nullable
DamageInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager);
 
Example 18
Source File: EventResolver.java    From ProjectAres with GNU Affero General Public License v3.0 votes vote down vote up
DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable Entity damager); 
Example 19
Source File: EventResolver.java    From ProjectAres with GNU Affero General Public License v3.0 votes vote down vote up
DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable Block damager); 
Example 20
Source File: DamageResolver.java    From ProjectAres with GNU Affero General Public License v3.0 votes vote down vote up
@Nullable DamageInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager);