Solved Why is this Happening?

Discussion in 'Plugin Development' started by Giorgio, Oct 20, 2012.

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

    Giorgio

    Hello everyone im recently made my Dyrocraft plugin (kitpvp), and i add this listener class to the plugin here it is:

    Code:Java
    1.  
    2.  
    3. @EventHandler
    4. public void OnEggHit(EntityDamageByEntityEvent e) {
    5. Player player = (Player) e.getEntity();
    6. if(e.getDamager() instanceof Egg) {
    7. if(e.getEntity()instanceof Player) {
    8. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 300 ,0));
    9. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 300 ,0));
    10. }
    11. }
    12. }


    When i hit an Entity mob/or Animal it gives me this, but when i hit a player nothing happends to there health :
    Code:
    08:02:38 [SEVERE] Could not pass event EntityDamageByEntityEvent to Dyrocraft v1
    .0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:341)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callEvent(CraftEventFa
    ctory.java:80)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDamageEvent(
    CraftEventFactory.java:364)
            at org.bukkit.craftbukkit.event.CraftEventFactory.handleEntityDamageEven
    t(CraftEventFactory.java:386)
            at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:591)
     
            at net.minecraft.server.EntityAnimal.damageEntity(SourceFile:124)
            at net.minecraft.server.EntityWolf.damageEntity(EntityWolf.java:169)
            at net.minecraft.server.EntityArrow.h_(EntityArrow.java:222)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1245)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:5
    11)
            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:547)
            at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
            at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.entity.CraftWolf
    cannot be cast to org.bukkit.entity.Player
            at me.giorgio.Dyrocraft.Playercontanct.OnEggHit(Playercontanct.java:26)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:339)
            ... 20 more
     
  2. Offline

    ZeusAllMighty11 Retired Staff

    Well I can already see you casted Player to the entity, when you check for instanceof player as well... No need for a double check. I just do 'if(e.getEntity() instanceof Player){ ' and that works fine for me. Then if I get errors, I add an else statement.
     
  3. Offline

    Giorgio

    ZeusAllMighty11
    Ok so your saying delete "if(e.getDamager() instnaceof Egg){ " ?
     
  4. Offline

    ZeusAllMighty11 Retired Staff


    No, delete your cast of:
    Player player = (Player) e.getEntity()
     
  5. Offline

    gcflames5

    You can leave that if you check if the entity is a player first. My guess is that you get this error whenever you hit a non-player, am i correct?
     
  6. Offline

    kroltan

    Move the Player player part to inside your inner if. Explicitly:
    Code:java
    1. @EventHandler
    2. public void OnEggHit(EntityDamageByEntityEvent e) {
    3. //FROM HERE
    4. if(e.getDamager() instanceof Egg) {
    5. if(e.getEntity()instanceof Player) {
    6. Player player = (Player) e.getEntity(); //TO HERE
    7. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 300 ,0));
    8. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 300 ,0));
    9. }
    10. }
    11. }
     
    ZeusAllMighty11 likes this.
  7. Offline

    Giorgio

    Ok it works thank you all!
     
Thread Status:
Not open for further replies.

Share This Page