aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-07-30 11:42:13 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-07-30 11:42:13 +0200
commit9a7d509cf07542ae23bda0b15ba27f22955b1e51 (patch)
tree397c00bfe2585dea79125eebedc0198ff5dc0b66
parent29682879dd0375d83e27fb07084e0822945d8e3f (diff)
downloadskyhanni-9a7d509cf07542ae23bda0b15ba27f22955b1e51.tar.gz
skyhanni-9a7d509cf07542ae23bda0b15ba27f22955b1e51.tar.bz2
skyhanni-9a7d509cf07542ae23bda0b15ba27f22955b1e51.zip
use null instead of empty string
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt20
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/chat/PowderMiningChatFilter.kt41
2 files changed, 29 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt
index a4ffb7e7e..3f2897aae 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt
@@ -9,7 +9,6 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
@@ -460,10 +459,9 @@ object ChatFilter {
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
var blockReason = block(event.message)
- if (blockReason == "" && config.powderMiningFilter.enabled) blockReason = powderMiningBlock(event)
- if (blockReason == "") return
+ if (blockReason == null && config.powderMiningFilter.enabled) blockReason = powderMiningBlock(event)
- event.blockedReason = blockReason
+ event.blockedReason = blockReason ?: return
}
/**
@@ -471,7 +469,7 @@ object ChatFilter {
* @param message The message to check
* @return The reason why the message was blocked, empty if not blocked
*/
- private fun block(message: String): String = when {
+ private fun block(message: String): String? = when {
config.hypixelHub && message.isPresent("lobby") -> "lobby"
config.empty && StringUtils.isEmpty(message) -> "empty"
config.warping && message.isPresent("warping") -> "warping"
@@ -496,7 +494,7 @@ object ChatFilter {
dungeonConfig.soloStats && DungeonAPI.inDungeon() && message.isPresent("solo_stats") -> "solo_stats"
dungeonConfig.fairy && DungeonAPI.inDungeon() && message.isPresent("fairy") -> "fairy"
- else -> ""
+ else -> null
}
/**
@@ -506,7 +504,7 @@ object ChatFilter {
* @return Block reason if applicable
* @see block
*/
- private fun powderMiningBlock(event: LorenzChatEvent): String {
+ private fun powderMiningBlock(event: LorenzChatEvent): String? {
val powderMiningMatchResult = PowderMiningChatFilter.block(event.message)
if (powderMiningMatchResult == "no_filter") {
genericMiningRewardMessage.matchMatcher(event.message) {
@@ -516,12 +514,12 @@ object ChatFilter {
} ?: "§a+§r"
event.chatComponent = ChatComponentText("$amountFormat $reward")
}
- return ""
+ return null
}
return powderMiningMatchResult
}
- private var othersMsg = ""
+ private var othersMsg: String? = null
/**
* Checks if the message is an "other" message.
@@ -544,9 +542,9 @@ object ChatFilter {
message.isPresent("winter_island") -> "winter_island"
message.isPresent("useless_warning") -> "useless_warning"
message.isPresent("annoying_spam") -> "annoying_spam"
- else -> ""
+ else -> null
}
- return othersMsg != ""
+ return othersMsg != null
}
/**
diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/PowderMiningChatFilter.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/PowderMiningChatFilter.kt
index 600a615ae..1d414cea4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/chat/PowderMiningChatFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/chat/PowderMiningChatFilter.kt
@@ -238,7 +238,7 @@ object PowderMiningChatFilter {
"§r§[fa9][❤❈☘⸕✎✧] (?<tier>Rough|Flawed|Fine) (?<gem>Ruby|Amethyst|Jade|Amber|Sapphire|Topaz) Gemstone( §r§8x(?<amount>[\\d,]+))?",
)
- fun block(message: String): String {
+ fun block(message: String): String? {
// Generic "you uncovered a chest" message
if (uncoverChestPattern.matches(message)) return "powder_mining_chest"
if (successfulPickPattern.matches(message)) return "powder_mining_picked"
@@ -250,14 +250,14 @@ object PowderMiningChatFilter {
return "reward_wrapper"
}
- if (!unclosedRewards) return ""
+ if (!unclosedRewards) return null
if (lockPickedPattern.matches(message)) return "powder_chest_lockpicked"
if (lootChestCollectedPattern.matches(message)) return "loot_chest_opened"
if (rewardHeaderPattern.matches((message))) return "powder_reward_header"
// All powder and loot chest rewards start with 4 spaces
// To simplify regex statements, this check is done outside
- val ssMessage = message.takeIf { it.startsWith(" ") }?.substring(4) ?: return ""
+ val ssMessage = message.takeIf { it.startsWith(" ") }?.substring(4) ?: return null
//Powder
powderRewardPattern.matchMatcher(ssMessage) {
@@ -281,15 +281,15 @@ object PowderMiningChatFilter {
}
}
- blockSimpleRewards(ssMessage).takeIf { it.isNotEmpty() }?.let { return it }
- blockGoblinEggs(ssMessage).takeIf { it.isNotEmpty() }?.let { return it }
- blockGemstones(ssMessage).takeIf { it.isNotEmpty() }?.let { return it }
+ blockSimpleRewards(ssMessage)?.let { return it }
+ blockGoblinEggs(ssMessage)?.let { return it }
+ blockGemstones(ssMessage)?.let { return it }
//Fallback default
- return ""
+ return null
}
- private fun blockSimpleRewards(ssMessage: String): String {
+ private fun blockSimpleRewards(ssMessage: String): String? {
val rewardPatterns = mapOf(
ascensionRopeRewardPattern to ASCENSION_ROPE to "powder_mining_ascension_rope",
wishingCompassRewardPattern to WISHING_COMPASS to "powder_mining_wishing_compass",
@@ -308,24 +308,26 @@ object PowderMiningChatFilter {
else "no_filter"
}
}
- return ""
+ return null
}
- private fun blockGoblinEggs(ssMessage: String): String {
+ private fun blockGoblinEggs(ssMessage: String): String? {
goblinEggPattern.matchMatcher(ssMessage) {
if (config.goblinEggs == PowderMiningFilterConfig.GoblinEggFilterEntry.SHOW_ALL) return "no_filter"
if (config.goblinEggs == PowderMiningFilterConfig.GoblinEggFilterEntry.HIDE_ALL) return "powder_mining_goblin_eggs"
- val colorStr = groupOrNull("color")?.lowercase() ?: ""
+ val colorStr = groupOrNull("color")?.lowercase()
return when (colorStr) {
//'Colorless', base goblin eggs will never be shown in this code path
- "" -> "powder_mining_goblin_eggs"
+ null -> "powder_mining_goblin_eggs"
"green" -> if (config.goblinEggs > PowderMiningFilterConfig.GoblinEggFilterEntry.GREEN_UP) {
"powder_mining_goblin_eggs"
} else "no_filter"
+
"yellow" -> if (config.goblinEggs > PowderMiningFilterConfig.GoblinEggFilterEntry.YELLOW_UP) {
"powder_mining_goblin_eggs"
} else "no_filter"
+
"red" -> if (config.goblinEggs > PowderMiningFilterConfig.GoblinEggFilterEntry.RED_UP) {
"powder_mining_goblin_eggs"
} else "no_filter"
@@ -336,22 +338,19 @@ object PowderMiningChatFilter {
ErrorManager.logErrorWithData(
NoSuchElementException(),
"Unknown Goblin Egg color detected in Powder Mining Filter: '${colorStr}' - please report this in the Discord!",
- noStackTrace = true
+ noStackTrace = true,
)
"no_filter"
}
}
}
- return ""
+ return null
}
- private fun blockGemstones(ssMessage: String): String {
+ private fun blockGemstones(ssMessage: String): String? {
gemstonePattern.matchMatcher(ssMessage) {
- val gemStr = groupOrNull("gem")?.lowercase() ?: ""
- val tierStr = groupOrNull("tier")?.lowercase() ?: ""
-
- //Theoretically impossible but ?
- if (gemStr.isEmpty() || tierStr.isEmpty()) return ""
+ val gemStr = groupOrNull("gem")?.lowercase() ?: return null
+ val tierStr = groupOrNull("tier")?.lowercase() ?: return null
val gemSpecificFilterEntry = when (gemStr) {
"ruby" -> gemstoneConfig.rubyGemstones
@@ -380,6 +379,6 @@ object PowderMiningChatFilter {
else -> "no_filter"
}
}
- return ""
+ return null
}
}