From c614724dd0a92d89fa96c3468be156a407f924db Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:50:08 +0200 Subject: stop initializing the map on every function call Co-authored-by: Empa <42304516+itsempa@users.noreply.github.com> --- .../commands/tabcomplete/PlayerTabComplete.kt | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'src') 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 bf4428211..070ab478e 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 @@ -15,6 +15,24 @@ object PlayerTabComplete { private val config get() = SkyHanniMod.feature.misc.commands.tabComplete private var vipVisits = listOf() + private val ignoredCommandCategories = mapOf( + "f" to listOf(PlayerCategory.FRIENDS), + "friend" to listOf(PlayerCategory.FRIENDS), + + "msg" to listOf(), + "w" to listOf(), + "tell" to listOf(), + "boop" to listOf(), + + "visit" to listOf(), + "invite" to listOf(), + "ah" to listOf(), + + "pv" to listOf(), // NEU's Profile Viewer + "shmarkplayer" to listOf(), // SkyHanni's Mark Player + + "trade" to listOf(PlayerCategory.FRIENDS, PlayerCategory.PARTY), + ) @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { @@ -34,41 +52,21 @@ object PlayerTabComplete { } fun handleTabComplete(command: String): List? { - val commands = mapOf( - "f" to listOf(PlayerCategory.FRIENDS), - "friend" to listOf(PlayerCategory.FRIENDS), - - "msg" to listOf(), - "w" to listOf(), - "tell" to listOf(), - "boop" to listOf(), - - "visit" to listOf(), - "invite" to listOf(), - "ah" to listOf(), - - "pv" to listOf(), // NEU's Profile Viewer - "shmarkplayer" to listOf(), // SkyHanni's Mark Player - - "trade" to listOf(PlayerCategory.FRIENDS, PlayerCategory.PARTY) - ) - val ignored = commands[command] ?: return null + val ignoredCategories = ignoredCommandCategories[command] ?: return null return buildList { - if (config.friends && PlayerCategory.FRIENDS !in ignored) { - FriendAPI.getAllFriends() - .filter { it.bestFriend || !config.onlyBestFriends } - .forEach { add(it.name) } + if (config.friends && PlayerCategory.FRIENDS !in ignoredCategories) { + FriendAPI.getAllFriends().filter { it.bestFriend || !config.onlyBestFriends }.forEach { add(it.name) } } - if (config.islandPlayers && PlayerCategory.ISLAND_PLAYERS !in ignored) { + if (config.islandPlayers && PlayerCategory.ISLAND_PLAYERS !in ignoredCategories) { for (entity in EntityUtils.getPlayerEntities()) { add(entity.name) } } - if (config.party && PlayerCategory.PARTY !in ignored) { + if (config.party && PlayerCategory.PARTY !in ignoredCategories) { for (member in PartyAPI.partyMembers) { add(member) } -- cgit