Changing custom chat tokens and bad words list in GUI should update live server state immediately.

This commit is contained in:
UnknownShadow200 2017-07-26 11:58:50 +10:00
parent 57d34b9c68
commit 9cb259fd32
3 changed files with 16 additions and 0 deletions

View File

@ -104,11 +104,17 @@ namespace MCGalaxy {
};
public static List<ChatToken> Custom = new List<ChatToken>();
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) {

View File

@ -27,6 +27,7 @@ namespace MCGalaxy {
public static class ProfanityFilter {
static string[] reduceKeys, reduceValues;
static List<string> 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<string>();

View File

@ -30,6 +30,9 @@ namespace MCGalaxy.Util {
/// <summary> Default text that the file contains. </summary>
public readonly string[] DefaultText;
/// <summary> Callback invoked when contents of this file are changed. </summary>
public Action OnTextChanged;
public TextFile(string filename, params string[] defaultText) {
Filename = filename;
DefaultText = defaultText;
@ -59,6 +62,7 @@ namespace MCGalaxy.Util {
/// <summary> Updates the text in this text file. </summary>
public void SetText(string[] text) {
File.WriteAllLines(Filename, text);
if (OnTextChanged != null) OnTextChanged();
}