Add tpa commands, add back command, change login message

master
Julius 2019-08-20 22:46:38 +02:00
parent 144d2d3025
commit 8963598077
20 changed files with 452 additions and 30 deletions

View File

@ -1,5 +1,6 @@
package nl.voidcorp.mainplugin
import org.bukkit.ChatColor
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
@ -16,6 +17,8 @@ object VoidEvents : Listener {
evt.player.setDisplayName(nick)
}
}
evt.joinMessage = "Hello ${evt.player.displayName}, and welcome to the server!"
evt.joinMessage =
"Hello ${ChatColor.BLUE}${evt.player.displayName}${ChatColor.RESET}, and welcome to ${ChatColor.BOLD}Xirion.net${ChatColor.RESET}!"
}
}

View File

@ -15,6 +15,9 @@ bukkit {
author = 'J00LZ'
depend = ['VoidPlugin']
commands {
spawn {
description = "Warp to the worldspawn"
}
home {
description = "Teleport to a home"
}
@ -24,12 +27,34 @@ bukkit {
delhome {
description = "Delete a home"
}
homes{
description = "List all your homes"
}
warp {
description = "Warp to a location"
}
spawn {
description = "Warp to the worldspawn"
setwarp {
description = "Set a warp"
}
delwarp {
description = "Delete a warp"
}
warps{
description = "List all the warps"
}
tpa {
description = "Request to teleport to a player"
}
tpaccept {
description = "Accept a teleport request"
}
tpdeny {
description = "Deny a teleport request"
}
back{
description = "Go back to your previous location"
}
}
permissions {
@ -48,6 +73,14 @@ bukkit {
description = "Allows usage of the spawn command"
setDefault("true")
}
'voidteleport.setwarp' {
description = "Allows setting warps"
setDefault("OP")
}
'voidteleport.warp' {
description = "Allows usage of the warp command"
setDefault("true")
}
}

View File

@ -0,0 +1,42 @@
package nl.voidcorp.teleportplugin
import nl.voidcorp.teleportplugin.models.TeleportLocation
import nl.voidcorp.teleportplugin.models.TeleportLocations
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.player.PlayerTeleportEvent
import org.jetbrains.exposed.sql.transactions.transaction
object TpEvents : Listener {
@EventHandler
fun onDeath(evt: EntityDamageEvent) {
val entity = evt.entity
if (entity is Player) {
if (entity.health <= 0.0) {
setLastTpLoc(entity)
}
}
}
@EventHandler
fun onTeleport(evt: PlayerTeleportEvent) {
setLastTpLoc(evt.player, evt.from)
}
fun setLastTpLoc(player: Player, location: Location = player.location) {
transaction {
val tp = TeleportLocation.find { TeleportLocations.player eq player.uniqueId }.firstOrNull()
if (tp == null)
TeleportLocation.new {
this.location = location
this.player = player.uniqueId
}
else
tp.location = location
}
}
}

View File

@ -2,8 +2,21 @@ package nl.voidcorp.teleportplugin
import nl.voidcorp.mainplugin.CommandHandler
import nl.voidcorp.mainplugin.VoidPluginBase
import nl.voidcorp.teleportplugin.commands.*
import nl.voidcorp.teleportplugin.commands.SpawnCommand
import nl.voidcorp.teleportplugin.commands.home.DelHomeCommand
import nl.voidcorp.teleportplugin.commands.home.HomeCommand
import nl.voidcorp.teleportplugin.commands.home.ListHomeCommand
import nl.voidcorp.teleportplugin.commands.home.SetHomeCommand
import nl.voidcorp.teleportplugin.commands.tpx.BackCommand
import nl.voidcorp.teleportplugin.commands.tpx.TpAcceptCommand
import nl.voidcorp.teleportplugin.commands.tpx.TpDenyCommand
import nl.voidcorp.teleportplugin.commands.tpx.TpaCommand
import nl.voidcorp.teleportplugin.commands.warp.DelWarpCommand
import nl.voidcorp.teleportplugin.commands.warp.SetWarpCommand
import nl.voidcorp.teleportplugin.commands.warp.WarpCommand
import nl.voidcorp.teleportplugin.models.Homes
import nl.voidcorp.teleportplugin.models.TeleportLocations
import nl.voidcorp.teleportplugin.models.TpRequests
import nl.voidcorp.teleportplugin.models.Warps
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
@ -13,14 +26,22 @@ class VoidTeleport(override val comment: String = "Teleport around :D") :
override fun enable() {
CommandHandler(this)
.registerCommand("spawn", SpawnCommand())
.registerCommand("sethome", SetHomeCommand())
.registerCommand("home", HomeCommand())
.registerCommand("delhome", DelHomeCommand())
.registerCommand("homes", ListHomeCommand(HomeCommand(), "Your homes are"))
.registerCommand("warp", WarpCommand())
.registerCommand("spawn",SpawnCommand())
.registerCommand("setworldspawn", SetWorldspawnCommand())
.registerCommand("setwarp", SetWarpCommand())
.registerCommand("delwarp", DelWarpCommand())
.registerCommand("warps", ListHomeCommand(WarpCommand(),"The warps are"))
.registerCommand("tpa", TpaCommand())
.registerCommand("tpaccept", TpAcceptCommand())
.registerCommand("tpdeny", TpDenyCommand())
.registerCommand("back",BackCommand())
server.pluginManager.registerEvents(TpEvents, this)
transaction {
SchemaUtils.createMissingTablesAndColumns(Homes, Warps)
SchemaUtils.createMissingTablesAndColumns(Homes, Warps, TpRequests, TeleportLocations)
}
}
}

View File

@ -1,16 +0,0 @@
package nl.voidcorp.teleportplugin.commands
import nl.voidcorp.mainplugin.commands.VoidCommand
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
class SetWorldspawnCommand : VoidCommand() {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if ((sender is Player) && sender.hasPermission("voidteleport.setspawn")) {
sender.world.spawnLocation = sender.location
}
return true
}
}

View File

@ -1,4 +1,4 @@
package nl.voidcorp.teleportplugin.commands
package nl.voidcorp.teleportplugin.commands.home
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.Homes

View File

@ -1,4 +1,4 @@
package nl.voidcorp.teleportplugin.commands
package nl.voidcorp.teleportplugin.commands.home
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.Home
@ -17,7 +17,7 @@ class HomeCommand : VoidCommand() {
args: Array<out String>
): List<String> {
return if (sender is Player) {
val current = args.lastOrNull()
val current = args.lastOrNull() ?: ""
transaction {
Home.find { (Homes.userid eq sender.uniqueId) and (Homes.name like "$current%") }
.map { it.name }.toList()

View File

@ -0,0 +1,18 @@
package nl.voidcorp.teleportplugin.commands.home
import nl.voidcorp.mainplugin.commands.VoidCommand
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
class ListHomeCommand(private val cmd: VoidCommand, val string: String) : VoidCommand() {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
val tab = cmd.onTabComplete(sender, object : Command("oof") {
override fun execute(sender: CommandSender, commandLabel: String, args: Array<out String>): Boolean {
return true
}
}, "", emptyArray())
sender.sendMessage("$string: ${tab.joinToString()}")
return true
}
}

View File

@ -1,4 +1,4 @@
package nl.voidcorp.teleportplugin.commands
package nl.voidcorp.teleportplugin.commands.home
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.Home
@ -7,7 +7,6 @@ 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() {

View File

@ -0,0 +1,26 @@
package nl.voidcorp.teleportplugin.commands.tpx
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.TeleportLocation
import nl.voidcorp.teleportplugin.models.TeleportLocations
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.transactions.transaction
class BackCommand : VoidCommand() {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
return if (sender is Player) {
transaction {
val tp = TeleportLocation.find { TeleportLocations.player eq sender.uniqueId }.firstOrNull()
if (tp == null) {
sender.sendMessage("Sorry, you don't have a location to go back to on record...")
} else {
sender.teleport(tp.location)
sender.sendMessage("Welcome back!")
}
}
true
} else false
}
}

View File

@ -0,0 +1,34 @@
package nl.voidcorp.teleportplugin.commands.tpx
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.TpRequest
import nl.voidcorp.teleportplugin.models.TpRequests
import org.bukkit.Bukkit
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*
class TpAcceptCommand : VoidCommand() {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player) {
transaction {
val req = TpRequest.find { TpRequests.to eq sender.uniqueId }.toList()
if (req.isEmpty()) {
sender.sendMessage("You have no requests open...")
} else {
val teleport = req.first()
val from = Bukkit.getPlayer(teleport.from)
if (from != null) {
sender.sendMessage("Accepted request from ${from.displayName}")
from.sendMessage("Teleported to ${sender.displayName}")
from.teleport(sender.location)
}
teleport.delete()
}
}
}
return true
}
}

View File

@ -0,0 +1,32 @@
package nl.voidcorp.teleportplugin.commands.tpx
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.TpRequest
import nl.voidcorp.teleportplugin.models.TpRequests
import org.bukkit.Bukkit
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*
class TpDenyCommand : VoidCommand() {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player) {
transaction {
val req = TpRequest.find { TpRequests.to eq sender.uniqueId }.toList()
if (req.isEmpty()) {
sender.sendMessage("You have no requests open...")
} else {
val teleport = req.first()
val from = Bukkit.getPlayer(teleport.from)
if (from != null) {
sender.sendMessage("Denied request from ${from.displayName}")
}
teleport.delete()
}
}
}
return true
}
}

