From d761d2e083fbbb4748bc56018f695b4971eb943e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 14 Apr 2013 11:47:21 +0200 Subject: [PATCH] =?utf8?q?Send=20event=20when=20a=20client=E2=80=99s=20nic?= =?utf8?q?kname=20changes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/irc/Connection.java | 5 ++ .../pterodactylus/irc/event/NicknameChanged.java | 74 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/net/pterodactylus/irc/event/NicknameChanged.java diff --git a/src/main/java/net/pterodactylus/irc/Connection.java b/src/main/java/net/pterodactylus/irc/Connection.java index 9a2bcd5..f5b29b4 100644 --- a/src/main/java/net/pterodactylus/irc/Connection.java +++ b/src/main/java/net/pterodactylus/irc/Connection.java @@ -51,6 +51,7 @@ import net.pterodactylus.irc.event.ConnectionFailed; import net.pterodactylus.irc.event.DccAcceptReceived; import net.pterodactylus.irc.event.DccSendReceived; import net.pterodactylus.irc.event.MotdReceived; +import net.pterodactylus.irc.event.NicknameChanged; import net.pterodactylus.irc.event.NicknameInUseReceived; import net.pterodactylus.irc.event.NoNicknameGivenReceived; import net.pterodactylus.irc.event.PrivateMessageReceived; @@ -399,6 +400,10 @@ public class Connection extends AbstractExecutionThreadService implements Servic eventBus.post(new NicknameInUseReceived(this, reply)); } + /* client stuff. */ + } else if (command.equalsIgnoreCase("NICK")) { + eventBus.post(new NicknameChanged(this, reply.source().get(), parameters.get(0))); + /* channel stuff. */ } else if (command.equalsIgnoreCase("JOIN")) { eventBus.post(new ChannelJoined(this, parameters.get(0), reply.source().get())); diff --git a/src/main/java/net/pterodactylus/irc/event/NicknameChanged.java b/src/main/java/net/pterodactylus/irc/event/NicknameChanged.java new file mode 100644 index 0000000..9b223dd --- /dev/null +++ b/src/main/java/net/pterodactylus/irc/event/NicknameChanged.java @@ -0,0 +1,74 @@ +/* + * XdccDownloader - NicknameChanged.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.irc.event; + +import net.pterodactylus.irc.Connection; +import net.pterodactylus.irc.Source; + +/** + * Notifies a listener that a client has changed its nickname. + * + * @author David ‘Bombe’ Roden + */ +public class NicknameChanged extends AbstractConnectionEvent { + + /** The client that changed its nickname. */ + private final Source client; + + /** The new nickname of the client. */ + private final String newNickname; + + /** + * Creates a new nickname changed event. + * + * @param connection + * The connection the event occured on + * @param client + * The client that changed its nickname + * @param newNickname + * The new nickname of the client + */ + public NicknameChanged(Connection connection, Source client, String newNickname) { + super(connection); + this.client = client; + this.newNickname = newNickname; + } + + // + // ACCESSORS + // + + /** + * Returns the client that changed its nickname. + * + * @return The client that changed its nickname + */ + public Source client() { + return client; + } + + /** + * Returns the new nickname of the client. + * + * @return The new nickname of the client + */ + public String newNickname() { + return newNickname; + } + +} -- 2.7.4