Solved Converting PotionEffect to PotionEffectType and Vise Versa

Discussion in 'Plugin Development' started by Birdgeek3, May 5, 2014.

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

    Birdgeek3

    Hey guys,

    I am working on applying potion effects to mobs. I need to get a potion effect type from a list of strings set in the config and set those to the mob.

    Currently I have this

    Code:java
    1. @EventHandler
    2. public void onCreatureSpawnEvent(CreatureSpawnEvent ev) {
    3. ev.getEntityType();
    4.  
    5. if (EntityType.CREEPER != null) {
    6. if (checkX(ev.getEntity(), getConfig().getInt("zones.zone1.range"))) {
    7. for (int i = 0; i < getConfig().getStringList("zones.zone1.attributes").size(); i++) {
    8. ev.getEntity().addPotionEffect( getConfig().getStringList("zones.zone1.attributes").get(i));
    9. }
    10. }
    11. }
    12.  
    13. }


    I am stuck on the converting the String from the config into the PotionEffect to add to the mob. Any ideas on how to get around this?
    Thanks
     
  2. Offline

    Barnyard_Owl

    1. You didn't set ev.getEntityType(); to a variable.
    2. You didn't check if ev.getEntityType(); was EntityType.CREEPER.
    As for converting the string to a potioneffect? PotionEffectType.getByName(/*read from config*/)
    And potioneffecttype to potioneffect? new PotionEffect( potionEffectType, duration, amplifier [starts at 0] );

    Some of your code has basic mistakes -- I recommend picking up a book or watching some tutorials on Java.
     
    AdamQpzm likes this.
  3. Offline

    Birdgeek3

    Thank you this worked out, I couldn't wrap my head around how to get it converted. Much appreciated!
     
Thread Status:
Not open for further replies.

Share This Page