/* ** j###t ########## #### #### ** j###t ########## #### #### ** j###T "###L J###" ** ######P' ########## ######### ** ######k, ########## T######T ** ####~###L #### ** #### q###L ########## .##### ** #### \###L ########## #####" */ package key.commands; import key.*; import key.primitive.*; import java.io.IOException; import java.util.StringTokenizer; import java.util.Enumeration; public class Finger extends Command { private static final long serialVersionUID = 511480019705872281L; public Finger() { setKey( "finger" ); usage = "<player>"; } public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException { String targetPlayer; if( args.hasMoreTokens() ) { targetPlayer = args.nextToken( " " ); Object o; //Container c = (Container) Key.shortcuts(); o = getElementInside( ic, targetPlayer, Key.shortcuts() ); if( o == null ) return; if( o instanceof Player ) { Player a = (Player) o; a.sendFingerScreen( ic ); } else if( o instanceof Container && ((Container)o).getConstraint() == Type.PLAYER ) { Container c = (Container) o; if( c.count() == 0 ) { // output an appropriate message if( c instanceof Friends ) ic.sendFailure( "You have no friends." ); else ic.sendFailure( "There is no-one in " + c.getName() ); } // this is a group of some sort containing players, we can // finger each one of them, quickly. for( Enumeration e = c.elements(); e.hasMoreElements(); ) sendLastLogin( (Player) e.nextElement(), ic, p ); } else ic.send( "'" + targetPlayer + "' is not something that is fingerable." ); } else usage( ic ); } public static void sendLastLogin( Player f, InteractiveConnection ic, Player p ) { TimeStatistics loginStats = f.loginStats; if( f.connected() ) { ic.send( f.getName() + " has been logged in for " + loginStats.getTimeSinceConnection() ); } else { DateTime dateTime = (DateTime) loginStats.getLastConnection(); if( dateTime == null ) ic.send( f.getName() + " has never logged in." ); else ic.send( f.getName() + " was last seen at " + dateTime.toString( p ) ); } } }