diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-04-24 08:41:11 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 00:41:11 +0200 |
commit | c2a0e59d760b64b0fe7d1676470ebf931434be6d (patch) | |
tree | 9a42a880b175d34c2b2815648fdb8a62f72f4a03 /src | |
parent | 53da6585ecb9b4cc123707d54556b85a8500b599 (diff) | |
download | skyhanni-c2a0e59d760b64b0fe7d1676470ebf931434be6d.tar.gz skyhanni-c2a0e59d760b64b0fe7d1676470ebf931434be6d.tar.bz2 skyhanni-c2a0e59d760b64b0fe7d1676470ebf931434be6d.zip |
Feature: Allow party members to request allinvite to be enabled (#1464)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
3 files changed, 32 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java index fb28b6544..cee11c99b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/PartyCommandsConfig.java @@ -23,6 +23,11 @@ public class PartyCommandsConfig { @ConfigOption(name = "Party Warp", desc = "Automatically warp the party if someone types §b!warp") public boolean warpCommand = false; + @Expose + @ConfigEditorBoolean + @ConfigOption(name = "Party All Invite", desc = "Automatically turn on allinvite if someone types §b!allinv") + public boolean allInviteCommand = false; + public enum TrustedUser { BEST_FRIENDS("Best Friends"), FRIENDS("Friends"), diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index 3bd3967be..10739720a 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -168,19 +168,16 @@ object PartyAPI { // party disbanded disbandedPattern.matchMatcher(message) { - partyMembers.clear() - partyLeader = null + partyLeft() } kickedPattern.matchMatcher(message) { - partyMembers.clear() - partyLeader = null + partyLeft() } if (message == "§eYou left the party." || message == "§cThe party was disbanded because all invites expired and the party was empty." || message == "§cYou are not currently in a party." ) { - partyMembers.clear() - partyLeader = null + partyLeft() } // party list @@ -206,4 +203,9 @@ object PartyAPI { if (playerName == LorenzUtils.getPlayerName()) return partyMembers.add(playerName) } + + private fun partyLeft() { + partyMembers.clear() + partyLeader = null + } } 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<String>, 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 |