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 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)