[Solved] Lightning strike conflict with EntityDamageByEntityEvent

Discussion in 'Spigot Plugin Development' started by RandomPanda30, May 9, 2015.

  1. So it appears whenever lightning strikes a player, this error occurs

    Code (Text):
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R2.entity.CraftLightningStrike cannot be cast to org.bukkit.entity.Projectile
        at co.uk.RandomPanda30.Murge.Events.OnEntityDamageByEntityEvent.onEntityDamageByEntityEvent(OnEntityDamageByEntityEvent.java:137) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]
        ... 20 more
    [21:27:49 ERROR]: Could not pass event EntityDamageByEntityEvent to Murge v1.3
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callEvent(CraftEventFactory.java:86) [spigot.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:492) [spigot.jar:git-Spigot-870264a-0a645a2]
        at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.handleLivingEntityDamageEvent(CraftEventFactory.java:571) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.EntityLiving.d(EntityLiving.java:1101) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.EntityHuman.d(EntityHuman.java:859) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.EntityLiving.damageEntity(EntityLiving.java:742) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.EntityHuman.damageEntity(EntityHuman.java:800) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.EntityPlayer.damageEntity(EntityPlayer.java:496) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.Entity.onLightningStrike(Entity.java:1742) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.EntityLightning.t_(EntityLightning.java:122) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.World.tickEntities(World.java:1360) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.WorldServer.tickEntities(WorldServer.java:597) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:783) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-870264a-0a645a2]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-870264a-0a645a2]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R2.entity.CraftLightningStrike cannot be cast to org.bukkit.entity.Projectile
        at co.uk.RandomPanda30.Murge.Events.OnEntityDamageByEntityEvent.onEntityDamageByEntityEvent(OnEntityDamageByEntityEvent.java:137) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
        at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]
        ... 20 more
     
    Any suggestions as to what to do to fix this?
     
  2. This is an issue with the plugin Murge, ask him
    @RandomPanda30

    EDIT: oops, you're the author of Murge
    Well, just read the error and fix it in your code
    We can't help you if you don't show code
     
    • Funny Funny x 1
  3. Erm, I am "him" xD I'm just getting this error and wondering how I can fix it?
     
  4. Looks like you are casting a CraftLightningStrike to a Projectile.
     
  5. Hmmmm you see I have this in my code -

    Code (Text):
    if (((Projectile) damager).getShooter() instanceof Player) {
                        attacker = (Player) ((Projectile) damager).getShooter();
                        attackerUUID = attacker.getUniqueId();

                        if (MurgeData.isPurge()) {
                            if (!StatsHandler.inSpectators(attackerUUID)) {
                                if (!StatsHandler.inCombatLog(victimUUID)) {
                                    StatsHandler.addCombatLog(victimUUID,
                                            attackerUUID);
                                    StringMethods.sendMessage((String) Murge.mMap
                                            .getStat(MessagesValues.INCOMBAT),
                                            victim);
                                    StringMethods.sendMessage((String) Murge.mMap
                                            .getStat(MessagesValues.INCOMBAT),
                                            attacker);
                                }
                            } else {
                                StringMethods.sendMessage((String) Murge.mMap
                                        .getStat(MessagesValues.SPECTATE_NOPVP),
                                        attacker);
                                event.setCancelled(true);
                            }
                        } else {
                            if (!MiscCollection.isPVPAllowed()) {
                                StringMethods.sendMessage((String) Murge.mMap
                                        .getStat(MessagesValues.PVPNOTALLOWED),
                                        attacker);
                                event.setCancelled(true);
                            }
                        }
                    }
                } else if (((Projectile) damager).getShooter() instanceof Skeleton) {
                    if (!MiscCollection.mobDamageCountAsCombat()) {
                        if (!StatsHandler.inCombatLog(victimUUID)) {
                            StatsHandler.addCombatLog(victimUUID, null);
                            StringMethods.sendMessage((String) Murge.mMap
                                    .getStat(MessagesValues.INCOMBAT), victim);
                        }
                    }
    So erm I'm not casting the LightningStrike directly. I don't understand why this would be throwing errors
     
  6. I know sorry just seeing if anyone could throw a starting point as to what to look out for
     
  7. What's line 137 ?
     
  8. Line 137 is this -

    Code (Text):
            } else if (((Projectile) damager).getShooter() instanceof Skeleton) {
     
  9. Yes, you need to check if the damager is a projectile before casting.
     
  10. Check if damager is a projectile before casting
    EDIT: Ninja'd
     
  11. I did that here D: -

    Code (Text):
        } else if (damager instanceof Projectile) {
     
  12. The error says you didn't
     
  13. And the error was correct. Thank you for pointing this out. Even the most simple things can break everything. Turns out I just needed to but the code in another block. Thank you!