Skip to content

Commit

Permalink
Merge branch 'hannibal002:beta' into item-stack-size
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDeeUx authored Dec 4, 2023
2 parents ae2a379 + d9a1a8d commit 4d9976f
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/FriendAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/data/GuildAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ object GuildAPI {
fun isInGuild(name: String) = ProfileStorageData.playerSpecific?.guildMembers?.let {
name in it
} ?: false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<name>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
private val potionSplashEffectOthersPattern =
"§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
private val potionSplashEffectPattern =
"§a§lBUFF! §fYou splashed yourself with §r(?<name>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern()
private val potionEffectPatternList = listOf(
"§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(),
"§a§lBUFF! §fYou have gained §r(?<effectName>.*)§r§f! Press TAB or type /effects to view your active effects!".toPattern(),
"§a§lBUFF! §fYou splashed yourself with §r(?<effectName>.*)§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(?<effectName>§2Poisoned Candy I)§r§f!§r".toPattern(),
"§a§lBUFF! §fYou splashed yourself with §r(?<effectName>§2Poisoned Candy I)§r§f!§r".toPattern(),
"§a§lBUFF! §fYou were splashed by (?<playerName>.*) §fwith §r(?<effectName>§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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -47,7 +46,12 @@ object InquisitorWaypointShare {

var waypoints = mapOf<String, SharedInquisitor>()

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

Expand Down Expand Up @@ -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()
Expand All @@ -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.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class NonGodPotEffectDisplay {
private var patternEffectsCount = "§7You have §e(?<name>\\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!") {
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
13 changes: 12 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,7 +81,7 @@ object StringUtils {
inline fun <T> 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()
Expand All @@ -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 <T> List<Pattern>.matchMatchers(text: String, consumer: Matcher.() -> T): T? {
for (pattern in iterator()) {
pattern.matchMatcher<T>(text) {
Expand Down

0 comments on commit 4d9976f

Please sign in to comment.