Skip to content

Commit

Permalink
Removed Quartz Dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
PokeMichele authored Nov 28, 2022
1 parent c4f8613 commit c25c6df
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 61 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 1 addition & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</properties>

<build>
<finalName>${project.name}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -40,32 +41,10 @@
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<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 @@ -100,10 +79,5 @@
<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>
41 changes: 10 additions & 31 deletions src/main/java/me/pokemichele/logdel8/LogDel8.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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");
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/me/pokemichele/logdel8/LogDelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c25c6df

Please sign in to comment.