fCraft.CommandManager.ParseCommand C# (CSharp) Method

ParseCommand() public static method

Parses and calls a specified command.
public static ParseCommand ( [ player, [ cmd, bool fromConsole ) : bool
player [ Player who issued the command.
cmd [ Command to be parsed and executed.
fromConsole bool Whether this command is being called from a non-player (e.g. Console).
return bool
        public static bool ParseCommand( [NotNull] Player player, [NotNull] Command cmd, bool fromConsole )
        {
            if ( player == null )
                throw new ArgumentNullException( "player" );
            if ( cmd == null )
                throw new ArgumentNullException( "cmd" );
            CommandDescriptor descriptor = GetDescriptor( cmd.Name, true );

            if ( descriptor == null ) {
                player.Message( "Unknown command \"{0}\". See &H/Commands", cmd.Name );
                return false;
            }

            if ( !descriptor.IsConsoleSafe && fromConsole ) {
                player.Message( "You cannot use this command from console." );
            } else {
                if ( descriptor.Permissions != null ) {
                    if ( !descriptor.CanBeCalledBy( player.Info.Rank ) ) {
                        player.MessageNoAccess( descriptor );
                    } else if ( !descriptor.Call( player, cmd, true ) ) {
                        player.Message( "Command was cancelled." );
                    } else {
                        return true;
                    }
                } else {
                    if ( descriptor.Call( player, cmd, true ) ) {
                        return true;
                    } else {
                        player.Message( "Command was cancelled." );
                    }
                }
            }
            return false;
        }

Usage Example

Example #1
0
        static void ConfirmCommandCallback([NotNull] Player player, [NotNull] object tag, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }
            CommandReader cmd = (CommandReader)tag;

            cmd.Rewind();
            cmd.IsConfirmed = true;
            CommandManager.ParseCommand(player, cmd, fromConsole);
        }
All Usage Examples Of fCraft.CommandManager::ParseCommand