From 988e8c1eaae15be0e51ff22c701070bb3fb3d345 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 14 Apr 2025 11:34:21 -0400 Subject: [PATCH] Fixed #10652 --- .../src/mindustry/server/ServerControl.java | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/server/src/mindustry/server/ServerControl.java b/server/src/mindustry/server/ServerControl.java index e3e538cfba..6c843b99b5 100644 --- a/server/src/mindustry/server/ServerControl.java +++ b/server/src/mindustry/server/ServerControl.java @@ -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();