View File

@ -0,0 +1,80 @@
package nl.voidcorp.teleportplugin.commands.tpx
import net.md_5.bungee.api.chat.ClickEvent
import net.md_5.bungee.api.chat.TextComponent
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.TpRequest
import nl.voidcorp.teleportplugin.models.TpRequests
import org.bukkit.Bukkit
import org.bukkit.ChatColor
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.transactions.transaction
class TpaCommand : VoidCommand() {
override fun onTabComplete(
sender: CommandSender,
command: Command,
alias: String,
args: Array<out String>
): List<String> {
if (sender is Player) {
val toComplete = args.lastOrNull() ?: ""
return Bukkit.getOnlinePlayers().toList().map { ChatColor.stripColor(it.name)!! }
.filter { it.startsWith(toComplete) }
}
return emptyList()
}
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player) {
if (args.isEmpty()) {
sender.sendMessage("The first argument should be a nickname of an online player")
return true
}
val pl = Bukkit.getPlayer(args.first())
if (pl == null || !pl.isOnline) {
sender.sendMessage("The first argument should be a nickname of an online player")
return true
}
transaction {
val open =
TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList()
open.forEach {
if (it.timeout.isAfterNow) {
it.delete()
}
}
if (TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList().isNotEmpty()) {
sender.sendMessage("You already have a request open for ${pl.displayName}")
} else {
TpRequest.new {
from = sender.uniqueId
to = pl.uniqueId
}
sender.sendMessage("Sent a teleport request to ${pl.displayName}")
pl.sendMessage(
TextComponent("Received a new Teleport request from "),
TextComponent(sender.displayName).apply { color = net.md_5.bungee.api.ChatColor.AQUA },
TextComponent(", use "),
TextComponent("/tpaccept").apply {
color = net.md_5.bungee.api.ChatColor.GREEN
clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpaccept")
},
TextComponent(" or "),
TextComponent("/tpdeny").apply {
color = net.md_5.bungee.api.ChatColor.RED
clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tpdeny")
},
TextComponent(" to accept or deny it!")
)
//pl.sendMessage("Received a new teleport request from ${sender.displayName}, use /tpaccept or /tpdeny to accept or deny it!")
}
}
}
return true
}
}

