Vehicle collide/enter event exception with horses
LadyCailinBot opened this issue ยท 10 comments
CMDHELPER-2750 - Reported by PseudoKnight
When you have a vehicle_collide event bound (with any prefilters), you can quickly run into this error on CraftBukkit #2811. It seems to occur any time a horse runs into a block, as the error would suggest. It does not occur with entity collisions.
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
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 net.minecraft.server.v1_6_R2.Entity.move(Entity.java:634)
at net.minecraft.server.v1_6_R2.EntityLiving.e(EntityLiving.java:1165)
at net.minecraft.server.v1_6_R2.EntityHorse.e(EntityHorse.java:939)
at net.minecraft.server.v1_6_R2.EntityLiving.c(EntityLiving.java:1421)
at net.minecraft.server.v1_6_R2.EntityInsentient.c(EntityInsentient.java:303)
at net.minecraft.server.v1_6_R2.EntityAgeable.c(EntityAgeable.java:87)
at net.minecraft.server.v1_6_R2.EntityAnimal.c(SourceFile:32)
at net.minecraft.server.v1_6_R2.EntityHorse.c(EntityHorse.java:712)
at net.minecraft.server.v1_6_R2.EntityLiving.l_(EntityLiving.java:1254)
at net.minecraft.server.v1_6_R2.EntityInsentient.l_(EntityInsentient.java:147)
at net.minecraft.server.v1_6_R2.EntityHorse.l_(EntityHorse.java:740)
at net.minecraft.server.v1_6_R2.World.entityJoinedWorld(World.java:1354)
at net.minecraft.server.v1_6_R2.World.playerJoinedWorld(World.java:1335)
at net.minecraft.server.v1_6_R2.World.tickEntities(World.java:1223)
at net.minecraft.server.v1_6_R2.WorldServer.tickEntities(WorldServer.java:480)
at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:572)
at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
Caused by: java.lang.ClassCastException: com.laytonsmith.abstraction.bukkit.BukkitMCAgeable cannot be cast to com.laytonsmith.abstraction.MCVehicle
at com.laytonsmith.abstraction.bukkit.events.BukkitVehicleEvents$BukkitMCVehicleEvent.getVehicle(BukkitVehicleEvents.java:133)
at com.laytonsmith.core.events.drivers.VehicleEvents$vehicle_collide.matches(VehicleEvents.java:191)
at com.laytonsmith.core.events.EventUtils.GetMatchingEvents(EventUtils.java:173)
at com.laytonsmith.core.events.EventUtils.TriggerListener(EventUtils.java:193)
at com.laytonsmith.abstraction.bukkit.events.drivers.BukkitVehicleListener.onBlockCollide(BukkitVehicleListener.java:48)
at sun.reflect.GeneratedMethodAccessor44.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.java:425)
... 23 more```
Tested on CH #1568.
Comment by PseudoKnight
On a hunch, I confirmed this happens when you bind a vehicle_enter event as well. Same problem:
Caused by: java.lang.ClassCastException: com.laytonsmith.abstraction.bukkit.BukkitMCAgeable cannot be cast to com.laytonsmith.abstraction.MCVehicle
Comment by jb_aero
Yep, I'm 80% finished horse fixes, will PR in an hour or two. Also, currently I have it so vehicle_collide does not fire when a pig runs into a block. Should I do the same for horses or remove that filter altogether?
Comment by PseudoKnight
I can't think of a use for vehicle block collisions with horses at the moment, but one could use vehicle entity collisions to prevent people from pushing someone else's horses into hazards. That might be useful in a horse protection/locking system. Though it might be better to just turn off almost all horse damage to owned horses that are not being ridden. Horses are pretty unique, unlike pigs. What's the drawback of leaving that option open to people?
Comment by jb_aero
In bukkit there are actually two events, VehicleBlockCollisionEvent and VehicleEntityCollisionEvent. The way I coded it, both call an appropriately constructed vehicle_collide, but I noticed that if a pig decided to be near-sighted, the block collide one is called every tick the pig's nose was touching a block. So I put an if() in to make block collisions fire if it's not a pig. I didn't mess with entity collisions at all, though I suspect they just aren't called for living vehicles.
Comment by PseudoKnight
Then it's probably best to filter them out for now. I noticed the above error could get spammy in certain situations with a horse. I don't want to even know how many times it'd fire per tick with a whole stable full.
Comment by jb_aero
or maybe even just have it fire when it's actually being used as a vehicle
Comment by PseudoKnight
It'd break some of my functionality if you applied that to minecarts. If type is horse or pig and has rider? Not sure. The one use I considered for horse collisions doesn't apply when there's a rider. It's safer to fix the error for now and consider adding functionality later.
Comment by PseudoKnight
I guess as long as you maintain current minecart functionality and performance, either way works for me.
Comment by PseudoKnight
This is fixed now in build 1581. Thanks, aero. I also haven't noticed any horse issues. It all works as expected.
Comment by jb_aero
Hopefully someday we will actually get an event for entities colliding with other entities, that'd be useful for pretty much all of them. Though we do have player_interact_entity, so now that leashes exist, maybe griefers will be too lazy to steal the old fashioned way? lol