mirror of
https://github.com/zaaarf/geb.git
synced 2024-11-13 01:49:21 +01:00
feat: IBus interface
This commit is contained in:
parent
0dbbe17261
commit
d48726c80f
4 changed files with 31 additions and 6 deletions
|
@ -1,4 +1,7 @@
|
|||
package ftbsc.geb.api;
|
||||
package ftbsc.geb;
|
||||
|
||||
import ftbsc.geb.api.IBus;
|
||||
import ftbsc.geb.api.IEvent;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Map;
|
||||
|
@ -6,10 +9,10 @@ import java.util.ServiceLoader;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The main event bus class.
|
||||
* The official GEB implementation of {@link IBus}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public class GEB {
|
||||
public class GEB implements IBus {
|
||||
|
||||
/**
|
||||
* The identifier of this bus. Methods
|
||||
|
@ -40,6 +43,7 @@ public class GEB {
|
|||
/**
|
||||
* @return the identifier of this bus
|
||||
*/
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
@ -50,6 +54,7 @@ public class GEB {
|
|||
* @param event the event to fire
|
||||
* @return true if the event was canceled, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean handleEvent(IEvent event) {
|
||||
try {
|
||||
return eventMapper.get(event.getClass()).newInstance(event).callListeners(this.getIdentifier());
|
20
src/main/java/ftbsc/geb/api/IBus.java
Normal file
20
src/main/java/ftbsc/geb/api/IBus.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package ftbsc.geb.api;
|
||||
|
||||
/**
|
||||
* A generic interface for a bus that can work with this
|
||||
* event system.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public interface IBus {
|
||||
/**
|
||||
* @return the identifier of this bus
|
||||
*/
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Dispatches an event, calling all of its listeners that are subscribed to this bus.
|
||||
* @param event the event to fire
|
||||
* @return true if the event was canceled, false otherwise
|
||||
*/
|
||||
boolean handleEvent(IEvent event);
|
||||
}
|
|
@ -10,7 +10,7 @@ public interface IEvent {
|
|||
* calls to listeners, but its return values will be ignored. You probably
|
||||
* don't want to touch this.
|
||||
* @param identifier the identifier of the bus that's calling this
|
||||
* @return the value {@link GEB#handleEvent(IEvent)} will return for this
|
||||
* @return the value {@link IBus#handleEvent(IEvent)} will return for this
|
||||
*/
|
||||
default boolean callListeners(String identifier) {
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ftbsc.geb.api.annotations;
|
||||
|
||||
import ftbsc.geb.api.GEB;
|
||||
import ftbsc.geb.api.IBus;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
@ -8,7 +8,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation should mark either a static instance of {@link GEB}
|
||||
* This annotation should mark either a static instance of {@link IBus}
|
||||
* or a static method returning one.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue