/// <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); }
/// <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); } }