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

Fixed countdown players #185

Merged
merged 1 commit into from
Feb 9, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2019.
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2020.
*/
package net.darkdevelopers.darkbedrock.darkness.spigot.countdowns

Expand Down Expand Up @@ -30,8 +30,8 @@ abstract class Countdown internal constructor(var seconds: Int, private val logg
logger.info("[${javaClass.simpleName}] Thread started")
try {
while (true) {
lambda()
Thread.sleep(sleep)
lambda()
}
} catch (ex: InterruptedException) {
logger.info("[${javaClass.simpleName}] Thread stoped")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2019.
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2020.
*/
package net.darkdevelopers.darkbedrock.darkness.spigot.countdowns

Expand All @@ -8,18 +8,16 @@ import net.darkdevelopers.darkbedrock.darkness.spigot.events.countdown.EndGameCo
import net.darkdevelopers.darkbedrock.darkness.spigot.functions.call
import net.darkdevelopers.darkbedrock.darkness.spigot.functions.events.plugin
import net.darkdevelopers.darkbedrock.darkness.spigot.functions.sendTo
import net.darkdevelopers.darkbedrock.darkness.spigot.utils.Utils
import org.bukkit.entity.Player
import net.darkdevelopers.darkbedrock.darkness.spigot.utils.Utils.players as allPlayers

/**
* Created on 24.06.2017 17:22.
* @author Lars Artmann | LartyHD
*/
class EndGameCountdown(
seconds: Int = 15,
val players: Collection<Player> = Utils.players
private val inputPlayers: () -> Collection<Player> = { allPlayers }
) : Countdown(seconds) {

val players get() = inputPlayers()

override fun start(): Unit = if (!isRunning) {
isRunning = true
loop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class LobbyCountdown(
seconds: Int = 60,
val minPlayers: Int,
val gameName: String,
val players: Collection<Player> = allPlayers
private val inputPlayers: () -> Collection<Player> = { allPlayers }
) : Countdown(seconds) {

val players get() = inputPlayers()
var idling: Boolean = false
private lateinit var idle: Thread

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2019.
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2020.
*/
package net.darkdevelopers.darkbedrock.darkness.spigot.countdowns

Expand All @@ -10,15 +10,16 @@ import net.darkdevelopers.darkbedrock.darkness.spigot.functions.sendTimings
import net.darkdevelopers.darkbedrock.darkness.spigot.functions.sendTitle
import net.darkdevelopers.darkbedrock.darkness.spigot.functions.sendTo
import net.darkdevelopers.darkbedrock.darkness.spigot.messages.Colors.SECONDARY
import net.darkdevelopers.darkbedrock.darkness.spigot.utils.Utils.players
import org.bukkit.Sound
import org.bukkit.entity.Player
import net.darkdevelopers.darkbedrock.darkness.spigot.utils.Utils.players as allPlayers

/**
* @author Lars Artmann | LartyHD
* Created by LartyHD on 24.06.2017 18:01.
* Last edit 01.06.2019
*/
class PreGameCountdown(seconds: Int = 5) : Countdown(seconds) {
class PreGameCountdown(
seconds: Int = 5,
private val inputPlayers: () -> Collection<Player> = { allPlayers }
) : Countdown(seconds) {

val players get() = inputPlayers()

override fun start(): Unit = if (!isRunning) {
isRunning = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2019.
* © Copyright by Astride UG (haftungsbeschränkt) 2018 - 2020.
*/
package net.darkdevelopers.darkbedrock.darkness.spigot.countdowns

Expand All @@ -9,25 +9,23 @@ import net.darkdevelopers.darkbedrock.darkness.spigot.functions.call
import net.darkdevelopers.darkbedrock.darkness.spigot.functions.sendTo
import net.darkdevelopers.darkbedrock.darkness.spigot.utils.Utils
import org.bukkit.entity.Player
import net.darkdevelopers.darkbedrock.darkness.spigot.utils.Utils.players as allPlayers

/**
* @author Lars Artmann | LartyHD
* Created by LartyHD on 24.06.2017 18:01.
* Last edit 01.06.2019
*/
class SaveTimeCountdown(
seconds: Int = 60,
val players: Collection<Player> = Utils.players
private val inputPlayers: () -> Collection<Player> = { allPlayers }
) : Countdown(seconds) {

val players get() = inputPlayers()

override fun start(): Unit = if (!isRunning) {
isRunning = true
loop {

if (SaveTimeCountdownCallEvent(this).call().isCancelled) return@loop

if (seconds == 0 || Utils.players.isEmpty()) {
messages.saveTimeCountdownEndProtection.sendTo(Utils.players)
if (seconds == 0 || players.isEmpty()) {
messages.saveTimeCountdownEndProtection.sendTo(players)
stop()
} else if (seconds in messages.saveTimeCountdownEndProtectionInIfIn) messages.saveTimeCountdownEndProtectionIn
.replace("@seconds@", seconds.toString(), true)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ subprojects {
apply plugin: 'maven'

group = "net.darkdevelopers.darkbedrock"
version = "4.0.1"
version = "4.0.2"

libsDirName = "libraries"

Expand Down