Details
Description
When using the PluginManager.registerEvent() method (not register events) and registering the EntityDamageByEntityEvent class. The event parameter that is then passed to the executor when the event is fired is not an instance of EntityDamageByEntityEvent but of EntityDamageEvent.
The following code
Bukkit.getPluginManager().registerEvent(paramClass, listener, annotation.priority(), (l, e) -> {Bukkit.getPluginManager().registerEvent(paramClass, listener, annotation.priority(), (l, e) -> { try { if (condition == null || condition.check(e)) { if (e instanceof EntityDamageEvent) { if (paramClass.equals(EntityDamageByEntityEvent.class)) { System.out.println((EntityDamageByEntityEvent) e); } } method.invoke(l, e); } } catch (Exception ex) { ex.printStackTrace(); } }, VoidFlameCore.getPlugin());
Throws
java.lang.ClassCastException: org.bukkit.event.entity.EntityDamageEvent cannot be cast to org.bukkit.event.entity.EntityDamageByEntityEvent
on this line:
System.out.println((EntityDamageByEntityEvent) e);
Even though the paramClass is what was passed to the registerEvent method originally.