X-Git-Url: https://git.pterodactylus.net/?p=xudocci.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Firc%2Fconnection%2FSimpleCommandHandler.java;h=373b75eab1f3764e06b99a4bea0243f234f2822a;hp=3f75d0ed2271568f5fbb12d9569e002af03f92cc;hb=199b296635b8b881359c0839e3a6b1e2d3745cf4;hpb=32912dccba0d2b74b1cc2b5b30af5725368ca613 diff --git a/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java b/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java index 3f75d0e..373b75e 100644 --- a/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java +++ b/src/main/java/net/pterodactylus/irc/connection/SimpleCommandHandler.java @@ -8,9 +8,11 @@ import net.pterodactylus.irc.Reply; import net.pterodactylus.irc.Source; import com.google.common.base.Optional; +import com.google.common.eventbus.EventBus; /** - * Handler that can process any number of events. + * Handler that can send events associated with commands to an {@link + * EventBus}. * * @author David ‘Bombe’ Roden */ @@ -18,6 +20,11 @@ public class SimpleCommandHandler implements Handler { private final Map commandEventSenders = new HashMap<>(); + private final EventBus eventBus; + + public SimpleCommandHandler(EventBus eventBus) { + this.eventBus = eventBus; + } public SimpleCommandHandler addCommand(String command, EventProcessor eventProcessor) { @@ -34,18 +41,19 @@ public class SimpleCommandHandler implements Handler { public void handleReply(Reply reply) { EventProcessor eventProcessor = commandEventSenders.get(reply.command().toLowerCase()); - eventProcessor.processEvent(reply.source(), reply.parameters()); + eventBus.post(eventProcessor.createEvent(reply.source(), + reply.parameters())); } /** - * Interface for event processors. + * Interface for event creators. * * @author David ‘Bombe’ Roden */ @FunctionalInterface public static interface EventProcessor { - void processEvent(Optional source, List parameters); + Object createEvent(Optional source, List parameters); }