diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GeneralGameListener.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GeneralGameListener.kt index ed8edde..b10b763 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GeneralGameListener.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GeneralGameListener.kt @@ -186,6 +186,7 @@ object GeneralGameListener : Listener { val packetListener = object : PacketAdapter(plugin, PacketType.Play.Server.PLAYER_INFO) { override fun onPacketSending(event: PacketEvent) { + val receivingTTTPlayer = TTTPlayer.of(event.player) ?: return val packet = WrapperPlayServerPlayerInfo(event.packet) if ( @@ -196,15 +197,23 @@ object GeneralGameListener : Listener { val tttPlayer = PlayerManager.tttPlayers.find { it.player.uniqueId == info.profile.uuid } if (tttPlayer == null) info - else PlayerInfoData( - info.profile, - info.latency, - if (event.player.uniqueId == info.profile.uuid) { - if (event.player.gameMode == GameMode.SPECTATOR) EnumWrappers.NativeGameMode.SPECTATOR - else EnumWrappers.NativeGameMode.SURVIVAL - } else EnumWrappers.NativeGameMode.SURVIVAL, - info.displayName - ) + else { + val nativeGameMode = when { + event.player.uniqueId == info.profile.uuid -> { + if (event.player.gameMode == GameMode.SPECTATOR) EnumWrappers.NativeGameMode.SPECTATOR + else EnumWrappers.NativeGameMode.SURVIVAL + } + !receivingTTTPlayer.alive && !tttPlayer.alive -> EnumWrappers.NativeGameMode.SPECTATOR + else -> EnumWrappers.NativeGameMode.SURVIVAL + } + + PlayerInfoData( + info.profile, + info.latency, + nativeGameMode, + info.displayName + ) + } }.toMutableList() } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt index 7e33818..bebeaf8 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/TTTPlayer.kt @@ -1,5 +1,10 @@ package de.moritzruth.spigot_ttt.game.players +import com.comphenix.packetwrapper.WrapperPlayServerPlayerInfo +import com.comphenix.protocol.wrappers.EnumWrappers +import com.comphenix.protocol.wrappers.PlayerInfoData +import com.comphenix.protocol.wrappers.WrappedChatComponent +import com.comphenix.protocol.wrappers.WrappedGameProfile import de.moritzruth.spigot_ttt.Resourcepack import de.moritzruth.spigot_ttt.Settings import de.moritzruth.spigot_ttt.TTTPlugin @@ -21,6 +26,24 @@ import org.bukkit.entity.Player class TTTPlayer(player: Player, role: Role, val tttClass: TTTClassCompanion = TTTClass.None) { var alive = true + set(value) { + field = value + val packet = WrapperPlayServerPlayerInfo() + packet.action = EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE + packet.data = PlayerManager.tttPlayers + .map { tttPlayer -> + PlayerInfoData( + WrappedGameProfile.fromPlayer(tttPlayer.player), + 1, + if (alive || tttPlayer.alive) EnumWrappers.NativeGameMode.SURVIVAL + else EnumWrappers.NativeGameMode.SPECTATOR, + WrappedChatComponent.fromText(tttPlayer.player.displayName) + ) } + + nextTick { + packet.sendPacket(player) + } + } // Used for corpse clicks var ignoreNextInteract = false