|
| 1 | +package me.owdding.mortem.features.comands |
| 2 | + |
| 3 | +import com.mojang.serialization.Codec |
| 4 | +import com.mojang.serialization.codecs.RecordCodecBuilder |
| 5 | +import me.owdding.ktmodules.Module |
| 6 | +import me.owdding.lib.events.FinishRepoLoadingEvent |
| 7 | +import me.owdding.mortem.config.category.CommandsConfig |
| 8 | +import me.owdding.repo.RemoteRepo |
| 9 | +import tech.thatgravyboat.skyblockapi.api.area.dungeon.DungeonFloor |
| 10 | +import tech.thatgravyboat.skyblockapi.api.events.base.Subscription |
| 11 | +import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent |
| 12 | +import tech.thatgravyboat.skyblockapi.helpers.McClient |
| 13 | +import tech.thatgravyboat.skyblockapi.utils.json.Json.toData |
| 14 | + |
| 15 | +@Module |
| 16 | +object JoinCommand { |
| 17 | + |
| 18 | + private val dungeonsCommands = mutableMapOf<DungeonFloor, String>() |
| 19 | + //private val kuudraCommands = mutableMapOf<KuudraTier, String>() |
| 20 | + |
| 21 | + private val DUNGEON_FLOOR_CODEC: Codec<DungeonFloor> = Codec.STRING.xmap( |
| 22 | + { name -> DungeonFloor.getByName(name) }, |
| 23 | + { floor -> floor?.name }, |
| 24 | + ) |
| 25 | + //private val KUUDRA_TIER_CODEC: Codec<KuudraTier> = Codec.STRING.xmap( |
| 26 | + // { name -> KuudraTier.getByName(name) }, |
| 27 | + // { tier -> tier?.name }, |
| 28 | + //) |
| 29 | + |
| 30 | + private val CODEC: Codec<Pair<Map<DungeonFloor, String>, Map<DungeonFloor, String>>> = RecordCodecBuilder.create { |
| 31 | + it.group( |
| 32 | + Codec.unboundedMap(DUNGEON_FLOOR_CODEC, Codec.STRING).fieldOf("dungeons").forGetter { it.first }, |
| 33 | + Codec.unboundedMap(DUNGEON_FLOOR_CODEC, Codec.STRING).fieldOf("dungeons").forGetter { it.second }, |
| 34 | + //Codec.unboundedMap(KUUDRA_TIER_CODEC, Codec.STRING).fieldOf("kuudra").forGetter { it.second }, |
| 35 | + ).apply(it) { a, b -> |
| 36 | + dungeonsCommands.apply { |
| 37 | + clear() |
| 38 | + putAll(a) |
| 39 | + } |
| 40 | + //kuudraCommands.apply { |
| 41 | + // clear() |
| 42 | + // putAll(b) |
| 43 | + //} |
| 44 | + a to b |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @Subscription |
| 49 | + fun onCommand(event: RegisterCommandsEvent) { |
| 50 | + if (!CommandsConfig.join) return |
| 51 | + |
| 52 | + dungeonsCommands.forEach { (dungeon, command) -> |
| 53 | + event.registerWithCallback("join${dungeon.name.lowercase()}") { |
| 54 | + McClient.sendCommand("joininstance $command") |
| 55 | + } |
| 56 | + } |
| 57 | + // kuudraCommands.forEach { (tier, command) -> |
| 58 | + // event.registerWithCallback("joinkuudra${tier.name.lowercase()}") { |
| 59 | + // McClient.sendCommand("joininstance $command") |
| 60 | + // } |
| 61 | + // } |
| 62 | + } |
| 63 | + |
| 64 | + @Subscription |
| 65 | + fun onRepo(event: FinishRepoLoadingEvent) { |
| 66 | + RemoteRepo.getFileContentAsJson("dungeons/joincommands.json")?.toData(CODEC) |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments