Skip to content

Commit b3b65fb

Browse files
committed
show delete & rename buttons in /e list
1 parent 51be639 commit b3b65fb

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/main/kotlin/me/apyr/chatemotes/commands/ListCommand.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package me.apyr.chatemotes.commands
22

33
import me.apyr.chatemotes.ChatEmotes
44
import me.apyr.chatemotes.ChatEmotesCommand
5+
import me.apyr.chatemotes.ChatEmotesPermission
56
import me.apyr.chatemotes.emote.Emote
7+
import me.apyr.chatemotes.hasPermission
68
import net.md_5.bungee.api.ChatColor
79
import net.md_5.bungee.api.chat.ClickEvent
810
import net.md_5.bungee.api.chat.ComponentBuilder
@@ -35,13 +37,28 @@ class ListCommand : ChatEmotesCommand {
3537
return sender.spigot().sendMessage(TextComponent("This page does not exists").apply { color = ChatColor.GRAY })
3638
}
3739

40+
val canManage: Boolean = sender.hasPermission(ChatEmotesPermission.MANAGE)
41+
3842
emotes
3943
.foldIndexed(ComponentBuilder()) { index, builder, emote ->
4044
if (index == 0) {
4145
builder.append("\n")
4246
}
47+
builder.append("\n", ComponentBuilder.FormatRetention.NONE)
48+
if (canManage) {
49+
builder
50+
.append("[ ").color(ChatColor.GRAY)
51+
.append("x", ComponentBuilder.FormatRetention.NONE).color(ChatColor.RED)
52+
.event(ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/emote del ${emote.name}"))
53+
.event(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("Click to delete ${emote.char}")))
54+
.append(" ", ComponentBuilder.FormatRetention.NONE)
55+
.append("").color(ChatColor.GRAY)
56+
.event(ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/emote rename ${emote.name} "))
57+
.event(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("Click to rename ${emote.char}")))
58+
.append(" ] ", ComponentBuilder.FormatRetention.NONE).color(ChatColor.GRAY)
59+
}
4360
builder
44-
.append("\n${emote.char} ", ComponentBuilder.FormatRetention.NONE)
61+
.append("${emote.char} ", ComponentBuilder.FormatRetention.NONE)
4562
.append("- ${emote.name}").color(ChatColor.GRAY)
4663
.event(ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, emote.char))
4764
.event(HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("Click to copy ${emote.char}")))
@@ -101,6 +118,12 @@ class ListCommand : ChatEmotesCommand {
101118
)
102119
}
103120

104-
override fun onTabComplete(sender: CommandSender, args: List<String>): List<String> = emptyList()
121+
override fun onTabComplete(sender: CommandSender, args: List<String>): List<String> {
122+
return when {
123+
args.size == 1 && args[0].isEmpty() -> listOf("<page>")
124+
else -> emptyList()
125+
}
126+
}
127+
105128
override fun hasPermission(sender: CommandSender): Boolean = true
106129
}

0 commit comments

Comments
 (0)