43 lines
1.6 KiB
Kotlin
43 lines
1.6 KiB
Kotlin
package nl.voidcorp.teleportplugin.commands
|
|
|
|
import nl.voidcorp.mainplugin.commands.VoidCommand
|
|
import nl.voidcorp.teleportplugin.models.Warps
|
|
import org.bukkit.Bukkit
|
|
import org.bukkit.Location
|
|
import org.bukkit.command.Command
|
|
import org.bukkit.command.CommandSender
|
|
import org.bukkit.entity.Player
|
|
import org.jetbrains.exposed.sql.select
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
|
|
class WarpCommand : VoidCommand() {
|
|
override fun onTabComplete(
|
|
sender: CommandSender,
|
|
command: Command,
|
|
alias: String,
|
|
args: Array<out String>
|
|
): List<String> {
|
|
return if (sender is Player) {
|
|
transaction {
|
|
Warps.select { Warps.name like "${args.lastOrNull() ?: ""}%" }.map { it[Warps.name] }
|
|
}
|
|
} else mutableListOf()
|
|
}
|
|
|
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
|
return if (sender is Player) {
|
|
val where = args.firstOrNull() ?: return false
|
|
transaction {
|
|
val res = Warps.select { (Warps.name eq where) }.firstOrNull()
|
|
if (res == null) {
|
|
sender.sendMessage("The warp '$where' does not exist!")
|
|
} else {
|
|
val w = Bukkit.getWorld(res[Warps.world]) ?: throw NullPointerException()
|
|
val loc = Location(w, res[Warps.x], res[Warps.y], res[Warps.z], res[Warps.yaw], res[Warps.pitch])
|
|
sender.teleport(loc)
|
|
}
|
|
}
|
|
true
|
|
} else false
|
|
}
|
|
} |