Commit aa5c9e24 authored by Linus K.'s avatar Linus K.
Browse files

Add hover messages to /homes and add /delhome

parent 815b01b7
......@@ -14,6 +14,9 @@ commands:
sethome:
description: Set a home
usage: /<command> <name>
delhome:
description: Delete a home
usage: /<command> <name>
home:
description: Go to a home
usage: /<command> <name>
......
......@@ -42,6 +42,7 @@ class Plugin: JavaPlugin() {
getCommand("homes")?.setExecutor(HomesCommand())
getCommand("home")?.setExecutor(HomeCommand())
getCommand("sethome")?.setExecutor(SetHomeCommand())
getCommand("delhome")?.setExecutor(DelHomeCommand())
getCommand("back")?.setExecutor(BackCommand())
getCommand("bed")?.setExecutor(BedCommand())
getCommand("spawn")?.setExecutor(SpawnCommand())
......@@ -51,7 +52,7 @@ class Plugin: JavaPlugin() {
}
fun registerTabCompleters() {
for (commandName in arrayOf("home", "sethome", "spawn", "tpaccept", "tpdeny")) {
for (commandName in arrayOf("home", "sethome", "delhome", "spawn", "tpaccept", "tpdeny")) {
getCommand(commandName)?.tabCompleter = getCommand(commandName)?.executor as TabCompleter
}
}
......
package me.linuscde.mcplugins.teleportastic.commands
import me.linuscde.mcplugins.teleportastic.Plugin
import me.linuscde.mcplugins.teleportastic.utils.deleteHome
import me.linuscde.mcplugins.teleportastic.utils.homes
import me.linuscde.mcplugins.teleportastic.utils.setHome
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import org.bukkit.entity.Player
class DelHomeCommand: CommandExecutor, TabCompleter {
override fun onCommand(sender: CommandSender, cmd: Command, label: String, args: Array<out String>): Boolean {
if(sender !is Player) {
sender.sendMessage("This command is only for players.")
return true
}
if(args.size != 1) return false
if(sender.deleteHome(args[0])) {
sender.sendMessage("${Plugin.prefix} §aThe Home §c${args[0]}§a was removed.")
}else {
sender.sendMessage("${Plugin.prefix} §cYou don't have a home called §4${args[0]}§c.")
}
return true
}
override fun onTabComplete(sender: CommandSender, cmd: Command, label: String, args: Array<out String>): MutableList<String> {
if(sender !is Player) return arrayListOf()
if(args.size != 1) return arrayListOf()
val homeNameBeginning = args[0]
return sender.homes.filter { (name, _) -> name.startsWith(homeNameBeginning, true) }.map { (name, _) -> name }.toMutableList()
}
}
\ No newline at end of file
......@@ -2,6 +2,11 @@ package me.linuscde.mcplugins.teleportastic.commands
import me.linuscde.mcplugins.teleportastic.Plugin
import me.linuscde.mcplugins.teleportastic.utils.homes
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.chat.ClickEvent
import net.md_5.bungee.api.chat.HoverEvent
import net.md_5.bungee.api.chat.TextComponent
import net.md_5.bungee.api.chat.hover.content.Text
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
......@@ -15,7 +20,23 @@ class HomesCommand: CommandExecutor {
return true
}
sender.sendMessage(Plugin.prefix + " §aHomes: §c" + sender.homes.keys.joinToString(", "))
val homes = TextComponent()
homes.color = ChatColor.RED
for(comp in TextComponent.fromLegacyText("${Plugin.prefix} §aHomes: "))
homes.addExtra(comp)
for((i, home) in sender.homes.keys.withIndex()) {
if(i > 0)
homes.addExtra(", ")
val entry = TextComponent(home)
entry.color = ChatColor.RED
entry.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("§7Click to teleport"))
entry.clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/${Plugin.instance.name}:home $home")
homes.addExtra(entry)
}
sender.spigot().sendMessage(homes)
return true
}
......
......@@ -19,7 +19,7 @@ class SetHomeCommand: CommandExecutor, TabCompleter {
if(args.size != 1) return false
sender.setHome(args[0], sender.location)
sender.sendMessage("${Plugin.prefix} §aHome §c${args[0]}§a was set.")
sender.sendMessage("${Plugin.prefix} §c${args[0]}§a is set.")
return true
}
......
......@@ -17,3 +17,14 @@ fun Player.setHome(name: String, location: Location) {
Plugin.instance.config.set("${this.uniqueId}.homes.${name.replace(".", "\\.")}", location)
Plugin.instance.saveConfig()
}
fun Player.deleteHome(name: String): Boolean {
val key = "${this.uniqueId}.homes.${name.replace(".", "\\.")}";
return if(Plugin.instance.config.contains(key)) {
Plugin.instance.config.set(key, null)
Plugin.instance.saveConfig()
true
}else {
false
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment