From edee75a522ddf22693d0300e8b556d124c24950e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 24 Nov 2021 17:32:09 +0100 Subject: [PATCH] Add SWCommand description hover and suggest part command on click --- .../src/de/steamwar/command/SWCommand.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index bcf15da..258ab5c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -21,6 +21,7 @@ package de.steamwar.command; import de.steamwar.message.Message; import lombok.Setter; +import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -249,13 +250,7 @@ public abstract class SWCommand { boolean hasTabCompletes = tabCompletes.stream() .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); if (hasTabCompletes) { - try { - for (String s : subCommand.description) { - message.sendPrefixless(s, p); - } - } catch (Exception e) { - Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); - } + send(p, subCommand); } else { atomicInteger.incrementAndGet(); } @@ -264,18 +259,24 @@ public abstract class SWCommand { if (args.length == 0 || atomicInteger.get() == commandList.size()) { commandList.forEach(subCommand -> { if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { - try { - for (String s : subCommand.description) { - message.sendPrefixless(s, p); - } - } catch (Exception e) { - Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); - } + send(p, subCommand); } }); } } + private void send(Player p, SubCommand subCommand) { + try { + for (String s : subCommand.description) { + String hover = "§8/§e" + command.getName() + " " + String.join(" ", subCommand.subCommand); + String suggest = "/" + command.getName() + " " + String.join(" ", subCommand.subCommand); + message.sendPrefixless(s, p, hover, new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, suggest)); + } + } catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); + } + } + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Repeatable(Register.Registeres.class)