#3090: Register events in parent classes

This commit is contained in:
md_5 2021-05-19 18:41:07 +10:00
parent a0b7f09252
commit 5823f47467
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 29 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package net.md_5.bungee.event; package net.md_5.bungee.event;
import com.google.common.collect.ImmutableSet;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -61,7 +62,8 @@ public class EventBus
private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener) private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener)
{ {
Map<Class<?>, Map<Byte, Set<Method>>> handler = new HashMap<>(); Map<Class<?>, Map<Byte, Set<Method>>> handler = new HashMap<>();
for ( Method m : listener.getClass().getDeclaredMethods() ) Set<Method> methods = ImmutableSet.<Method>builder().add( listener.getClass().getMethods() ).add( listener.getClass().getDeclaredMethods() ).build();
for ( final Method m : methods )
{ {
EventHandler annotation = m.getAnnotation( EventHandler.class ); EventHandler annotation = m.getAnnotation( EventHandler.class );
if ( annotation != null ) if ( annotation != null )

View File

@ -0,0 +1,26 @@
package net.md_5.bungee.event;
import java.util.concurrent.CountDownLatch;
import org.junit.Assert;
import org.junit.Test;
public class SubclassTest extends EventBusTest
{
private final CountDownLatch latch = new CountDownLatch( 1 );
@Test
@Override
public void testNestedEvents()
{
super.testNestedEvents();
Assert.assertEquals( 0, latch.getCount() );
}
@EventHandler
protected void extraListener(FirstEvent event)
{
Assert.assertEquals( 1, latch.getCount() );
latch.countDown();
}
}