From 8963598077156d13c600f3f73b8e95533b98b682 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Tue, 20 Aug 2019 22:46:38 +0200 Subject: [PATCH] Add tpa commands, add back command, change login message --- .../nl/voidcorp/mainplugin/VoidEvents.kt | 5 +- VoidTeleport/build.gradle | 37 ++++++++- .../nl/voidcorp/teleportplugin/TpEvents.kt | 42 ++++++++++ .../voidcorp/teleportplugin/VoidTeleport.kt | 29 ++++++- .../commands/SetWorldspawnCommand.kt | 16 ---- .../commands/{ => home}/DelHomeCommand.kt | 2 +- .../commands/{ => home}/HomeCommand.kt | 4 +- .../commands/home/ListHomeCommand.kt | 18 +++++ .../commands/{ => home}/SetHomeCommand.kt | 3 +- .../commands/tpx/BackCommand.kt | 26 ++++++ .../commands/tpx/TpAcceptCommand.kt | 34 ++++++++ .../commands/tpx/TpDenyCommand.kt | 32 ++++++++ .../teleportplugin/commands/tpx/TpaCommand.kt | 80 +++++++++++++++++++ .../commands/warp/DelWarpCommand.kt | 46 +++++++++++ .../commands/warp/SetWarpCommand.kt | 37 +++++++++ .../commands/{ => warp}/WarpCommand.kt | 6 +- .../teleportplugin/models/TeleportLocation.kt | 29 +++++++ .../models/TeleportLocations.kt | 13 +++ .../teleportplugin/models/TpRequest.kt | 13 +++ .../teleportplugin/models/TpRequests.kt | 10 +++ 20 files changed, 452 insertions(+), 30 deletions(-) create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/TpEvents.kt delete mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetWorldspawnCommand.kt rename VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/{ => home}/DelHomeCommand.kt (96%) rename VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/{ => home}/HomeCommand.kt (93%) create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/ListHomeCommand.kt rename VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/{ => home}/SetHomeCommand.kt (93%) create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/BackCommand.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpAcceptCommand.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpDenyCommand.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/DelWarpCommand.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/SetWarpCommand.kt rename VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/{ => warp}/WarpCommand.kt (84%) create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocation.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocations.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt b/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt index 9d1edd9..3f0ee53 100644 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt +++ b/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt @@ -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}!" } + } \ No newline at end of file diff --git a/VoidTeleport/build.gradle b/VoidTeleport/build.gradle index 463c757..d0f4fa6 100644 --- a/VoidTeleport/build.gradle +++ b/VoidTeleport/build.gradle @@ -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") + } } diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/TpEvents.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/TpEvents.kt new file mode 100644 index 0000000..19b75a2 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/TpEvents.kt @@ -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 + } + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt index db13cc6..170a95b 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt @@ -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) } } } \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetWorldspawnCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetWorldspawnCommand.kt deleted file mode 100644 index 504f819..0000000 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetWorldspawnCommand.kt +++ /dev/null @@ -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): Boolean { - if ((sender is Player) && sender.hasPermission("voidteleport.setspawn")) { - sender.world.spawnLocation = sender.location - } - - return true - } -} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/DelHomeCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/DelHomeCommand.kt similarity index 96% rename from VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/DelHomeCommand.kt rename to VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/DelHomeCommand.kt index ebea7fc..7e0f7e2 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/DelHomeCommand.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/DelHomeCommand.kt @@ -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 diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/HomeCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/HomeCommand.kt similarity index 93% rename from VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/HomeCommand.kt rename to VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/HomeCommand.kt index acbce86..0bb13ca 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/HomeCommand.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/HomeCommand.kt @@ -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 ): List { 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() diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/ListHomeCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/ListHomeCommand.kt new file mode 100644 index 0000000..d29cffd --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/ListHomeCommand.kt @@ -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): Boolean { + val tab = cmd.onTabComplete(sender, object : Command("oof") { + override fun execute(sender: CommandSender, commandLabel: String, args: Array): Boolean { + return true + } + }, "", emptyArray()) + sender.sendMessage("$string: ${tab.joinToString()}") + return true + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetHomeCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/SetHomeCommand.kt similarity index 93% rename from VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetHomeCommand.kt rename to VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/SetHomeCommand.kt index 5da0f34..09f7bf9 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/SetHomeCommand.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/home/SetHomeCommand.kt @@ -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() { diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/BackCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/BackCommand.kt new file mode 100644 index 0000000..b8be4be --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/BackCommand.kt @@ -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): 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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpAcceptCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpAcceptCommand.kt new file mode 100644 index 0000000..82b0bb1 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpAcceptCommand.kt @@ -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): 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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpDenyCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpDenyCommand.kt new file mode 100644 index 0000000..7262dfa --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpDenyCommand.kt @@ -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): 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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt new file mode 100644 index 0000000..f626f63 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt @@ -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 + ): List { + 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): 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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/DelWarpCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/DelWarpCommand.kt new file mode 100644 index 0000000..5d04766 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/DelWarpCommand.kt @@ -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 + ): List { + 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): 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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/SetWarpCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/SetWarpCommand.kt new file mode 100644 index 0000000..ddb53c5 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/SetWarpCommand.kt @@ -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): 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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/WarpCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/WarpCommand.kt similarity index 84% rename from VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/WarpCommand.kt rename to VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/WarpCommand.kt index 52bab09..135a70d 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/WarpCommand.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/warp/WarpCommand.kt @@ -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 { 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): 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() diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocation.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocation.kt new file mode 100644 index 0000000..c85a309 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocation.kt @@ -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) : IntEntity(id) { + companion object : IntEntityClass(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 + } +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocations.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocations.kt new file mode 100644 index 0000000..2be80f6 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TeleportLocations.kt @@ -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) +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt new file mode 100644 index 0000000..fea14d8 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt @@ -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) : IntEntity(id) { + companion object : IntEntityClass(TpRequests) + + var to by TpRequests.to + var from by TpRequests.from + var timeout by TpRequests.timeout +} \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt new file mode 100644 index 0000000..f46c773 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt @@ -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) } +} \ No newline at end of file