Skip to content

Commit

Permalink
Automatically update the scoreboard on a few game events
Browse files Browse the repository at this point in the history
  • Loading branch information
FluxCapacitor2 committed Nov 8, 2023
1 parent 682f778 commit 0af0976
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bluedragonmc.server.event

import com.bluedragonmc.server.Game

class CountdownEvent {
class CountdownStartEvent(game: Game) : GameEvent(game)
class CountdownTickEvent(game: Game, val secondsLeft: Int) : GameEvent(game)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.bluedragonmc.server.module.gameplay

import com.bluedragonmc.server.*
import com.bluedragonmc.server.api.Environment
import com.bluedragonmc.server.event.CountdownEvent
import com.bluedragonmc.server.event.GameStartEvent
import com.bluedragonmc.server.event.GameStateChangedEvent
import com.bluedragonmc.server.event.PlayerLeaveGameEvent
import com.bluedragonmc.server.module.GameModule
import com.bluedragonmc.server.module.minigame.CountdownModule
Expand Down Expand Up @@ -171,6 +174,11 @@ class SidebarModule(private val title: String) : GameModule() {

init {
update()

module.eventNode.addListener(GameStateChangedEvent::class.java) { _ -> update() }
module.eventNode.addListener(GameStartEvent::class.java) { _ -> update() }
module.eventNode.addListener(CountdownEvent.CountdownStartEvent::class.java) { _ -> update() }
module.eventNode.addListener(CountdownEvent.CountdownTickEvent::class.java) { _ -> update() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.bluedragonmc.server.module.minigame

import com.bluedragonmc.server.BRAND_COLOR_PRIMARY_2
import com.bluedragonmc.server.Game
import com.bluedragonmc.server.event.CountdownEvent
import com.bluedragonmc.server.event.GameStartEvent
import com.bluedragonmc.server.module.GameModule
import com.bluedragonmc.server.utils.GameState
Expand Down Expand Up @@ -115,6 +116,7 @@ class CountdownModule(
Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ZERO)
)
)
parent.callEvent(CountdownEvent.CountdownTickEvent(parent, secondsLeft!!))
secondsLeft = secondsLeft!! - 1
} else {
parent.sendTitlePart(
Expand All @@ -130,6 +132,7 @@ class CountdownModule(

private fun startCountdown(parent: Game) {
cancelCountdown()
parent.callEvent(CountdownEvent.CountdownStartEvent(parent))
if (!allowMoveDuringCountdown) parent.players.filter { it.isActive }.forEach { it.teleport(it.respawnPoint) }
secondsLeft = countdownSeconds
countdownRunning = true
Expand Down

0 comments on commit 0af0976

Please sign in to comment.