EntityDamageEvent error!

Discussion in 'Plugin Development' started by zDubsCrazy, May 4, 2014.

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

    zDubsCrazy

    The event works, but hit chicken or other entity cause the error. Please help-me!
    EVENT:
    Code:java
    1. @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
    2. public void FallMessages(EntityDamageEvent event) {
    3.  
    4. final Player p = (Player) event.getEntity();
    5.  
    6. if(event.getEntity().getType().equals(EntityType.PLAYER) && event.getCause() == DamageCause.FALL && p.getWorld().getName().equals("d1") && p.getHealth() - event.getDamage() <= 0) {
    7. for(Player all : getServer().getWorld("d1").getPlayers()) {
    8. all.sendMessage("§c" + p.getName() + " §ecaiu e morreu.");
    9. }
    10. new BukkitRunnable() {
    11. public void run() {
    12. World w = Bukkit.getServer().getWorld(settings.getData().getString("descida.arena1.world"));
    13. double x = settings.getData().getDouble("descida.arena1.x");
    14. double y = settings.getData().getDouble("descida.arena1.y");
    15. double z = settings.getData().getDouble("descida.arena1.z");
    16. p.teleport(new Location(w,x,y,z));
    17. }
    18. }.runTaskLater(this, 1);
    19. }
    20. }


    THE ERROR:
    PHP:
    [14:17:45] [Server thread/ERROR]: Could not pass event EntityDamageByEntityEvent to OCIOSODescida v1.0
    org
    .bukkit.event.EventException
        at org
    .bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEvent(CraftEventFactory.java:98) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:386) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:414) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.EntityLiving.damageEntity(EntityLiving.java:656) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.EntityAnimal.damageEntity(SourceFile:145) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.EntityHuman.attack(EntityHuman.java:918) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:1102) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.PacketPlayInUseEntity.a(SourceFile:55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.PacketPlayInUseEntity.handle(SourceFile:10) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused byjava.lang.ClassCastExceptionorg.bukkit.craftbukkit.v1_7_R1.entity.CraftChicken cannot be cast to org.bukkit.entity.Player
        at ocioso
    .descida.MiniGame.FallMessages(MiniGame.java:149) ~[?:?]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 
    19 more
     
  2. Offline

    mibac138

    You are trying to make a chicken be a player
    (final Player p = (Player) event.getEntity())
     
  3. Offline

    zDubsCrazy

  4. Offline

    GreatBlitz

    Check if the enity is an instance of Player.
     
  5. Offline

    zDubsCrazy

    GreatBlitz
    (event.getEntity() instanceof Player) { ? Not Work! Same error! :/
     
  6. Offline

    GreatBlitz

    Alright I'll come back to this tomorrow.
    zDubsCrazy
     
  7. Offline

    zDubsCrazy

  8. Offline

    xTigerRebornx

    zDubsCrazy Post the current error and code that goes w/ it.
     
  9. Offline

    Zacky1

    You might want to consider different event listeners... it seems like your event checks if the fall has killed a player. So instead of listening to entityDamage you should actually listen to PlayerDeathEvent, there you could look for the death reason. Then create a Bukkit task to run later (when s/he respawns preferable) which teleports them back.
     
  10. Offline

    zDubsCrazy

    xTigerRebornx
    The error is in the topic.

    Zacky1
    I will try this.

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

    xTigerRebornx

    zDubsCrazy You still haven't given your current code. The error with the one first posted is that you are casting the Entity to a Player before checking if it is actually a Player, therefor it throws an error, since the Entity isn't a Player.
     
  12. Offline

    zDubsCrazy

  13. Offline

    zDubsCrazy

  14. Offline

    zDubsCrazy

Thread Status:
Not open for further replies.

Share This Page