Detecting what kind of potion

Discussion in 'Plugin Development' started by CarPet, Oct 21, 2012.

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

    CarPet

    Is there anyway to detect if a player is splashed with a poison potion and if it was a poison potion then don't take damage?

    Please paste your code if you find an answer thanks:D
     
  2. EntityDamageByEntityEvent -> check if the damaging entity is a ThrownPotion -> get the effects from the thrown potion -> check if one of them is the posion effect. Then do what you want with it.
     
  3. Offline

    one4me

    That event doesn't get called when a player gets damaged by a splash potion, however the code below should work for what he wants.
    Code:
    @EventHandler
    public void onPotionSplashEvent(PotionSplashEvent event) {
      for(PotionEffect pe : event.getPotion().getEffects()) {
        for(LivingEntity le : event.getAffectedEntities()) {
          if(pe.getType().equals(PotionEffectType.POISON) && le instanceof Player) {
            continue;
          }
          le.addPotionEffect(pe);
        }
      }
      event.setCancelled(true);
    }
    
     
  4. Offline

    LukeSFT

    or you can use the EntityDamageEvent and get the DamageCause.
     
  5. Offline

    one4me

    You could stop poison damage like that, but you could not determine whether or not the poison damage happened because of a splash potion.
     
  6. Offline

    LukeSFT

    oh
    I thought he meaned the Detection of Damage caused by Potions in general.
     
Thread Status:
Not open for further replies.

Share This Page