From 9cb259fd3203357481eff7fde122c71aae94b88a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 26 Jul 2017 11:58:50 +1000 Subject: [PATCH] Changing custom chat tokens and bad words list in GUI should update live server state immediately. --- MCGalaxy/Chat/ChatTokens.cs | 6 ++++++ MCGalaxy/Chat/ProfanityFilter.cs | 6 ++++++ MCGalaxy/util/IO/TextFile.cs | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/MCGalaxy/Chat/ChatTokens.cs b/MCGalaxy/Chat/ChatTokens.cs index b0667c0d9..852d1bd99 100644 --- a/MCGalaxy/Chat/ChatTokens.cs +++ b/MCGalaxy/Chat/ChatTokens.cs @@ -104,11 +104,17 @@ namespace MCGalaxy { }; public static List Custom = new List(); + static bool hookedCustom; internal static void LoadCustom() { Custom.Clear(); TextFile tokensFile = TextFile.Files["Custom $s"]; tokensFile.EnsureExists(); + if (!hookedCustom) { + hookedCustom = true; + tokensFile.OnTextChanged += LoadCustom; + } + string[] lines = tokensFile.GetText(); char[] colon = null; foreach (string line in lines) { diff --git a/MCGalaxy/Chat/ProfanityFilter.cs b/MCGalaxy/Chat/ProfanityFilter.cs index ba9e495b4..4191c2e45 100644 --- a/MCGalaxy/Chat/ProfanityFilter.cs +++ b/MCGalaxy/Chat/ProfanityFilter.cs @@ -27,6 +27,7 @@ namespace MCGalaxy { public static class ProfanityFilter { static string[] reduceKeys, reduceValues; static List filters; + static bool hookedFilter; public static void Init() { InitReduceTable(); @@ -69,6 +70,11 @@ namespace MCGalaxy { static void LoadBadWords() { TextFile filterFile = TextFile.Files["Profanity filter"]; filterFile.EnsureExists(); + + if (!hookedFilter) { + hookedFilter = true; + filterFile.OnTextChanged += LoadBadWords; + } string[] lines = filterFile.GetText(); filters = new List(); diff --git a/MCGalaxy/util/IO/TextFile.cs b/MCGalaxy/util/IO/TextFile.cs index 83b83fbc9..824da2ab2 100644 --- a/MCGalaxy/util/IO/TextFile.cs +++ b/MCGalaxy/util/IO/TextFile.cs @@ -30,6 +30,9 @@ namespace MCGalaxy.Util { /// Default text that the file contains. public readonly string[] DefaultText; + /// Callback invoked when contents of this file are changed. + public Action OnTextChanged; + public TextFile(string filename, params string[] defaultText) { Filename = filename; DefaultText = defaultText; @@ -59,6 +62,7 @@ namespace MCGalaxy.Util { /// Updates the text in this text file. public void SetText(string[] text) { File.WriteAllLines(Filename, text); + if (OnTextChanged != null) OnTextChanged(); }