SteamWar/SpigotCore
Archiviert
13
0

Add SWCommand description hover and suggest part command on click

Dieser Commit ist enthalten in:
yoyosource 2021-11-24 17:32:09 +01:00
Ursprung aaeaf7c334
Commit edee75a522

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.command;
import de.steamwar.message.Message; import de.steamwar.message.Message;
import lombok.Setter; import lombok.Setter;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -249,13 +250,7 @@ public abstract class SWCommand {
boolean hasTabCompletes = tabCompletes.stream() boolean hasTabCompletes = tabCompletes.stream()
.anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())); .anyMatch(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase()));
if (hasTabCompletes) { if (hasTabCompletes) {
try { send(p, subCommand);
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);
}
} else { } else {
atomicInteger.incrementAndGet(); atomicInteger.incrementAndGet();
} }
@ -264,17 +259,23 @@ public abstract class SWCommand {
if (args.length == 0 || atomicInteger.get() == commandList.size()) { if (args.length == 0 || atomicInteger.get() == commandList.size()) {
commandList.forEach(subCommand -> { commandList.forEach(subCommand -> {
if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) { if (subCommand.guardChecker == null || subCommand.guardChecker.guard(p, GuardCheckType.TAB_COMPLETE, new String[0], null) == GuardResult.ALLOWED) {
send(p, subCommand);
}
});
}
}
private void send(Player p, SubCommand subCommand) {
try { try {
for (String s : subCommand.description) { for (String s : subCommand.description) {
message.sendPrefixless(s, p); 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) { } catch (Exception e) {
Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e); Bukkit.getLogger().log(Level.WARNING, "Failed to send description of registered method '" + subCommand.method + "' with description '" + subCommand.description + "'", e);
} }
} }
});
}
}
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD}) @Target({ElementType.METHOD})