diff --git a/pom.xml b/pom.xml
index 1cea0f0..27462bd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
net.t2code
- automatedMessages
+ T2C-AutomatedMessages
1.0-SNAPSHOT
jar
@@ -95,6 +95,7 @@
org.quartz-scheduler
quartz
2.3.2
+ compile
diff --git a/src/main/java/net/t2code/automatedMessages/command/Commands.java b/src/main/java/net/t2code/automatedMessages/command/Commands.java
index fe80a10..005eea2 100644
--- a/src/main/java/net/t2code/automatedMessages/command/Commands.java
+++ b/src/main/java/net/t2code/automatedMessages/command/Commands.java
@@ -3,7 +3,7 @@ package net.t2code.automatedMessages.command;
import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.config.Config;
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.t2codelib.SPIGOT.api.messages.T2Csend;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
@@ -11,16 +11,18 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commands {
- public static void reload(CommandSender sender) {
+ public static void reload(CommandSender sender) {
if (!sender.hasPermission("t2c.automatedmessages.admin")) {
sender.sendMessage(Util.getPrefix() + "§cYou do not have permission for OPSecurity! §7");
return;
}
T2Csend.console(Config.msgReloadStart.valueString);
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadStart.valueString);
- TimerManagement.end();
- FileBuild.selectConfig();
- TimerManagement.startTimer();
+ Management.end();
+
+ FileBuild.selectConfig();
+
+ Management.start();
if (sender instanceof Player) T2Csend.sender(sender, Config.msgReloadEnd.valueString);
T2Csend.console(Config.msgReloadEnd.valueString);
}
diff --git a/src/main/java/net/t2code/automatedMessages/config/FileBuild.java b/src/main/java/net/t2code/automatedMessages/config/FileBuild.java
index 9a916e9..6a88216 100644
--- a/src/main/java/net/t2code/automatedMessages/config/FileBuild.java
+++ b/src/main/java/net/t2code/automatedMessages/config/FileBuild.java
@@ -5,6 +5,7 @@ import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.objects.Message;
import net.t2code.automatedMessages.system.Main;
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
+import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
@@ -49,10 +50,10 @@ public class FileBuild {
if (!yamlConfiguration.contains(value.msgPath)) {
setExample("exampleDiscord", true,
"[prefix] If you need help, just contact us on our dc.t2code.net'>T2Code Support Discord server.",
- 20, false, "*/5 * * * *", yamlConfiguration);
+ 20, false, "0 0/5 * ? * * *", yamlConfiguration);
setExample("exampleTime", true,
"[prefix] Es ist jetzt [time]",
- 0, true, "*/20 * * * *", yamlConfiguration);
+ 0, true, "0 0/20 * ? * * *", yamlConfiguration);
}
for (String key : yamlConfiguration.getConfigurationSection(value.msgPath).getKeys(false)) {
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));
String cronJobString = yamlConfiguration.getString(value.msgCronJobStringPath.replace("KEY", key));
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);
}
break;
diff --git a/src/main/java/net/t2code/automatedMessages/messages/CronJob.java b/src/main/java/net/t2code/automatedMessages/messages/CronJob.java
new file mode 100644
index 0000000..5994360
--- /dev/null
+++ b/src/main/java/net/t2code/automatedMessages/messages/CronJob.java
@@ -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);
+ }
+}
diff --git a/src/main/java/net/t2code/automatedMessages/messages/Management.java b/src/main/java/net/t2code/automatedMessages/messages/Management.java
new file mode 100644
index 0000000..b6078b1
--- /dev/null
+++ b/src/main/java/net/t2code/automatedMessages/messages/Management.java
@@ -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 jobList = new ArrayList<>();
+
+ public static HashMap hashMap = new HashMap<>();
+
+ private static final List timerJobList = new ArrayList<>();
+
+ public static void start() {
+ for (Map.Entry 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);
+ }
+ }
+ }
+}
diff --git a/src/main/java/net/t2code/automatedMessages/messages/Timer.java b/src/main/java/net/t2code/automatedMessages/messages/Timer.java
new file mode 100644
index 0000000..c26e45f
--- /dev/null
+++ b/src/main/java/net/t2code/automatedMessages/messages/Timer.java
@@ -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;
+}
diff --git a/src/main/java/net/t2code/automatedMessages/messages/cron/CronJob.java b/src/main/java/net/t2code/automatedMessages/messages/cron/CronJob.java
deleted file mode 100644
index 563de45..0000000
--- a/src/main/java/net/t2code/automatedMessages/messages/cron/CronJob.java
+++ /dev/null
@@ -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 {
-
-
-
-
-
- }
-}
diff --git a/src/main/java/net/t2code/automatedMessages/messages/cron/CronJobManagement.java b/src/main/java/net/t2code/automatedMessages/messages/cron/CronJobManagement.java
deleted file mode 100644
index 88ce9bf..0000000
--- a/src/main/java/net/t2code/automatedMessages/messages/cron/CronJobManagement.java
+++ /dev/null
@@ -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 {
-
-
-}
diff --git a/src/main/java/net/t2code/automatedMessages/messages/timer/TimerManagement.java b/src/main/java/net/t2code/automatedMessages/messages/timer/TimerManagement.java
deleted file mode 100644
index a9a36db..0000000
--- a/src/main/java/net/t2code/automatedMessages/messages/timer/TimerManagement.java
+++ /dev/null
@@ -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 jobList = new ArrayList<>();
-
- public static void startTimer() {
- for (Map.Entry 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);
- }
- }
- }
-}
diff --git a/src/main/java/net/t2code/automatedMessages/objects/Message.java b/src/main/java/net/t2code/automatedMessages/objects/Message.java
index af5a810..c4a390f 100644
--- a/src/main/java/net/t2code/automatedMessages/objects/Message.java
+++ b/src/main/java/net/t2code/automatedMessages/objects/Message.java
@@ -22,5 +22,6 @@ public class Message {
this.message = message;
this.interval = interval;
this.cronJob = cronJob;
+ this.cronJobString=cronJobString;
}
}
diff --git a/src/main/java/net/t2code/automatedMessages/system/Load.java b/src/main/java/net/t2code/automatedMessages/system/Load.java
index 83135aa..a1a6e9f 100644
--- a/src/main/java/net/t2code/automatedMessages/system/Load.java
+++ b/src/main/java/net/t2code/automatedMessages/system/Load.java
@@ -4,7 +4,7 @@ import net.t2code.automatedMessages.Util;
import net.t2code.automatedMessages.command.CmdExecuter;
import net.t2code.automatedMessages.config.Config;
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.update.T2CupdateAPI;
@@ -14,8 +14,10 @@ public class Load {
public static void onLoad(Main plugin, List autor, String version) {
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
plugin.getCommand("t2c-automatedmessages").setExecutor(new CmdExecuter());
+
FileBuild.selectConfig();
- TimerManagement.startTimer();
+
+ Management.start();
T2CupdateAPI.onUpdateCheck(plugin, Util.getPrefix(),Util.getGit(),Util.getSpigotID(),Util.getDiscord(), Config.updateCheckOnJoin.valueBoolean,
Config.updateCheckSeePreReleaseUpdates.valueBoolean, Config.updateCheckTimeInterval.valueInteger);
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 1b00f5a..438da95 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,4 +1,4 @@
-name: T2C-AutomatedMessages
+name: '${project.artifactId}'
version: '${project.version}'
prefix: "[T2C-AutomatedMessages]"
main: net.t2code.automatedMessages.system.Main
diff --git a/src/test/java/test/Job1.java b/src/test/java/test/Job1.java
deleted file mode 100644
index bc02174..0000000
--- a/src/test/java/test/Job1.java
+++ /dev/null
@@ -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());
- }
-}
diff --git a/src/test/java/test/MyApp.java b/src/test/java/test/MyApp.java
deleted file mode 100644
index c6366fc..0000000
--- a/src/test/java/test/MyApp.java
+++ /dev/null
@@ -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();
- }
- }
-}