47 lines
1.5 KiB
Kotlin
47 lines
1.5 KiB
Kotlin
package nl.voidcorp.teleportplugin.commands
|
|
|
|
import nl.voidcorp.mainplugin.commands.VoidCommand
|
|
import nl.voidcorp.teleportplugin.models.Homes
|
|
import org.bukkit.command.Command
|
|
import org.bukkit.command.CommandSender
|
|
import org.bukkit.entity.Player
|
|
import org.jetbrains.exposed.sql.Op
|
|
import org.jetbrains.exposed.sql.and
|
|
import org.jetbrains.exposed.sql.deleteWhere
|
|
import org.jetbrains.exposed.sql.select
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
|
|
class DelHomeCommand : VoidCommand() {
|
|
override fun onTabComplete(
|
|
sender: CommandSender,
|
|
command: Command,
|
|
alias: String,
|
|
args: Array<out String>
|
|
): MutableList<String> {
|
|
return if (sender is Player) {
|
|
val current = args.lastOrNull()
|
|
transaction {
|
|
Homes.select {
|
|
(Homes.userid eq sender.uniqueId) and if (current != null) (Homes.name like "$current%") else Op.TRUE
|
|
}.map { it[Homes.name] }.toMutableList()
|
|
}
|
|
|
|
} else mutableListOf()
|
|
}
|
|
|
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
|
if (sender is Player) {
|
|
|
|
transaction {
|
|
Homes.deleteWhere {
|
|
(Homes.userid eq sender.uniqueId) and
|
|
(Homes.name eq (args.firstOrNull() ?: "home"))
|
|
}
|
|
|
|
commit()
|
|
sender.sendMessage("Delete home '${args.firstOrNull() ?: "home"}'")
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
} |