diff --git a/src/mightypork/utils/eventbus/BusEvent.java b/src/mightypork/utils/eventbus/BusEvent.java index aba4f5e..ff21d52 100644 --- a/src/mightypork/utils/eventbus/BusEvent.java +++ b/src/mightypork/utils/eventbus/BusEvent.java @@ -31,19 +31,19 @@ import mightypork.utils.eventbus.events.flags.SingleReceiverEvent; * @param handler type */ public abstract class BusEvent { - + private boolean consumed; private boolean served; - - + + /** * Ask handler to handle this message. * * @param handler handler instance */ protected abstract void handleBy(HANDLER handler); - - + + /** * Consume the event, so no other clients will receive it. * @@ -53,15 +53,17 @@ public abstract class BusEvent { public final void consume() { if (consumed) throw new IllegalStateException("Already consumed."); - + if (getClass().isAnnotationPresent(NonConsumableEvent.class)) { throw new UnsupportedOperationException("Not consumable."); } + (new Throwable()).printStackTrace(); + consumed = true; } - - + + /** * Deliver to a handler using the handleBy method. * @@ -70,17 +72,17 @@ public abstract class BusEvent { final void deliverTo(HANDLER handler) { handleBy(handler); - + if (!served) { if (getClass().isAnnotationPresent(SingleReceiverEvent.class)) { consumed = true; } - + served = true; } } - - + + /** * Check if the event is consumed. When an event is consumed, no other * clients will receive it. @@ -91,8 +93,8 @@ public abstract class BusEvent { { return consumed; } - - + + /** * @return true if the event was served to at least 1 client */ @@ -100,8 +102,8 @@ public abstract class BusEvent { { return served; } - - + + /** * Clear "served" and "consumed" flags before dispatching. */ @@ -110,8 +112,8 @@ public abstract class BusEvent { served = false; consumed = false; } - - + + /** * Called after all clients have received the event. *