Allow players who have the permission for it to force a specific map
This commit is contained in:
parent
4984924ec7
commit
29b7b43a54
1 changed files with 22 additions and 23 deletions
|
@ -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) {
|
fun vote(player: Player, map: TTTWorld) {
|
||||||
votes[player.uniqueId] = map
|
votes[player.uniqueId] = map
|
||||||
inventory.setItem(maps.indexOf(map), createMapItemStack(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() }
|
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 {
|
companion object {
|
||||||
var current: MapVoting? = null; private set
|
var current: MapVoting? = null; private set
|
||||||
|
|
||||||
|
@ -148,8 +145,10 @@ class MapVoting private constructor() {
|
||||||
if (event.clickedInventory != voting.inventory) return
|
if (event.clickedInventory != voting.inventory) return
|
||||||
event.isCancelled = true
|
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)
|
voting.vote(whoClicked, map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue