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
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);
        }
Ejemplo n.º 2
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>
        public static void ParseCommand(Player player, Command cmd, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            CommandDescriptor descriptor = GetDescriptor(cmd.Name);

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

            if (!descriptor.IsConsoleSafe && fromConsole)
            {
                player.Message("You cannot use this command from console.");
            }
            else
            {
                if (descriptor.Permissions != null)
                {
                    if (player.Can(descriptor.Permissions))
                    {
                        descriptor.Call(player, cmd, true);
                    }
                    else
                    {
                        player.NoAccessMessage(descriptor.Permissions);
                    }
                }
                else
                {
                    descriptor.Call(player, cmd, true);
                }
            }
        }
Ejemplo n.º 3
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>
        /// <exception cref="ArgumentNullException"> player or cmd is null. </exception>
        public static bool ParseCommand([NotNull] Player player, [NotNull] CommandReader cmd, bool fromConsole)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }
            CommandDescriptor descriptor = cmd.Descriptor;

            if (descriptor == null)
            {
                if (CommandManager.ParseUnknownCommand(player, cmd))
                {
                    return(true);
                }
                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.");
                return(false);
            }

            if (descriptor.Permissions != null)
            {
                if (!descriptor.CanBeCalledBy(player.Info.Rank))
                {
                    player.MessageNoAccess(descriptor);
                    return(false);
                }

                if (descriptor.MinRank != RankManager.LowestRank && !player.Info.ClassicubeVerified)
                {
                    player.Message("As you had an older minecraft.net account, you must have an admin verify your " +
                                   "new classicube.net account actually is you with /verify before you can use non-guest commands.");
                    return(false);
                }
            }

            if (descriptor.Call(player, cmd, true))
            {
                return(true);
            }
            else
            {
                player.Message("Command was cancelled.");
                return(false);
            }
        }