Skip to content

Commit

Permalink
improve a bit (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
j10a1n15 authored Aug 20, 2024
1 parent 380fb2b commit bfc7947
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String?>(
private val pattern = "(?<ability>.*) 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(
Expand All @@ -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<String>()
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<String>()
if (isListOfStringsInLore(pickaxeAbilities.toList(), loreOfItemInHand)) {
event.setCanceled(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ object MinecraftUtils {
)
}

fun isArrOfStringsInLore(arr: Array<String?>, lore: Array<String>): Boolean {
fun isListOfStringsInLore(arr: List<String>, lore: Array<String>): Boolean {
for (line in lore) {
for (arrItem in arr) {
if (line.contains(arrItem!!)) {
if (line.contains(arrItem)) {
return true
}
}
Expand Down

0 comments on commit bfc7947

Please sign in to comment.