diff --git a/.gitignore b/.gitignore
index a1c2a23..e140c94 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,23 +1,4 @@
-# Compiled class file
-*.class
-
-# Log file
-*.log
-
-# BlueJ files
-*.ctxt
-
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.nar
-*.ear
-*.zip
-*.tar.gz
-*.rar
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
+# User-specific stuff
+.idea/
+out/
+target/
diff --git a/AutomaticLogDeleter.iml b/AutomaticLogDeleter.iml
new file mode 100644
index 0000000..83c8111
--- /dev/null
+++ b/AutomaticLogDeleter.iml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+ PAPER
+ ADVENTURE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..14f4032
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,76 @@
+
+
+ 4.0.0
+
+ net.limework
+ AutomaticLogDeleter
+ 1.0-SNAPSHOT
+ jar
+
+ AutomaticLogDeleter
+
+ Delete your old server logs on startup
+
+ 1.8
+ UTF-8
+
+ limework.net
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+
+ package
+
+ shade
+
+
+ false
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ papermc-repo
+ https://papermc.io/repo/repository/maven-public/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+
+
+
+ com.destroystokyo.paper
+ paper-api
+ 1.16.5-R0.1-SNAPSHOT
+ provided
+
+
+
diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4d46785
--- /dev/null
+++ b/src/main/java/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: net.limework.automaticlogdeleter.AutomaticLogDeleter
+
diff --git a/src/main/java/net/limework/automaticlogdeleter/AutomaticLogDeleter.java b/src/main/java/net/limework/automaticlogdeleter/AutomaticLogDeleter.java
new file mode 100644
index 0000000..e2547db
--- /dev/null
+++ b/src/main/java/net/limework/automaticlogdeleter/AutomaticLogDeleter.java
@@ -0,0 +1,53 @@
+package net.limework.automaticlogdeleter;
+
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.File;
+import java.util.logging.Level;
+
+public final class AutomaticLogDeleter extends JavaPlugin {
+
+ @Override
+ public void onEnable() {
+ new Thread(() -> {
+ this.saveDefaultConfig();
+ deleteLogs();
+ }).start();
+ }
+
+ @Override
+ public void onDisable() {
+
+ new Thread(() -> {
+ FileConfiguration config = getConfig();
+ if (config.getBoolean("also-delete-logs-on-shutdown")) {
+ deleteLogs();
+ }
+ }).start();
+ }
+
+ public void deleteLogs() {
+ File path = new File("logs");
+
+ File[] files = path.listFiles();
+ if (files == null) { return; }
+ FileConfiguration config = getConfig();
+
+ //maximum file age allowed
+
+ long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000;
+
+ for (File file : files) {
+ if (file.isFile()) {
+ if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) {
+
+ if (!file.delete()) {
+ Bukkit.getLogger().log(Level.WARNING, "Failed to delete server log file! Are you sure the file permissions are correct?");
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..ae6ea26
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,12 @@
+#AutomaticLogDeleter plugin config
+#lines that start with a hashtag are comments
+
+#delete logs older than 24 hours by default
+#default value: 86400
+
+delete-logs-older-than-seconds: 86400
+
+#by default old logs are deleted only on startup
+#default value: false
+
+also-delete-logs-on-shutdown: false
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..ef1955c
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,8 @@
+name: AutomaticLogDeleter
+version: ${project.version}
+main: net.limework.automaticlogdeleter.AutomaticLogDeleter
+api-version: 1.13
+load: STARTUP
+authors: [ Govindas ]
+description: Delete your old server logs on startup
+website: limework.net