37 lines
1.4 KiB
Kotlin
37 lines
1.4 KiB
Kotlin
package nl.voidcorp.teleportplugin.commands
|
|
|
|
import nl.voidcorp.mainplugin.commands.VoidCommand
|
|
import nl.voidcorp.teleportplugin.models.Home
|
|
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.and
|
|
import org.jetbrains.exposed.sql.select
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
|
|
class SetHomeCommand : VoidCommand() {
|
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
|
if (sender is Player) {
|
|
|
|
transaction {
|
|
val home = Home.find {
|
|
(Homes.userid eq sender.uniqueId) and
|
|
(Homes.name eq (args.firstOrNull() ?: "home"))
|
|
}.any()
|
|
if (home) {
|
|
sender.sendMessage("The home '${args.firstOrNull() ?: "home"}' already exists!")
|
|
} else {
|
|
val name = args.firstOrNull() ?: "home"
|
|
Home.new {
|
|
location = sender.location
|
|
this.name = name
|
|
userId = sender.uniqueId
|
|
}
|
|
sender.sendMessage("Created home '$name'")
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
} |