feat(hamster-auto-restart): done
This commit is contained in:
@@ -58,9 +58,8 @@ subprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
|
||||||
filesMatching(["plugin.yml", "bungee.yml"]) {
|
filesMatching(["plugin.yml", "bungee.yml"]) {
|
||||||
expand "version": project.version
|
expand project.properties
|
||||||
}
|
}
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
}
|
}
|
||||||
|
2
hamster-auto-restart/build.gradle
Normal file
2
hamster-auto-restart/build.gradle
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
version = '1.0.0'
|
||||||
|
setArchivesBaseName("HamsterAuto-Restart")
|
@@ -0,0 +1,51 @@
|
|||||||
|
package cn.hamster3.mc.plugin.auto.restart.bukkit;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class AutoRestartPlugin extends JavaPlugin {
|
||||||
|
private ScheduledExecutorService scheduler;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
reloadConfig();
|
||||||
|
FileConfiguration config = getConfig();
|
||||||
|
int hour = config.getInt("restart-hour", 23);
|
||||||
|
int minute = config.getInt("restart-minute", 0);
|
||||||
|
int second = config.getInt("restart-second", 0);
|
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
if (calendar.get(Calendar.HOUR_OF_DAY) > hour) {
|
||||||
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||||
|
}
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
|
calendar.set(Calendar.MINUTE, minute);
|
||||||
|
calendar.set(Calendar.SECOND, second);
|
||||||
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
|
long delay = calendar.getTimeInMillis() - System.currentTimeMillis();
|
||||||
|
scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
scheduler.schedule(Bukkit::shutdown, delay, TimeUnit.MILLISECONDS);
|
||||||
|
long time = delay / 1000;
|
||||||
|
getLogger().info(String.format(
|
||||||
|
"已计划在 %02d时%02d分%02d秒 后关闭服务器.",
|
||||||
|
time / 3600,
|
||||||
|
time % 3600 / 60,
|
||||||
|
time % 60
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,84 @@
|
|||||||
|
package cn.hamster3.mc.plugin.auto.restart.bungee;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class AutoRestartPlugin extends Plugin {
|
||||||
|
private ScheduledExecutorService scheduler;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
Configuration config = getPluginConfig();
|
||||||
|
int hour = config.getInt("restart-hour", 23);
|
||||||
|
int minute = config.getInt("restart-minute", 0);
|
||||||
|
int second = config.getInt("restart-second", 0);
|
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
if (calendar.get(Calendar.HOUR_OF_DAY) > hour) {
|
||||||
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||||
|
}
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
|
calendar.set(Calendar.MINUTE, minute);
|
||||||
|
calendar.set(Calendar.SECOND, second);
|
||||||
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
|
long delay = calendar.getTimeInMillis() - System.currentTimeMillis();
|
||||||
|
scheduler = Executors.newScheduledThreadPool(1);
|
||||||
|
scheduler.schedule(() -> ProxyServer.getInstance().stop(), delay, TimeUnit.MILLISECONDS);
|
||||||
|
long time = delay / 1000;
|
||||||
|
getLogger().info(String.format(
|
||||||
|
"已计划在 %02d时%02d分%02d秒 后关闭服务器.",
|
||||||
|
time / 3600,
|
||||||
|
time % 3600 / 60,
|
||||||
|
time % 60
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
scheduler.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Configuration getPluginConfig() {
|
||||||
|
File configFile = new File(getDataFolder(), "config.yml");
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
return saveDefaultConfig();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Configuration saveDefaultConfig() {
|
||||||
|
if (getDataFolder().mkdir()) {
|
||||||
|
getLogger().info("创建插件文件夹...");
|
||||||
|
}
|
||||||
|
File configFile = new File(getDataFolder(), "config.yml");
|
||||||
|
try {
|
||||||
|
InputStream in = getResourceAsStream("config.yml");
|
||||||
|
Files.copy(in, configFile.toPath());
|
||||||
|
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
hamster-auto-restart/src/main/resources/bungee.yml
Normal file
4
hamster-auto-restart/src/main/resources/bungee.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
name: HamsterAuto-Restart
|
||||||
|
main: cn.hamster3.mc.plugin.auto.restart.bungee.AutoRestartPlugin
|
||||||
|
version: ${version}
|
||||||
|
author: MiniDay
|
3
hamster-auto-restart/src/main/resources/config.yml
Normal file
3
hamster-auto-restart/src/main/resources/config.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
restart-hour: 23
|
||||||
|
restart-minute: 0
|
||||||
|
restart-second: 0
|
6
hamster-auto-restart/src/main/resources/plugin.yml
Normal file
6
hamster-auto-restart/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
name: HamsterAuto-Restart
|
||||||
|
main: cn.hamster3.mc.plugin.auto.restart.bukkit.AutoRestartPlugin
|
||||||
|
version: ${version}
|
||||||
|
api-version: 1.13
|
||||||
|
|
||||||
|
author: MiniDay
|
@@ -14,4 +14,5 @@ include 'hamster-protect-explosion'
|
|||||||
include 'hamster-protect-piston-wool-carpet'
|
include 'hamster-protect-piston-wool-carpet'
|
||||||
include 'hamster-protect-farmland'
|
include 'hamster-protect-farmland'
|
||||||
include 'hamster-name-case-fix'
|
include 'hamster-name-case-fix'
|
||||||
|
include 'hamster-auto-restart'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user