add auto restart, npc autoload fix
All checks were successful
/ Auto-Build-App (push) Successful in 4m31s
All checks were successful
/ Auto-Build-App (push) Successful in 4m31s
This commit is contained in:
parent
6b690e16dc
commit
dc014a4fe5
2 changed files with 51 additions and 1 deletions
|
@ -2,8 +2,13 @@ package net.pietru.cookie_utils;
|
||||||
|
|
||||||
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
import dev.crmodders.cosmicquilt.api.entrypoint.ModInitializer;
|
||||||
import finalforeach.cosmicreach.GameSingletons;
|
import finalforeach.cosmicreach.GameSingletons;
|
||||||
|
import finalforeach.cosmicreach.Threads;
|
||||||
|
import finalforeach.cosmicreach.networking.netty.NettyServer;
|
||||||
|
import finalforeach.cosmicreach.networking.packets.MessagePacket;
|
||||||
|
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||||
import net.pietru.cookie_utils.api.Region;
|
import net.pietru.cookie_utils.api.Region;
|
||||||
import net.pietru.cookie_utils.kits.Kits;
|
import net.pietru.cookie_utils.kits.Kits;
|
||||||
|
import net.pietru.cookie_utils.npcs.NpcDef;
|
||||||
import net.pietru.cookie_utils.permissions.Permissions;
|
import net.pietru.cookie_utils.permissions.Permissions;
|
||||||
import net.pietru.cookie_utils.scripting.ScriptsDB;
|
import net.pietru.cookie_utils.scripting.ScriptsDB;
|
||||||
import net.pietru.cookie_utils.setups.setupCreator;
|
import net.pietru.cookie_utils.setups.setupCreator;
|
||||||
|
@ -12,6 +17,7 @@ import org.quiltmc.loader.api.ModContainer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class CookieUtils implements ModInitializer {
|
public class CookieUtils implements ModInitializer {
|
||||||
public static final String MOD_ID = "cookie_utils";
|
public static final String MOD_ID = "cookie_utils";
|
||||||
|
@ -48,6 +54,39 @@ public class CookieUtils implements ModInitializer {
|
||||||
System.out.println("CookieUtils loaded kits...");
|
System.out.println("CookieUtils loaded kits...");
|
||||||
|
|
||||||
GameSingletons.updateObservers.add(new CookieUtilsLogicRunner());
|
GameSingletons.updateObservers.add(new CookieUtilsLogicRunner());
|
||||||
|
|
||||||
|
if (prop.auto_restart){
|
||||||
|
int[] minutes = {1,5,10,15,30};
|
||||||
|
int[] seconds = {1,2,3,4,5,6,7,8,9,10,15,30};
|
||||||
|
delayer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Threads.runOnMainThread(()->{
|
||||||
|
ServerSingletons.SERVER.stop();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 1000L*60*60*prop.restart_hours_delay);
|
||||||
|
for (int i : minutes){
|
||||||
|
delayer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MessagePacket packet = new MessagePacket("[SERVER] Automatic restart in %d minutes...".formatted(i));
|
||||||
|
ServerSingletons.SERVER.broadcastToAll(packet);
|
||||||
|
}
|
||||||
|
}, ((1000L*60*60*prop.restart_hours_delay)-(1000L*60*i)));
|
||||||
|
}
|
||||||
|
for (int i : seconds){
|
||||||
|
delayer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
MessagePacket packet = new MessagePacket("[SERVER] Automatic restart in %d seconds...".formatted(i));
|
||||||
|
ServerSingletons.SERVER.broadcastToAll(packet);
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}, ((1000L*60*60*prop.restart_hours_delay)-(1000L*i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ public class prop {
|
||||||
public static Properties panel_prop;
|
public static Properties panel_prop;
|
||||||
public static int log_level = 1;
|
public static int log_level = 1;
|
||||||
public static boolean load_npcs = false;
|
public static boolean load_npcs = false;
|
||||||
|
public static boolean auto_restart = false;
|
||||||
|
public static int restart_hours_delay = 8;
|
||||||
|
|
||||||
public static ArrayList<String> get_server_property_array(String key, Object defaultValue) throws IOException {
|
public static ArrayList<String> get_server_property_array(String key, Object defaultValue) throws IOException {
|
||||||
String txt = (String) get_server_property(key,defaultValue);
|
String txt = (String) get_server_property(key,defaultValue);
|
||||||
|
@ -65,7 +67,16 @@ public class prop {
|
||||||
|
|
||||||
if (!panel_prop.containsKey("npc_load_on_start")){
|
if (!panel_prop.containsKey("npc_load_on_start")){
|
||||||
panel_prop.put("npc_load_on_start","false"); save=true;}
|
panel_prop.put("npc_load_on_start","false"); save=true;}
|
||||||
load_npcs = Boolean.parseBoolean((String) panel_prop.getOrDefault("log_level","false"));
|
load_npcs = Boolean.parseBoolean((String) panel_prop.getOrDefault("npc_load_on_start","false"));
|
||||||
|
|
||||||
|
|
||||||
|
if (!panel_prop.containsKey("auto_restart_hours_delay")){
|
||||||
|
panel_prop.put("auto_restart_hours_delay","8"); save=true;}
|
||||||
|
restart_hours_delay = Integer.parseInt((String) panel_prop.getOrDefault("auto_restart_hours_delay","8"));
|
||||||
|
restart_hours_delay = Math.max(1,restart_hours_delay);
|
||||||
|
if (!panel_prop.containsKey("auto_restart_enabled")){
|
||||||
|
panel_prop.put("auto_restart_enabled","true"); save=true;}
|
||||||
|
auto_restart = Boolean.parseBoolean((String) panel_prop.getOrDefault("auto_restart_enabled","true"));
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue