From e4d8aaa2bcebc52852e4259552822dfe88cb2283 Mon Sep 17 00:00:00 2001 From: Moritz Ruth Date: Mon, 15 Jun 2020 00:31:38 +0200 Subject: [PATCH] Spectator mode may be fixed now --- .../spigot_ttt/game/GameListener.kt | 34 +++++++++---------- .../spigot_ttt/game/classes/impl/Ninja.kt | 2 -- .../spigot_ttt/game/players/DamageInfo.kt | 10 ------ .../spigot_ttt/game/players/PlayerManager.kt | 2 +- 4 files changed, 18 insertions(+), 30 deletions(-) delete mode 100644 src/main/kotlin/de/moritzruth/spigot_ttt/game/players/DamageInfo.kt diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt index e563853..d305d0e 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/GameListener.kt @@ -12,6 +12,7 @@ import de.moritzruth.spigot_ttt.plugin import de.moritzruth.spigot_ttt.utils.call import de.moritzruth.spigot_ttt.utils.nextTick import org.bukkit.ChatColor +import org.bukkit.GameMode import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.EventHandler @@ -165,24 +166,23 @@ object GameListener : Listener { override fun onPacketSending(event: PacketEvent) { val packet = WrapperPlayServerPlayerInfo(event.packet) - if (packet.action == EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE || - packet.action == EnumWrappers.PlayerInfoAction.ADD_PLAYER) { + if ( + packet.action == EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE || + packet.action == EnumWrappers.PlayerInfoAction.ADD_PLAYER + ) { + packet.data = packet.data.map { info -> + val tttPlayer = PlayerManager.tttPlayers.find { it.player.uniqueId == info.profile.uuid } - packet.data = packet.data.mapNotNull { info -> - if (event.player.uniqueId == info.profile.uuid) info - else { - val tttPlayer = PlayerManager.tttPlayers.find { it.player.uniqueId == info.profile.uuid } - - if (tttPlayer == null) info - else PlayerInfoData( - info.profile, - info.latency, - if (info.gameMode == EnumWrappers.NativeGameMode.SPECTATOR) - EnumWrappers.NativeGameMode.SURVIVAL - else info.gameMode, - info.displayName - ) - } + 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 + ) }.toMutableList() } } diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/impl/Ninja.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/impl/Ninja.kt index c976adb..e561fb5 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/impl/Ninja.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/classes/impl/Ninja.kt @@ -43,8 +43,6 @@ object Ninja: TTTClass( tttPlayer.player.velocity = Vector(current.x * 3, 0.8, current.z * 3) state.jumpsRemaining -= 1 - println(state.jumpsRemaining) - if (state.jumpsRemaining == 0) { tttPlayer.player.allowFlight = false diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/DamageInfo.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/DamageInfo.kt deleted file mode 100644 index 6fb3f78..0000000 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/DamageInfo.kt +++ /dev/null @@ -1,10 +0,0 @@ -package de.moritzruth.spigot_ttt.game.players - -import org.bukkit.event.entity.EntityDamageEvent - -data class DamageInfo( - val damager: TTTPlayer, - val deathReason: DeathReason, - val expectedDamageCause: EntityDamageEvent.DamageCause = EntityDamageEvent.DamageCause.CUSTOM, - val scream: Boolean = true -) diff --git a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt index 71e6b04..6b6808f 100644 --- a/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt +++ b/src/main/kotlin/de/moritzruth/spigot_ttt/game/players/PlayerManager.kt @@ -112,7 +112,7 @@ object PlayerManager { playersWithoutRole.remove(player) } - for (index in 1..Settings.traitorCount) createTTTPlayer(Role.JACKAL) + for (index in 1..Settings.traitorCount) createTTTPlayer(Role.TRAITOR) if (Settings.detectiveEnabled) createTTTPlayer(Role.DETECTIVE)