Round up the traitor count
This commit is contained in:
parent
7d269ac777
commit
4246e957c1
2 changed files with 10 additions and 7 deletions
|
@ -5,12 +5,12 @@ import com.comphenix.protocol.PacketType
|
|||
import com.comphenix.protocol.events.PacketAdapter
|
||||
import com.comphenix.protocol.events.PacketEvent
|
||||
import de.moritzruth.spigot_ttt.Resourcepack
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItemListener
|
||||
import de.moritzruth.spigot_ttt.game.GameEndEvent
|
||||
import de.moritzruth.spigot_ttt.game.players.*
|
||||
import de.moritzruth.spigot_ttt.game.items.Buyable
|
||||
import de.moritzruth.spigot_ttt.game.items.PASSIVE
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItem
|
||||
import de.moritzruth.spigot_ttt.game.items.TTTItemListener
|
||||
import de.moritzruth.spigot_ttt.game.players.*
|
||||
import de.moritzruth.spigot_ttt.plugin
|
||||
import de.moritzruth.spigot_ttt.utils.applyMeta
|
||||
import de.moritzruth.spigot_ttt.utils.hideInfo
|
||||
|
@ -112,17 +112,19 @@ object Radar: TTTItem, Buyable {
|
|||
|
||||
override val packetListener = object : PacketAdapter(plugin, PacketType.Play.Server.ENTITY_METADATA) {
|
||||
override fun onPacketSending(event: PacketEvent) {
|
||||
val tttPlayer = TTTPlayer.of(event.player) ?: return
|
||||
val packet = WrapperPlayServerEntityMetadata(event.packet)
|
||||
val receivingTTTPlayer = TTTPlayer.of(event.player) ?: return
|
||||
|
||||
val packet = WrapperPlayServerEntityMetadata(event.packet)
|
||||
val playerOfPacket = plugin.server.onlinePlayers.find { it.entityId == packet.entityID } ?: return
|
||||
val tttPlayerOfPacket = TTTPlayer.of(playerOfPacket) ?: return
|
||||
|
||||
if (tttPlayerOfPacket.alive) {
|
||||
// https://wiki.vg/Entity_metadata#Entity_Metadata_Format
|
||||
try {
|
||||
val modifiers = packet.metadata[0].value as Byte
|
||||
packet.metadata[0].value = if (isc.get(tttPlayer)?.active == true) modifiers or 0x40
|
||||
else modifiers and 0b10111111.toByte()
|
||||
packet.metadata[0].value =
|
||||
if (isc.get(receivingTTTPlayer)?.active == true) modifiers or 0x40
|
||||
else modifiers and 0xBF.toByte()
|
||||
} catch (ignored: Exception) {
|
||||
// Idk why this throws exceptions, but it works anyways
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import de.moritzruth.spigot_ttt.utils.teleportToWorldSpawn
|
|||
import org.bukkit.ChatColor
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.entity.Player
|
||||
import kotlin.math.ceil
|
||||
import kotlin.random.Random
|
||||
|
||||
object PlayerManager {
|
||||
|
@ -94,7 +95,7 @@ object PlayerManager {
|
|||
fun createTTTPlayers() {
|
||||
val playersWithoutRole = availablePlayers.toMutableSet()
|
||||
var playersWithoutRoleCount = playersWithoutRole.count()
|
||||
val traitorCount: Int = if (playersWithoutRoleCount <= 4) 1 else playersWithoutRoleCount / 4
|
||||
val traitorCount: Int = if (playersWithoutRoleCount <= 4) 1 else ceil(playersWithoutRoleCount / 4.0).toInt()
|
||||
|
||||
for (index in 1..traitorCount) {
|
||||
val player = playersWithoutRole.random()
|
||||
|
|
Reference in a new issue