Skip to content

Commit

Permalink
Added Schedule Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
PokeMichele authored Nov 27, 2022
1 parent 51e81a4 commit 597221f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
4 changes: 3 additions & 1 deletion LogDel8.iml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="commons-io-2.11.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:31.0.1-jre" level="project" />
Expand All @@ -35,5 +34,8 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.30" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.11.0" level="project" />
<orderEntry type="library" name="Maven: org.quartz-scheduler:quartz:2.2.3" level="project" />
<orderEntry type="library" name="Maven: c3p0:c3p0:0.9.1.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
</component>
</module>
29 changes: 28 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,32 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<outputFile>/home/michele/Scaricati\LogDel8.jar</outputFile>
<outputFile>/home/michele/Scaricati/LogDel8.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>

<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>

</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -78,5 +99,11 @@
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
</project>
56 changes: 40 additions & 16 deletions src/main/java/me/pokemichele/logdel8/LogDel8.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 597221f

Please sign in to comment.