Add team chat
This commit is contained in:
parent
876fc531b9
commit
d36250d6ea
3 changed files with 39 additions and 3 deletions
|
@ -2,6 +2,7 @@ package de.moritzruth.spigot_ttt.game
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary
|
import com.comphenix.protocol.ProtocolLibrary
|
||||||
import de.moritzruth.spigot_ttt.Settings
|
import de.moritzruth.spigot_ttt.Settings
|
||||||
|
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||||
import de.moritzruth.spigot_ttt.game.classes.TTTClassManager
|
import de.moritzruth.spigot_ttt.game.classes.TTTClassManager
|
||||||
import de.moritzruth.spigot_ttt.game.corpses.CorpseListener
|
import de.moritzruth.spigot_ttt.game.corpses.CorpseListener
|
||||||
import de.moritzruth.spigot_ttt.game.corpses.CorpseManager
|
import de.moritzruth.spigot_ttt.game.corpses.CorpseManager
|
||||||
|
@ -20,6 +21,8 @@ import org.bukkit.block.Block
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
object GameManager {
|
object GameManager {
|
||||||
|
const val TEAM_CHAT_PREFIX = "."
|
||||||
|
|
||||||
var phase: GamePhase? = null
|
var phase: GamePhase? = null
|
||||||
private set(value) {
|
private set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
@ -158,7 +161,14 @@ object GameManager {
|
||||||
if (!it.alive) {
|
if (!it.alive) {
|
||||||
it.revive(world.spawnLocation, Settings.initialCredits)
|
it.revive(world.spawnLocation, Settings.initialCredits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (it.role.group.canUseTeamChat) {
|
||||||
|
it.player.sendMessage(
|
||||||
|
"${TTTPlugin.prefix}Schreibe '$TEAM_CHAT_PREFIX' vor deine Nachrichten, um den Team-Chat" +
|
||||||
|
"zu verwenden.")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ScoreboardHelper.forEveryScoreboard { it.updateTeams() }
|
ScoreboardHelper.forEveryScoreboard { it.updateTeams() }
|
||||||
|
|
||||||
Timers.playTimerSound()
|
Timers.playTimerSound()
|
||||||
|
@ -183,7 +193,7 @@ object GameManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ensurePhase(phase: GamePhase?) {
|
private fun ensurePhase(phase: GamePhase?) {
|
||||||
if (this.phase !== phase) throw IllegalStateException("The game must be in $phase phase")
|
if (this.phase !== phase) throw IllegalStateException("The game must be in $phase phase")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,9 @@ import com.comphenix.protocol.events.PacketAdapter
|
||||||
import com.comphenix.protocol.events.PacketEvent
|
import com.comphenix.protocol.events.PacketEvent
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers
|
import com.comphenix.protocol.wrappers.EnumWrappers
|
||||||
import com.comphenix.protocol.wrappers.PlayerInfoData
|
import com.comphenix.protocol.wrappers.PlayerInfoData
|
||||||
|
import de.moritzruth.spigot_ttt.COMMAND_RESPONSE_PREFIX
|
||||||
import de.moritzruth.spigot_ttt.TTTPlugin
|
import de.moritzruth.spigot_ttt.TTTPlugin
|
||||||
|
import de.moritzruth.spigot_ttt.game.GameManager.TEAM_CHAT_PREFIX
|
||||||
import de.moritzruth.spigot_ttt.game.players.*
|
import de.moritzruth.spigot_ttt.game.players.*
|
||||||
import de.moritzruth.spigot_ttt.plugin
|
import de.moritzruth.spigot_ttt.plugin
|
||||||
import de.moritzruth.spigot_ttt.utils.call
|
import de.moritzruth.spigot_ttt.utils.call
|
||||||
|
@ -139,6 +141,26 @@ object GeneralGameListener : Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
event.isCancelled = true
|
event.isCancelled = true
|
||||||
|
} else {
|
||||||
|
if (event.message.startsWith(TEAM_CHAT_PREFIX)) {
|
||||||
|
if (senderTTTPlayer.role.group.canUseTeamChat) {
|
||||||
|
PlayerManager.tttPlayers
|
||||||
|
.filter { senderTTTPlayer.role.group == it.role.group }
|
||||||
|
.forEach {
|
||||||
|
it.player.sendMessage(
|
||||||
|
"${ChatColor.GRAY}[${ChatColor.LIGHT_PURPLE}TEAM${ChatColor.GRAY}] " +
|
||||||
|
"${ChatColor.WHITE}<${event.player.displayName}> ${event.message.drop(1)}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
senderTTTPlayer.player.sendMessage(
|
||||||
|
"$COMMAND_RESPONSE_PREFIX${ChatColor.RED}Als ${senderTTTPlayer.role.coloredDisplayName}" +
|
||||||
|
" ${ChatColor.RED}kannst du den Team-Chat nicht verwenden"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
event.isCancelled = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,12 @@ package de.moritzruth.spigot_ttt.game.players
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
enum class RoleGroup(val primaryRole: Role, val additionalRoles: EnumSet<Role> = EnumSet.noneOf(Role::class.java)) {
|
enum class RoleGroup(
|
||||||
INNOCENT(Role.INNOCENT, EnumSet.of(Role.DETECTIVE)),
|
val primaryRole: Role,
|
||||||
|
val additionalRoles: EnumSet<Role> = EnumSet.noneOf(Role::class.java),
|
||||||
|
val canUseTeamChat: Boolean = true
|
||||||
|
) {
|
||||||
|
INNOCENT(Role.INNOCENT, EnumSet.of(Role.DETECTIVE), false),
|
||||||
JACKAL(Role.JACKAL, EnumSet.of(Role.SIDEKICK)),
|
JACKAL(Role.JACKAL, EnumSet.of(Role.SIDEKICK)),
|
||||||
TRAITOR(Role.TRAITOR);
|
TRAITOR(Role.TRAITOR);
|
||||||
|
|
||||||
|
|
Reference in a new issue