Fix death players not seeing each other as spectators
This commit is contained in:
parent
a6ca587655
commit
d31b44693f
2 changed files with 41 additions and 9 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue