From 4a0c14197a8b515336baf6e9a425b7f0a13ee291 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sun, 25 Aug 2019 20:02:11 +0200 Subject: [PATCH] All: Update apiVersion to 1.14, Teleport: Add tphere command --- VoidAdmin/build.gradle | 2 +- VoidBank/build.gradle | 2 +- VoidPlugin/build.gradle | 2 +- VoidTeleport/build.gradle | 5 +- .../voidcorp/teleportplugin/VoidTeleport.kt | 6 +- .../commands/tpx/TpAcceptCommand.kt | 13 ++- .../commands/tpx/TpHereCommand.kt | 81 +++++++++++++++++++ .../teleportplugin/models/TpRequest.kt | 1 + .../teleportplugin/models/TpRequests.kt | 1 + VoidUtils/build.gradle | 2 +- 10 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpHereCommand.kt diff --git a/VoidAdmin/build.gradle b/VoidAdmin/build.gradle index d376a7a..e8541bd 100644 --- a/VoidAdmin/build.gradle +++ b/VoidAdmin/build.gradle @@ -11,7 +11,7 @@ dependencies { bukkit { main = "nl.voidcorp.adminplugin.VoidAdmin" - apiVersion = '1.13' + apiVersion = '1.14' author = 'J00LZ' depend = ['VoidPlugin'] commands { diff --git a/VoidBank/build.gradle b/VoidBank/build.gradle index c5f5093..9af8918 100644 --- a/VoidBank/build.gradle +++ b/VoidBank/build.gradle @@ -10,7 +10,7 @@ dependencies { } bukkit { main = "nl.voidcorp.bankplugin.VoidBank" - apiVersion = '1.13' + apiVersion = '1.14' author = 'J00LZ' depend = ['VoidPlugin'] commands { diff --git a/VoidPlugin/build.gradle b/VoidPlugin/build.gradle index d97ac8f..eb0861b 100644 --- a/VoidPlugin/build.gradle +++ b/VoidPlugin/build.gradle @@ -15,6 +15,6 @@ dependencies { bukkit { main = "nl.voidcorp.mainplugin.VoidPlugin" - apiVersion = '1.13' + apiVersion = '1.14' author = 'J00LZ' } \ No newline at end of file diff --git a/VoidTeleport/build.gradle b/VoidTeleport/build.gradle index d0f4fa6..91e5b82 100644 --- a/VoidTeleport/build.gradle +++ b/VoidTeleport/build.gradle @@ -11,7 +11,7 @@ dependencies { bukkit { main = "nl.voidcorp.teleportplugin.VoidTeleport" - apiVersion = '1.13' + apiVersion = '1.14' author = 'J00LZ' depend = ['VoidPlugin'] commands { @@ -45,6 +45,9 @@ bukkit { tpa { description = "Request to teleport to a player" } + tphere{ + description = "Request a player to teleport to you" + } tpaccept { description = "Accept a teleport request" } diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt index 3e0d7d0..d51700e 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt @@ -7,10 +7,7 @@ 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.tpx.* import nl.voidcorp.teleportplugin.commands.warp.DelWarpCommand import nl.voidcorp.teleportplugin.commands.warp.SetWarpCommand import nl.voidcorp.teleportplugin.commands.warp.WarpCommand @@ -39,6 +36,7 @@ class VoidTeleport(override val comment: String = "Teleport around :D") : .registerCommand("delwarp", DelWarpCommand()) .registerCommand("warps", ListHomeCommand(WarpCommand(),"The warps are")) .registerCommand("tpa", TpaCommand()) + .registerCommand("tphere", TpHereCommand()) .registerCommand("tpaccept", TpAcceptCommand()) .registerCommand("tpdeny", TpDenyCommand()) .registerCommand("back",BackCommand()) 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 index 82b0bb1..b042a0a 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpAcceptCommand.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpAcceptCommand.kt @@ -8,7 +8,6 @@ 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 { @@ -21,9 +20,15 @@ class TpAcceptCommand : VoidCommand() { 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) + if (!teleport.here) { + sender.sendMessage("Accepted request from ${from.displayName}") + from.sendMessage("Teleported to ${sender.displayName}") + from.teleport(sender.location) + } else { + sender.sendMessage("Teleported to ${from.name}") + from.sendMessage("${sender.name} accepted your request") + sender.teleport(from.location) + } } teleport.delete() } diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpHereCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpHereCommand.kt new file mode 100644 index 0000000..db0a3a2 --- /dev/null +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpHereCommand.kt @@ -0,0 +1,81 @@ +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.deleteWhere +import org.jetbrains.exposed.sql.transactions.transaction +import org.joda.time.DateTime + +class TpHereCommand : 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 { + TpRequests.deleteWhere { TpRequests.timeout lessEq DateTime.now() } + + if (TpRequest.find { TpRequests.to eq pl.uniqueId }.toList().isNotEmpty()) { + sender.sendMessage("${pl.displayName} already has a request open...") + if (TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList().isNotEmpty()) { + sender.sendMessage("Actually, you sent that request...") + } + } else { + TpRequest.new { + from = sender.uniqueId + to = pl.uniqueId + here = true + } + 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(" to teleport to them, 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/models/TpRequest.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt index fea14d8..ad53678 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequest.kt @@ -10,4 +10,5 @@ class TpRequest(id: EntityID) : IntEntity(id) { var to by TpRequests.to var from by TpRequests.from var timeout by TpRequests.timeout + var here by TpRequests.here } \ 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 index 058f487..4b6ef91 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt @@ -6,5 +6,6 @@ import org.joda.time.DateTime object TpRequests : IntIdTable() { val from = uuid("from") val to = uuid("to") + val here = bool("here").default(false) val timeout = datetime("timeout").clientDefault { DateTime.now().plusSeconds(30) } } \ No newline at end of file diff --git a/VoidUtils/build.gradle b/VoidUtils/build.gradle index cf5e09e..0f8d3f8 100644 --- a/VoidUtils/build.gradle +++ b/VoidUtils/build.gradle @@ -10,7 +10,7 @@ dependencies { } bukkit { main = "nl.voidcorp.utilsplugin.VoidUtils" - apiVersion = '1.13' + apiVersion = '1.14' author = 'J00LZ' depend = ['VoidPlugin'] commands {