From 860d446d28776ec842fa53e8e08538d4e093d6e9 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 12 Oct 2011 03:14:07 +0200 Subject: EssentialsUpdate WIP --- .../f00f/net/irc/martyr/commands/NickCommand.java | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 EssentialsUpdate/src/f00f/net/irc/martyr/commands/NickCommand.java (limited to 'EssentialsUpdate/src/f00f/net/irc/martyr/commands/NickCommand.java') diff --git a/EssentialsUpdate/src/f00f/net/irc/martyr/commands/NickCommand.java b/EssentialsUpdate/src/f00f/net/irc/martyr/commands/NickCommand.java new file mode 100644 index 000000000..6cdcb0224 --- /dev/null +++ b/EssentialsUpdate/src/f00f/net/irc/martyr/commands/NickCommand.java @@ -0,0 +1,97 @@ +/* + * Original version: Ben Damm + * Changes by: Mog + * - added getOldNick + * */ +package f00f.net.irc.martyr.commands; + +import java.util.Enumeration; + +import f00f.net.irc.martyr.InCommand; +import f00f.net.irc.martyr.clientstate.Channel; +import f00f.net.irc.martyr.clientstate.ClientState; +import f00f.net.irc.martyr.clientstate.Member; +import f00f.net.irc.martyr.util.FullNick; + +/** + * Defines NICK command. + */ +public class NickCommand extends AbstractCommand +{ + + private FullNick oldNick; + private FullNick newNick; + + /** For use as a factory */ + public NickCommand() + { + this( null, null ); + } + + public NickCommand( FullNick oldNick, FullNick newNick ) + { + this.oldNick = oldNick; + this.newNick = newNick; + } + + public NickCommand( String newNick ) + { + this( null, new FullNick( newNick ) ); + } + + public InCommand parse( String prefix, String identifier, String params ) + { + return new NickCommand( new FullNick( prefix ), new FullNick ( getParameter( params, 0 ) ) ); + } + + public String getIrcIdentifier() + { + return "NICK"; + } + + public String renderParams() + { + return getNick(); + } + + public String getNick() + { + return newNick.getNick(); + } + + public String getOldNick() + { + return oldNick.getNick(); + } + + public boolean updateClientState( ClientState state ) + { + // Does this apply to us? + if( oldNick.equals( state.getNick() ) ) + { + state.setNick( newNick ); + return true; + } + else + { + // Ok, so we need to change someone's nick. + // This needs to occur for each member with that nick in each + // channel that we are in. Just use Member.setNick for each + // occurance. + // Note: I do not believe this code has received a vigorous + // test. + Enumeration channels = state.getChannels(); + while( channels.hasMoreElements() ) + { + Channel channel = (Channel)channels.nextElement(); + Member member = channel.findMember( oldNick.getNick() ); + if( member != null ) + member.setNick( newNick ); + } + } + return false; + } + +} + + -- cgit v1.2.3