/* ** j###t ########## #### #### ** j###t ########## #### #### ** j###T "###L J###" ** ######P' ########## ######### ** ######k, ########## T######T ** ####~###L #### ** #### q###L ########## .##### ** #### \###L ########## #####" ** ** Class History ** ** Date Name Description ** ---------|------------|----------------------------------------------- ** 09Jul97 merlin created this command ** 24Aug98 subtle converted to new element system ** */ package key.commands; import key.*; import key.primitive.*; import java.io.*; import java.util.StringTokenizer; /** * This command is intended to change the players context to * the site specified in the argument */ public class BanType extends Command { public static final AtomicElement[] ELEMENTS = { AtomicElement.construct( BanType.class, String.class, "banType", AtomicElement.PUBLIC_FIELD, "the type this ban" ) }; public static final AtomicStructure STRUCTURE = new AtomicStructure( Command.STRUCTURE, ELEMENTS ); public String banType = ""; public BanType() { setKey( "bantype" ); usage = "<duration> <reason>"; } public AtomicStructure getDeclaredStructure() { return( STRUCTURE ); } private boolean isNewbieCommand() { return( banType.equals( "N" ) ); } private boolean isSiteCommand() { return( banType.equals( "C" ) ); } public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException { // Make sure our context is a site if( !( p.getContext() instanceof Site ) ) { ic.sendFeedback( "This command can not be run unless a site is being referenced" ); return; } // have we got a duration if( !args.hasMoreTokens() ) { usage( ic ); return; } Duration banDuration = null; String duration = args.nextToken(); //get the reason why the site was banned if( !args.hasMoreTokens() ) { usage( ic ); return; } String banReason = new String( args.nextToken( "" ) ); try { banDuration = new Duration( Duration.parse( duration ) ); } catch( NumberFormatException n ) { ic.sendFeedback( "How about setting a valid duration" ); return; } Site site = (Site) p.getContext(); String siteBanType = site.banType; if( banType.equals( siteBanType ) ) { // the ban for the site is being extended ic.sendFeedback( "Amending " + (site.newbiesAllowed()?"newbie":"site") + " ban on site " + (String)p.getContext().toString() ); } else if( isNewbieCommand() && !site.connectionsAllowed() ) { ic.sendFeedback( "Site " + (String)p.getContext().toString() + " wassite banned - making newbie banned" ); } else if( siteBanType.length() > 0 && isSiteCommand() && !site.newbiesAllowed() ) { ic.sendFeedback( "Upgrading site " + (String) p.getContext().toString() + " to complete site ban" ); } else if( isSiteCommand() ) { // Complete Siteban in Place ic.sendFeedback( "Complete ban added for site" + (String)p.getContext().toString()); } else if( isNewbieCommand() ) { // Newbie Ban in Place ic.sendFeedback( "Newbie ban added for site " + (String)p.getContext().toString() ); } DateTime dateNow = new DateTime(); site.setBan( new String( banType ), p, dateNow, new DateTime( dateNow.getTime() + banDuration.getTime() ), new String( banReason.toString() ) ); } }