Solved onEntityDamageByEntity Error With (Unknown Source)

Discussion in 'Plugin Development' started by Tenetri, Oct 8, 2012.

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

    Tenetri

    I've been getting a reallllly weird errror in my plugin.

    Code:
    2012-10-09 01:31:29 [SEVERE] Could not pass event EntityDamageByEntityEvent to ZombieEscape
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.event.CraftEventFactory.callEvent(CraftEventFactory.java:80)
        at org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:364)
        at org.bukkit.craftbukkit.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:386)
        at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:591)
        at net.minecraft.server.EntityHuman.damageEntity(EntityHuman.java:595)
        at net.minecraft.server.EntityPlayer.damageEntity(EntityPlayer.java:353)
        at net.minecraft.server.EntitySmallFireball.a(EntitySmallFireball.java:28)
        at net.minecraft.server.EntityFireball.h_(EntityFireball.java:137)
        at net.minecraft.server.World.entityJoinedWorld(World.java:1245)
        at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:511)
        at net.minecraft.server.World.playerJoinedWorld(World.java:1227)
        at net.minecraft.server.World.tickEntities(World.java:1125)
        at net.minecraft.server.WorldServer.tickEntities(WorldServer.java:428)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:563)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:473)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:405)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
        at me.Tenetri.zombieescape.ZombieEscape.onEntityDamageByEntity(ZombieEscape.java:1892)
        at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
        ... 21 more
    
    Line 1892 is

    Code:
    Player player = (Player) event.getEntity();
    and the code around it is this...

    Code:
    @EventHandler
        public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
        {
    Entity Damager = event.getDamager();
                if (event.getEntity() instanceof Player && Damager instanceof Projectile)
          {   
                    Player player = (Player) event.getEntity();
     
                    //MoreCodeHere--
          }
        
    I'm not sure why this is happening, its really bothering me. Any help is greatly appreciated!
     
  2. Offline

    Drkmaster83

    Well, I can't be sure of it, but maybe, JUST MAYBE, before you check if the damaged entity is a player, you have to cast it to be a damaged entity. I doubt this is it. :p

    Code:
    Entity damaged = event.getEntity();
    Entity damager = event.getDamager();
    if(damaged instanceof Player && damager instanceof Projectile)
    {
        Player harmed = (Player) damaged;
        Projectile proj = (Projectile) damager;
    }
    
     
    Tenetri likes this.
  3. Offline

    Tenetri

    Excellent! Thank you so much! <3 Fixed the error right up!

    Not sure what was causing it, but its gone now. It was coming up like crazy.

    Thankyou, i'm gunna edit the title to solved

    I guess I can't edit the title. I must just not know how.

    If anyone can edit the title, something better would be

    '[Solved] onEntityDamageByEntity Error With (Unknown Source)'

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    ZeusAllMighty11

    To edit thread title, go to plugin development forum, on under the title of your post on the list of posts, there's an edit button. Click prefix > solved
     
  5. Offline

    Tenetri

    tyty<3
     
  6. Offline

    Drkmaster83

    You were trying to cast the Entity as a player prematurely. I bet that was it.
     
Thread Status:
Not open for further replies.

Share This Page