Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Fix Skyhanni version crash #36

Merged
merged 1 commit into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod_name = Rat-ons
mod_id = ratons
mod_version = 0.1
skyhanni_version = 0.28.Beta.10.1
skyhanni_version = 0.28.Beta.19

loom.platform=forge
org.gradle.jvmargs=-Xmx4g
19 changes: 17 additions & 2 deletions src/main/kotlin/com/ratons/Ratons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package com.ratons
import at.hannibal2.skyhanni.api.event.SkyHanniEvents
import at.hannibal2.skyhanni.deps.moulconfig.managed.ManagedConfig
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
import com.ratons.config.features.Features
import com.ratons.events.RatCommandRegistrationEvent
import com.ratons.mixins.transformers.skyhanni.AccessorSkyHanniEvents
import com.ratons.modules.Modules
import net.minecraft.client.Minecraft
import net.minecraftforge.common.MinecraftForge
Expand Down Expand Up @@ -45,8 +47,21 @@ class Ratons {
private fun List<Any>.loadModules() = forEach(::loadModule)

private fun loadModule(obj: Any) {
modules += obj
MinecraftForge.EVENT_BUS.register(obj)
if (obj in modules) return
try {
for (method in obj.javaClass.declaredMethods) {
@Suppress("CAST_NEVER_SUCCEEDS")
(SkyHanniEvents as AccessorSkyHanniEvents).`ratons$registerMethod`(method, obj)
}
MinecraftForge.EVENT_BUS.register(obj)
modules.add(obj)
} catch (e: Exception) {
ErrorManager.logErrorWithData(
e,
"§cRATONS ERROR!! Something went wrong while initializing events. " +
"Please report this if you are on latest SkyHanni beta, or update if you aren't.",
)
}
}

companion object {
Expand Down
13 changes: 4 additions & 9 deletions src/main/kotlin/com/ratons/features/instances/AutoRefill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@ package com.ratons.features.instances
import at.hannibal2.skyhanni.api.GetFromSackAPI
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
import at.hannibal2.skyhanni.events.DungeonStartEvent
import at.hannibal2.skyhanni.events.dungeon.DungeonStartEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.dungeon.DungeonFloor
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import com.ratons.Ratons
import com.ratons.events.KuudraStartEvent
import com.ratons.modules.RatModule
import com.ratons.utils.ChatUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@RatModule
object AutoRefill {

private val config get() = Ratons.feature.instancesConfig.autoRefill

@SubscribeEvent
fun onDungeonStart(event: DungeonStartEvent) {
newInstance()
}
@HandleEvent
fun onDungeonStart(event: DungeonStartEvent) = newInstance()

@HandleEvent
fun onKuudraStart(event: KuudraStartEvent) {
newInstance()
}
fun onKuudraStart(event: KuudraStartEvent) = newInstance()

private fun newInstance() {
if (!config.enabled) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.ratons.features.instances

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.RegexUtils.find
import com.ratons.Ratons
import com.ratons.modules.RatModule
import net.minecraft.item.ItemStack
Expand All @@ -16,8 +17,8 @@ object PartyFinderFeatures {

private val config get() = Ratons.feature.instancesConfig.partyFinder

private val partyPattern = ".*('s Party)".toPattern()
private val dungeonPartyPattern = "§7Dungeon: .+".toPattern()
private val partyPattern = "'s Party$".toPattern()
private val dungeonPartyPattern = "^§7Dungeon: ".toPattern()

private val stackSizes = mutableMapOf<Int, Int>()

Expand All @@ -26,12 +27,12 @@ object PartyFinderFeatures {
partySize(event.inventoryItems)
}

@SubscribeEvent
@HandleEvent(onlyOnSkyblock = true)
fun onRenderItemTip(event: RenderInventoryItemTipEvent) {
val slot = event.slot
if (!config.partySizeDisplay || slot.slotNumber != slot.slotIndex) return

if (stackSizes.contains(slot.slotIndex)) event.stackTip = stackSizes[slot.slotIndex].toString()
event.stackTip = stackSizes[slot.slotIndex]?.toString() ?: return
}

@SubscribeEvent
Expand All @@ -42,12 +43,11 @@ object PartyFinderFeatures {
private fun partySize(inventory: Map<Int, ItemStack>) {
if (InventoryUtils.openInventoryName() != "Party Finder" || !config.partySizeDisplay) return
for ((slot, item) in inventory){
if (partyPattern.matches(item.displayName)) {
if (partyPattern.find(item.displayName)) {

val isDungeon = dungeonPartyPattern.matches(item.getLore()[0])
var openSlots = 0
val isDungeon = dungeonPartyPattern.find(item.getLore()[0])

item.getLore().forEach { if (it == "§8 Empty") ++openSlots }
val openSlots = item.getLore().count { it == "§8 Empty" }

stackSizes[slot] = (if (isDungeon) 5 else 4) - openSlots
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ratons.features.instances.dungeons

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import com.ratons.Ratons
Expand All @@ -14,7 +15,7 @@ object DungeonFeatures {

private val config get() = Ratons.feature.instancesConfig.dungeonsCategory

@HandleEvent(receiveCancelled = true)
@HandleEvent(onlyOnIsland = IslandType.CATACOMBS, receiveCancelled = true)
fun onPacket(event: PacketReceivedEvent) {
val packet = event.packet as? S2DPacketOpenWindow ?: return
if (!config.closeSecretChest || !DungeonAPI.inDungeon()) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ratons.features.instances.dungeons

import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
Expand Down Expand Up @@ -44,7 +45,7 @@ object RelicSpawnTimer {
}
}

@HandleEvent
@HandleEvent(onlyOnIsland = IslandType.CATACOMBS)
fun onServerTick(event: ServerTickEvent) {
timer = timer.tick()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ object UpdateManager {

private val config get() = Ratons.feature.about

private var _activePromise: CompletableFuture<*>? = null
private var activePromise: CompletableFuture<*>?
get() = _activePromise
private var activePromise: CompletableFuture<*>? = null
set(value) {
_activePromise?.cancel(true)
_activePromise = value
field?.cancel(true)
field = value
}

private var potentialUpdate: PotentialUpdate? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ratons.mixins.transformers.skyhanni;

import at.hannibal2.skyhanni.api.event.SkyHanniEvents;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.lang.reflect.Method;

@Mixin(SkyHanniEvents.class)
public interface AccessorSkyHanniEvents {

@Invoker("registerMethod")
void ratons$registerMethod(Method method, Object instance);

}
4 changes: 0 additions & 4 deletions src/main/kotlin/com/ratons/utils/ChatUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,4 @@ object ChatUtils {
val msgPrefix = if (prefix) prefixColor + CHAT_PREFIX else ""
ChatUtils.chat(Text.join(components).prefix(msgPrefix))
}

fun sendMessageToServer(message: String) = ChatUtils.sendMessageToServer(message)

fun sendCommandToServer(command: String) = ChatUtils.sendCommandToServer(command)
}
Loading