-
Notifications
You must be signed in to change notification settings - Fork 1
feat: item refill #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/me/owdding/mortem/config/category/MiscConfig.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } | ||
| } | ||
|
|
||
| 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, | ||
| ; | ||
|
j10a1n15 marked this conversation as resolved.
|
||
|
|
||
| val id = SkyBlockId.item(id ?: name) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.