diff --git a/LogDel8.iml b/LogDel8.iml index 2ce603b..50412b9 100644 --- a/LogDel8.iml +++ b/LogDel8.iml @@ -21,7 +21,6 @@ - @@ -35,5 +34,8 @@ + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 012d564..4abc162 100644 --- a/pom.xml +++ b/pom.xml @@ -40,11 +40,32 @@ false - /home/michele/Scaricati\LogDel8.jar + /home/michele/Scaricati/LogDel8.jar + + org.apache.maven.plugins + maven-assembly-plugin + 3.1.1 + + + jar-with-dependencies + + + + + + make-assembly + package + + single + + + + + @@ -78,5 +99,11 @@ commons-io 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 18b96c4..531bf49 100644 --- a/src/main/java/me/pokemichele/logdel8/LogDel8.java +++ b/src/main/java/me/pokemichele/logdel8/LogDel8.java @@ -1,12 +1,15 @@ package me.pokemichele.logdel8; import java.io.File; -import java.io.IOException; -import java.util.Timer; -import java.util.TimerTask; -import org.apache.commons.io.FileUtils; 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; + @SuppressWarnings("unused") public class LogDel8 extends JavaPlugin { @@ -25,18 +28,8 @@ public static LogDel8 getInstance() { File LogDir = new File(MainDir+"/logs/"); - public void enableAutoRemover(){ - //delete Logs - //wait 10 minutes or x minutes - // - - //repeat - enableAutoRemover(); - } - - //OnEnable public void onEnable() { plugin = this; @@ -47,15 +40,46 @@ public void onEnable() { //crea cartella del config.yml saveDefaultConfig(); - //Setting permissions to the file + //Setting permissions to the file (+rwx) LogDir.setReadable(true); //read LogDir.setWritable(true); //write LogDir.setExecutable(true); //execute - //enableAutoRemover(); + try { + enableAutoRemover(); + } catch (SchedulerException e) { + throw new RuntimeException(e); + } + + } + + 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(10).repeatForever()) + .build(); + scheduler.scheduleJob(job, trigger); } + public static class AutoRemover implements Job { + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + LogDelCommand.LogDelete(); + } + + } + + //OnDisable public void onDisable() { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b589a77..10edfd2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ name: LogDel8 version: 1.0 author: PokeMichele description: Log File Remover -api-version: 1.16 +api-version: 1.18 commands: logdel: description: Delete Logs Manually