初始化提交

This commit is contained in:
2022-11-06 18:37:18 +08:00
commit 0a77aef84e
55 changed files with 3550 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
version = '1.0.0'
setArchivesBaseName("HamsterAuto-LogClear")
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.19.2-R0.1-SNAPSHOT'
}
processResources {
inputs.property "version", project.version
filesMatching("plugin.yml") {
expand "version": project.version
}
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
}

View File

@@ -0,0 +1,34 @@
package cn.hamster3.mc.plugin.auto.log.clear;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.logging.Logger;
@SuppressWarnings("unused")
public class LogClearPlugin extends JavaPlugin {
@Override
public void onEnable() {
saveDefaultConfig();
reloadConfig();
FileConfiguration config = getConfig();
long time = config.getLong("clear-time", 8) * 60 * 60 * 1000;
File file = new File("logs");
File[] files = file.listFiles();
if (files == null) {
return;
}
Logger logger = getLogger();
long now = System.currentTimeMillis();
for (File logFile : files) {
if (logFile.lastModified() + time > now) {
continue;
}
if (logFile.delete()) {
logger.info("已删除日志文件: " + logFile.getName());
}
}
}
}

View File

@@ -0,0 +1,3 @@
# 日志文件最后更改时间超过设定值则会被清理
# 单位:小时
clear-time: 168

View File

@@ -0,0 +1,8 @@
name: HamsterAuto-LogClear
main: cn.hamster3.mc.plugin.auto.log.clear.LogClearPlugin
version: ${version}
api-version: 1.13
author: MiniDay
website: https://github.com/MiniDay/hamster-little-plugins
description: 服务器启动后自动清理过期日志