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 History
**  
**  Date        Name         Description
**  ---------|------------|-----------------------------------------------
**  16Jul97     merlin       created this command
**
*/

package key.commands;

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

/**
  *  This command is intended to return the context of the player
  *  back to the player's own context - the player itself.    
 */
public class StringSetAdd extends Command
{
	public static final AtomicElement[] ELEMENTS =
	{
		AtomicElement.construct( StringSetAdd.class, StringSet.class, "stringSet",
			AtomicElement.PUBLIC_FIELD,
			"the stringset the modify" )
	};
	
	public static final AtomicStructure STRUCTURE = new AtomicStructure( Command.STRUCTURE, ELEMENTS );
	
	public Reference stringSet = Reference.EMPTY;
	
	public StringSetAdd()
	{
		setKey( "stringsetadd" );
		usage = "<name>";
	}
	
	public AtomicStructure getDeclaredStructure()
	{
		return( STRUCTURE );
	}
	
	public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
	{
		if( !args.hasMoreTokens() )
		{
			usage( ic );
			return;
		}
		
		StringSet names = (StringSet) stringSet.get();
		
		if( names == null )
		{
			ic.sendError( "No string set" );
			return;
		}
		
		String name = args.nextToken( "" );
		
		try
		{
			names.addString( name );
		}
		catch( NonUniqueKeyException n )
		{
				//  name is already here;
			ic.sendFeedback( name + " is already in " + names.getName() );
			return;
		}
		catch( BadKeyException b )
		{
			ic.sendFeedback( "Could not add " + name + " to the list" );
			return;
		}

			//  name added successfully
		ic.sendFeedback( "'" + name + "' added to the reserved name list" );
	}
}