key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/*
**               j###t  ########## ####   ####
**              j###t   ########## ####   ####
**             j###T               "###L J###"
**          ######P'    ##########  #########
**          ######k,    ##########   T######T
**          ####~###L   ####
**          #### q###L  ##########   .#####
**          ####  \###L ##########   #####"
**
**  Class: take
**
**  Class History
**
**  Date        Name         Description
**  ---------|------------|-----------------------------------------------
**  15Jul97     snapper      creation
**  20Jul97     snapper      added logging
*/

package key.commands.clan;

import key.*;
import java.util.StringTokenizer;
import java.io.IOException;

import java.util.Enumeration;

public class Take extends Command
{
	public Take()
	{
		setKey( "take" );
		usage = "<command>";
	}
	
	public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
	{
		if( !args.hasMoreTokens() )
		{
			usage( ic );
			return;
		}
		
		Object o = p.getContext();
		
		if( o != null )
		{
			if( o instanceof Rank )
			{
				Rank rank = (Rank) o;
				//CommandList cl = (CommandList) rank.getProperty( "commands" );
				CommandList cl = (CommandList) new Search( ".commands/clan.commands", rank ).result;
				if( cl == null )
				{
					ic.sendFeedback( "The command list is empty!  No commands to take!" );
					return;
				}
				
				String takeCommand = args.nextToken();
				Command taken = (Command) cl.getElement( takeCommand );	
				if( taken == null )
				{
					ic.sendFeedback( "That command does not exist inside '" + rank.getName() + "'" );
					return;
				}
				try
				{
					cl.remove( taken );
				}
				catch( BadKeyException e )
				{
					throw new UnexpectedResult( e.toString() + " on removing a matched atom." );
				}
				catch( NonUniqueKeyException e )
				{
					throw new UnexpectedResult( e.toString() + " on removing a matched atom" );
				}
				ic.sendFeedback( "Command '" + takeCommand + "' taken from '" + rank.getName() + "'" );
					// logging
				Log.log( "clans/" + p.getClan().getName() + ".notes", "'" + p.getName() + "' took the command '" + takeCommand + " from " + rank.getName() + "'" );
			}
			else
				ic.sendError( "You are not referencing a rank.  Use: rank <rank> first!" );
		}
		else
			ic.sendError( "Could not find that rank?" );
	}
}