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),
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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
private final Map<String, EventProcessor> commandEventSenders =
new HashMap<>();
+ private final EventBus eventBus;
+
+ public SimpleCommandHandler(EventBus eventBus) {
+ this.eventBus = eventBus;
+ }
public SimpleCommandHandler addCommand(String command,
EventProcessor eventProcessor) {
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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
@FunctionalInterface
public static interface EventProcessor {
- void processEvent(Optional<Source> source, List<String> parameters);
+ Object createEvent(Optional<Source> source, List<String> parameters);
}