PotionEffect Errors

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

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

    Birdgeek3

    Hey,

    I am making a plugin that will take the zone a mob spawns in and apply potion effects based on the zone they spawn in.
    I am getting a null error that I have been trying to debug but I can't seem to fix it. Any help would be nice.

    Here is the Creature Spawn Event which implements other methods.

    Code:java
    1. @EventHandler
    2. public void creatureSpawnEvent(CreatureSpawnEvent ev) {
    3. if (isAffectedMob(ev.getEntityType())) {
    4. int zone = getZoneMobSpawnIn(ev.getEntity());
    5. addAttributes(ev.getEntity(), zone);
    6. // ERROR #1
    7. }
    8. }


    The addAttributes method is here.

    Code:java
    1. public void addAttributes(LivingEntity e, int zone) {
    2. for (int i = 0; i < getConfig().getStringList("zones.zone" + zone + ".attributes").size(); i++) {
    3. e.addPotionEffect(convertStringToPotion(getConfig().getStringList("zones.zone" + zone + ".attributes").get(i)));
    4. // ERROR #2
    5. }
    6. }


    and the convertStringToPotion method is here.

    Code:java
    1. public PotionEffect convertStringToPotion(String s) {
    2. if (s.equalsIgnoreCase("none") || s.equalsIgnoreCase(null)) {
    3. PotionEffect deadPotion = new PotionEffect(PotionEffectType.SLOW, 1, 0);
    4. return deadPotion;
    5. }
    6. else {
    7. //ERROR #3
    8. PotionEffect potion = new PotionEffect(PotionEffectType.getByName(s), 10000, 1);
    9. return potion;
    10. }
    11. }


    and this is the error.

    Code:
    [16:03:35] [Server thread/ERROR]: Could not pass event CreatureSpawnEvent to Mobs v0.0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callCreatureSpawnEvent(CraftEventFactory.java:244) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.World.addEntity(World.java:899) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ItemMonsterEgg.spawnCreature(ItemMonsterEgg.java:115) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ItemMonsterEgg.a(ItemMonsterEgg.java:96) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ItemMonsterEgg.interactWith(ItemMonsterEgg.java:36) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ItemStack.placeItem(ItemStack.java:78) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerInteractManager.interact(PlayerInteractManager.java:390) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:628) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.a(SourceFile:60) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInBlockPlace.handle(SourceFile:9) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.IllegalArgumentException: effect type cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.potion.PotionEffect.<init>(PotionEffect.java:40) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.potion.PotionEffect.<init>(PotionEffect.java:56) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at com.github.birdgeek.mobs.Mobs.convertStringToPotion(Mobs.java:73) ~[?:?]
        at com.github.birdgeek.mobs.Mobs.addAttributes(Mobs.java:45) ~[?:?]
        at com.github.birdgeek.mobs.Mobs.creatureSpawnEvent(Mobs.java:34) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_21]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_21]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_21]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit-1.7.2-R0.3.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 20 more
    I tried adding code to detect if the zone is not supposed to have any potions added to the mobs and then add a dead potion that only lasts for 1 second, still doesn't work :/
    Thanks in advance.
     
  2. Offline

    mine-care

    This is caused because as it claims your effect type is null..

    Caused by: java.lang.IllegalArgumentException: effect type cannot be null

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  3. Offline

    Birdgeek3

    Yeah I see that, that's why I added the check in the convertStringToPotion method that checks to see if the string is "none" or null and then just proceeds with a dead potion. But it never works.
     
  4. Offline

    mine-care

    I believe it's also case sensitive soo make sure it's exactly the right type... If it is FIRE_RESISTANCE try to use .touppercase on the name string.

    Also at your last code instead of by name isn't it value of (string)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  5. Offline

    xTigerRebornx

    Birdgeek3 SysOut the type, see what it is, and see if its what you expect it to be.
     
  6. Offline

    Birdgeek3

    It says the correct things, just doesn't get converted... >.<
     
Thread Status:
Not open for further replies.

Share This Page