1
0
Fork 0

Finish the map voting once all players have voted

This commit is contained in:
Moritz Ruth 2020-06-20 17:33:14 +02:00
parent 1b2fc74c65
commit 4984924ec7
No known key found for this signature in database
GPG key ID: AFD57E23E753841B

View file

@ -52,24 +52,7 @@ class MapVoting private constructor() {
timerTask = plugin.server.scheduler.runTaskTimer(plugin, fun() {
if (secondsRemaining == 0) {
stop()
val votedMaps = votes.values
val winnerMap =
if (votedMaps.count() == 0) maps.random()
else {
val mapsSortedByVotes = votedMaps.sortedBy { votedMap -> votedMaps.count { it === votedMap } }
mapsSortedByVotes[0]
}
plugin.broadcast("${ChatColor.GREEN}Ausgewählte Map: " +
winnerMap.config.getString("title"))
if (winnerMap.world != null) winnerMap.unload()
winnerMap.load()
GameManager.tttWorld = winnerMap
plugin.server.onlinePlayers.forEach {
it.teleport(winnerMap.world!!.spawnLocation)
}
finish()
} else {
inventory.setItem(26, ItemStack(Material.CLOCK, secondsRemaining).applyMeta {
setDisplayName("${ChatColor.GREEN}Verbleibende Zeit: ${ChatColor.WHITE}${secondsRemaining}s")
@ -84,9 +67,32 @@ class MapVoting private constructor() {
}
}
private fun finish() {
stop()
val votedMaps = votes.values
val winnerMap =
if (votedMaps.count() == 0) maps.random()
else {
val mapsSortedByVotes = votedMaps.sortedBy { votedMap -> votedMaps.count { it === votedMap } }
mapsSortedByVotes[0]
}
plugin.broadcast("${ChatColor.GREEN}Ausgewählte Map: " +
winnerMap.config.getString("title"))
if (winnerMap.world != null) winnerMap.unload()
winnerMap.load()
GameManager.tttWorld = winnerMap
plugin.server.onlinePlayers.forEach {
it.teleport(winnerMap.world!!.spawnLocation)
}
}
fun vote(player: Player, map: TTTWorld) {
votes[player.uniqueId] = map
inventory.setItem(maps.indexOf(map), createMapItemStack(map))
if (votes.keys.containsAll(PlayerManager.getAvailablePlayers().map { it.uniqueId })) finish()
}
fun cancel() {