mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
ScriptSheduler improvments
- Add triggerOnInterval feature (every X seconds) - Fix triggerOnTime triggering scripts only one time - Update sample task list file
This commit is contained in:
parent
47a3cdc783
commit
5cace4e7ff
2 changed files with 39 additions and 7 deletions
|
|
@ -18,8 +18,11 @@ namespace MinecraftClient.ChatBots
|
|||
public bool triggerOnFirstLogin = false;
|
||||
public bool triggerOnLogin = false;
|
||||
public bool triggerOnTime = false;
|
||||
public bool triggerOnInterval = false;
|
||||
public int triggerOnInterval_Interval = 0;
|
||||
public int triggerOnInterval_Interval_Countdown = 0;
|
||||
public List<DateTime> triggerOnTime_Times = new List<DateTime>();
|
||||
public bool alreadyTriggered = false;
|
||||
public bool triggerOnTime_alreadyTriggered = false;
|
||||
}
|
||||
|
||||
private static bool firstlogin_done = false;
|
||||
|
|
@ -69,8 +72,9 @@ namespace MinecraftClient.ChatBots
|
|||
case "triggeronfirstlogin": current_task.triggerOnFirstLogin = Settings.str2bool(argValue); break;
|
||||
case "triggeronlogin": current_task.triggerOnLogin = Settings.str2bool(argValue); break;
|
||||
case "triggerontime": current_task.triggerOnTime = Settings.str2bool(argValue); break;
|
||||
case "timevalue": try { current_task.triggerOnTime_Times.Add(DateTime.ParseExact(argValue, "HH:mm", CultureInfo.InvariantCulture)); }
|
||||
catch { } break;
|
||||
case "triggeroninterval": current_task.triggerOnInterval = Settings.str2bool(argValue); break;
|
||||
case "timevalue": try { current_task.triggerOnTime_Times.Add(DateTime.ParseExact(argValue, "HH:mm", CultureInfo.InvariantCulture)); } catch { } break;
|
||||
case "timeinterval": int interval = 1; int.TryParse(argValue, out interval); current_task.triggerOnInterval_Interval = interval; break;
|
||||
case "script": current_task.script_file = argValue; break;
|
||||
}
|
||||
}
|
||||
|
|
@ -92,8 +96,11 @@ namespace MinecraftClient.ChatBots
|
|||
{
|
||||
//Check if we built a valid task before adding it
|
||||
if (current_task.script_file != null && Script.lookForScript(ref current_task.script_file) //Check if file exists
|
||||
&& (current_task.triggerOnLogin || (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))) //Look for a valid trigger
|
||||
&& (current_task.triggerOnLogin
|
||||
|| (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))
|
||||
|| (current_task.triggerOnInterval && current_task.triggerOnInterval_Interval > 0)) //Look for a valid trigger
|
||||
{
|
||||
current_task.triggerOnInterval_Interval_Countdown = current_task.triggerOnInterval_Interval; //Init countdown for interval
|
||||
tasks.Add(current_task);
|
||||
}
|
||||
}
|
||||
|
|
@ -110,19 +117,34 @@ namespace MinecraftClient.ChatBots
|
|||
{
|
||||
if (task.triggerOnTime)
|
||||
{
|
||||
bool matching_time_found = false;
|
||||
|
||||
foreach (DateTime time in task.triggerOnTime_Times)
|
||||
{
|
||||
if (time.Hour == DateTime.Now.Hour && time.Minute == DateTime.Now.Minute)
|
||||
{
|
||||
if (!task.alreadyTriggered)
|
||||
matching_time_found = true;
|
||||
if (!task.triggerOnTime_alreadyTriggered)
|
||||
{
|
||||
task.alreadyTriggered = true;
|
||||
task.triggerOnTime_alreadyTriggered = true;
|
||||
RunScript(task.script_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!matching_time_found)
|
||||
task.triggerOnTime_alreadyTriggered = false;
|
||||
}
|
||||
|
||||
if (task.triggerOnInterval)
|
||||
{
|
||||
if (task.triggerOnInterval_Interval_Countdown == 0)
|
||||
{
|
||||
task.triggerOnInterval_Interval_Countdown = task.triggerOnInterval_Interval;
|
||||
RunScript(task.script_file);
|
||||
}
|
||||
else task.triggerOnInterval_Interval_Countdown--;
|
||||
}
|
||||
else task.alreadyTriggered = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@
|
|||
triggerOnFirstLogin=false
|
||||
triggerOnLogin=false
|
||||
triggerOnTime=true
|
||||
triggerOnInterval=false
|
||||
timeValue=19:30
|
||||
timeValue=08:10
|
||||
timeInterval=0
|
||||
script=event.txt
|
||||
|
||||
# Another minimal example: some properties may be omitted
|
||||
|
|
@ -30,5 +32,13 @@ triggerOnTime=true
|
|||
timeValue=00:00
|
||||
script=midnight.txt
|
||||
|
||||
# Example of task occuring every 30 seconds
|
||||
# Could be used for making a custom antiAFK procedure
|
||||
|
||||
[Task]
|
||||
triggerOnInterval=true
|
||||
timeInterval=30
|
||||
script=advanced-anti-afk.txt
|
||||
|
||||
# Enjoy!
|
||||
# - ORelio
|
||||
Loading…
Add table
Add a link
Reference in a new issue