using StardewValley; using StardewValley.Menus; namespace StardewModdingAPI.Framework { /// SMAPI's implementation of the chatbox which intercepts errors for logging. internal class SChatBox : ChatBox { /********* ** Fields *********/ /// Encapsulates monitoring and logging. private readonly IMonitor Monitor; /********* ** Public methods *********/ /// Construct an instance. /// Encapsulates monitoring and logging. public SChatBox(IMonitor monitor) { this.Monitor = monitor; } /// protected override void runCommand(string command) { this.Monitor.Log($"> chat command: {command}"); base.runCommand(command); } /// public override void receiveChatMessage(long sourceFarmer, int chatKind, LocalizedContentManager.LanguageCode language, string message) { if (chatKind == ChatBox.errorMessage) { // log error this.Monitor.Log(message, LogLevel.Error); // add event details if applicable if (Game1.CurrentEvent != null && message.StartsWith("Event script error:")) this.Monitor.Log($"In event #{Game1.CurrentEvent.id} for location {Game1.currentLocation?.NameOrUniqueName}", LogLevel.Error); } base.receiveChatMessage(sourceFarmer, chatKind, language, message); } } }