From 952b6afe61c374a20f0f417258f0f5d5f1110e55 Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Mon, 23 Oct 2023 02:59:36 +1100 Subject: Feature: Add Party Commands (#584) Added shortcuts for Party commands and smart tab complete. --- .../skyhanni/features/commands/PartyCommands.kt | 82 ++++++++++++++++++++++ .../features/commands/PartyTransferCommand.kt | 26 ------- .../commands/tabcomplete/PlayerTabComplete.kt | 6 +- .../features/commands/tabcomplete/TabComplete.kt | 2 + 4 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/commands/PartyTransferCommand.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features/commands') diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt new file mode 100644 index 000000000..0b4da88ab --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyCommands.kt @@ -0,0 +1,82 @@ +package at.hannibal2.skyhanni.features.commands + +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.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object PartyCommands { + private val config get() = SkyHanniMod.feature.commands + fun kickOffline() { + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + LorenzUtils.sendCommandToServer("party kickoffline") + } + + fun warp() { + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + LorenzUtils.sendCommandToServer("party warp") + } + + fun kick(args: Array) { + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + if (args.isEmpty()) return + LorenzUtils.sendCommandToServer("party kick ${args[0]}") + } + + fun transfer(args: Array) { + if (args.isEmpty()) LorenzUtils.sendCommandToServer("pt") + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + LorenzUtils.sendCommandToServer("party transfer ${args[0]}") + } + + fun promote(args: Array) { + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + if (args.isEmpty()) return + LorenzUtils.sendCommandToServer("party promote ${args[0]}") + } + + fun customTabComplete(command: String): List? { + if (command == "pk" || command == "pt" || command == "pp" && config.shortCommands) { + return PartyAPI.partyMembers + } + + if (command == "p" || command == "party") { + val friends = if (config.tabComplete.friends) { + FriendAPI.getAllFriends().filter { it.bestFriend || config.tabComplete.onlyBestFriends }.map { it.name } + } else { + emptyList() + } + return friends + getPartyCommands() + } + return null + } + + private fun getPartyCommands(): List { + return if (config.tabComplete.partyCommands && PartyAPI.partyMembers.isNotEmpty()) { + otherPartyCommands + } else emptyList() + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(5, "commands.usePartyTransferAlias", "commands.shortCommands") + } +} + +private val otherPartyCommands = listOf( + "Disband", + "KickOffline", + "Leave", + "List", + "Mute", + "Private", + "Warp", + "Settings" +) \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyTransferCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/PartyTransferCommand.kt deleted file mode 100644 index 485a3569f..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/PartyTransferCommand.kt +++ /dev/null @@ -1,26 +0,0 @@ -package at.hannibal2.skyhanni.features.commands - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import net.minecraft.network.play.client.C01PacketChatMessage -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class PartyTransferCommand { - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - if (!SkyHanniMod.feature.commands.usePartyTransferAlias) return - - val packet = event.packet - if (packet is C01PacketChatMessage) { - val pattern = "/pt (?.*)".toPattern() - pattern.matchMatcher(packet.message.lowercase()) { - event.isCanceled = true - val args = group("args") - LorenzUtils.sendCommandToServer("party transfer $args") - } - } - } - -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/PlayerTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/PlayerTabComplete.kt index 688d6f6b3..e6b2baaf8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/PlayerTabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/PlayerTabComplete.kt @@ -27,16 +27,12 @@ object PlayerTabComplete { } enum class PlayerCategory { - PARTY, FRIENDS, ISLAND_PLAYERS, } fun handleTabComplete(command: String): List? { val commands = mapOf( - "p" to listOf(PlayerCategory.PARTY), - "party" to listOf(PlayerCategory.PARTY), - "pt" to listOf(PlayerCategory.FRIENDS, PlayerCategory.ISLAND_PLAYERS), // /party transfer "f" to listOf(PlayerCategory.FRIENDS), "friend" to listOf(PlayerCategory.FRIENDS), @@ -69,7 +65,7 @@ object PlayerTabComplete { } } - if (config.party && PlayerCategory.PARTY !in ignored) { + if (config.party) { for (member in PartyAPI.partyMembers) { add(member) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/TabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/TabComplete.kt index 352748c0b..9c03e3a87 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/TabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/TabComplete.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.commands.tabcomplete +import at.hannibal2.skyhanni.features.commands.PartyCommands import at.hannibal2.skyhanni.features.misc.CollectionTracker object TabComplete { @@ -24,6 +25,7 @@ object TabComplete { WarpTabComplete.handleTabComplete(command)?.let { return it } PlayerTabComplete.handleTabComplete(command)?.let { return it } CollectionTracker.handleTabComplete(command)?.let { return it } + PartyCommands.customTabComplete(command)?.let { return it } return null } -- cgit