X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Firc%2FConnection.java;h=86de5354d28183649892d8020e9e6869fe2e266b;hb=e4793dbb593cf8babe654ed9311eae466d4e6291;hp=6354c906403d0c2c0a3bc8ec233e5f9b5dd3a243;hpb=c4867f883cce2d99972bb14dd5937c6348ff29f5;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index 6354c90..86de535 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -18,6 +18,7 @@ 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; @@ -42,6 +43,7 @@ import javax.net.SocketFactory; 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; @@ -382,8 +384,10 @@ public class Connection extends AbstractExecutionThreadService implements Servic Map nickPrefixes = Maps.newHashMap(); Set channelTypes = Sets.newHashSet(); - ConnectionEstablishHandler connectionEstablishHandler = new ConnectionEstablishHandler(eventBus, this); - ChannelNotJoinedHandler channelNotJoinedHandler = new ChannelNotJoinedHandler(eventBus, this); + List handlers = asList( + new ConnectionEstablishHandler(eventBus, this), + new ChannelNotJoinedHandler(eventBus, this) + ); while (connected) { Reply reply = connectionHandler.readReply(); @@ -392,6 +396,13 @@ public class Connection extends AbstractExecutionThreadService implements Servic String command = reply.command(); List 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); @@ -455,16 +466,10 @@ public class Connection extends AbstractExecutionThreadService implements Servic } 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) {