Get Splash_Potion type within EntityDamageByEntityEvent

Discussion in 'Plugin Development' started by boduzapho, Aug 26, 2012.

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

    boduzapho

    I am able to detect when a player is hit by a splash_potion, however I am trying to find out which one was thrown, to prevent harmful potion from being used on players outside of pvp.

    Its sloppy, but what I have so far is :

    Code:
    if (event.getDamager().getType().equals(EntityType.SPLASH_POTION))
                        {
                            Projectile potion = (ThrownPotion) event.getDamager();                       
                            ThrownPotion potione = (ThrownPotion) event.getDamager();                       
                            attacker = potion.getShooter();
                           
                            Collection<PotionEffect> eff = potione.getEffects();
                           
                            String pot = potion.getType().name();
                            if (attacker instanceof Player)
                            {
                                shooter = (Player) attacker;
                                sn = shooter.getDisplayName();
                            }
                            else
                            {
                                Bukkit.broadcastMessage("Not Player");
                                sn = event.getDamager().toString();
                            }
                            hsmg = sn + " hit " + player.getDisplayName() + " with a potion(" + pot + "-" + eff.toString() + ") at " + loc.toString();
                        }
    What it displayes to me is:

    12:52:45 [INFO] ----------------------------------
    12:52:45 [INFO] DamageCause : MAGIC
    12:52:45 [INFO] EntityDamageByEntityEvent
    12:52:45 [INFO] Land :freebuild
    12:52:45 [INFO] BODUZAPHO hit modemqueen with a potion(SPLASH_POTION-[org.bukkit
    [email protected]]) at Location{world=CraftWorld{name=world},x=-154.300000
    01192093,y=65.0,z=258.30000001192093,pitch=4.2000155,yaw=50.84985}
    12:52:45 [INFO] ----------------------------------

    This part: SPLASH_POTION-[[email protected]] is coming from "eff.toString()"

    Not sure if the 26 is a reference I have not seen any look up tables or int references to the types.

    Any help is appreciated,
     
  2. Offline

    Mak

  3. In every class the toString() method, if not overwritten to return a user friendly string, will return by default "[email protected]"... but that class changes the toString() but only to add the potion type prefix.
    Anyway, the '26' is the hashcode, you don't need it :p

    Mak
    .getType() returns an enum, so it can be compared with == ... it's also faster.
     
  4. Offline

    boduzapho

    Digi

    Thanks for the info, however I still have not figured out hot to identify the type of splash potion that was thrown.
     
  5. The effects lists contains all the effects of that potion, you can't get a single type because it can contain many.

    You need to loop through that and if you find any harmful stuff you should cancel the event (and break the loop ofc).
     
Thread Status:
Not open for further replies.

Share This Page