Skip to content

Commit

Permalink
Merge pull request #18 from m4kvn/m4kvn/feature/tab-complete
Browse files Browse the repository at this point in the history
Implemented tab completer for homes command
  • Loading branch information
m4kvn authored Jan 8, 2023
2 parents 16ac3a1 + a270d54 commit 543d9a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ class HomesCommandExecutor : BaseCommandExecutor() {
}

override fun onTabComplete(sender: CommandSender, args: Array<out String>, index: Int?): List<String> {
return emptyList()
val player = sender as? Player ?: return emptyList()
if (args.lastIndex > 0) return emptyList()
return playerHomeManager
.getPlayerHomeListData(player.uniqueId)
.namedList
.map { it.name }
}

private fun teleportDefault(player: Player): CommandResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package com.github.m4kvn.spigot.homes.command.homes
import com.github.m4kvn.spigot.homes.Constants
import com.github.m4kvn.spigot.homes.command.core.CommandResponse
import com.github.m4kvn.spigot.homes.command.core.SubCommandExecutor
import com.github.m4kvn.spigot.homes.playerhome.PlayerHomeManager
import com.github.m4kvn.spigot.homes.usecase.RemoveDefaultHomeUseCase
import com.github.m4kvn.spigot.homes.usecase.RemoveNamedHomeUseCase
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.koin.core.component.inject

class HomesRemoveCommandExecutor : SubCommandExecutor() {
private val playerHomeManager: PlayerHomeManager by inject()
private val removeDefaultHomeUseCase: RemoveDefaultHomeUseCase by inject()
private val removeNamedHomeUseCase: RemoveNamedHomeUseCase by inject()

Expand All @@ -29,7 +31,15 @@ class HomesRemoveCommandExecutor : SubCommandExecutor() {
}

override fun onTabComplete(sender: CommandSender, args: List<String>): List<String> {
return emptyList()
val player = sender as? Player ?: return emptyList()
if (args.lastIndex > 1) return emptyList()
val homeListData = playerHomeManager.getPlayerHomeListData(player.uniqueId)
return buildList {
if (homeListData.default != null) {
add(Constants.DEFAULT_HOME_NAME)
}
addAll(homeListData.namedList.map { it.name })
}
}

private fun removeDefaultHome(player: Player): CommandResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class HomesSetCommandExecutor : SubCommandExecutor() {
}

override fun onTabComplete(sender: CommandSender, args: List<String>): List<String> {
return emptyList()
if (sender !is Player) return emptyList()
if (args.lastIndex > 1) return emptyList()
return listOf(Constants.DEFAULT_HOME_NAME)
}
}

0 comments on commit 543d9a3

Please sign in to comment.