diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt index 49fabcea..c1c45a83 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/features/mining/PickaxeWarning.kt @@ -8,11 +8,13 @@ package me.partlysanestudios.partlysaneskies.features.mining import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.config import me.partlysanestudios.partlysaneskies.PartlySaneSkies.Companion.minecraft import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType +import me.partlysanestudios.partlysaneskies.data.skyblockdata.IslandType.Companion.onIslands import me.partlysanestudios.partlysaneskies.render.gui.hud.BannerRenderer.renderNewBanner import me.partlysanestudios.partlysaneskies.render.gui.hud.PSSBanner import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.getCurrentlyHoldingItem import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.getLore -import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.isArrOfStringsInLore +import me.partlysanestudios.partlysaneskies.utils.MinecraftUtils.isListOfStringsInLore +import me.partlysanestudios.partlysaneskies.utils.StringUtils.getMatcher import me.partlysanestudios.partlysaneskies.utils.StringUtils.removeColorCodes import net.minecraftforge.client.event.ClientChatReceivedEvent import net.minecraftforge.event.entity.player.PlayerInteractEvent @@ -21,26 +23,24 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object PickaxeWarning { - private val pattern = "(Mining Speed Boost|Pickobulus|Maniac Miner|Vein Seeker|Hazardous Miner|Gemstone Infusion) is now available!".toPattern() - private val pickaxeAbilities = arrayOf( + private val pattern = "(?.*) is now available!".toPattern() + private val pickaxeAbilities = setOf( "Mining Speed Boost", "Pickobulus", "Maniac Miner", "Vein Seeker", "Hazardous Miner", - "Gemstone Infusion" + "Gemstone Infusion", ) @SubscribeEvent(priority = EventPriority.HIGHEST) fun onChat(event: ClientChatReceivedEvent) { - if (config.onlyGiveWarningOnMiningIsland) { - if (!IslandType.DWARVEN_MINES.onIsland() && !IslandType.CRYSTAL_HOLLOWS.onIsland()) { - return - } - } + if (config.onlyGiveWarningOnMiningIsland && !onIslands(IslandType.DWARVEN_MINES, IslandType.CRYSTAL_HOLLOWS)) return val message = event.message.formattedText.removeColorCodes() - val matcher = pattern.matcher(message) - if (matcher.find()) { + + pattern.getMatcher(message) { + if (group("ability") !in pickaxeAbilities) return@getMatcher + if (config.pickaxeAbilityReadyBanner) { renderNewBanner( PSSBanner( @@ -52,32 +52,28 @@ object PickaxeWarning { ) } if (config.pickaxeAbilityReadySound) { - if (config.pickaxeAbilityReadySiren) { - minecraft.thePlayer.playSound("partlysaneskies:airraidsiren", 100f, 1f) - } else { - minecraft.thePlayer.playSound("partlysaneskies:bell", 100f, 1f) - } - } - if (config.hideReadyMessageFromChat) { - event.setCanceled(true) + minecraft.thePlayer.playSound( + if (config.pickaxeAbilityReadySiren) { + "partlysaneskies:airraidsiren" + } else { + "partlysaneskies:bell" + }, + 100f, 1f, + ) } + if (config.hideReadyMessageFromChat) event.setCanceled(true) } } @SubscribeEvent fun onClick(event: PlayerInteractEvent) { - if (!config.blockAbilityOnPrivateIsland) { - return - } - if (!IslandType.GARDEN.onIsland() && !IslandType.PRIVATE_ISLAND.onIsland()) { - return - } - if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR) { - if (getCurrentlyHoldingItem() == null) return - val loreOfItemInHand = getCurrentlyHoldingItem()!!.getLore().toTypedArray() - if (isArrOfStringsInLore(pickaxeAbilities, loreOfItemInHand)) { - event.setCanceled(true) - } + if (config.blockAbilityOnPrivateIsland && !onIslands(IslandType.PRIVATE_ISLAND, IslandType.GARDEN)) return + if (event.action !in listOf(PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK, PlayerInteractEvent.Action.RIGHT_CLICK_AIR)) return + if (getCurrentlyHoldingItem() == null) return + + val loreOfItemInHand = getCurrentlyHoldingItem()!!.getLore().toTypedArray() + if (isListOfStringsInLore(pickaxeAbilities.toList(), loreOfItemInHand)) { + event.setCanceled(true) } } } diff --git a/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/MinecraftUtils.kt b/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/MinecraftUtils.kt index 59062ebd..f084e7f0 100644 --- a/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/MinecraftUtils.kt +++ b/src/main/kotlin/me/partlysanestudios/partlysaneskies/utils/MinecraftUtils.kt @@ -212,10 +212,10 @@ object MinecraftUtils { ) } - fun isArrOfStringsInLore(arr: Array, lore: Array): Boolean { + fun isListOfStringsInLore(arr: List, lore: Array): Boolean { for (line in lore) { for (arrItem in arr) { - if (line.contains(arrItem!!)) { + if (line.contains(arrItem)) { return true } }