From baaf37f28b1cc1dc4f89267aae983e4a42a2d4f6 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 12 Jan 2014 13:41:40 +0100 Subject: [PATCH] Scripting bot : automatically find script file - Automatically look for script file in config/ and scripts/ folders - Automacically try to add '.txt' extension to the script filename - Eg "/script testscript" properly loads "config/testscript.txt" script --- MinecraftClient/Bots.cs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index ca3b34c7..d78a88d8 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -875,14 +875,33 @@ namespace MinecraftClient public override void Initialize() { - // Loads the given file from the startup parameters - if (System.IO.File.Exists(file)) + //Load the given file from the startup parameters + //Automatically look in subfolders and try to add ".txt" file extension + string[] files = new string[] { - lines = System.IO.File.ReadAllLines(file); // Load the given bot text file (containing commands) + file, + file + ".txt", + "scripts\\" + file, + "scripts\\" + file + ".txt", + "config\\" + file, + "config\\" + file + ".txt", + }; + + bool file_found = false; + + foreach (string possible_file in files) + { + if (System.IO.File.Exists(possible_file)) + { + lines = System.IO.File.ReadAllLines(possible_file); + file_found = true; + break; + } } - else + + if (!file_found) { - LogToConsole("File not found: " + file); + LogToConsole("File not found: '" + file + "'"); UnloadBot(); //No need to keep the bot active } }