diff --git a/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt index e3d256b2164a..834ccaa5573f 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt @@ -2,14 +2,14 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigFileType +import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson +import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson.PlayerFriends.Friend import at.hannibal2.skyhanni.events.HypixelJoinEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson -import at.hannibal2.skyhanni.data.jsonobjects.local.FriendsJson.PlayerFriends.Friend import net.minecraft.util.ChatStyle import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.UUID diff --git a/src/main/java/at/hannibal2/skyhanni/data/GuildAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/GuildAPI.kt index cb8288e52e45..5a4fb4f99fc4 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GuildAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GuildAPI.kt @@ -38,4 +38,4 @@ object GuildAPI { fun isInGuild(name: String) = ProfileStorageData.playerSpecific?.guildMembers?.let { name in it } ?: false -} \ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt index c823d83f0017..e624af88c6d9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/CompactSplashPotionMessage.kt @@ -3,49 +3,59 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.groupOrNull +import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CompactSplashPotionMessage { private val config get() = SkyHanniMod.feature.chat.compactPotionMessages - private val potionEffectPattern = - "§a§lBUFF! §fYou have gained §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() - private val potionSplashEffectOthersPattern = - "§a§lBUFF! §fYou were splashed by (?.*) §fwith §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() - private val potionSplashEffectPattern = - "§a§lBUFF! §fYou splashed yourself with §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern() + private val potionEffectPatternList = listOf( + "§a§lBUFF! §fYou were splashed by (?.*) §fwith §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(), + "§a§lBUFF! §fYou have gained §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(), + "§a§lBUFF! §fYou splashed yourself with §r(?.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(), + + // Fix for Hypixel having a different message for Poisoned Candy. + // Did not make the first pattern optional to prevent conflicts with Dungeon Buffs/other things + "§a§lBUFF! §fYou have gained §r(?§2Poisoned Candy I)§r§f!§r".toPattern(), + "§a§lBUFF! §fYou splashed yourself with §r(?§2Poisoned Candy I)§r§f!§r".toPattern(), + "§a§lBUFF! §fYou were splashed by (?.*) §fwith §r(?§2Poisoned Candy I)§r§f!§r".toPattern() + ) @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock || !config.enabled) return - - potionEffectPattern.matchMatcher(event.message) { - val name = group("name") - sendMessage("§a§lPotion Effect! §r$name") - event.blockedReason = "compact_potion_effect" - } - - potionSplashEffectOthersPattern.matchMatcher(event.message) { - val playerName = group("playerName").removeColor() - val effectName = group("effectName") - sendMessage("§a§lPotion Effect! §r$effectName by §b$playerName") - event.blockedReason = "compact_potion_effect" - } - - potionSplashEffectPattern.matchMatcher(event.message) { - val name = group("name") - sendMessage("§a§lPotion Effect! §r$name") - event.blockedReason = "compact_potion_effect" - } + if (!isEnabled()) return + if (!event.message.isPotionMessage()) return + event.blockedReason = "compact_potion_effect" } private fun sendMessage(message: String) { if (config.clickableChatMessage) { - LorenzUtils.hoverableChat(message, listOf("§eClick to view your potion effects."), "/effects") + LorenzUtils.hoverableChat( + message, + listOf("§eClick to view your potion effects."), + "/effects", + prefix = false + ) } else { - LorenzUtils.chat(message) + LorenzUtils.chat(message, prefix = false) } } + + private fun String.isPotionMessage(): Boolean { + return potionEffectPatternList.any { + it.matchMatcher(this) { + val effectName = group("effectName") + // If splashed by a player, append their name. + val byPlayer = groupOrNull("playerName")?.let { player -> + val displayName = player.cleanPlayerName(displayName = true) + " §aby $displayName" + } ?: "" + sendMessage("§a§lPotion Effect! §r$effectName$byPlayer") + } != null + } + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled } diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt index 9a28dcc06e40..46e2e051426a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonRankTabListColor.kt @@ -20,13 +20,13 @@ class DungeonRankTabListColor { val playerName = group("playerName") val split = playerName.split(" ") val sbLevel = split[0] - val cleanName = split[1].cleanPlayerName() + val cleanName = split[1].cleanPlayerName(displayName = true) val className = group("className") val level = group("classLevel").romanToDecimal() val color = getColor(level) - event.text = "$sbLevel §b$cleanName §7(§e$className $color$level§7)" + event.text = "$sbLevel $cleanName §7(§e$className $color$level§7)" } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt index 01aabed387b4..14422e6b46ad 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/GriffinBurrowHelper.kt @@ -152,7 +152,6 @@ object GriffinBurrowHelper { val playerLocation = LocationUtils.playerLocation() if (config.inquisitorSharing.enabled) { for (inquis in InquisitorWaypointShare.waypoints.values) { - val playerName = inquis.fromPlayer val location = inquis.location event.drawColor(location, LorenzColor.LIGHT_PURPLE) val distance = location.distance(playerLocation) @@ -163,9 +162,9 @@ object GriffinBurrowHelper { event.drawDynamicText(location.add(y = 1), "§d§lInquisitor", 1.7) } if (distance < 5) { - InquisitorWaypointShare.maybeRemove(playerName) + InquisitorWaypointShare.maybeRemove(inquis) } - event.drawDynamicText(location.add(y = 1), "§eFrom §b$playerName", 1.6, yOff = 9f) + event.drawDynamicText(location.add(y = 1), "§eFrom §b${inquis.displayName}", 1.6, yOff = 9f) if (config.inquisitorSharing.showDespawnTime) { val spawnTime = inquis.spawnTime diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index a99be4102697..5532d70e9786 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -1,6 +1,5 @@ package at.hannibal2.skyhanni.features.event.diana - import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -47,7 +46,12 @@ object InquisitorWaypointShare { var waypoints = mapOf() - class SharedInquisitor(val fromPlayer: String, val location: LorenzVec, val spawnTime: SimpleTimeMark) + class SharedInquisitor( + val fromPlayer: String, + val displayName: String, + val location: LorenzVec, + val spawnTime: SimpleTimeMark + ) private var test = false @@ -221,22 +225,23 @@ object InquisitorWaypointShare { if (packet.type.toInt() != 0) return partyPattern.matchMatcher(message) { - val playerName = group("playerName") + val rawName = group("playerName") val x = group("x").trim().toInt() val y = group("y").trim().toInt() val z = group("z").trim().toInt() val location = LorenzVec(x, y, z) - val cleanName = playerName.cleanPlayerName() - if (!waypoints.containsKey(cleanName)) { - LorenzUtils.chat("$playerName §l§efound an inquisitor at §l§c$x $y $z!") - if (cleanName != LorenzUtils.getPlayerName()) { - LorenzUtils.sendTitle("§dINQUISITOR §efrom §b$cleanName", 5.seconds) + val name = rawName.cleanPlayerName() + val displayName = rawName.cleanPlayerName(displayName = true) + if (!waypoints.containsKey(name)) { + LorenzUtils.chat("$displayName §l§efound an inquisitor at §l§c$x $y $z!") + if (name != LorenzUtils.getPlayerName()) { + LorenzUtils.sendTitle("§dINQUISITOR §efrom §b$displayName", 5.seconds) SoundUtils.playBeepSound() } } - val inquis = SharedInquisitor(cleanName, location, SimpleTimeMark.now()) - waypoints = waypoints.editCopy { this[cleanName] = inquis } + val inquis = SharedInquisitor(name, displayName, location, SimpleTimeMark.now()) + waypoints = waypoints.editCopy { this[name] = inquis } if (config.focusInquisitor) { GriffinBurrowHelper.setTargetLocation(location.add(y = 1)) GriffinBurrowHelper.animationLocation = LocationUtils.playerLocation() @@ -245,18 +250,20 @@ object InquisitorWaypointShare { event.isCanceled = true } diedPattern.matchMatcher(message) { - val playerName = group("playerName").cleanPlayerName() - waypoints = waypoints.editCopy { remove(playerName) } - logger.log("Inquisitor died from '$playerName'") + val rawName = group("playerName") + val name = rawName.cleanPlayerName() + val displayName = rawName.cleanPlayerName(displayName = true) + waypoints = waypoints.editCopy { remove(name) } + logger.log("Inquisitor died from '$displayName'") } } fun isEnabled() = DianaAPI.featuresEnabled() && config.enabled - fun maybeRemove(playerName: String) { + fun maybeRemove(inquis: SharedInquisitor) { if (inquisitorsNearby.isEmpty()) { - waypoints = waypoints.editCopy { remove(playerName) } - LorenzUtils.chat("Inquisitor from $playerName not found, deleting.") + waypoints = waypoints.editCopy { remove(inquis.fromPlayer) } + LorenzUtils.chat("Inquisitor from ${inquis.displayName} not found, deleting.") } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index 80c3b870d729..d08dd888ad0d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -63,6 +63,7 @@ class NonGodPotEffectDisplay { private var patternEffectsCount = "§7You have §e(?\\d+) §7non-god effects\\.".toPattern() private var totalEffectsCount = 0 + // todo : cleanup and add support for poison candy I, and add support for splash / other formats @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { if (event.message == "§aYou cleared all of your active effects!") { @@ -95,6 +96,7 @@ class NonGodPotEffectDisplay { effectDuration[NonGodPotEffect.GOBLIN] = Timer(20.minutes) update() } + if (event.message == "§cThe Goblin King's §r§afoul stench §r§chas dissipated!") { effectDuration.remove(NonGodPotEffect.GOBLIN) update() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 3d7e024ecc91..9650a1f0a829 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -36,6 +36,7 @@ import java.text.SimpleDateFormat import java.util.Collections import java.util.Timer import java.util.TimerTask +import java.util.regex.Matcher import kotlin.properties.ReadWriteProperty import kotlin.reflect.KMutableProperty1 import kotlin.reflect.KProperty @@ -644,4 +645,12 @@ object LorenzUtils { } FMLCommonHandler.instance().handleExit(-1) } + + /** + * Get the group, otherwise, return null + * @param groupName The group name in the pattern + */ + fun Matcher.groupOrNull(groupName: String): String? { + return runCatching { this.group(groupName) }.getOrNull() + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 8c75475c91ad..cb7a0fa2353e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.mixins.transformers.AccessorChatComponentText import at.hannibal2.skyhanni.utils.GuiRenderUtils.darkenColor import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -80,7 +81,7 @@ object StringUtils { inline fun Pattern.matchMatcher(text: String, consumer: Matcher.() -> T) = matcher(text).let { if (it.matches()) consumer(it) else null } - fun String.cleanPlayerName(): String { + private fun String.internalCleanPlayerName(): String { val split = trim().split(" ") return if (split.size > 1) { split[1].removeColor() @@ -89,6 +90,16 @@ object StringUtils { } } + fun String.cleanPlayerName(displayName: Boolean = false): String { + return if (displayName) { + if (SkyHanniMod.feature.chat.playerMessage.playerRankHider) { + "§b" + internalCleanPlayerName() + } else this + } else { + internalCleanPlayerName() + } + } + inline fun List.matchMatchers(text: String, consumer: Matcher.() -> T): T? { for (pattern in iterator()) { pattern.matchMatcher(text) {