From d9cac0af5ab917d8d33c5cf0b5d599f58f8ff854 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Sat, 20 Jun 2020 23:40:41 +0200 Subject: [PATCH] Change how teams are assigned --- .../spigot_ttt/game/players/RoleGroup.kt | 9 +-- .../spigot_ttt/game/players/TTTScoreboard.kt | 59 ++++++++++++------- .../utils/SurroundWithGraySquareBrackets.kt | 6 ++ 3 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 src/main/kotlin/de/moritzruth/spigot_ttt/utils/SurroundWithGraySquareBrackets.kt diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/RoleGroup.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/RoleGroup.kt index b161c29..79c2b9e 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/RoleGroup.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/RoleGroup.kt @@ -5,11 +5,12 @@ import java.util.* enum class RoleGroup( val primaryRole: Role, val additionalRoles: EnumSet = EnumSet.noneOf(Role::class.java), - val canUseTeamChat: Boolean = true + val canUseTeamChat: Boolean, + val knowEachOther: Boolean ) { - INNOCENT(Role.INNOCENT, EnumSet.of(Role.DETECTIVE), false), - JACKAL(Role.JACKAL, EnumSet.of(Role.SIDEKICK)), - TRAITOR(Role.TRAITOR); + INNOCENT(Role.INNOCENT, EnumSet.of(Role.DETECTIVE), canUseTeamChat = false, knowEachOther = false), + JACKAL(Role.JACKAL, EnumSet.of(Role.SIDEKICK), canUseTeamChat = true, knowEachOther = true), + TRAITOR(Role.TRAITOR, canUseTeamChat = true, knowEachOther = true); fun bothAre(firstTTTPlayer: TTTPlayer, secondTTTPlayer: TTTPlayer) = firstTTTPlayer.role.group == this && secondTTTPlayer.role.group == this diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt index e20705f..a65c6e6 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTScoreboard.kt @@ -5,6 +5,7 @@ import de.moritzruth.spigot_ttt.game.GamePhase import de.moritzruth.spigot_ttt.game.Timers import de.moritzruth.spigot_ttt.game.classes.TTTClass import de.moritzruth.spigot_ttt.plugin +import de.moritzruth.spigot_ttt.utils.surroundWithGraySquareBrackets import org.bukkit.ChatColor import org.bukkit.scoreboard.DisplaySlot import org.bukkit.scoreboard.RenderType @@ -73,16 +74,19 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) { } scoreboard.registerNewTeam(SPECIAL_TEAM_NAME).apply { - setAllowFriendlyFire(true) setCanSeeFriendlyInvisibles(true) setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS) } - scoreboard.registerNewTeam(DEFAULT_TEAM_NAME).apply { - setAllowFriendlyFire(true) + scoreboard.registerNewTeam(DETECTIVE_TEAM_NAME).apply { + color = Role.DETECTIVE.chatColor + prefix = surroundWithGraySquareBrackets(Role.DETECTIVE.coloredDisplayName) + " " + setCanSeeFriendlyInvisibles(false) + setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS) + } + + scoreboard.registerNewTeam(DEFAULT_TEAM_NAME).apply { setCanSeeFriendlyInvisibles(false) - setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.ALWAYS) - setOption(Team.Option.DEATH_MESSAGE_VISIBILITY, Team.OptionStatus.NEVER) setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER) } @@ -125,31 +129,43 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) { fun updateTeams() { val defaultTeam = scoreboard.getTeam(DEFAULT_TEAM_NAME)!! - val phase = GameManager.phase + val detectiveTeam = scoreboard.getTeam(DETECTIVE_TEAM_NAME)!! + val specialTeam = scoreboard.getTeam(SPECIAL_TEAM_NAME)!! - if (phase === GamePhase.COMBAT) { - if (tttPlayer.role.group == RoleGroup.JACKAL || tttPlayer.role === Role.TRAITOR) { - val specialTeam = scoreboard.getTeam(SPECIAL_TEAM_NAME)!! + if (GameManager.phase == GamePhase.PREPARING || GameManager.phase == GamePhase.COMBAT ) { + defaultTeam.setOption( + Team.Option.NAME_TAG_VISIBILITY, + Team.OptionStatus.NEVER + ) + + if (tttPlayer.role.group.knowEachOther) { specialTeam.color = tttPlayer.role.chatColor + specialTeam.prefix = surroundWithGraySquareBrackets(tttPlayer.role.coloredDisplayName) + " " + defaultTeam.color = Role.INNOCENT.chatColor PlayerManager.tttPlayers.forEach { - if (RoleGroup.JACKAL.bothAre(tttPlayer, it) || - RoleGroup.TRAITOR.bothAre(tttPlayer, it)) { - specialTeam.addEntry(it.player.displayName) - } else { - defaultTeam.addEntry(it.player.displayName) + when { + it.role == Role.DETECTIVE -> detectiveTeam.addEntry(it.player.name) + it.role.group == tttPlayer.role.group -> specialTeam.addEntry(it.player.name) + else -> defaultTeam.addEntry(it.player.name) + } + } + } else { + PlayerManager.tttPlayers.forEach { + when (it.role) { + Role.DETECTIVE -> detectiveTeam.addEntry(it.player.name) + else -> defaultTeam.addEntry(it.player.name) } } - - return } - } + } else { + PlayerManager.tttPlayers.forEach { defaultTeam.addEntry(it.player.name) } - defaultTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, if (phase === null) Team.OptionStatus.ALWAYS else Team.OptionStatus.NEVER) - - PlayerManager.tttPlayers.forEach { - defaultTeam.addEntry(it.player.displayName) + defaultTeam.setOption( + Team.Option.NAME_TAG_VISIBILITY, + Team.OptionStatus.ALWAYS + ) } } @@ -190,6 +206,7 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) { companion object { private const val SPECIAL_TEAM_NAME = "special" private const val DEFAULT_TEAM_NAME = "default" + private const val DETECTIVE_TEAM_NAME = "detective" private const val INACTIVE_OBJECTIVE = "1" private const val ACTIVE_OBJECTIVE = "2" private const val ACTIVE_WITH_CREDITS_OBJECTIVE = "3" diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/utils/SurroundWithGraySquareBrackets.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/utils/SurroundWithGraySquareBrackets.kt new file mode 100644 index 0000000..d56c367 --- /dev/null +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/utils/SurroundWithGraySquareBrackets.kt @@ -0,0 +1,6 @@ +package de.moritzruth.spigot_ttt.utils + +import org.bukkit.ChatColor + +fun surroundWithGraySquareBrackets(string: String) = + "${ChatColor.RESET}${ChatColor.GRAY}[${ChatColor.RESET}$string${ChatColor.GRAY}]${ChatColor.RESET}"