diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2023-10-23 02:59:36 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-22 17:59:36 +0200 |
commit | 952b6afe61c374a20f0f417258f0f5d5f1110e55 (patch) | |
tree | 9a457c70107bebe02037c5be03f422852a2e8680 /src/main/java | |
parent | 0e981c3cc50bfae6dd6cf4bab0cc7e983f6a2743 (diff) | |
download | skyhanni-952b6afe61c374a20f0f417258f0f5d5f1110e55.tar.gz skyhanni-952b6afe61c374a20f0f417258f0f5d5f1110e55.tar.bz2 skyhanni-952b6afe61c374a20f0f417258f0f5d5f1110e55.zip |
Feature: Add Party Commands (#584)
Added shortcuts for Party commands and smart tab complete.
Diffstat (limited to 'src/main/java')
9 files changed, 126 insertions, 52 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 88618e4c7..a45540926 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -57,7 +57,7 @@ import at.hannibal2.skyhanni.features.chat.PlayerDeathMessages import at.hannibal2.skyhanni.features.chat.WatchdogHider import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatModifier -import at.hannibal2.skyhanni.features.commands.PartyTransferCommand +import at.hannibal2.skyhanni.features.commands.PartyCommands import at.hannibal2.skyhanni.features.commands.SendCoordinatedCommand import at.hannibal2.skyhanni.features.commands.WarpIsCommand import at.hannibal2.skyhanni.features.commands.WikiCommand @@ -372,7 +372,7 @@ class SkyHanniMod { loadModule(CollectionAPI()) loadModule(FarmingContestAPI) loadModule(FriendAPI()) - loadModule(PartyAPI()) + loadModule(PartyAPI) loadModule(GuildAPI) loadModule(SlayerAPI) loadModule(PurseAPI()) @@ -420,7 +420,7 @@ class SkyHanniMod { loadModule(WikiCommand()) loadModule(SendCoordinatedCommand()) loadModule(WarpIsCommand()) - loadModule(PartyTransferCommand()) + loadModule(PartyCommands) loadModule(SummoningMobManager()) loadModule(AreaMiniBossFeatures()) loadModule(MobHighlight()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 1ba66f130..abd448ccd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - val configVersion = 4 + val configVersion = 5 fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null 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 439e6cd0f..9c8894967 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.features.bingo.BingoCardDisplay import at.hannibal2.skyhanni.features.bingo.BingoNextStepHelper import at.hannibal2.skyhanni.features.combat.ghostcounter.GhostUtil +import at.hannibal2.skyhanni.features.commands.PartyCommands import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.features.event.diana.InquisitorWaypointShare import at.hannibal2.skyhanni.features.fame.AccountUpgradeReminder @@ -83,7 +84,7 @@ object Commands { "A Command that is useful for monitoring/debugging existing features. §cIntended for developers only!" ), INTERNAL("§8", "Internal Command", "A Command that should §cnever §7be called manually!"), - + SHORTENED_COMMANDS("§b", "Shortened Commands", "Commands that shorten or improve existing Hypixel commands!") } class CommandInfo(val name: String, val description: String, val category: CommandCategory) @@ -108,6 +109,9 @@ object Commands { currentCategory = CommandCategory.INTERNAL internalCommands() + + currentCategory = CommandCategory.SHORTENED_COMMANDS + shortenedCommands() } private fun usersMain() { @@ -294,6 +298,14 @@ object Commands { // ) { Translator.toEnglish(it) } } + private fun shortenedCommands() { + registerCommand("pko", "Kicks offline party members") { PartyCommands.kickOffline() } + registerCommand("pw", "Warps your party") { PartyCommands.warp() } + registerCommand("pk", "Kick a specific party member") { PartyCommands.kick(it) } + registerCommand("pt", "Transfer the party to another party member") { PartyCommands.transfer(it) } + registerCommand("pp", "Promote a specific party member") { PartyCommands.promote(it) } + } + private fun commandHelp(args: Array<String>) { var filter: (String) -> Boolean = { true } val title: String diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java index 40248d74d..67d60ec2b 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/CommandsConfig.java @@ -54,6 +54,12 @@ public class CommandsConfig { @ConfigEditorBoolean @FeatureToggle public boolean gfsSack = true; + + @Expose + @ConfigOption(name = "Party Commands", desc = "Tab complete commonly used party commands.") + @ConfigEditorBoolean + @FeatureToggle + public boolean partyCommands = true; } @Expose @@ -62,12 +68,11 @@ public class CommandsConfig { @FeatureToggle public boolean useFandomWiki = false; + @ConfigOption(name = "Party Commands", desc = "Shortens party commands and allows tab-completing for them. " + + "\n§eCommands: /pt /pp /pko /pk §7SkyBlock command §e/pt §7to check the play time still works.") @Expose - @ConfigOption(name = "Party transfer", desc = "Allows §e/pt <player> §7as alias for §e/party transfer§7.\n" + - "§7SkyBlock command §e/pt §7to check the play time still works.") @ConfigEditorBoolean - @FeatureToggle - public boolean usePartyTransferAlias = true; + public boolean shortCommands = true; @Expose @ConfigOption(name = "Replace Warp Is", desc = "Adds §e/warp is §7alongside §e/is§7. Idk why. Ask §cKaeso") diff --git a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt index e00ea2c51..c572628b7 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PartyAPI.kt @@ -12,21 +12,24 @@ import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.random.Random -class PartyAPI { - companion object { - fun listMembers() { - LorenzUtils.chat("§a[SkyHanni] Tracked party members §7(${partyMembers.size}) §f:") - for (member in partyMembers) { - LorenzUtils.chat(" §a- §7$member") - } +object PartyAPI { + val partyMembers = mutableListOf<String>() - if (Random.nextDouble() < 0.1) { - OSUtils.openBrowser("https://www.youtube.com/watch?v=iANP7ib7CPA") - LorenzUtils.hoverableChat("§7Are You Ready To Party?", listOf("§b~Spongebob")) - } + fun listMembers() { + val size = partyMembers.size + if (size == 0) { + LorenzUtils.chat("§e[SkyHanni] No tracked party members!") + return + } + LorenzUtils.chat("§a[SkyHanni] Tracked party members §7($size) §f:") + for (member in partyMembers) { + LorenzUtils.chat(" §a- §7$member") } - val partyMembers = mutableListOf<String>() + if (Random.nextDouble() < 0.1) { + OSUtils.openBrowser("https://www.youtube.com/watch?v=iANP7ib7CPA") + LorenzUtils.hoverableChat("§7Are You Ready To Party?", listOf("§b~Spongebob")) + } } @SubscribeEvent 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<String>) { + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + if (args.isEmpty()) return + LorenzUtils.sendCommandToServer("party kick ${args[0]}") + } + + fun transfer(args: Array<String>) { + 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<String>) { + if (!config.shortCommands) return + if (PartyAPI.partyMembers.isEmpty()) return + if (args.isEmpty()) return + LorenzUtils.sendCommandToServer("party promote ${args[0]}") + } + + fun customTabComplete(command: String): List<String>? { + 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<String>() + } + return friends + getPartyCommands() + } + return null + } + + private fun getPartyCommands(): List<String> { + 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 (?<args>.*)".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<String>? { 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 } |