#3090: Register events in parent classes
This commit is contained in:
parent
a0b7f09252
commit
5823f47467
@ -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 )
|
||||||
|
26
event/src/test/java/net/md_5/bungee/event/SubclassTest.java
Normal file
26
event/src/test/java/net/md_5/bungee/event/SubclassTest.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user