Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mindustry): better autoPause implementation #323

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.UnpauseListener
import com.xpdustry.imperium.mindustry.game.formation.FormationListener
import com.xpdustry.imperium.mindustry.history.HistoryCommand
import com.xpdustry.imperium.mindustry.metrics.MetricsListener
Expand Down Expand Up @@ -184,7 +184,7 @@ class ImperiumPlugin : AbstractMindustryPlugin() {
TeamCommand::class,
FormationListener::class,
ControlListener::class,
UnpauseListener::class,
PauseListener::class,
AchievementCommand::class,
LogicListener::class,
SaveCommand::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
*/
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.game.EventType
import mindustry.gen.Groups
import mindustry.net.Administration

class UnpauseListener : ImperiumApplication.Listener {
class PauseListener : ImperiumApplication.Listener {

override fun onImperiumInit() {
onEvent<PlayerJoin> {
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<StateChangeEvent> {
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)
}
}

Expand Down
Loading