From c25c6df7ab9167847041560790426792da76fe38 Mon Sep 17 00:00:00 2001 From: Michele <50552288+PokeMichele@users.noreply.github.com> Date: Mon, 28 Nov 2022 19:22:39 +0100 Subject: [PATCH] Removed Quartz Dependency --- README.md | 3 +- pom.xml | 28 +------------ .../java/me/pokemichele/logdel8/LogDel8.java | 41 +++++-------------- .../me/pokemichele/logdel8/LogDelCommand.java | 4 +- 4 files changed, 15 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 06bf7fc..f986268 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,10 @@ This is how the "config.yml" file appears at first time-between-log-removing-in-minutes: 10 The Auto-Remover is enabled by default and the default time is set to 10 minutes. -If you want you change the time or you can completely disable the Auto-Remover. +If you want you can change the time or you can completely disable the Auto-Remover. ## Build This plugin has been built using the following dependencies: - [Apache Commons-IO](https://commons.apache.org/proper/commons-io/ "Apache Commons-IO"), distributed under [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.txt "Apache 2.0 License") -- [Quartz](http://www.quartz-scheduler.org/ "Quartz"), distributed under [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.txt "Apache 2.0 License") [![Anurag’s github stats](https://github-readme-stats.vercel.app/api?username=PokeMichele)](https://github.com/PokeMichele) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 4abc162..34dc14c 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ + ${project.name} org.apache.maven.plugins @@ -40,32 +41,10 @@ false - /home/michele/Scaricati/LogDel8.jar - - org.apache.maven.plugins - maven-assembly-plugin - 3.1.1 - - - jar-with-dependencies - - - - - - make-assembly - package - - single - - - - - @@ -100,10 +79,5 @@ 2.11.0 - - org.quartz-scheduler - quartz - 2.2.3 - diff --git a/src/main/java/me/pokemichele/logdel8/LogDel8.java b/src/main/java/me/pokemichele/logdel8/LogDel8.java index b9e3ba3..780ee6a 100644 --- a/src/main/java/me/pokemichele/logdel8/LogDel8.java +++ b/src/main/java/me/pokemichele/logdel8/LogDel8.java @@ -3,13 +3,7 @@ import java.io.File; import org.bukkit.plugin.java.JavaPlugin; -import org.quartz.*; -import org.quartz.impl.StdSchedulerFactory; - -import static org.quartz.JobBuilder.newJob; -import static org.quartz.SimpleScheduleBuilder.simpleSchedule; -import static org.quartz.TriggerBuilder.newTrigger; - +import org.bukkit.scheduler.BukkitScheduler; @SuppressWarnings("unused") public class LogDel8 extends JavaPlugin { @@ -48,7 +42,7 @@ public void onEnable() { if (plugin.getConfig().getBoolean("settings.enable-auto-remover") == true) { try { enableAutoRemover(); - } catch (SchedulerException e) { + } catch (Exception e) { throw new RuntimeException(e); } } else { @@ -57,34 +51,19 @@ public void onEnable() { } - //AutoRemover - public static void enableAutoRemover( ) throws SchedulerException { - //delete Logs - //wait 10 minutes - Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); - scheduler.start(); - - JobDetail job = newJob(AutoRemover.class) - .withIdentity("auto-remover") - .build(); - - SimpleTrigger trigger = newTrigger().withIdentity("trigger1") - .startNow() - .withSchedule(simpleSchedule().withIntervalInMinutes(plugin.getConfig().getInt("settings.time-between-log-removing-in-minutes")).repeatForever()) - .build(); - scheduler.scheduleJob(job, trigger); - } - public static class AutoRemover implements Job { - @Override - public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - LogDelCommand.LogDelete(); - } + public void enableAutoRemover(){ + BukkitScheduler scheduler = getServer().getScheduler(); + scheduler.scheduleSyncRepeatingTask(this, new Runnable() { + @Override + public void run() { + LogDelCommand.LogDelete(); + } + }, 0L, plugin.getConfig().getInt("settings.time-between-log-removing-in-minutes")*1200L); } - //OnDisable public void onDisable() { System.out.println("LogDel8 is now Disabled"); diff --git a/src/main/java/me/pokemichele/logdel8/LogDelCommand.java b/src/main/java/me/pokemichele/logdel8/LogDelCommand.java index 5c68dff..9ade519 100644 --- a/src/main/java/me/pokemichele/logdel8/LogDelCommand.java +++ b/src/main/java/me/pokemichele/logdel8/LogDelCommand.java @@ -9,10 +9,12 @@ import java.io.File; import java.io.IOException; +import static me.pokemichele.logdel8.LogDel8.plugin; + public class LogDelCommand implements CommandExecutor{ //define directory - static String MainDir = System.getProperty("user.dir"); + static String MainDir = plugin.getServer().getWorldContainer().getAbsolutePath(); static File LogDir = new File(MainDir+"/logs/"); //Delete Logs Method