namespace Aeshnidae.Codex; public static class Commands { [CommandHandler("codex", AccessLevel.Player, CommandHandlerFlag.RequiresWorld, -1, "Open your Aelrynth Codex - the book of everything the server knows about your character.", "/codex open it\n" + "/codex
open it at that section, e.g. /codex bank\n" + "/codex sections what is in it right now")] public static void HandleCodex(Session session, params string[] parameters) { var player = session.Player; if (player is null) return; if (parameters.Length > 0 && parameters[0].Equals("sections", StringComparison.OrdinalIgnoreCase)) { var sb = new StringBuilder($"{Mod.Name} sections, in order:\n"); foreach (var (mod, status) in Providers.Status()) sb.AppendLine($" {mod}: {status}"); Reply(session, sb.ToString().TrimEnd()); return; } var section = parameters.Length > 0 ? string.Join(" ", parameters) : null; try { Codex.Open(player, section); } catch (Exception ex) { ModManager.Log($"[{Mod.Name}] /codex failed for {player.Name}: {ex}", ModManager.LogLevel.Error); Reply(session, "The Codex would not open. Try the book in your pack."); } } [CommandHandler("codex-reload", AccessLevel.Admin, CommandHandlerFlag.None, 0, "Restart the Aeshnidae.Codex mod, re-reading Settings.json.", "/codex-reload")] public static void HandleReload(Session session, params string[] parameters) { var container = Mod.Container; if (container is null) { Reply(session, $"{Mod.Name} is not loaded."); return; } container.Restart(); Reply(session, $"{Mod.Name} restarted."); } /// /// The client renders an embedded newline as a music note, so a multi-line /// message has to go out as one SendMessage per line. /// private static void Reply(Session? session, string message) { if (session?.Player is null) { ModManager.Log(message); return; } foreach (var line in (message ?? "").Split('\n')) { var text = line.TrimEnd('\r'); if (!string.IsNullOrWhiteSpace(text)) session.Player.SendMessage(text); } } }