当前位置: 首页>>代码示例>>C#>>正文


C# ISender.GetAvailableCommands方法代码示例

本文整理汇总了C#中ISender.GetAvailableCommands方法的典型用法代码示例。如果您正苦于以下问题:C# ISender.GetAvailableCommands方法的具体用法?C# ISender.GetAvailableCommands怎么用?C# ISender.GetAvailableCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISender的用法示例。


在下文中一共展示了ISender.GetAvailableCommands方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowHelp

        /// <summary>
        /// Shows the help.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        public static void ShowHelp(ISender sender, ArgumentList args)
        {
            var commands = sender.GetAvailableCommands();
            if (commands != null && commands.Count > 0)
            {
                int page = 0;
                if (!args.TryGetInt(0, out page))
                {
                    if (args.Count > 0)
                    {
                        var command = args.GetString(0);
                        if (commands.ContainsKey(command))
                        {
                            sender.SendMessage(commands[command].description);
                            commands[command].ShowHelp(sender, true);
                            return;
                        }
                        else
                            throw new CommandError("No such command: " + command);
                    }
                }
                else
                    page--;

                //				const Int32 MaxLines = 5;
                var maxLines = sender is Player ? 5 : 15;
                var lineOffset = page * maxLines;
                var maxPages = (int)Math.Ceiling(commands.Count / (double)maxLines);

                if (page >= 0 && page < maxPages)
                {
                    var cmds = new List<CommandInfo>();
                    var sorted = commands
                        .OrderBy(x => x.Key.ToLower())
                        .Select(x => x.Value)
                        .ToArray();
                    for (var i = lineOffset; i < lineOffset + maxLines; i++)
                    {
                        if (i < sorted.Length)
                            cmds.Add(sorted[i]);
                    }

                    var prefixMax = cmds
                        .Select(x => x.Prefix.Length)
                        .OrderByDescending(x => x)
                        .First();
                    foreach (var cmd in cmds)
                        cmd.ShowDescription(sender, prefixMax);

                    sender.SendMessage(String.Format("[Page {0} / {1}]", page + 1, maxPages));
                }
                else
                {
                    sender.SendMessage("Usage:");
                    sender.SendMessage("    help <command> - Get help for a command.");
                    sender.SendMessage("    help <page> - View a list of commands. Valid page numbers are 1 to " + maxPages + ".");
                    sender.SendMessage("Examples:");
                    sender.SendMessage("    help oplogin");
                    sender.SendMessage("    help 1");
                }
            }
            else
                sender.SendMessage("You have no available commands.");
        }
开发者ID:claudiofreda,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:69,代码来源:DefaultCommands.cs


注:本文中的ISender.GetAvailableCommands方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。