<commit_before>package com.github.shynixn.blockball.bukkit.logic.business.service

import com.github.shynixn.blockball.api.business.enumeration.CompatibilityArmorSlotType
import com.github.shynixn.blockball.api.business.enumeration.Version
import com.github.shynixn.blockball.api.business.proxy.PluginProxy
import com.github.shynixn.blockball.api.business.service.InternalVersionPacketService
import com.github.shynixn.blockball.api.business.service.PacketService
import com.github.shynixn.blockball.api.business.service.ProxyService
import com.github.shynixn.blockball.api.persistence.entity.EntityMetaData
import com.github.shynixn.blockball.api.persistence.entity.Position
import com.github.shynixn.blockball.bukkit.logic.business.extension.findClazz
import com.google.inject.Inject
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled

class PacketJavaProtocolServiceImpl @Inject constructor(
    private val internalVersionPacketService: InternalVersionPacketService,
    private val proxyService: ProxyService,
    private val pluginProxy: PluginProxy
) :
    PacketService {
    private val dataSerializerClazz by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.PacketDataSerializer")
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.PacketDataSerializer")
        }
    }
    private val dataSerializerConstructor by lazy { dataSerializerClazz.getDeclaredConstructor(ByteBuf::class.java) }
    private val dataDeSerializationPacketMethod by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.protocol.Packet")
                .getDeclaredMethod("a", dataSerializerClazz)
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.Packet")
                .getDeclaredMethod("a", dataSerializerClazz)
        }
    }
    private val packetPlayOutEntityDestroyClazz by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy")
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.PacketPlayOutEntityDestroy")
        }
    }
    private val packetPlayOutEntityVelocity by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity")
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.PacketPlayOutEntityDestroy")
        }
    }

    /**
     * Sends a velocity packet.
     */
    override fun <P> sendEntityVelocityPacket(player: P, entityId: Int, velocity: Position) {
        if (pluginProxy.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_17_R1)) {
            val packet = packetPlayOutEntityVelocity.getDeclaredConstructor(
                Int::class.java,
                findClazz("net.minecraft.world.phys.Vec3D")
            )
                .newInstance(
                    entityId, findClazz("net.minecraft.world.phys.Vec3D")
                        .getDeclaredConstructor(Double::class.java, Double::class.java, Double::class.java)
                        .newInstance(velocity.x, velocity.y, velocity.z)
                )
            proxyService.sendPacket(player, packet)
        } else {
            val buffer = Unpooled.buffer()
            writeId(buffer, entityId)
            buffer.writeShort((mathhelperA(velocity.x, -3.9, 3.9) * 8000.0).toInt())<commit_msg>#397 Fixed introduced bug in 1.16.4. --snapshot<commit_after>package com.github.shynixn.blockball.bukkit.logic.business.service

import com.github.shynixn.blockball.api.business.enumeration.CompatibilityArmorSlotType
import com.github.shynixn.blockball.api.business.enumeration.Version
import com.github.shynixn.blockball.api.business.proxy.PluginProxy
import com.github.shynixn.blockball.api.business.service.InternalVersionPacketService
import com.github.shynixn.blockball.api.business.service.PacketService
import com.github.shynixn.blockball.api.business.service.ProxyService
import com.github.shynixn.blockball.api.persistence.entity.EntityMetaData
import com.github.shynixn.blockball.api.persistence.entity.Position
import com.github.shynixn.blockball.bukkit.logic.business.extension.findClazz
import com.google.inject.Inject
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled

class PacketJavaProtocolServiceImpl @Inject constructor(
    private val internalVersionPacketService: InternalVersionPacketService,
    private val proxyService: ProxyService,
    private val pluginProxy: PluginProxy
) :
    PacketService {
    private val dataSerializerClazz by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.PacketDataSerializer")
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.PacketDataSerializer")
        }
    }
    private val dataSerializerConstructor by lazy { dataSerializerClazz.getDeclaredConstructor(ByteBuf::class.java) }
    private val dataDeSerializationPacketMethod by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.protocol.Packet")
                .getDeclaredMethod("a", dataSerializerClazz)
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.Packet")
                .getDeclaredMethod("a", dataSerializerClazz)
        }
    }
    private val packetPlayOutEntityDestroyClazz by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy")
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.PacketPlayOutEntityDestroy")
        }
    }
    private val packetPlayOutEntityVelocity by lazy {
        try {
            pluginProxy.findClazz("net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity")
        } catch (e: Exception) {
            pluginProxy.findClazz("net.minecraft.server.VERSION.PacketPlayOutEntityVelocity")
        }
    }

    /**
     * Sends a velocity packet.
     */
    override fun <P> sendEntityVelocityPacket(player: P, entityId: Int, velocity: Position) {
        if (pluginProxy.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_17_R1)) {
            val packet = packetPlayOutEntityVelocity.getDeclaredConstructor(
                Int::class.java,
                findClazz("net.minecraft.world.phys.Vec3D")
            )
                .newInstance(
                    entityId, findClazz("net.minecraft.world.phys.Vec3D")
                        .getDeclaredConstructor(Double::class.java, Double::class.java, Double::class.java)
                        .newInstance(velocity.x, velocity.y, velocity.z)
                )
            proxyService.sendPacket(player, packet)
        } else {
            val buffer = Unpooled.buffer()
            writeId(buffer, entityId)
            buffer.writeShort((mathhelperA(velocity.x, -3.9, 3.9) * 8000.0).toInt())
{'fraction_non_alphanumeric': 0.0953198797767282, 'fraction_numerical': 0.005295548876484901, 'mean_word_length': 3.062790697674419, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022442', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1947, 'n_words': 281}