Zedly / Zenchantments

More enchantments without mods or resource packs. CB/Spigot 1.14.4 / 1.12 / 1.11.x / 1.10.x
GNU General Public License v3.0
12 stars 23 forks source link

1.15.1 cannot be cast to entity player warning #36

Closed DrakePork closed 4 years ago

DrakePork commented 4 years ago

I know you dont have a 1.15 version out yet but uh after updating to 1.15 I started getting this warning in console when people hit mobs with custom enchants. Pastebin

Zedly commented 4 years ago

This error is now fixed!

Geolykt commented 4 years ago

I might be wrong, but looking at the code it shouldn't be fixed:

public boolean onBeingHit(EntityDamageByEntityEvent evt, int level, boolean usedHand) {
    if (!(evt.getEntity() instanceof LivingEntity) ||
        !ADAPTER.attackEntity((LivingEntity) evt.getEntity(), (Player) evt.getDamager(), 0)) {
        return true;
    }
}

We have already established that evt.getEntity() is not of instance of LivingEntity, so why cast it into a LivingEntity? The same goes for evt.getDamager(). I assume evt.getDamager() and evt.getEntity() were mixed up?

Zedly commented 4 years ago

Hi, should I have mentioned that the fix is on the dev branch? Sorry if this caused confusion. The offending code was removed in 4b51a7d47c21c6fc405bb13abae1a9aaa76a0dc9. Thanks for keeping me informed!

Geolykt commented 4 years ago

I'm a bit confused since I swear that this commit was pushed just a few hours ago. Anyways, I will try to reproduce it (once I am able to set up a 1.16.2 testing environment) and then make an update statement. anyways, thanks

Geolykt commented 4 years ago

Checked, and the issue (on the dev branch) should still occour. However, this test has been done logically, and not in a bukkit environment, which is quite different

Zedly commented 4 years ago

The typecast in onBeingHit is safe because the type is checked in WatcherEnchant.java:154. I will change the type of the parameter in onBeingHit to Player, though.

Zedly commented 4 years ago

Nevermind that's not how the code works. It's been a while since I looked at it