private void CMDgetnews(CommandArgs args) { try { int page = 1; if (args.Parameters.Count > 0) { int.TryParse(args.Parameters[0], out page); } page--; string path = Path.Combine(SavePath, getConfig.news_file); TSUtils.CheckFile(path); var NewsFile = File.ReadAllLines(path); Dictionary <string, Color> messages = new Dictionary <string, Color>(); foreach (var n in NewsFile) { messages.Add(n, Color.SeaGreen); } var header = TSUtils.GetPaginationHeader("Get News", "/gnews", page + 1, (messages.Count / 6) + 1); TSUtils.Paginate(header, messages, page, args.Player); } catch (Exception ex) { args.Player.SendErrorMessage("An error occoured while reading the news file! Check the logs.", Color.IndianRed); TShock.Log.Error("[TSDocs] error while reading the news file: \n" + ex.ToString()); } }
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()); } }