aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/apis/ingame/HypixelModAPI.kt
blob: 460df91040af9fa51f716844a844e7d813f43da8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

package moe.nea.firmament.apis.ingame

import net.minecraft.network.packet.c2s.common.CustomPayloadC2SPacket
import net.minecraft.text.Text
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.apis.ingame.packets.PartyInfoRequest
import moe.nea.firmament.apis.ingame.packets.PartyInfoResponse
import moe.nea.firmament.commands.thenExecute
import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.events.FirmamentCustomPayloadEvent
import moe.nea.firmament.events.subscription.SubscriptionOwner
import moe.nea.firmament.features.FirmamentFeature
import moe.nea.firmament.features.debug.DeveloperFeatures
import moe.nea.firmament.util.MC


object HypixelModAPI : SubscriptionOwner {
    init {
        InGameCodecWrapper.Direction.C2S.customCodec =
            InGameCodecWrapper.createStealthyCodec(
                PartyInfoRequest.intoType()
            )
        InGameCodecWrapper.Direction.S2C.customCodec =
            InGameCodecWrapper.createStealthyCodec(
                PartyInfoResponse.intoType()
            )
    }

    @JvmStatic
    fun sendRequest(packet: FirmamentCustomPayload) {
        MC.networkHandler?.sendPacket(CustomPayloadC2SPacket(packet))
    }

    @Subscribe
    fun testCommand(event: CommandEvent.SubCommand) {
        event.subcommand("sendpartyrequest") {
            thenExecute {
                sendRequest(PartyInfoRequest(1))
            }
        }
    }

    @Subscribe
    fun logEvents(event: FirmamentCustomPayloadEvent) {
        MC.sendChat(Text.stringifiedTranslatable("firmament.modapi.event", event.toString()))
    }

    override val delegateFeature: FirmamentFeature
        get() = DeveloperFeatures
}