From 29b7b43a547df5742ad6ab0f5a60a0bade00fe1c Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Sat, 20 Jun 2020 17:38:55 +0200 Subject: [PATCH] Allow players who have the permission for it to force a specific map --- .../spigot_ttt/game/worlds/MapVoting.kt | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/worlds/MapVoting.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/worlds/MapVoting.kt index cc2fa42..44aae0d 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/worlds/MapVoting.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/worlds/MapVoting.kt @@ -67,27 +67,6 @@ 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)) @@ -109,6 +88,24 @@ class MapVoting private constructor() { plugin.server.onlinePlayers.forEach { if (it.openInventory.topInventory === inventory) it.closeInventory() } } + private fun finish(force: TTTWorld? = null) { + stop() + val winnerMap = force ?: votes.values.let { votedMaps -> + if (votedMaps.count() == 0) maps.random() + else votedMaps.sortedBy { votedMap -> votedMaps.count { it === votedMap } }[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) + } + } + companion object { var current: MapVoting? = null; private set @@ -148,8 +145,10 @@ class MapVoting private constructor() { if (event.clickedInventory != voting.inventory) return event.isCancelled = true - if (event.click.isLeftClick) { - val map = voting.maps.getOrNull(event.slot) ?: return + val map = voting.maps.getOrNull(event.slot) ?: return + if (event.isShiftClick && whoClicked.hasPermission("ttt.force-map")) { + voting.finish(force = map) + } else if (event.click.isLeftClick) { voting.vote(whoClicked, map) } }