this.listeners.add(listener);
}
@Override
public void onMessage(Message message) {
User user = User.fromPrefix(message.getPrefix());
switch (message.getType()) {
case JOIN:
/* Must have valid user prefix */
if (user == null) {
break;
}
/*
* Once we've received a join message from the server we ourselves
* have actually joined
*/
this.joined.countDown();
/* Add user to names list */
if (!this.names.contains(user.getNick())) {
this.names.add(user.getNick());
}
/* Call listeners */
for (ChannelListener listener : this.listeners) {
listener.onJoin(this, user);
}
break;
case PART:
/* Must have valid user prefix */
if (user == null) {
break;
}
/* Remove nick from names list */
if (this.names.contains(user.getNick())) {
this.names.remove(user.getNick());
}
/* Call listeners */
for (ChannelListener listener : this.listeners) {
listener.onPart(this, user);
}
break;
case PRIVMSG:
/* Must have valid user prefix */
if (user == null) {
break;
}
/* Call listeners */
for (ChannelListener listener : this.listeners) {
listener.onMessage(this, user, message.getArgs()[1]);
}
break;
case QUIT:
/* Must have valid user prefix */
if (user == null) {
break;
}
/* Remove nick from names list */
if (this.names.contains(user.getNick())) {
this.names.remove(user.getNick());
}
/* Call listeners */
for (ChannelListener listener : this.listeners) {
listener.onQuit(this, user);
}
break;
case NICK:
/* Must have valid user prefix */
if (user == null) {
break;
}
/* Replace nick in names list */
if (this.names.contains(user.getNick())) {
this.names.remove(user.getNick());
this.names.add(message.getArgs()[0]);
}
break;
default: