From: David ‘Bombe’ Roden Date: Wed, 22 Oct 2014 19:51:03 +0000 (+0200) Subject: Move event sending into the command handler. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=199b296635b8b881359c0839e3a6b1e2d3745cf4;p=xudocci.git Move event sending into the command handler. --- diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index 82e2ea1..5345294 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -369,15 +369,16 @@ public class Connection extends AbstractExecutionThreadService implements Servic new MessageHandler(eventBus, this, prefixHandler), new CtcpHandler(eventBus, this), new ChannelNickHandler(eventBus, this, prefixHandler), - new SimpleCommandHandler() - .addCommand("431", (s, p) -> eventBus.post( - new NoNicknameGivenReceived(this))) - .addCommand("NICK", (s, p) -> eventBus.post( - new NicknameChanged(this, s.get(), - p.get(0)))) - .addCommand("JOIN", (s, p) -> eventBus.post( - new ChannelJoined(this, p.get(0), - s.get()))), + new SimpleCommandHandler(eventBus) + .addCommand("431", + (s, p) -> new NoNicknameGivenReceived( + this)) + .addCommand("NICK", + (s, p) -> new NicknameChanged(this, + s.get(), p.get(0))) + .addCommand("JOIN", + (s, p) -> new ChannelJoined(this, + p.get(0), s.get())), new MotdHandler(eventBus, this), new ChannelNotJoinedHandler(eventBus, this), new ConnectionEstablishHandler(eventBus, this), 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); }