This commit is contained in:
Anuken 2025-04-14 11:34:21 -04:00
parent c59daa5bbb
commit 988e8c1eaa

View file

@ -2,7 +2,7 @@ package mindustry.server;
import arc.*;
import arc.files.*;
import arc.func.Cons;
import arc.func.*;
import arc.struct.*;
import arc.util.*;
import arc.util.Timer;
@ -10,6 +10,7 @@ import arc.util.CommandHandler.*;
import arc.util.Timer.*;
import arc.util.serialization.*;
import arc.util.serialization.JsonValue.*;
import mindustry.*;
import mindustry.core.GameState.*;
import mindustry.core.*;
import mindustry.game.EventType.*;
@ -254,6 +255,25 @@ public class ServerControl implements ApplicationListener{
toggleSocket(Config.socketInput.bool());
});
Events.on(ResetEvent.class, e -> {
autoPaused = false;
});
Events.run(Trigger.update, () -> {
if(Config.autoPause.bool()){
if(Groups.player.isEmpty()){
autoPaused = true;
state.set(State.paused);
}else if(autoPaused){
autoPaused = false;
state.set(State.playing);
}
}else if(autoPaused && Vars.state.isPaused()){ //unpause when the config is disabled
state.set(State.playing);
autoPaused = false;
}
});
Events.on(PlayEvent.class, e -> {
try{
JsonValue value = JsonIO.json.fromJson(null, Core.settings.getString("globalrules"));
@ -294,31 +314,6 @@ public class ServerControl implements ApplicationListener{
info("Server loaded. Type @ for help.", "'help'");
});
Events.on(SaveLoadEvent.class, e -> {
Core.app.post(() -> {
if(Config.autoPause.bool() && Groups.player.size() == 0){
state.set(State.paused);
autoPaused = true;
}
});
});
Events.on(PlayerJoin.class, e -> {
if(state.isPaused() && autoPaused && Config.autoPause.bool()){
state.set(State.playing);
autoPaused = false;
}
});
Events.on(PlayerLeave.class, e -> {
// The player list length is compared with 1 and not 0 here,
// because when PlayerLeave gets fired, the player hasn't been removed from the player list yet
if(!state.isPaused() && Config.autoPause.bool() && Groups.player.size() == 1){
state.set(State.paused);
autoPaused = true;
}
});
}
protected void registerCommands(){
@ -402,11 +397,6 @@ public class ServerControl implements ApplicationListener{
info("Map loaded.");
netServer.openServer();
if(Config.autoPause.bool()){
state.set(State.paused);
autoPaused = true;
}
}catch(MapException e){
err("@: @", e.map.plainName(), e.getMessage());
}
@ -1117,7 +1107,7 @@ public class ServerControl implements ApplicationListener{
public void play(boolean wait, Runnable run){
inGameOverWait = true;
cancelPlayTask();
Runnable reload = () -> {
try{
WorldReloader reloader = new WorldReloader();