Change how teams are assigned
This commit is contained in:
parent
165a2c056b
commit
d9cac0af5a
3 changed files with 49 additions and 25 deletions
|
@ -5,11 +5,12 @@ import java.util.*
|
||||||
enum class RoleGroup(
|
enum class RoleGroup(
|
||||||
val primaryRole: Role,
|
val primaryRole: Role,
|
||||||
val additionalRoles: EnumSet<Role> = EnumSet.noneOf(Role::class.java),
|
val additionalRoles: EnumSet<Role> = EnumSet.noneOf(Role::class.java),
|
||||||
val canUseTeamChat: Boolean = true
|
val canUseTeamChat: Boolean,
|
||||||
|
val knowEachOther: Boolean
|
||||||
) {
|
) {
|
||||||
INNOCENT(Role.INNOCENT, EnumSet.of(Role.DETECTIVE), false),
|
INNOCENT(Role.INNOCENT, EnumSet.of(Role.DETECTIVE), canUseTeamChat = false, knowEachOther = false),
|
||||||
JACKAL(Role.JACKAL, EnumSet.of(Role.SIDEKICK)),
|
JACKAL(Role.JACKAL, EnumSet.of(Role.SIDEKICK), canUseTeamChat = true, knowEachOther = true),
|
||||||
TRAITOR(Role.TRAITOR);
|
TRAITOR(Role.TRAITOR, canUseTeamChat = true, knowEachOther = true);
|
||||||
|
|
||||||
fun bothAre(firstTTTPlayer: TTTPlayer, secondTTTPlayer: TTTPlayer) =
|
fun bothAre(firstTTTPlayer: TTTPlayer, secondTTTPlayer: TTTPlayer) =
|
||||||
firstTTTPlayer.role.group == this && secondTTTPlayer.role.group == this
|
firstTTTPlayer.role.group == this && secondTTTPlayer.role.group == this
|
||||||
|
|
|
@ -5,6 +5,7 @@ import de.moritzruth.spigot_ttt.game.GamePhase
|
||||||
import de.moritzruth.spigot_ttt.game.Timers
|
import de.moritzruth.spigot_ttt.game.Timers
|
||||||
import de.moritzruth.spigot_ttt.game.classes.TTTClass
|
import de.moritzruth.spigot_ttt.game.classes.TTTClass
|
||||||
import de.moritzruth.spigot_ttt.plugin
|
import de.moritzruth.spigot_ttt.plugin
|
||||||
|
import de.moritzruth.spigot_ttt.utils.surroundWithGraySquareBrackets
|
||||||
import org.bukkit.ChatColor
|
import org.bukkit.ChatColor
|
||||||
import org.bukkit.scoreboard.DisplaySlot
|
import org.bukkit.scoreboard.DisplaySlot
|
||||||
import org.bukkit.scoreboard.RenderType
|
import org.bukkit.scoreboard.RenderType
|
||||||
|
@ -73,16 +74,19 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreboard.registerNewTeam(SPECIAL_TEAM_NAME).apply {
|
scoreboard.registerNewTeam(SPECIAL_TEAM_NAME).apply {
|
||||||
setAllowFriendlyFire(true)
|
|
||||||
setCanSeeFriendlyInvisibles(true)
|
setCanSeeFriendlyInvisibles(true)
|
||||||
setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS)
|
setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.ALWAYS)
|
||||||
}
|
}
|
||||||
|
|
||||||
scoreboard.registerNewTeam(DEFAULT_TEAM_NAME).apply {
|
scoreboard.registerNewTeam(DETECTIVE_TEAM_NAME).apply {
|
||||||
setAllowFriendlyFire(true)
|
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)
|
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)
|
setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,31 +129,43 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) {
|
||||||
|
|
||||||
fun updateTeams() {
|
fun updateTeams() {
|
||||||
val defaultTeam = scoreboard.getTeam(DEFAULT_TEAM_NAME)!!
|
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 (GameManager.phase == GamePhase.PREPARING || GameManager.phase == GamePhase.COMBAT ) {
|
||||||
if (tttPlayer.role.group == RoleGroup.JACKAL || tttPlayer.role === Role.TRAITOR) {
|
defaultTeam.setOption(
|
||||||
val specialTeam = scoreboard.getTeam(SPECIAL_TEAM_NAME)!!
|
Team.Option.NAME_TAG_VISIBILITY,
|
||||||
|
Team.OptionStatus.NEVER
|
||||||
|
)
|
||||||
|
|
||||||
|
if (tttPlayer.role.group.knowEachOther) {
|
||||||
specialTeam.color = tttPlayer.role.chatColor
|
specialTeam.color = tttPlayer.role.chatColor
|
||||||
|
specialTeam.prefix = surroundWithGraySquareBrackets(tttPlayer.role.coloredDisplayName) + " "
|
||||||
|
|
||||||
defaultTeam.color = Role.INNOCENT.chatColor
|
defaultTeam.color = Role.INNOCENT.chatColor
|
||||||
|
|
||||||
PlayerManager.tttPlayers.forEach {
|
PlayerManager.tttPlayers.forEach {
|
||||||
if (RoleGroup.JACKAL.bothAre(tttPlayer, it) ||
|
when {
|
||||||
RoleGroup.TRAITOR.bothAre(tttPlayer, it)) {
|
it.role == Role.DETECTIVE -> detectiveTeam.addEntry(it.player.name)
|
||||||
specialTeam.addEntry(it.player.displayName)
|
it.role.group == tttPlayer.role.group -> specialTeam.addEntry(it.player.name)
|
||||||
} else {
|
else -> defaultTeam.addEntry(it.player.name)
|
||||||
defaultTeam.addEntry(it.player.displayName)
|
}
|
||||||
|
}
|
||||||
|
} 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)
|
defaultTeam.setOption(
|
||||||
|
Team.Option.NAME_TAG_VISIBILITY,
|
||||||
PlayerManager.tttPlayers.forEach {
|
Team.OptionStatus.ALWAYS
|
||||||
defaultTeam.addEntry(it.player.displayName)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +206,7 @@ class TTTScoreboard(private val tttPlayer: TTTPlayer) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val SPECIAL_TEAM_NAME = "special"
|
private const val SPECIAL_TEAM_NAME = "special"
|
||||||
private const val DEFAULT_TEAM_NAME = "default"
|
private const val DEFAULT_TEAM_NAME = "default"
|
||||||
|
private const val DETECTIVE_TEAM_NAME = "detective"
|
||||||
private const val INACTIVE_OBJECTIVE = "1"
|
private const val INACTIVE_OBJECTIVE = "1"
|
||||||
private const val ACTIVE_OBJECTIVE = "2"
|
private const val ACTIVE_OBJECTIVE = "2"
|
||||||
private const val ACTIVE_WITH_CREDITS_OBJECTIVE = "3"
|
private const val ACTIVE_WITH_CREDITS_OBJECTIVE = "3"
|
||||||
|
|
|
@ -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}"
|
Reference in a new issue