Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/kotlin/me/owdding/mortem/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.teamresourceful.resourcefulconfig.api.types.info.ResourcefulConfigLin
import com.teamresourceful.resourcefulconfig.api.types.options.TranslatableValue
import com.teamresourceful.resourcefulconfigkt.api.ConfigKt
import me.owdding.mortem.Mortem
import me.owdding.mortem.config.category.MiscConfig
import me.owdding.mortem.config.category.NotifierConfig
import me.owdding.mortem.config.category.OverlayConfig
import me.owdding.mortem.config.category.OverlayPositions
import java.util.function.UnaryOperator
Expand All @@ -17,6 +19,8 @@ object Config : ConfigKt("mortem/config") {

init {
category(OverlayConfig)
category(NotifierConfig)
category(MiscConfig)

category(OverlayPositions)
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/me/owdding/mortem/config/category/MiscConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.owdding.mortem.config.category

import com.teamresourceful.resourcefulconfigkt.api.CategoryKt
import me.owdding.mortem.features.ItemRefill

object MiscConfig : CategoryKt("misc") {
override val name = Translated("mortem.config.misc")

var itemRefill by select(ItemRefill.RefillItems.ENDER_PEARL) {
translation = "mortem.config.misc.item_refill"
}

var automaticRefillOnEnter by boolean(false) {
translation = "mortem.config.misc.automatic_refill_on_enter"
condition = { false }
}

}
67 changes: 67 additions & 0 deletions src/main/kotlin/me/owdding/mortem/features/ItemRefill.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package me.owdding.mortem.features

import me.owdding.ktmodules.Module
import me.owdding.mortem.config.category.MiscConfig
import me.owdding.mortem.utils.GfsQueue
import me.owdding.mortem.utils.extensions.sendWithPrefix
import tech.thatgravyboat.skyblockapi.api.events.base.Subscription
import tech.thatgravyboat.skyblockapi.api.events.dungeon.DungeonEnterEvent
import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent
import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent.Companion.argument
import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId
import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId.Companion.getSkyBlockId
import tech.thatgravyboat.skyblockapi.helpers.McPlayer
import tech.thatgravyboat.skyblockapi.utils.command.EnumArgument
import tech.thatgravyboat.skyblockapi.utils.text.Text

@Module
object ItemRefill {

@Subscription
fun onCommand(event: RegisterCommandsEvent) {
event.register("mortem refill") {
thenCallback("item", EnumArgument<RefillItems>()) {
refill(argument<RefillItems>("item"))
}

callback {
refill(*MiscConfig.itemRefill)
}
}
}

@Subscription
fun onEnter(event: DungeonEnterEvent) {
if (!MiscConfig.automaticRefillOnEnter) return

refill(*MiscConfig.itemRefill)
}

private fun refill(vararg items: RefillItems, sendOutput: Boolean = true) {
val output = items.mapNotNull {
val count = countItem(it.id)
if (count < it.maxStackSize) {
GfsQueue.add(it.id, it.maxStackSize - count)
"${it.maxStackSize - count}x ${it.name}"
} else null
}

if (sendOutput) {
// TODO fancy colors
Text.join("Item Refill | ", output.joinToString(", ")).sendWithPrefix()
Comment thread
j10a1n15 marked this conversation as resolved.
}
}

private fun countItem(id: SkyBlockId) = McPlayer.inventory.filter { it.getSkyBlockId() == id }.sumOf { it.count }

enum class RefillItems(val maxStackSize: Int = 64, id: String? = null) {
SPIRIT_LEAP(maxStackSize = 16),
SUPERBOOM_TNT,
ENDER_PEARL(maxStackSize = 16),
DECOY,
INFLATABLE_JERRY,
;
Comment thread
j10a1n15 marked this conversation as resolved.

val id = SkyBlockId.item(id ?: name)
}
}
44 changes: 44 additions & 0 deletions src/main/kotlin/me/owdding/mortem/utils/GfsQueue.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package me.owdding.mortem.utils

import me.owdding.ktmodules.Module
import tech.thatgravyboat.skyblockapi.api.events.base.Subscription
import tech.thatgravyboat.skyblockapi.api.events.hypixel.ServerChangeEvent
import tech.thatgravyboat.skyblockapi.api.events.time.TickEvent
import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId
import tech.thatgravyboat.skyblockapi.helpers.McClient
import tech.thatgravyboat.skyblockapi.utils.time.currentInstant
import tech.thatgravyboat.skyblockapi.utils.time.since
import java.util.*
import kotlin.time.Duration.Companion.seconds

@Module
// TODO: MLIB
// check wether item is actually in the sack
// combine same ids
// last message send by player to server
// last server switch
object GfsQueue {

private val queue: Queue<Pair<SkyBlockId, Int>> = LinkedList()
private var lastFetch = currentInstant()

fun add(id: SkyBlockId, amount: Int) {
queue.add(Pair(id, amount))
}

@Subscription(ServerChangeEvent::class)
fun onServerSwap() {
lastFetch = currentInstant().plus(2.seconds)
}

@Subscription
fun onTick(event: TickEvent) {
if (queue.isEmpty()) return
if (lastFetch.since() <= 2.5.seconds) return

val (id, amount) = queue.poll() ?: return

McClient.sendCommand("/gfs ${id.skyblockId} $amount")
lastFetch = currentInstant()
}
}