Send event when a client’s nickname changes.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Apr 2013 09:47:21 +0000 (11:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 14 Apr 2013 09:47:21 +0000 (11:47 +0200)
src/main/java/net/pterodactylus/irc/Connection.java
src/main/java/net/pterodactylus/irc/event/NicknameChanged.java [new file with mode: 0644]

index 9a2bcd5..f5b29b4 100644 (file)
@@ -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 (file)
index 0000000..9b223dd
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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;
+       }
+
+}