private static void Print <T>(IMonitor monitor, ICollection <T> values, string singular, string plural, Func <T, string> getId, Func <T, string> getName, Func <T, string, string> getAttr, string[] what) { int total = values.Count; string message = $"{total} {(total == 1 ? singular : plural)}"; CAS.AddChatMessage(message); monitor.Log($"{message}{(total == 0 ? "." : ":")}", LogLevel.Info); if (total != 0) { // Display column names string columns = String.Join(" ", what.Select(_ => _.ToUpper())); monitor.Log($"- ID: NAME {columns}", LogLevel.Info); // Display entries foreach (var value in values) { string attributes = String.Join(" ", what.Select(_ => getAttr(value, _.ToLower())).Where(_ => _.Length != 0)); monitor.Log($"- {getId(value)}: {getName(value)} {attributes}", LogLevel.Info); } } }
private static bool OnChatParseCommandPrefix(string sMessage, int iConnection) { // Maybe a transpiler could do the job better, but I'm not familliar enough with the technique // Consider this a TODO try { // Original code int iIndex = sMessage.IndexOf(' '); bool bNoSecondPart = iIndex == -1; if (iIndex == -1) { iIndex = sMessage.Length; } string sFirst = sMessage.Substring(0, iIndex); sMessage = sMessage.Substring(sMessage.IndexOf(' ') + 1); if (bNoSecondPart) { sMessage = ""; } sFirst.ToLowerInvariant(); // End bool vanillaExecution = true; foreach (var onChatParseCommandCallback in _onChatParseCommandCallbacks) { // If a mod callback returns false, the original function will not run // This means that vanilla commands won't run in tandem with mod commands for "false" return // Multiple mod commands with the same name will still run though... vanillaExecution &= onChatParseCommandCallback(sFirst, sMessage, iConnection); } return(vanillaExecution); } catch (Exception e) { CAS.AddChatMessage("GrindScript: " + e.Message); } return(true); }