37 lines
1.3 KiB
Kotlin
37 lines
1.3 KiB
Kotlin
package nl.voidcorp.mainplugin.commands
|
|
|
|
import nl.voidcorp.mainplugin.Nick
|
|
import nl.voidcorp.mainplugin.NickTable
|
|
import org.bukkit.ChatColor
|
|
import org.bukkit.command.Command
|
|
import org.bukkit.command.CommandSender
|
|
import org.bukkit.entity.Player
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
|
|
class NickCommand : VoidCommand() {
|
|
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
|
|
if (sender is Player) {
|
|
if (args.isEmpty()) {
|
|
sender.sendMessage("Your nickname is ${sender.displayName}")
|
|
} else {
|
|
val nick = args[0]
|
|
|
|
transaction {
|
|
val n = Nick.find { NickTable.userid eq sender.uniqueId }.firstOrNull()
|
|
if (n != null) {
|
|
n.nickname = nick + ChatColor.RESET
|
|
} else {
|
|
Nick.new {
|
|
userid = sender.uniqueId
|
|
nickname = nick + ChatColor.RESET
|
|
}
|
|
}
|
|
}
|
|
sender.setDisplayName(nick)
|
|
sender.sendMessage("Set nickname to ${sender.displayName}")
|
|
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
} |