From bf3d938a0b3c9a420310a3d7d473185196de18ad Mon Sep 17 00:00:00 2001 From: Jason <131086642+JasonP01@users.noreply.github.com> Date: Mon, 30 Dec 2024 00:41:15 +0200 Subject: [PATCH 1/8] add upstream --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09ecae38..298f8090 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,6 +33,11 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 + - name: Add upstream + run: | + git remote add upstream https://github.com/xpdustry/imperium.git --tags + git fetch upstream + - name: Build Artifact run: ./gradlew build From 8ae9c9674b062ec179b731c132f96ef2a47434d0 Mon Sep 17 00:00:00 2001 From: Jason <131086642+JasonP01@users.noreply.github.com> Date: Mon, 30 Dec 2024 00:47:42 +0200 Subject: [PATCH 2/8] add upstream --- .github/workflows/publish.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e302bb59..150fc2f0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,6 +25,11 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 + - name: Add upstream + run: | + git remote add upstream https://github.com/xpdustry/imperium.git --tags + git fetch upstream + - name: Build Artifacts run: ./gradlew build From 0afbc3292948e5a4af764103603aa3f74ce4b950 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 30 Dec 2024 01:55:09 +0200 Subject: [PATCH 3/8] better pause listener --- .../{UnpauseListener.kt => PauseListener.kt} | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) rename imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/{UnpauseListener.kt => PauseListener.kt} (70%) diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/UnpauseListener.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt similarity index 70% rename from imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/UnpauseListener.kt rename to imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt index 793b6e48..4d078b5f 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/UnpauseListener.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt @@ -17,32 +17,30 @@ */ package com.xpdustry.imperium.mindustry.game +import com.xpdustry.distributor.api.annotation.TriggerHandler import com.xpdustry.distributor.api.command.CommandSender import com.xpdustry.imperium.common.application.ImperiumApplication import com.xpdustry.imperium.common.command.ImperiumCommand import com.xpdustry.imperium.mindustry.command.annotation.ClientSide import com.xpdustry.imperium.mindustry.command.annotation.ServerSide -import com.xpdustry.imperium.mindustry.misc.onEvent import mindustry.Vars import mindustry.core.GameState -import mindustry.game.EventType.PlayerJoin -import mindustry.game.EventType.StateChangeEvent -import mindustry.gen.Call +import mindustry.gen.Groups -class UnpauseListener : ImperiumApplication.Listener { +class PauseListener : ImperiumApplication.Listener { override fun onImperiumInit() { - onEvent { - if (Vars.state.isPaused) { - Call.sendMessage( - "[lightgray]The server is paused, type [orange]/unpause[lightgray] to unpause the server") - } - } + // autoPause is bad + Administration.Config.autoPause.set(false) + } - onEvent { - if (it.from == GameState.State.paused && it.to == GameState.State.playing) { - Call.sendMessage("[lightgray]The server has been unpaused") - } + // TODO: remove when v8 is released + @TriggerHandler(EventType.Trigger.update) + fun pauseListener() { + if (Vars.state.isPlaying && Groups.player.size() == 0) { + Vars.state.set(GameState.State.paused) + } else if (Vars.state.isPaused && Groups.player.size() > 0) { + Vars.state.set(GameState.State.playing) } } From c00ecd409caefe60b6b171388ba9b3465e1361e9 Mon Sep 17 00:00:00 2001 From: Jason <131086642+JasonP01@users.noreply.github.com> Date: Mon, 30 Dec 2024 02:16:55 +0200 Subject: [PATCH 4/8] fix: i added this in local why didnt it save???? --- .../kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt index 7c2dc3ff..86aa15db 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt @@ -61,7 +61,7 @@ import com.xpdustry.imperium.mindustry.game.LogicListener import com.xpdustry.imperium.mindustry.game.RatingListener import com.xpdustry.imperium.mindustry.game.TeamCommand import com.xpdustry.imperium.mindustry.game.TipListener -import com.xpdustry.imperium.mindustry.game.UnpauseListener +import com.xpdustry.imperium.mindustry.game.PauseListener import com.xpdustry.imperium.mindustry.game.formation.FormationListener import com.xpdustry.imperium.mindustry.history.HistoryCommand import com.xpdustry.imperium.mindustry.metrics.MetricsListener @@ -184,7 +184,7 @@ class ImperiumPlugin : AbstractMindustryPlugin() { TeamCommand::class, FormationListener::class, ControlListener::class, - UnpauseListener::class, + PauseListener::class, AchievementCommand::class, LogicListener::class, SaveCommand::class, From 04fea708e147b23bda1a16d68305b3165b4f5338 Mon Sep 17 00:00:00 2001 From: JasonP01 Date: Mon, 30 Dec 2024 00:26:20 +0000 Subject: [PATCH 5/8] chore: Format code --- .../kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt index 86aa15db..ece562aa 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt @@ -58,10 +58,10 @@ import com.xpdustry.imperium.mindustry.game.ChangelogCommand import com.xpdustry.imperium.mindustry.game.GameListener import com.xpdustry.imperium.mindustry.game.ImperiumLogicListener import com.xpdustry.imperium.mindustry.game.LogicListener +import com.xpdustry.imperium.mindustry.game.PauseListener import com.xpdustry.imperium.mindustry.game.RatingListener import com.xpdustry.imperium.mindustry.game.TeamCommand import com.xpdustry.imperium.mindustry.game.TipListener -import com.xpdustry.imperium.mindustry.game.PauseListener import com.xpdustry.imperium.mindustry.game.formation.FormationListener import com.xpdustry.imperium.mindustry.history.HistoryCommand import com.xpdustry.imperium.mindustry.metrics.MetricsListener From 8bfb7d11b9c8c90b73d49cf620b1e5b8c0904097 Mon Sep 17 00:00:00 2001 From: Jason <131086642+JasonP01@users.noreply.github.com> Date: Mon, 30 Dec 2024 02:27:27 +0200 Subject: [PATCH 6/8] ci: quick build test From f8c3c20b53ba42229e5cd859505382d8b92be2e7 Mon Sep 17 00:00:00 2001 From: Jason <131086642+JasonP01@users.noreply.github.com> Date: Mon, 30 Dec 2024 02:35:59 +0200 Subject: [PATCH 7/8] fix: comp issues --- .../com/xpdustry/imperium/mindustry/game/PauseListener.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt index 4d078b5f..5e7455d4 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt @@ -25,7 +25,9 @@ import com.xpdustry.imperium.mindustry.command.annotation.ClientSide import com.xpdustry.imperium.mindustry.command.annotation.ServerSide import mindustry.Vars import mindustry.core.GameState +import mindustry.game.EventType import mindustry.gen.Groups +import mindustry.net.Administration class PauseListener : ImperiumApplication.Listener { From 124876667f26f1a126adf2c64e65236bdf4da4cc Mon Sep 17 00:00:00 2001 From: phinner <62483793+Phinner@users.noreply.github.com> Date: Tue, 14 Jan 2025 13:08:03 +0100 Subject: [PATCH 8/8] chore: Actually, let's backport the fix instead --- .github/workflows/build.yml | 5 --- .github/workflows/publish.yml | 5 --- .../imperium/mindustry/ImperiumPlugin.kt | 37 +++++++++++++---- .../imperium/mindustry/game/PauseListener.kt | 40 +++++++------------ 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 298f8090..09ecae38 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,11 +33,6 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - name: Add upstream - run: | - git remote add upstream https://github.com/xpdustry/imperium.git --tags - git fetch upstream - - name: Build Artifact run: ./gradlew build diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 150fc2f0..e302bb59 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,11 +25,6 @@ jobs: - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - - name: Add upstream - run: | - git remote add upstream https://github.com/xpdustry/imperium.git --tags - git fetch upstream - - name: Build Artifacts run: ./gradlew build diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt index ece562aa..d8630397 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/ImperiumPlugin.kt @@ -67,6 +67,7 @@ import com.xpdustry.imperium.mindustry.history.HistoryCommand import com.xpdustry.imperium.mindustry.metrics.MetricsListener import com.xpdustry.imperium.mindustry.misc.ImperiumMetadataChunkReader import com.xpdustry.imperium.mindustry.misc.getMindustryVersion +import com.xpdustry.imperium.mindustry.misc.onEvent import com.xpdustry.imperium.mindustry.permission.ImperiumRankPermissionSource import com.xpdustry.imperium.mindustry.permission.ImperiumRankProvider import com.xpdustry.imperium.mindustry.security.AdminRequestListener @@ -95,20 +96,20 @@ import com.xpdustry.imperium.mindustry.world.WorldEditCommand import kotlin.reflect.KClass import kotlin.system.exitProcess import kotlinx.coroutines.runBlocking +import mindustry.Vars +import mindustry.core.GameState +import mindustry.game.EventType.SaveLoadEvent +import mindustry.gen.Groups import mindustry.io.SaveVersion +import mindustry.net.Administration +import mindustry.server.ServerControl class ImperiumPlugin : AbstractMindustryPlugin() { private val application = MindustryImperiumApplication() override fun onInit() { - // https://github.com/Anuken/Arc/pull/158 if (getMindustryVersion().build < 147) { - Core.app = - object : Application by Core.app { - override fun removeListener(listener: ApplicationListener) { - post { synchronized(listeners) { listeners.remove(listener) } } - } - } + applyBackportFixes() } } @@ -234,6 +235,28 @@ class ImperiumPlugin : AbstractMindustryPlugin() { .register(this@ImperiumPlugin, klass.java, instance, Priority.NORMAL) } + private fun applyBackportFixes() { + // https://github.com/Anuken/Arc/pull/158 + Core.app = + object : Application by Core.app { + override fun removeListener(listener: ApplicationListener) { + post { synchronized(listeners) { listeners.remove(listener) } } + } + } + + // https://github.com/Anuken/Mindustry/issues/9422 + onEvent { _ -> + Core.app.post { + if (Administration.Config.autoPause.bool() && Groups.player.size() == 0) { + Vars.state.set(GameState.State.paused) + val autoPaused = ServerControl::class.java.getField("autoPaused") + autoPaused.isAccessible = true + autoPaused.set(ServerControl.instance, true) + } + } + } + } + private inner class MindustryImperiumApplication : BaseImperiumApplication(logger) { private var exited = false diff --git a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt index 5e7455d4..7bec1436 100644 --- a/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt +++ b/imperium-mindustry/src/main/kotlin/com/xpdustry/imperium/mindustry/game/PauseListener.kt @@ -17,43 +17,31 @@ */ package com.xpdustry.imperium.mindustry.game -import com.xpdustry.distributor.api.annotation.TriggerHandler import com.xpdustry.distributor.api.command.CommandSender +import com.xpdustry.imperium.common.account.Rank import com.xpdustry.imperium.common.application.ImperiumApplication import com.xpdustry.imperium.common.command.ImperiumCommand import com.xpdustry.imperium.mindustry.command.annotation.ClientSide -import com.xpdustry.imperium.mindustry.command.annotation.ServerSide import mindustry.Vars import mindustry.core.GameState -import mindustry.game.EventType -import mindustry.gen.Groups -import mindustry.net.Administration class PauseListener : ImperiumApplication.Listener { - override fun onImperiumInit() { - // autoPause is bad - Administration.Config.autoPause.set(false) - } - - // TODO: remove when v8 is released - @TriggerHandler(EventType.Trigger.update) - fun pauseListener() { - if (Vars.state.isPlaying && Groups.player.size() == 0) { - Vars.state.set(GameState.State.paused) - } else if (Vars.state.isPaused && Groups.player.size() > 0) { - Vars.state.set(GameState.State.playing) - } - } - - @ImperiumCommand(["unpause"]) + @ImperiumCommand(["pause"], rank = Rank.MODERATOR) @ClientSide - @ServerSide - fun onUnpauseCommand(sender: CommandSender) { + fun onPauseCommand(sender: CommandSender) { when (Vars.state.state!!) { - GameState.State.playing -> sender.error("The server is already unpaused") - GameState.State.paused -> Vars.state.set(GameState.State.playing) - GameState.State.menu -> sender.error("The server is not running") + GameState.State.paused -> { + Vars.state.set(GameState.State.playing) + sender.reply("The server has been un-paused") + } + GameState.State.playing -> { + Vars.state.set(GameState.State.paused) + sender.reply("The server has been paused") + } + GameState.State.menu -> { + sender.error("The server is not running") + } } } }