/**
* This source file is part of WZ Hybrid Bots
* For the latest information, see http://sourceforge.net/projects/wzhybridbots
*
* Copyright (c) 2006 - WzCtf
* For more information about WzCtf, see http://www.wzctf.net
* Also see the license in license.txt
*/
package plugins.LagCheck.tools.command;
/** The imported classes/interfaces */
import hybrid.core.consts.MessageTypes;
import frontend.alphaspawn.ASConnection;
import frontend.alphaspawn.Player;
import frontend.alphaspawn.tools.arena.ASArena;
import frontend.alphaspawn.tools.command.Command;
import wzhybridbots.tools.actions.ActionTarget;
import wzhybridbots.tools.actions.ServerCommands;
import wzhybridbots.tools.actions.TargetPlayer;
/**
* Lag command used to check a player's lagging statistics.
*
* @author Witlospock
* @version 1.0
*/
public class Lag extends Command {
/** A connection object used to track and handle commands */
protected ASConnection objConnection = null;
/** A server commands object used to call server commands */
protected ServerCommands objServerCommands = null;
/**
* The class constructor. Initialize the command object.
*
* @param conn A fully functionnal connection object.
* @param cmds An object that calls server commands.
*/
public Lag ( ASConnection conn, ServerCommands cmds ) {
// Initialize the class
super( "!lag <playerName>", "Checks the lagging statistics of a player" );
// Checks for valid parameters
if ( conn == null ) { throw new NullPointerException(); }
if ( cmds == null ) { throw new NullPointerException(); }
// Sets the fields
this.objConnection = conn;
this.objServerCommands = cmds;
}
/**
* Returns true if the player has sufficient access level,
* false otherwise.
*
* @param playerName The name of the player to check access.
*
* @return see above.
*/
public boolean checkAccess ( String playerName ) {
// No Access level required to call this command
return true;
}
/**
* Returns a bit field representing the command type this command can be fired from.
*
* @return see above.
*/
public int getMessageTypes () {
return (1 << MessageTypes.Private) | (1 << MessageTypes.Public);
}
/**
* Called when a player with the proper access level execute a command
* that belongs to this Command object.
*
* @param playerName The name of the player executing the command.
* @param command The command to be execute.
* @param args Additionnal arguments beside the command .
*/
public void handleCommand( String playerName, String command, String args ) {
boolean hasArgs = (args != null && args.trim().length() > 0);
// Checks if the player has specified a player name next to the command
if ( !hasArgs ) { return; }
// The player has specified a player name
ASArena arena = ASArena.getInstance();
Player player = arena.getFuzzyPlayer( args );
if ( player == null ) {
// The player was not found
// Display a message to the player requesting a lag check
this.objConnection.sendPrivateMessage( playerName, "Unable to reconize a player that sounds like '" + args + "'." );
return;
}
// Set the target of the action taken
ActionTarget target = new TargetPlayer( player.getName() );
// Calls the server command that checks for lagging stats
this.objServerCommands.checkLag( this.objConnection, target );
}
/**
* Called when a player with insufficient permission want to execute
* a command that belongs to this Command object.
*
* @param playerName The name of the player executing the command.
* @param command The command to be execute.
* @param args Additionnal arguments beside the command.
*/
public void ignoreCommand( String playerName, String command, String args ) {
}
}