Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3944

Event API Bug - registerEvent not working correctly with subclasses

XMLWordPrintable

      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.

            Unassigned Unassigned
            kmecpp kmecpp
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: