diff options
5 files changed, 106 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index c14023dba..f7101cd4b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -612,6 +612,7 @@ object Commands { registerCommand("pt", "Transfer the party to another party member") { PartyCommands.transfer(it) } registerCommand("pp", "Promote a specific party member") { PartyCommands.promote(it) } registerCommand("pd", "Disbands the party") { PartyCommands.disband() } + registerCommand("rpt", "Reverse transfer party to the previous leader") { PartyCommands.reverseTransfer() } } @JvmStatic diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java index 783d43d74..1747baee6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/commands/CommandsConfig.java @@ -18,6 +18,11 @@ public class CommandsConfig { @Expose public BetterWikiCommandConfig betterWiki = new BetterWikiCommandConfig(); + @ConfigOption(name = "Reverse Party Transfer", desc = "") + @Accordion + @Expose + public ReversePartyTransferConfig reversePT = new ReversePartyTransferConfig(); + @ConfigOption(name = "Party Commands", desc = "Shortens party commands and allows tab-completing for them. " + "\n§eCommands: /pt, /pp, /pko, /pk, /pd §7(SkyBlock command §e/pt §7to check your play time will still work)") @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/commands/ReversePartyTransferConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/commands/ReversePartyTransferConfig.java new file mode 100644 index 000000000..555733667 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/commands/ReversePartyTransferConfig.java @@ -0,0 +1,27 @@ +package at.hannibal2.skyhanni.config.features.commands; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class ReversePartyTransferConfig { + + @Expose + @ConfigOption(name = "Command", desc = "Adds §e/rpt §7to transfer a party back to its previous leader.") + @ConfigEditorBoolean + @FeatureToggle + public boolean command = true; + + @Expose + @ConfigOption(name = "Clickable Message", desc = "Allows transfer message to be clicked to transfer a party back to its previous leader if it has been transferred to you.") + @ConfigEditorBoolean + @FeatureToggle + public boolean clickable = false; + + @Expose + @ConfigOption(name = "Response Message", desc = "Sends a custom message to party chat when the party is reverse transferred.") + @ConfigEditorText + public String message = "Nuh Uh"; +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index f06619169..2ee30c27e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -21,68 +21,69 @@ object PartyAPI { private val patternGroup = RepoPattern.group("data.party") private val youJoinedPartyPattern by patternGroup.pattern( "you.joined", - "§eYou have joined (?<name>.*)'s? §eparty!" + "§eYou have joined (?<name>.*)'s? §eparty!", ) private val othersJoinedPartyPattern by patternGroup.pattern( "others.joined", - "(?<name>.*) §ejoined the party\\." + "(?<name>.*) §ejoined the party\\.", ) private val othersInThePartyPattern by patternGroup.pattern( "others.inparty", - "§eYou'll be partying with: (?<names>.*)" + "§eYou'll be partying with: (?<names>.*)", ) private val otherLeftPattern by patternGroup.pattern( "others.left", - "(?<name>.*) §ehas left the party\\." + "(?<name>.*) §ehas left the party\\.", ) private val otherKickedPattern by patternGroup.pattern( "others.kicked", - "(?<name>.*) §ehas been removed from the party\\." + "(?<name>.*) §ehas been removed from the party\\.", ) private val otherOfflineKickedPattern by patternGroup.pattern( "others.offline", - "§eKicked (?<name>.*) because they were offline\\." + "§eKicked (?<name>.*) because they were offline\\.", ) private val otherDisconnectedPattern by patternGroup.pattern( "others.disconnect", - "(?<name>.*) §ewas removed from your party because they disconnected\\." + "(?<name>.*) §ewas removed from your party because they disconnected\\.", ) private val transferOnLeavePattern by patternGroup.pattern( "others.transfer.leave", - "The party was transferred to (?<newowner>.*) because (?<name>.*) left" + "The party was transferred to (?<newowner>.*) because (?<name>.*) left", ) - private val transferVoluntaryPattern by patternGroup.pattern( + val transferVoluntaryPattern by patternGroup.pattern( "others.transfer.voluntary", - "The party was transferred to (?<newowner>.*) by .*" + "The party was transferred to (?<newowner>.*) by (?<name>.*)", ) private val disbandedPattern by patternGroup.pattern( "others.disband", - ".* §ehas disbanded the party!" + ".* §ehas disbanded the party!", ) private val kickedPattern by patternGroup.pattern( "you.kicked", - "§eYou have been kicked from the party by .* §e" + "§eYou have been kicked from the party by .* §e", ) private val partyMembersStartPattern by patternGroup.pattern( "members.start", - "§6Party Members \\(\\d+\\)" + "§6Party Members \\(\\d+\\)", ) private val partyMemberListPattern by patternGroup.pattern( "members.list.withkind", - "Party (?<kind>Leader|Moderators|Members): (?<names>.*)" + "Party (?<kind>Leader|Moderators|Members): (?<names>.*)", ) private val kuudraFinderJoinPattern by patternGroup.pattern( "kuudrafinder.join", - "§dParty Finder §f> (?<name>.*?) §ejoined the group! \\(§[a-fA-F0-9]+Combat Level \\d+§e\\)" + "§dParty Finder §f> (?<name>.*?) §ejoined the group! \\(§[a-fA-F0-9]+Combat Level \\d+§e\\)", ) private val dungeonFinderJoinPattern by patternGroup.pattern( "dungeonfinder.join", - "§dParty Finder §f> (?<name>.*?) §ejoined the dungeon group! \\(§[a-fA-F0-9].* Level \\d+§[a-fA-F0-9]\\)" + "§dParty Finder §f> (?<name>.*?) §ejoined the dungeon group! \\(§[a-fA-F0-9].* Level \\d+§[a-fA-F0-9]\\)", ) val partyMembers = mutableListOf<String>() var partyLeader: String? = null + var prevPartyLeader: String? = null fun listMembers() { val size = partyMembers.size @@ -145,15 +146,15 @@ object PartyAPI { // one member got removed otherLeftPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() - partyMembers.remove(name) + removeWithLeader(name) } otherKickedPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() - partyMembers.remove(name) + removeWithLeader(name) } otherOfflineKickedPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() - partyMembers.remove(name) + removeWithLeader(name) } otherDisconnectedPattern.matchMatcher(message) { val name = group("name").cleanPlayerName() @@ -166,6 +167,7 @@ object PartyAPI { } transferVoluntaryPattern.matchMatcher(message.removeColor()) { partyLeader = group("newowner").cleanPlayerName() + prevPartyLeader = group("name").cleanPlayerName() } // party disbanded @@ -201,6 +203,13 @@ object PartyAPI { } } + private fun removeWithLeader(name: String) { + partyMembers.remove(name) + if (name == prevPartyLeader) { + prevPartyLeader = null + } + } + private fun addPlayer(playerName: String) { if (partyMembers.contains(playerName)) return if (playerName == LorenzUtils.getPlayerName()) return @@ -210,5 +219,6 @@ object PartyAPI { private fun partyLeft() { partyMembers.clear() partyLeader = null + prevPartyLeader = null } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt index c60c84ae5..e7b3333dd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt @@ -4,11 +4,20 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.data.FriendAPI import at.hannibal2.skyhanni.data.PartyAPI +import at.hannibal2.skyhanni.data.PartyAPI.partyLeader +import at.hannibal2.skyhanni.data.PartyAPI.transferVoluntaryPattern +import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.features.misc.limbo.LimboTimeTracker import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.EntityUtils import at.hannibal2.skyhanni.utils.HypixelCommands +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RegexUtils.matches +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpace +import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @SkyHanniModule @@ -67,14 +76,29 @@ object PartyCommands { HypixelCommands.partyPromote(args[0]) } + fun reverseTransfer() { + if (!config.reversePT.command) return + if (PartyAPI.partyMembers.isEmpty()) return + val prevPartyLeader = PartyAPI.prevPartyLeader ?: return + + autoPartyTransfer(prevPartyLeader) + } + + private fun autoPartyTransfer(prevPartyLeader: String) { + HypixelCommands.partyTransfer(prevPartyLeader) + config.reversePT.message?.let { + if (it.isNotBlank()) { + HypixelCommands.partyChat(it) + } + } + } + @SubscribeEvent fun onMessageSendToServer(event: MessageSendToServerEvent) { if (!config.partyKickReason) { return } - if (!event.message.startsWith("/party kick ", ignoreCase = true) - && !event.message.startsWith("/p kick ", ignoreCase = true) - ) { + if (!event.message.startsWith("/party kick ", ignoreCase = true) && !event.message.startsWith("/p kick ", ignoreCase = true)) { return } val args = event.message.substringAfter("kick").trim().split(" ") @@ -116,6 +140,22 @@ object PartyCommands { event.move(31, "commands", "misc.commands") } + + @SubscribeEvent(priority = EventPriority.LOW) + fun onChat(event: LorenzChatEvent) { + if (!config.reversePT.clickable) return + if (!transferVoluntaryPattern.matches(event.message.trimWhiteSpace().removeColor())) return + if (partyLeader != LorenzUtils.getPlayerName()) return + + val prevPartyLeader = PartyAPI.prevPartyLeader ?: return + event.blockedReason = "replacing" + + ChatUtils.clickableChat( + event.message, + onClick = { autoPartyTransfer(prevPartyLeader) }, + prefix = false, + ) + } } private val otherPartyCommands = listOf( @@ -126,5 +166,5 @@ private val otherPartyCommands = listOf( "Mute", "Private", "Warp", - "Settings" + "Settings", ) |