From c2a0e59d760b64b0fe7d1676470ebf931434be6d Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Wed, 24 Apr 2024 08:41:11 +1000 Subject: Feature: Allow party members to request allinvite to be enabled (#1464) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/commands/PartyChatCommands.kt | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/commands') 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 2f53a232d..8bb8e46ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyChatCommands.kt @@ -7,10 +7,14 @@ import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.data.hypixel.chat.event.PartyChatEvent import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds object PartyChatCommands { + private val config get() = SkyHanniMod.feature.misc.partyCommands + data class PartyChatCommand( val names: List, val isEnabled: () -> Boolean, @@ -18,12 +22,13 @@ object PartyChatCommands { val executable: (PartyChatEvent) -> Unit, ) - private fun useConfig() = SkyHanniMod.feature.misc.partyCommands + private var lastWarp = SimpleTimeMark.farPast() + private var lastAllInvite = SimpleTimeMark.farPast() private val allPartyCommands = listOf( PartyChatCommand( listOf("pt", "ptme", "transfer"), - { useConfig().transferCommand }, + { config.transferCommand }, requiresPartyLead = true, executable = { ChatUtils.sendCommandToServer("party transfer ${it.cleanedAuthor}") @@ -31,12 +36,22 @@ object PartyChatCommands { ), PartyChatCommand( listOf("pw", "warp", "warpus"), - { useConfig().warpCommand }, + { config.warpCommand && lastWarp.passedSince() > 5.seconds }, requiresPartyLead = true, executable = { + lastWarp = SimpleTimeMark.now() ChatUtils.sendCommandToServer("party warp") } ), + PartyChatCommand( + listOf("allinv", "allinvite"), + { config.allInviteCommand && lastAllInvite.passedSince() > 2.seconds }, + requiresPartyLead = true, + executable = { + lastAllInvite = SimpleTimeMark.now() + ChatUtils.sendCommandToServer("party settings allinvite") + } + ), ) private val indexedPartyChatCommands = buildMap { @@ -49,7 +64,7 @@ object PartyChatCommands { private fun isTrustedUser(name: String): Boolean { val friend = FriendAPI.getAllFriends().find { it.name == name } - return when (useConfig().defaultRequiredTrustLevel) { + return when (config.defaultRequiredTrustLevel) { PartyCommandsConfig.TrustedUser.FRIENDS -> friend != null PartyCommandsConfig.TrustedUser.BEST_FRIENDS -> friend?.bestFriend == true PartyCommandsConfig.TrustedUser.ANYONE -> true -- cgit