diff options
author | zaaarf <zaaarf@proton.me> | 2023-08-18 18:12:58 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-08-18 18:12:58 +0200 |
commit | d48726c80f0edb159f8df80d10267ad26a3efe03 (patch) | |
tree | 77738c0e67c5212421b58e429a48e5211a3238e2 /src/main/java/ftbsc | |
parent | 0dbbe17261f740a3ee9deb1a6ffd0e3c57e229be (diff) |
feat: IBus interface
Diffstat (limited to 'src/main/java/ftbsc')
-rw-r--r-- | src/main/java/ftbsc/geb/GEB.java (renamed from src/main/java/ftbsc/geb/api/GEB.java) | 11 | ||||
-rw-r--r-- | src/main/java/ftbsc/geb/api/IBus.java | 20 | ||||
-rw-r--r-- | src/main/java/ftbsc/geb/api/IEvent.java | 2 | ||||
-rw-r--r-- | src/main/java/ftbsc/geb/api/annotations/BusInstance.java | 4 |
4 files changed, 31 insertions, 6 deletions
diff --git a/src/main/java/ftbsc/geb/api/GEB.java b/src/main/java/ftbsc/geb/GEB.java index 5d65511..123447b 100644 --- a/src/main/java/ftbsc/geb/api/GEB.java +++ b/src/main/java/ftbsc/geb/GEB.java @@ -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()); diff --git a/src/main/java/ftbsc/geb/api/IBus.java b/src/main/java/ftbsc/geb/api/IBus.java new file mode 100644 index 0000000..e75e25c --- /dev/null +++ b/src/main/java/ftbsc/geb/api/IBus.java @@ -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); +} diff --git a/src/main/java/ftbsc/geb/api/IEvent.java b/src/main/java/ftbsc/geb/api/IEvent.java index d75ed15..fd2a343 100644 --- a/src/main/java/ftbsc/geb/api/IEvent.java +++ b/src/main/java/ftbsc/geb/api/IEvent.java @@ -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; diff --git a/src/main/java/ftbsc/geb/api/annotations/BusInstance.java b/src/main/java/ftbsc/geb/api/annotations/BusInstance.java index b785b15..cacab39 100644 --- a/src/main/java/ftbsc/geb/api/annotations/BusInstance.java +++ b/src/main/java/ftbsc/geb/api/annotations/BusInstance.java @@ -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 */ |