diff options
author | nobaboy <84668101+nobaboy@users.noreply.github.com> | 2024-04-24 00:07:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-23 23:07:14 +0200 |
commit | 7175920bcccf4036109a937d2967612732eeafaa (patch) | |
tree | fa5770b562c333d2a722baa172cd4b63e70e9868 | |
parent | 2b8b4d90bcda89e1b0c109d6531bf13208bc487b (diff) | |
download | skyhanni-7175920bcccf4036109a937d2967612732eeafaa.tar.gz skyhanni-7175920bcccf4036109a937d2967612732eeafaa.tar.bz2 skyhanni-7175920bcccf4036109a937d2967612732eeafaa.zip |
Fixed transfer command (#1505)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt | 7 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt | 16 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt index dc9e921cc..bb3abad24 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/hypixel/chat/event/PartyChatEvent.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.data.hypixel.chat.event +import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName import net.minecraft.util.IChatComponent class PartyChatEvent( @@ -7,4 +8,8 @@ class PartyChatEvent( message: String, chatComponent: IChatComponent, blockedReason: String? = null, -) : AbstractChatEvent(author, message, chatComponent, blockedReason) +) : AbstractChatEvent(author, message, chatComponent, blockedReason) { + val cleanedAuthor by lazy { + author.cleanPlayerName() + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt index 8ead93fcf..2f53a232d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -19,13 +19,14 @@ object PartyChatCommands { ) private fun useConfig() = SkyHanniMod.feature.misc.partyCommands - val allPartyCommands = listOf( + + private val allPartyCommands = listOf( PartyChatCommand( listOf("pt", "ptme", "transfer"), { useConfig().transferCommand }, requiresPartyLead = true, executable = { - ChatUtils.sendCommandToServer("party transfer ${it.author}") + ChatUtils.sendCommandToServer("party transfer ${it.cleanedAuthor}") } ), PartyChatCommand( @@ -38,7 +39,7 @@ object PartyChatCommands { ), ) - val indexedPartyChatCommands = buildMap { + private val indexedPartyChatCommands = buildMap { for (command in allPartyCommands) { for (name in command.names) { put(name.lowercase(), command) @@ -46,7 +47,7 @@ object PartyChatCommands { } } - fun isTrustedUser(name: String): Boolean { + private fun isTrustedUser(name: String): Boolean { val friend = FriendAPI.getAllFriends().find { it.name == name } return when (useConfig().defaultRequiredTrustLevel) { PartyCommandsConfig.TrustedUser.FRIENDS -> friend != null @@ -64,15 +65,16 @@ object PartyChatCommands { return val commandLabel = event.message.substring(1).substringBefore(' ') val command = indexedPartyChatCommands[commandLabel.lowercase()] ?: return - if (event.author == LorenzUtils.getPlayerName()) { + val name = event.cleanedAuthor + if (name == LorenzUtils.getPlayerName()) { return } if (!command.isEnabled()) return if (command.requiresPartyLead && PartyAPI.partyLeader != LorenzUtils.getPlayerName()) { return } - if (!isTrustedUser(event.author)) { - ChatUtils.chat("§cIgnoring chat command from ${event.author}. Change your party chat command settings or /friend (best) them.") + if (!isTrustedUser(name)) { + ChatUtils.chat("§cIgnoring chat command from $name. Change your party chat command settings or /friend (best) them.") return } command.executable(event) |