forked from stefatorus/LagAssist
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
3 years ago
|
package com.entryrise.lagassist.logpurger;
|
||
4 years ago
|
|
||
|
import java.io.File;
|
||
|
|
||
|
import org.bukkit.Bukkit;
|
||
|
|
||
3 years ago
|
import com.entryrise.lagassist.Main;
|
||
|
import com.entryrise.lagassist.utils.MathUtils;
|
||
4 years ago
|
|
||
|
public class PurgerMain {
|
||
|
|
||
|
public static void Enabler() {
|
||
|
if (!Main.config.getBoolean("logcleaner.enabled")) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
for (String directories : Main.config.getStringList("logcleaner.list")) {
|
||
|
File f = new File(directories);
|
||
|
if (f.exists() && f.isDirectory()) {
|
||
|
File[] fls = f.listFiles();
|
||
|
for (File fl : fls) {
|
||
|
if (isOld(fl) && fl.canWrite()) {
|
||
|
fl.delete();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Bukkit.getLogger().info(" §e[§a✔§e] §fLogCleaner System.");
|
||
|
|
||
|
}
|
||
|
|
||
|
public static boolean isOld(File fl) {
|
||
|
int maxsize = Main.config.getInt("logcleaner.conditions.maxsize");
|
||
|
int maxage = Main.config.getInt("logcleaner.conditions.maxage");
|
||
|
|
||
|
boolean sizereq = (MathUtils.toMegaByte(fl.length()) > maxsize);
|
||
|
boolean agereq = (((System.currentTimeMillis() - fl.lastModified()) / 86400000) > maxage);
|
||
|
|
||
|
return (sizereq || agereq);
|
||
|
}
|
||
|
|
||
|
}
|