package net.pterodactylus.irc;
import static com.google.common.base.Preconditions.checkState;
+import static java.util.Arrays.asList;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.io.BufferedReader;
import net.pterodactylus.irc.connection.ChannelNotJoinedHandler;
import net.pterodactylus.irc.connection.ConnectionEstablishHandler;
+import net.pterodactylus.irc.connection.Handler;
import net.pterodactylus.irc.event.ChannelJoined;
import net.pterodactylus.irc.event.ChannelLeft;
import net.pterodactylus.irc.event.ChannelMessageReceived;
Map<String, String> nickPrefixes = Maps.newHashMap();
Set<Character> channelTypes = Sets.newHashSet();
- ConnectionEstablishHandler connectionEstablishHandler = new ConnectionEstablishHandler(eventBus, this);
- ChannelNotJoinedHandler channelNotJoinedHandler = new ChannelNotJoinedHandler(eventBus, this);
+ List<Handler> handlers = asList(
+ new ConnectionEstablishHandler(eventBus, this),
+ new ChannelNotJoinedHandler(eventBus, this)
+ );
while (connected) {
Reply reply = connectionHandler.readReply();
String command = reply.command();
List<String> parameters = reply.parameters();
+ for (Handler handler : handlers) {
+ if (handler.willHandle(reply)) {
+ handler.handleReply(reply);
+ break;
+ }
+ }
+
/* most common events. */
if (command.equalsIgnoreCase("PRIVMSG")) {
String recipient = parameters.get(0);
} else if (command.equalsIgnoreCase("QUIT")) {
eventBus.post(new ClientQuit(this, reply.source().get(), parameters.get(0)));
- } else if (channelNotJoinedHandler.willHandle(reply)) {
- channelNotJoinedHandler.handleReply(reply);
-
/* basic connection housekeeping. */
} else if (command.equalsIgnoreCase("PING")) {
connectionHandler.sendCommand("PONG", getOptional(parameters, 0), getOptional(parameters, 1));
- } else if (connectionEstablishHandler.willHandle(reply)) {
- connectionEstablishHandler.handleReply(reply);
-
/* 005 originally was a bounce message, now used to transmit useful information about the server. */
} else if (command.equals("005")) {
for (String parameter : parameters) {