Exemple #1
0
        public static void ShowFile(TSCommand command, string chat, TSPlayer player)
        {
            try
            {
                String filetoshow = Path.Combine(SavePath, command.file);
                foreach (var group in command.groups)
                {
                    if (group.Key == player.Group.Name)
                    {
                        filetoshow = Path.Combine(SavePath, group.Value);
                    }
                }

                Dictionary <string, Color> displayLines = new Dictionary <string, Color>();

                TSUtils.CheckFile(filetoshow);

                var file = File.ReadAllLines(filetoshow);

                var messages = TSUtils.ReplaceVariables(file, player);

                int page = 0;
                if (chat.Contains(" "))
                {
                    var data = chat.Split(' ');
                    if (int.TryParse(data[1], out page))
                    {
                        page--;
                    }
                    else
                    {
                        player.SendErrorMessage(string.Format("Invalid page number ({0})", data[1]), Color.Red);
                    }
                }

                TSUtils.Paginate(TSUtils.GetPaginationHeader(command.name, command.command, page + 1, (messages.Count / 6) + 1),
                                 messages, page, player);
            }
            catch (Exception ex)
            {
                TShock.Log.ConsoleError("Something when wrong when showing {0} \"{1}\". Check the Logs.".SFormat(player.Name, command.command));
                TShock.Log.Error(ex.ToString());
            }
        }
Exemple #2
0
        public static void ShowFile(TSCommand command, string chat, TSPlayer player)
        {
            try
            {
                String filetoshow = Path.Combine(SavePath, command.file);
                foreach (var group in command.groups)
                {
                    if (group.Key == player.Group.Name)
                    {
                        filetoshow = Path.Combine(SavePath, group.Value);
                    }
                }

                Dictionary<string, Color> displayLines = new Dictionary<string, Color>();

                TSUtils.CheckFile(filetoshow);

                var file = File.ReadAllLines(filetoshow);

                var messages = TSUtils.ReplaceVariables(file, player);

                int page = 0;
                if (chat.Contains(" "))
                {
                    var data = chat.Split(' ');
                    if (int.TryParse(data[1], out page))
                        page--;
                    else
                        player.SendMessage(string.Format("Invalid page number ({0})", data[1]), Color.Red);
                }

                TSUtils.Paginate(TSUtils.GetPaginationHeader(command.name, command.command, page + 1, (messages.Count / 6) + 1),
                                 messages, page, player);
            }
            catch (Exception ex)
            {
                Log.ConsoleError("Something when wrong when showing {0} \"{1}\". Check the Logs.".SFormat(player.Name, command.command));
                Log.Error(ex.ToString());
            }
        }