Skip to content

Commit

Permalink
#581 Add queue timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Dec 20, 2024
1 parent 92cc5a8 commit fd81e42
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,6 @@ class BlockBallLanguageImpl : Language, LanguageProviderImpl() {
override var commandPlaceHolderMessage = LanguageItem("Evaluated placeholder: %1$1s")

override var playerNotFoundMessage = LanguageItem("&0&l[&f&lBlockBall&0&l]&c Player %1$1s not found.")

override var queueTimeOutMessage = LanguageItem("&0&l[&f&lBlockBall&0&l]&c Not enough players joined in time to start the game.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,6 @@ interface Language : LanguageProvider {
var commandPlaceHolderMessage: LanguageItem

var playerNotFoundMessage: LanguageItem

var queueTimeOutMessage: LanguageItem
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class SoccerArena : Selection(), Element{
/** Is the soccerArena ready to be placed. */
var enabled: Boolean = false

/**
* Amount of seconds until the queue timeouts.
*/
var queueTimeOutSec: Int = 30

/** [gameType] of the soccerArena */
var gameType: GameType = GameType.HUBGAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class SoccerMiniGameImpl constructor(
private val bossBarService: BossBarService,
private val chatMessageService: ChatMessageService,
private val soundService: SoundService,
language: Language,
private val language: Language,
packetService: PacketService,
scoreboardService: ScoreboardService,
commandService: CommandService,
Expand All @@ -45,6 +45,8 @@ open class SoccerMiniGameImpl constructor(
language,
playerDataRepository
), SoccerMiniGame {
private var currentQueueTime = arena.queueTimeOutSec
private var isQueueTimeRunning = false

/**
* Is the lobby countdown active.
Expand Down Expand Up @@ -85,6 +87,7 @@ open class SoccerMiniGameImpl constructor(
return JoinResult.GAME_FULL
}

queueTimeOut()
return super.join(player, team)
}

Expand Down Expand Up @@ -116,6 +119,8 @@ open class SoccerMiniGameImpl constructor(

if (ticks >= 20) {
if (lobbyCountDownActive) {
isQueueTimeRunning = false

if (lobbyCountdown > 10) {
val amountPlayers = arena.meta.blueTeamMeta.maxAmount + arena.meta.redTeamMeta.maxAmount

Expand Down Expand Up @@ -335,4 +340,32 @@ open class SoccerMiniGameImpl constructor(

return false
}


private fun queueTimeOut() {
currentQueueTime = arena.queueTimeOutSec // Reset queue timer each time someone joins.

if (isQueueTimeRunning) {
return
}

isQueueTimeRunning = true
plugin.launch {
while (isQueueTimeRunning && status == GameState.JOINABLE) {
currentQueueTime -= 1

if (currentQueueTime <= 0) {
isQueueTimeRunning = false
for (player in ingamePlayersStorage.keys.toTypedArray()) {
language.sendMessage(language.queueTimeOutMessage, player)
leave(player)
}
status = GameState.JOINABLE
return@launch
}

delay(20.ticks)
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/resources/arena_sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ displayName: "SoccerArena 3"
enabled: true
# Type of game. Accepts HUBGAME, MINIGAME and BUNGEE
gameType: "HUBGAME"
# Amount of time until the player queue timeouts.
queueTimeOutSec: 30
# The first corner of the playing field.
corner1:
x: 1641.0
Expand Down Expand Up @@ -71,8 +73,6 @@ meta:
minigameMeta:
# Time in seconds until the lobby Timer completes.
lobbyDuration: 20
# Message sent to players, with how many players are required to start.
playersRequiredToStartMessage: "%blockball_lang_miniGameRemainingPlayers%"
# Also called periods, are the sections (half times) you want to split your game in. You can remove/add as many stages as you want.
matchTimes:
# Duration in seconds until this stage completes.
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,6 @@ commandPlaceHolderMessage:
playerNotFoundMessage:
type: "CHAT"
text: "&0&l[&f&lBlockBall&0&l]&c Player %1$1s not found."
queueTimeOutMessage:
type: "CHAT"
text: "&0&l[&f&lBlockBall&0&l]&c Not enough players joined in time to start the game."

0 comments on commit fd81e42

Please sign in to comment.