Plugin error

Discussion in 'Plugin Development' started by spookyDHD, Feb 6, 2014.

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

    spookyDHD

    I'm making a plugin but i get a error.
    Do somebody have a fix?

    class:

    Code:java
    1. package me.Ricardo.WalkingCraftCore.Listeners;
    2.  
    3. import org.bukkit.entity.Entity;
    4. import org.bukkit.entity.EntityType;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.entity.Zombie;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.CreatureSpawnEvent;
    10. import org.bukkit.event.entity.EntityDamageEvent;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14. /**
    15. * Created by Ricardo on 2/3/14.
    16. */
    17. public class Zombies implements Listener {
    18.  
    19.  
    20.  
    21. @EventHandler
    22.  
    23. public void onPlayerDamage(EntityDamageEvent e) {
    24.  
    25. Player p = (Player) e.getEntity();
    26. if (e.getEntity() instanceof Player) {
    27. if(e.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)) { //Get the attack cause.
    28. for(Entity ent : p.getNearbyEntities(1.5D, 1.5D, 1.5D)) //Check nearby entities for possible damagecause
    29.  
    30.  
    31.  
    32. {
    33. if((ent instanceof Zombie)) // If it equals to a zombie (almost only close range mob which counts as ENTITY_ATTACK)
    34. {
    35. p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 30, 1)); //Add the PotionEffect
    36. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 10, 1)); //Add the PotionEffect
    37. e.setDamage(3.5);
    38. }
    39.  
    40.  
    41. }
    42. }
    43. }
    44. }
    45. }
    46.  
    47.  
    48.  
    49.  
    50.  



    And the error:

    Code:
    [17:29:38 ERROR]: Could not pass event EntityDamageByEntityEvent to WalkingCraft
    Core v1.0A
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEvent(Craf
    tEventFactory.java:98) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989j
    nks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEntityDama
    geEvent(CraftEventFactory.java:386) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4
    a588b7-b2989jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleEntityDa
    mageEvent(CraftEventFactory.java:414) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-
    g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityLiving.damageEntity(EntityLiving.j
    ava:656) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityMonster.m(EntityMonster.java:99) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityZombie.m(EntityZombie.java:218) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.PathfinderGoalMeleeAttack.e(PathfinderGo
    alMeleeAttack.java:100) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989
    jnks]
            at net.minecraft.server.v1_7_R1.PathfinderGoalSelector.a(PathfinderGoalS
    elector.java:108) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityInsentient.bn(EntityInsentient.jav
    a:427) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityLiving.e(EntityLiving.java:1436) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityInsentient.e(EntityInsentient.java
    :306) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityMonster.e(EntityMonster.java:20) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityZombie.e(EntityZombie.java:152) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityLiving.h(EntityLiving.java:1299) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityInsentient.h(EntityInsentient.java
    :150) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityMonster.h(EntityMonster.java:24) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.EntityZombie.h(EntityZombie.java:214) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.World.entityJoinedWorld(World.java:1338)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.World.playerJoinedWorld(World.java:1319)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.World.tickEntities(World.java:1207) [cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.WorldServer.tickEntities(WorldServer.jav
    a:480) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    37) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R1.entity.C
    raftVillager cannot be cast to org.bukkit.entity.Player
            at me.Ricardo.WalkingCraftCore.Listeners.Zombies.onPlayerDamage(Zombies.
    java:24) ~[?:?]
            at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_51]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-13-g4a588b7-b2989jnks]
            ... 29 more
     
  2. Offline

    HungerCraftNL

    Did you register the event in your main class?
     
  3. Offline

    spookyDHD

  4. Offline

    Rocoty

    Do an instanceof check before casting the entity to Player
     
Thread Status:
Not open for further replies.

Share This Page