View File

@ -0,0 +1,46 @@
package nl.voidcorp.teleportplugin.commands.warp
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.Warp
import nl.voidcorp.teleportplugin.models.Warps
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.transactions.transaction
class DelWarpCommand : VoidCommand() {
override fun onTabComplete(
sender: CommandSender,
command: Command,
alias: String,
args: Array<out String>
): List<String> {
return if (sender is Player) {
transaction {
Warp.find { Warps.name like "${args.lastOrNull() ?: ""}%" }.map { it.name }
}
} else mutableListOf()
}
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player) {
if (!sender.hasPermission("voidteleport.setwarp")) return false
if (args.isEmpty()) {
sender.sendMessage("You need to specify a warp name!")
return true
}
val loc = args.first()
transaction {
val warp = Warp.find { Warps.name eq loc }.firstOrNull()
if (warp != null) {
warp.delete()
sender.sendMessage("The warp $loc has been deleted")
} else {
sender.sendMessage("The warp $loc does not exist?")
}
}
}
return true
}
}

View File

@ -0,0 +1,37 @@
package nl.voidcorp.teleportplugin.commands.warp
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.Warp
import nl.voidcorp.teleportplugin.models.Warps
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.transactions.transaction
class SetWarpCommand : VoidCommand() {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
if (sender is Player) {
if (!sender.hasPermission("voidteleport.setwarp")) return false
if (args.isEmpty()) {
sender.sendMessage("You need to specify a warp name!")
return true
}
val loc = args.first()
transaction {
val warp = Warp.find {
Warps.name eq (args.firstOrNull() ?: "home")
}.any()
if (warp) {
sender.sendMessage("The warp '$loc' already exists!")
} else {
Warp.new {
location = sender.location
this.name = loc
}
sender.sendMessage("Created warp '$loc'")
}
}
}
return true
}
}

