mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
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
This commit is contained in:
parent
afff1ef89e
commit
baaf37f28b
1 changed files with 24 additions and 5 deletions
|
|
@ -875,14 +875,33 @@ namespace MinecraftClient
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
// Loads the given file from the startup parameters
|
//Load the given file from the startup parameters
|
||||||
if (System.IO.File.Exists(file))
|
//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
|
UnloadBot(); //No need to keep the bot active
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue