.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package net.t2code.automatedMessages.messages;
|
||||
|
||||
import net.t2code.automatedMessages.config.FileBuild;
|
||||
import net.t2code.automatedMessages.objects.Message;
|
||||
import net.t2code.automatedMessages.system.Main;
|
||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||
import org.quartz.*;
|
||||
import org.quartz.impl.StdSchedulerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Management {
|
||||
|
||||
private static List<Scheduler> jobList = new ArrayList<>();
|
||||
|
||||
public static HashMap<JobDetail, Scheduler> hashMap = new HashMap<>();
|
||||
|
||||
private static final List<Timer> timerJobList = new ArrayList<>();
|
||||
|
||||
public static void start() {
|
||||
for (Map.Entry<String, Message> value : FileBuild.getMessageHashMap().entrySet()) {
|
||||
Message message = value.getValue();
|
||||
if (!message.enable) continue;
|
||||
if (message.cronJob) {
|
||||
startCronJob(message);
|
||||
|
||||
|
||||
} else {
|
||||
Timer job = new Timer(message);
|
||||
timerJobList.add(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void startCronJob(Message message) {
|
||||
try {
|
||||
CronJob cronJob = new CronJob(message);
|
||||
JobDetail job = JobBuilder.newJob(cronJob.getClass())
|
||||
.withIdentity(message.key, message.key).build();
|
||||
Trigger trigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(message.key, message.key)
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule(message.cronJobString))
|
||||
//.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
|
||||
.build();
|
||||
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
|
||||
scheduler.start();
|
||||
scheduler.scheduleJob(job, trigger);
|
||||
jobList.add(scheduler);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void end() {
|
||||
for (Timer job : timerJobList) {
|
||||
job.disable = true;
|
||||
}
|
||||
for (Scheduler scheduler : jobList) {
|
||||
try {
|
||||
scheduler.shutdown();
|
||||
} catch (SchedulerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user