.
This commit is contained in:
parent
d700c73c8c
commit
8f5c9a9479
3
pom.xml
3
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>net.t2code</groupId>
|
<groupId>net.t2code</groupId>
|
||||||
<artifactId>automatedMessages</artifactId>
|
<artifactId>T2C-AutomatedMessages</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
@ -95,6 +95,7 @@
|
|||||||
<groupId>org.quartz-scheduler</groupId>
|
<groupId>org.quartz-scheduler</groupId>
|
||||||
<artifactId>quartz</artifactId>
|
<artifactId>quartz</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.3.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -3,7 +3,7 @@ package net.t2code.automatedMessages.command;
|
|||||||
import net.t2code.automatedMessages.Util;
|
import net.t2code.automatedMessages.Util;
|
||||||
import net.t2code.automatedMessages.config.Config;
|
import net.t2code.automatedMessages.config.Config;
|
||||||
import net.t2code.automatedMessages.config.FileBuild;
|
import net.t2code.automatedMessages.config.FileBuild;
|
||||||
import net.t2code.automatedMessages.messages.timer.TimerManagement;
|
import net.t2code.automatedMessages.messages.Management;
|
||||||
import net.t2code.automatedMessages.system.Main;
|
import net.t2code.automatedMessages.system.Main;
|
||||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
||||||
@ -11,16 +11,18 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class Commands {
|
public class Commands {
|
||||||
public static void reload(CommandSender sender) {
|
public static void reload(CommandSender sender) {
|
||||||
if (!sender.hasPermission("t2c.automatedmessages.admin")) {
|
if (!sender.hasPermission("t2c.automatedmessages.admin")) {
|
||||||
sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<t2c.automatedmessages.admin>");
|
sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7<t2c.automatedmessages.admin>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
T2Csend.console(Config.msgReloadStart.valueString);
|
T2Csend.console(Config.msgReloadStart.valueString);
|
||||||
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadStart.valueString);
|
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadStart.valueString);
|
||||||
TimerManagement.end();
|
Management.end();
|
||||||
FileBuild.selectConfig();
|
|
||||||
TimerManagement.startTimer();
|
FileBuild.selectConfig();
|
||||||
|
|
||||||
|
Management.start();
|
||||||
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadEnd.valueString);
|
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadEnd.valueString);
|
||||||
T2Csend.console(Config.msgReloadEnd.valueString);
|
T2Csend.console(Config.msgReloadEnd.valueString);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import net.t2code.automatedMessages.Util;
|
|||||||
import net.t2code.automatedMessages.objects.Message;
|
import net.t2code.automatedMessages.objects.Message;
|
||||||
import net.t2code.automatedMessages.system.Main;
|
import net.t2code.automatedMessages.system.Main;
|
||||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -49,10 +50,10 @@ public class FileBuild {
|
|||||||
if (!yamlConfiguration.contains(value.msgPath)) {
|
if (!yamlConfiguration.contains(value.msgPath)) {
|
||||||
setExample("exampleDiscord", true,
|
setExample("exampleDiscord", true,
|
||||||
"[prefix] <aqua>If you need help, just contact us on our <color:#ffcb2e><hover:show_text:'<red>dc.t2code.net</red>'><click:open_url:'https://discord.t2code.net'>T2Code Support Discord server</click></hover></color>.</aqua>",
|
"[prefix] <aqua>If you need help, just contact us on our <color:#ffcb2e><hover:show_text:'<red>dc.t2code.net</red>'><click:open_url:'https://discord.t2code.net'>T2Code Support Discord server</click></hover></color>.</aqua>",
|
||||||
20, false, "*/5 * * * *", yamlConfiguration);
|
20, false, "0 0/5 * ? * * *", yamlConfiguration);
|
||||||
setExample("exampleTime", true,
|
setExample("exampleTime", true,
|
||||||
"[prefix] <aqua>Es ist jetzt <yellow>[time]</yellow></aqua>",
|
"[prefix] <aqua>Es ist jetzt <yellow>[time]</yellow></aqua>",
|
||||||
0, true, "*/20 * * * *", yamlConfiguration);
|
0, true, "0 0/20 * ? * * *", yamlConfiguration);
|
||||||
}
|
}
|
||||||
for (String key : yamlConfiguration.getConfigurationSection(value.msgPath).getKeys(false)) {
|
for (String key : yamlConfiguration.getConfigurationSection(value.msgPath).getKeys(false)) {
|
||||||
Boolean enable = yamlConfiguration.getBoolean(value.msgEnablePath.replace("KEY", key));
|
Boolean enable = yamlConfiguration.getBoolean(value.msgEnablePath.replace("KEY", key));
|
||||||
@ -61,6 +62,9 @@ public class FileBuild {
|
|||||||
Boolean cronJob = yamlConfiguration.getBoolean(value.msgCronJobPath.replace("KEY", key));
|
Boolean cronJob = yamlConfiguration.getBoolean(value.msgCronJobPath.replace("KEY", key));
|
||||||
String cronJobString = yamlConfiguration.getString(value.msgCronJobStringPath.replace("KEY", key));
|
String cronJobString = yamlConfiguration.getString(value.msgCronJobStringPath.replace("KEY", key));
|
||||||
Message msg = new Message(key, enable, message, interval, cronJob, cronJobString);
|
Message msg = new Message(key, enable, message, interval, cronJob, cronJobString);
|
||||||
|
T2Csend.debugmsg(Main.getPlugin(),key);
|
||||||
|
T2Csend.debugmsg(Main.getPlugin(), String.valueOf(cronJob));
|
||||||
|
T2Csend.debugmsg(Main.getPlugin(),cronJobString);
|
||||||
messageHashMap.put(key, msg);
|
messageHashMap.put(key, msg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package net.t2code.automatedMessages.messages;
|
||||||
|
|
||||||
|
import net.t2code.automatedMessages.objects.Message;
|
||||||
|
import org.quartz.Job;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobExecutionException;
|
||||||
|
|
||||||
|
public class CronJob implements Job {
|
||||||
|
public Message message;
|
||||||
|
|
||||||
|
public CronJob(Message message) {
|
||||||
|
this.message=message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||||
|
SendMessage.send(message.message);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package net.t2code.automatedMessages.messages;
|
||||||
|
|
||||||
|
import net.t2code.automatedMessages.messages.SendMessage;
|
||||||
|
import net.t2code.automatedMessages.objects.Message;
|
||||||
|
import net.t2code.automatedMessages.system.Main;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class Timer {
|
||||||
|
|
||||||
|
public Timer(Message message) {
|
||||||
|
Bukkit.getScheduler().scheduleAsyncRepeatingTask(Main.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (disable) return;
|
||||||
|
SendMessage.send(message.message);
|
||||||
|
}
|
||||||
|
}, 0, 20L * 60 * message.interval);
|
||||||
|
}
|
||||||
|
public Boolean disable = false;
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
package net.t2code.automatedMessages.messages.cron;
|
|
||||||
|
|
||||||
import org.quartz.Job;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
import org.quartz.JobExecutionException;
|
|
||||||
|
|
||||||
public class CronJob implements Job {
|
|
||||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package net.t2code.automatedMessages.messages.cron;
|
|
||||||
|
|
||||||
import org.quartz.CronScheduleBuilder;
|
|
||||||
import org.quartz.JobBuilder;
|
|
||||||
import org.quartz.JobDetail;
|
|
||||||
import org.quartz.Scheduler;
|
|
||||||
import org.quartz.Trigger;
|
|
||||||
import org.quartz.TriggerBuilder;
|
|
||||||
import org.quartz.impl.StdSchedulerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CronJobManagement {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package net.t2code.automatedMessages.messages.timer;
|
|
||||||
|
|
||||||
import net.t2code.automatedMessages.config.FileBuild;
|
|
||||||
import net.t2code.automatedMessages.messages.cron.CronJob;
|
|
||||||
import net.t2code.automatedMessages.objects.Message;
|
|
||||||
import org.quartz.*;
|
|
||||||
import org.quartz.impl.StdSchedulerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TimerManagement {
|
|
||||||
|
|
||||||
private static List<Scheduler> jobList = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void startTimer() {
|
|
||||||
for (Map.Entry<String, Message> value : FileBuild.getMessageHashMap().entrySet()) {
|
|
||||||
Message message = value.getValue();
|
|
||||||
if (!message.enable) continue;
|
|
||||||
try {
|
|
||||||
JobDetail job = JobBuilder.newJob(CronJob.class)
|
|
||||||
.withIdentity("job-" + message.key, "group-" + message.key).build();
|
|
||||||
Trigger trigger = TriggerBuilder.newTrigger()
|
|
||||||
.withIdentity("cronTrigger-" + message.key, "group-" + message.key)
|
|
||||||
.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 (Scheduler scheduler : jobList) {
|
|
||||||
try {
|
|
||||||
scheduler.shutdown();
|
|
||||||
} catch (SchedulerException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,5 +22,6 @@ public class Message {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
this.interval = interval;
|
this.interval = interval;
|
||||||
this.cronJob = cronJob;
|
this.cronJob = cronJob;
|
||||||
|
this.cronJobString=cronJobString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import net.t2code.automatedMessages.Util;
|
|||||||
import net.t2code.automatedMessages.command.CmdExecuter;
|
import net.t2code.automatedMessages.command.CmdExecuter;
|
||||||
import net.t2code.automatedMessages.config.Config;
|
import net.t2code.automatedMessages.config.Config;
|
||||||
import net.t2code.automatedMessages.config.FileBuild;
|
import net.t2code.automatedMessages.config.FileBuild;
|
||||||
import net.t2code.automatedMessages.messages.timer.TimerManagement;
|
import net.t2code.automatedMessages.messages.Management;
|
||||||
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
||||||
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
||||||
|
|
||||||
@ -14,8 +14,10 @@ public class Load {
|
|||||||
public static void onLoad(Main plugin, List<String> autor, String version) {
|
public static void onLoad(Main plugin, List<String> autor, String version) {
|
||||||
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||||
plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter());
|
plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter());
|
||||||
|
|
||||||
FileBuild.selectConfig();
|
FileBuild.selectConfig();
|
||||||
TimerManagement.startTimer();
|
|
||||||
|
Management.start();
|
||||||
|
|
||||||
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(),Util.getSpigotID(),Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean,
|
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(),Util.getSpigotID(),Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean,
|
||||||
Config.updateCheckSeePreReleaseUpdates.valueBoolean, Config.updateCheckTimeInterval.valueInteger);
|
Config.updateCheckSeePreReleaseUpdates.valueBoolean, Config.updateCheckTimeInterval.valueInteger);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
name: T2C-AutomatedMessages
|
name: '${project.artifactId}'
|
||||||
version: '${project.version}'
|
version: '${project.version}'
|
||||||
prefix: "[T2C-AutomatedMessages]"
|
prefix: "[T2C-AutomatedMessages]"
|
||||||
main: net.t2code.automatedMessages.system.Main
|
main: net.t2code.automatedMessages.system.Main
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import org.quartz.Job;
|
|
||||||
import org.quartz.JobExecutionContext;
|
|
||||||
import org.quartz.JobExecutionException;
|
|
||||||
|
|
||||||
public class Job1 implements Job{
|
|
||||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
|
||||||
System.out.println("test.Job1 --->>> Hello user! Time is " + new Date());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import org.quartz.CronExpression;
|
|
||||||
import org.quartz.CronScheduleBuilder;
|
|
||||||
import org.quartz.JobBuilder;
|
|
||||||
import org.quartz.JobDetail;
|
|
||||||
import org.quartz.Scheduler;
|
|
||||||
import org.quartz.Trigger;
|
|
||||||
import org.quartz.TriggerBuilder;
|
|
||||||
import org.quartz.impl.StdSchedulerFactory;
|
|
||||||
|
|
||||||
public class MyApp {
|
|
||||||
public static void main(String args[]) {
|
|
||||||
try {
|
|
||||||
JobDetail job1 = JobBuilder.newJob(Job1.class)
|
|
||||||
.withIdentity("job1", "group1").build();
|
|
||||||
Trigger trigger1 = TriggerBuilder.newTrigger()
|
|
||||||
.withIdentity("cronTrigger1", "group1").withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
|
|
||||||
.build();
|
|
||||||
Scheduler scheduler1 = new StdSchedulerFactory().getScheduler();
|
|
||||||
scheduler1.start();
|
|
||||||
scheduler1.scheduleJob(job1, trigger1);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user