<commit_before>package net.gtaun.shoebill.streamer

import net.gtaun.shoebill.Shoebill
import net.gtaun.shoebill.`object`.Player
import net.gtaun.shoebill.amx.AmxInstanceManager
import net.gtaun.shoebill.constant.WeaponModel
import net.gtaun.shoebill.data.Vector3D
import net.gtaun.shoebill.streamer.data.DynamicArea
import net.gtaun.shoebill.streamer.data.DynamicObject
import net.gtaun.shoebill.streamer.data.DynamicPickup
import net.gtaun.shoebill.streamer.event.*
import net.gtaun.util.event.EventManager

/**
 * Created by marvin on 23.07.15 in project streamer-wrapper.
 * Copyright (c) 2015 <NAME>. All rights reserved.
 */
object Callbacks {

    private val amxInstanceManager: AmxInstanceManager
        get() = Shoebill.get().amxInstanceManager

    fun registerHandlers(eventManager: EventManager) {
        amxInstanceManager.apply {
            hookCallback("OnDynamicObjectMoved", { amxCallEvent ->
                val `object` = DynamicObject[amxCallEvent.parameters[0] as Int] ?: return@hookCallback
                val event = DynamicObjectMovedEvent(`object`)
                eventManager.dispatchEvent(event, `object`)
            }, "i")
            hookCallback("OnPlayerEditDynamicObject", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val `object` = DynamicObject[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerEditDynamicObjectEvent(`object`, player, amxCallEvent.parameters[2] as Int,
                        Vector3D(amxCallEvent.parameters[3] as Float, amxCallEvent.parameters[4] as Float, amxCallEvent.parameters[5] as Float),
                        Vector3D(amxCallEvent.parameters[6] as Float, amxCallEvent.parameters[7] as Float, amxCallEvent.parameters[8] as Float))
                eventManager.dispatchEvent(event, player, `object`)
            }, "iiiffffff")
            hookCallback("OnPlayerSelectDynamicObject", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val `object` = DynamicObject[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val modelid = amxCallEvent.parameters[2] as Int
                val event = PlayerSelectDynamicObjectEvent(`object`, player, modelid,
                        Vector3D(amxCallEvent.parameters[3] as Float, amxCallEvent.parameters[4] as Float, amxCallEvent.parameters[5] as Float))
                eventManager.dispatchEvent(event, player, `object`)
            }, "iiifff")
            hookCallback("OnPlayerShootDynamicObject", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val weaponModel = WeaponModel.get(amxCallEvent.parameters[1] as Int)
                val dynamicObject = DynamicObject[amxCallEvent.parameters[2] as Int] ?: return@hookCallback
                val event = PlayerShootDynamicObjectEvent(dynamicObject, player, weaponModel,
                        Vector3D(amxCallEvent.parameters[3] as Float, amxCallEvent.parameters[4] as Float, amxCallEvent.parameters[5] as Float))
                eventManager.dispatchEvent(event, player, dynamicObject)
            }, "iiifff")

            hookCallback("OnPlayerEnterDynamicArea", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val area = DynamicArea[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerEnterDynamicAreaEvent(player, area)
                eventManager.dispatchEvent(event)
            }, "ii")

            hookCallback("OnPlayerLeaveDynamicArea", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val area = DynamicArea[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerLeaveDynamicAreaEvent(player, area)
                eventManager.dispatchEvent(event)
            }, "ii")

            hookCallback("OnPlayerPickUpDynamicPickup", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val pickup = DynamicPickup[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerPickUpDynamicPickupEvent(player, pickup)
                eventManager.dispatchEvent(event)
            }, "ii")
        }
    }

    fun unregisterHandlers() {
        amxInstanceManager.apply {
            unhookCallback("OnDynamicObjectMoved")
            unhookCallback("OnPlayerEditDynamicObject")
            unhookCallback("OnPlayerSelectDynamicObject")
            unhookCallback("OnPlayerShootDynamicObject")
            unhookCallback("OnPlayerPickUpDynamicPickup")
            unhookCallback("OnPlayerEnterDynamicArea")
            unhookCallback("OnPlayerLeaveDynamicArea")
            unhookCallback("OnPlayerPickUpDynamicPickup")
        }<commit_msg>Add related objects to Callbacks<commit_after>package net.gtaun.shoebill.streamer

import net.gtaun.shoebill.Shoebill
import net.gtaun.shoebill.`object`.Player
import net.gtaun.shoebill.amx.AmxInstanceManager
import net.gtaun.shoebill.constant.WeaponModel
import net.gtaun.shoebill.data.Vector3D
import net.gtaun.shoebill.streamer.data.DynamicArea
import net.gtaun.shoebill.streamer.data.DynamicObject
import net.gtaun.shoebill.streamer.data.DynamicPickup
import net.gtaun.shoebill.streamer.event.*
import net.gtaun.util.event.EventManager

/**
 * Created by marvin on 23.07.15 in project streamer-wrapper.
 * Copyright (c) 2015 <NAME>. All rights reserved.
 */
object Callbacks {

    private val amxInstanceManager: AmxInstanceManager
        get() = Shoebill.get().amxInstanceManager

    fun registerHandlers(eventManager: EventManager) {
        amxInstanceManager.apply {
            hookCallback("OnDynamicObjectMoved", { amxCallEvent ->
                val `object` = DynamicObject[amxCallEvent.parameters[0] as Int] ?: return@hookCallback
                val event = DynamicObjectMovedEvent(`object`)
                eventManager.dispatchEvent(event, `object`)
            }, "i")
            hookCallback("OnPlayerEditDynamicObject", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val `object` = DynamicObject[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerEditDynamicObjectEvent(`object`, player, amxCallEvent.parameters[2] as Int,
                        Vector3D(amxCallEvent.parameters[3] as Float, amxCallEvent.parameters[4] as Float, amxCallEvent.parameters[5] as Float),
                        Vector3D(amxCallEvent.parameters[6] as Float, amxCallEvent.parameters[7] as Float, amxCallEvent.parameters[8] as Float))
                eventManager.dispatchEvent(event, player, `object`)
            }, "iiiffffff")
            hookCallback("OnPlayerSelectDynamicObject", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val `object` = DynamicObject[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val modelid = amxCallEvent.parameters[2] as Int
                val event = PlayerSelectDynamicObjectEvent(`object`, player, modelid,
                        Vector3D(amxCallEvent.parameters[3] as Float, amxCallEvent.parameters[4] as Float, amxCallEvent.parameters[5] as Float))
                eventManager.dispatchEvent(event, player, `object`, modelid)
            }, "iiifff")
            hookCallback("OnPlayerShootDynamicObject", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val weaponModel = WeaponModel.get(amxCallEvent.parameters[1] as Int)
                val dynamicObject = DynamicObject[amxCallEvent.parameters[2] as Int] ?: return@hookCallback
                val event = PlayerShootDynamicObjectEvent(dynamicObject, player, weaponModel,
                        Vector3D(amxCallEvent.parameters[3] as Float, amxCallEvent.parameters[4] as Float, amxCallEvent.parameters[5] as Float))
                eventManager.dispatchEvent(event, player, dynamicObject, weaponModel)
            }, "iiifff")

            hookCallback("OnPlayerEnterDynamicArea", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val area = DynamicArea[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerEnterDynamicAreaEvent(player, area)
                eventManager.dispatchEvent(event, player, area)
            }, "ii")

            hookCallback("OnPlayerLeaveDynamicArea", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val area = DynamicArea[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerLeaveDynamicAreaEvent(player, area)
                eventManager.dispatchEvent(event, player, area)
            }, "ii")

            hookCallback("OnPlayerPickUpDynamicPickup", { amxCallEvent ->
                val player = Player.get(amxCallEvent.parameters[0] as Int)
                val pickup = DynamicPickup[amxCallEvent.parameters[1] as Int] ?: return@hookCallback
                val event = PlayerPickUpDynamicPickupEvent(player, pickup)
                eventManager.dispatchEvent(event, player, pickup)
            }, "ii")
        }
    }

    fun unregisterHandlers() {
        amxInstanceManager.apply {
            unhookCallback("OnDynamicObjectMoved")
            unhookCallback("OnPlayerEditDynamicObject")
            unhookCallback("OnPlayerSelectDynamicObject")
            unhookCallback("OnPlayerShootDynamicObject")
            unhookCallback("OnPlayerPickUpDynamicPickup")
            unhookCallback("OnPlayerEnterDynamicArea")
            unhookCallback("OnPlayerLeaveDynamicArea")
            unhookCallback("OnPlayerPickUpDynamicPickup")
        }
{'fraction_non_alphanumeric': 0.092887952653225, 'fraction_numerical': 0.008626742902999298, 'mean_word_length': 2.800991231414411, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '2977042', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2694, 'n_words': 502}