fCraft.CommandDescriptor.Call C# (CSharp) Method

Call() public method

Calls this command.
public Call ( [ player, [ cmd, bool raiseEvent ) : bool
player [ Player who called the command.
cmd [ Command arguments.
raiseEvent bool Whether CommandCalling and CommandCalled events should be raised.
return bool
        public bool Call( [NotNull] Player player, [NotNull] Command cmd, bool raiseEvent )
        {
            if ( player == null )
                throw new ArgumentNullException( "player" );
            if ( cmd == null )
                throw new ArgumentNullException( "cmd" );
            if ( raiseEvent && CommandManager.RaiseCommandCallingEvent( cmd, this, player ) )
                return false;
            Handler( player, cmd );
            if ( raiseEvent )
                CommandManager.RaiseCommandCalledEvent( cmd, this, player );
            return true;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary> Parses and calls a specified command. </summary>
        /// <param name="player"> Player who issued the command. </param>
        /// <param name="cmd"> Command to be parsed and executed. </param>
        /// <param name="fromConsole"> Whether this command is being called from a non-player (e.g. Console). </param>
        /// <returns> True if the command was called, false if something prevented it from being called. </returns>
        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 = cmd.Descriptor;

            if (descriptor == null)
            {
                player.Message("Unknown command \"{0}\". See &H/Commands", cmd.Name);
                Logger.Log(LogType.UserCommand, "{0}: /{1}", player.Name, 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);
        }
All Usage Examples Of fCraft.CommandDescriptor::Call