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.PacketAdapter
|
||||||
import com.comphenix.protocol.events.PacketEvent
|
import com.comphenix.protocol.events.PacketEvent
|
||||||
import de.moritzruth.spigot_ttt.Resourcepack
|
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.GameEndEvent
|
||||||
import de.moritzruth.spigot_ttt.game.players.*
|
|
||||||
import de.moritzruth.spigot_ttt.game.items.Buyable
|
import de.moritzruth.spigot_ttt.game.items.Buyable
|
||||||
import de.moritzruth.spigot_ttt.game.items.PASSIVE
|
import de.moritzruth.spigot_ttt.game.items.PASSIVE
|
||||||
import de.moritzruth.spigot_ttt.game.items.TTTItem
|
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.plugin
|
||||||
import de.moritzruth.spigot_ttt.utils.applyMeta
|
import de.moritzruth.spigot_ttt.utils.applyMeta
|
||||||
import de.moritzruth.spigot_ttt.utils.hideInfo
|
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 val packetListener = object : PacketAdapter(plugin, PacketType.Play.Server.ENTITY_METADATA) {
|
||||||
override fun onPacketSending(event: PacketEvent) {
|
override fun onPacketSending(event: PacketEvent) {
|
||||||
val tttPlayer = TTTPlayer.of(event.player) ?: return
|
val receivingTTTPlayer = TTTPlayer.of(event.player) ?: return
|
||||||
val packet = WrapperPlayServerEntityMetadata(event.packet)
|
|
||||||
|
|
||||||
|
val packet = WrapperPlayServerEntityMetadata(event.packet)
|
||||||
val playerOfPacket = plugin.server.onlinePlayers.find { it.entityId == packet.entityID } ?: return
|
val playerOfPacket = plugin.server.onlinePlayers.find { it.entityId == packet.entityID } ?: return
|
||||||
val tttPlayerOfPacket = TTTPlayer.of(playerOfPacket) ?: return
|
val tttPlayerOfPacket = TTTPlayer.of(playerOfPacket) ?: return
|
||||||
|
|
||||||
if (tttPlayerOfPacket.alive) {
|
if (tttPlayerOfPacket.alive) {
|
||||||
// https://wiki.vg/Entity_metadata#Entity_Metadata_Format
|
// https://wiki.vg/Entity_metadata#Entity_Metadata_Format
|
||||||
try {
|
try {
|
||||||
val modifiers = packet.metadata[0].value as Byte
|
val modifiers = packet.metadata[0].value as Byte
|
||||||
packet.metadata[0].value = if (isc.get(tttPlayer)?.active == true) modifiers or 0x40
|
packet.metadata[0].value =
|
||||||
else modifiers and 0b10111111.toByte()
|
if (isc.get(receivingTTTPlayer)?.active == true) modifiers or 0x40
|
||||||
|
else modifiers and 0xBF.toByte()
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
// Idk why this throws exceptions, but it works anyways
|
// 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.ChatColor
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
import kotlin.math.ceil
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
object PlayerManager {
|
object PlayerManager {
|
||||||
|
@ -94,7 +95,7 @@ object PlayerManager {
|
||||||
fun createTTTPlayers() {
|
fun createTTTPlayers() {
|
||||||
val playersWithoutRole = availablePlayers.toMutableSet()
|
val playersWithoutRole = availablePlayers.toMutableSet()
|
||||||
var playersWithoutRoleCount = playersWithoutRole.count()
|
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) {
|
for (index in 1..traitorCount) {
|
||||||
val player = playersWithoutRole.random()
|
val player = playersWithoutRole.random()
|
||||||
|
|
Reference in a new issue