/* ** j###t ########## #### #### ** j###t ########## #### #### ** j###T "###L J###" ** ######P' ########## ######### ** ######k, ########## T######T ** ####~###L #### ** #### q###L ########## .##### ** #### \###L ########## #####" */ package key.commands; import key.*; import java.io.*; import java.util.StringTokenizer; import java.util.Hashtable; /** * This command implements *basic* alias handling. Ultimately * I'd like shell style substitution, with %1, %2 and all of * those handled correctly to remap badly placed words and * so forth. * <p> * Maybe consider command combinations, too? Or the ability * to put inline \n's somehow... * <p> * Going any *further* than that very basic, simple script * requires java code, of course. */ public class Alias extends Command { public static final AtomicElement[] ELEMENTS = { AtomicElement.construct( Alias.class, String.class, "command", AtomicElement.PUBLIC_FIELD, "the command to be executed by the alias (use %m for user args) (can be pipe seperated)" ) }; public static final AtomicStructure STRUCTURE = new AtomicStructure( Command.STRUCTURE, ELEMENTS ); public static final char messageCode = 'm'; public String command = ""; public Alias() { setKey( "alias" ); usage = ""; } public AtomicStructure getDeclaredStructure() { return( STRUCTURE ); } public String getWhichId() { return( getId() + " (command alias for '" + command + "')" ); } public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException { if( command == null || command.length() == 0 ) { ic.sendError( "This alias is incorrectly set up" ); return; } if( args.hasMoreTokens() ) p.putCode( messageCode, args.nextToken( "" ) ); else p.putCode( messageCode, "" ); StringTokenizer st = new StringTokenizer( command, "|" ); while( st.hasMoreTokens() ) p.command( Grammar.substitute( st.nextToken(), p.getCodes() ), ic, false ); } }