View File

@ -1,6 +1,7 @@
package nl.voidcorp.teleportplugin.commands
package nl.voidcorp.teleportplugin.commands.warp
import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.teleportplugin.models.Warp
import nl.voidcorp.teleportplugin.models.Warps
import org.bukkit.Bukkit
import org.bukkit.Location
@ -19,13 +20,14 @@ class WarpCommand : VoidCommand() {
): List<String> {
return if (sender is Player) {
transaction {
Warps.select { Warps.name like "${args.lastOrNull() ?: ""}%" }.map { it[Warps.name] }
Warp.find { Warps.name like "${args.lastOrNull() ?: ""}%" }.map { it.name }
}
} else mutableListOf()
}
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
return if (sender is Player) {
if (!sender.hasPermission("voidteleport.warp")) return false
val where = args.firstOrNull() ?: return false
transaction {
val res = Warps.select { (Warps.name eq where) }.firstOrNull()

View File

@ -0,0 +1,29 @@
package nl.voidcorp.teleportplugin.models
import org.bukkit.Bukkit
import org.bukkit.Location
import org.jetbrains.exposed.dao.EntityID
import org.jetbrains.exposed.dao.IntEntity
import org.jetbrains.exposed.dao.IntEntityClass
class TeleportLocation(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<TeleportLocation>(TeleportLocations)
var player by TeleportLocations.player
var x by TeleportLocations.x
var y by TeleportLocations.y
var z by TeleportLocations.z
var world by TeleportLocations.world
var pitch by TeleportLocations.pitch
var yaw by TeleportLocations.yaw
var location: Location
get() = Location(Bukkit.getWorld(world), x, y, z, yaw, pitch)
set(value) {
this.x = value.x
this.y = value.y
this.z = value.z
this.world = value.world.uid
this.yaw = value.yaw
this.pitch = value.pitch
}
}

View File

@ -0,0 +1,13 @@
package nl.voidcorp.teleportplugin.models
import org.jetbrains.exposed.dao.IntIdTable
object TeleportLocations : IntIdTable() {
val player = uuid("player").uniqueIndex()
val x = double("x")
val y = double("y")
val z = double("z")
val world = uuid("world")
val pitch = float("pitch").default(0.0f)
val yaw = float("yaw").default(0.0f)
}

View File

@ -0,0 +1,13 @@
package nl.voidcorp.teleportplugin.models
import org.jetbrains.exposed.dao.EntityID
import org.jetbrains.exposed.dao.IntEntity
import org.jetbrains.exposed.dao.IntEntityClass
class TpRequest(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<TpRequest>(TpRequests)
var to by TpRequests.to
var from by TpRequests.from
var timeout by TpRequests.timeout
}

View File

@ -0,0 +1,10 @@
package nl.voidcorp.teleportplugin.models
import org.jetbrains.exposed.dao.IntIdTable
import org.joda.time.DateTime
object TpRequests : IntIdTable() {
val from = uuid("from")
val to = uuid("to").uniqueIndex()
val timeout = datetime("timeout").clientDefault { DateTime.now().plusSeconds(30) }
}