diff --git a/gradle.properties b/gradle.properties index 7de8088..1e85239 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/kotlin/com/ratons/Ratons.kt b/src/main/kotlin/com/ratons/Ratons.kt index 5ba119e..bea3228 100644 --- a/src/main/kotlin/com/ratons/Ratons.kt +++ b/src/main/kotlin/com/ratons/Ratons.kt @@ -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 @@ -45,8 +47,21 @@ class Ratons { private fun List.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 { diff --git a/src/main/kotlin/com/ratons/features/instances/AutoRefill.kt b/src/main/kotlin/com/ratons/features/instances/AutoRefill.kt index f42cd5b..f37745f 100644 --- a/src/main/kotlin/com/ratons/features/instances/AutoRefill.kt +++ b/src/main/kotlin/com/ratons/features/instances/AutoRefill.kt @@ -3,7 +3,7 @@ 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 @@ -11,22 +11,17 @@ 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 diff --git a/src/main/kotlin/com/ratons/features/instances/PartyFinderFeatures.kt b/src/main/kotlin/com/ratons/features/instances/PartyFinderFeatures.kt index dae7132..245588b 100644 --- a/src/main/kotlin/com/ratons/features/instances/PartyFinderFeatures.kt +++ b/src/main/kotlin/com/ratons/features/instances/PartyFinderFeatures.kt @@ -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 @@ -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() @@ -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 @@ -42,12 +43,11 @@ object PartyFinderFeatures { private fun partySize(inventory: Map) { 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 } diff --git a/src/main/kotlin/com/ratons/features/instances/dungeons/DungeonFeatures.kt b/src/main/kotlin/com/ratons/features/instances/dungeons/DungeonFeatures.kt index cbab84d..c0e0bea 100644 --- a/src/main/kotlin/com/ratons/features/instances/dungeons/DungeonFeatures.kt +++ b/src/main/kotlin/com/ratons/features/instances/dungeons/DungeonFeatures.kt @@ -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 @@ -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 diff --git a/src/main/kotlin/com/ratons/features/instances/dungeons/RelicSpawnTimer.kt b/src/main/kotlin/com/ratons/features/instances/dungeons/RelicSpawnTimer.kt index 09f9161..22df846 100644 --- a/src/main/kotlin/com/ratons/features/instances/dungeons/RelicSpawnTimer.kt +++ b/src/main/kotlin/com/ratons/features/instances/dungeons/RelicSpawnTimer.kt @@ -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 @@ -44,7 +45,7 @@ object RelicSpawnTimer { } } - @HandleEvent + @HandleEvent(onlyOnIsland = IslandType.CATACOMBS) fun onServerTick(event: ServerTickEvent) { timer = timer.tick() } diff --git a/src/main/kotlin/com/ratons/features/misc/update/UpdateManager.kt b/src/main/kotlin/com/ratons/features/misc/update/UpdateManager.kt index b159563..baf82b8 100644 --- a/src/main/kotlin/com/ratons/features/misc/update/UpdateManager.kt +++ b/src/main/kotlin/com/ratons/features/misc/update/UpdateManager.kt @@ -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 diff --git a/src/main/kotlin/com/ratons/mixins/transformers/skyhanni/AccessorSkyHanniEvents.java b/src/main/kotlin/com/ratons/mixins/transformers/skyhanni/AccessorSkyHanniEvents.java new file mode 100644 index 0000000..4172ed5 --- /dev/null +++ b/src/main/kotlin/com/ratons/mixins/transformers/skyhanni/AccessorSkyHanniEvents.java @@ -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); + +} diff --git a/src/main/kotlin/com/ratons/utils/ChatUtils.kt b/src/main/kotlin/com/ratons/utils/ChatUtils.kt index 3f888ea..238f334 100644 --- a/src/main/kotlin/com/ratons/utils/ChatUtils.kt +++ b/src/main/kotlin/com/ratons/utils/ChatUtils.kt @@ -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) }