fCraft.CommandDescriptor.CanBeCalledBy C# (CSharp) Метод

CanBeCalledBy() публичный Метод

Checks whether this command may be called by players of a given rank.
public CanBeCalledBy ( [ rank ) : bool
rank [
Результат bool
        public bool CanBeCalledBy( [NotNull] Rank rank )
        {
            if ( rank == null )
                throw new ArgumentNullException( "rank" );
            return Permissions == null ||
                   Permissions.All( rank.Can ) ||
                   AnyPermission && Permissions.Any( rank.Can );
        }

Usage Example

Пример #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 = 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);
        }
All Usage Examples Of fCraft.CommandDescriptor::CanBeCalledBy