SteamWar/SpigotCore
Archiviert
13
0

Add SubCommand.description

Dieser Commit ist enthalten in:
yoyosource 2021-05-14 16:09:26 +02:00
Ursprung 8985393fe1
Commit 4b23274f8d
2 geänderte Dateien mit 27 neuen und 37 gelöschten Zeilen

Datei anzeigen

@ -92,16 +92,7 @@ public abstract class SWCommand {
Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
return; return;
} }
if (method.getName().equals("internalHelp")) { commandHelpList.add(new SubCommand(this, method, anno.description(), anno.value(), new HashMap<>()));
System.out.println(method + " " + hasHelp);
if (hasHelp) {
return;
}
} else if (!hasHelp) {
commandHelpList.clear();
hasHelp = true;
}
commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>()));
}); });
} }
for (Method method : methods) { for (Method method : methods) {
@ -123,7 +114,7 @@ public abstract class SWCommand {
return; return;
} }
} }
commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper)); commandList.add(new SubCommand(this, method, anno.description(), anno.value(), localTypeMapper));
}); });
this.commandList.sort((o1, o2) -> { this.commandList.sort((o1, o2) -> {
@ -171,15 +162,8 @@ public abstract class SWCommand {
} }
private List<Method> methods() { private List<Method> methods() {
Class<?> current = getClass(); List<Method> methods = Arrays.asList(getClass().getDeclaredMethods());
List<Method> methods = new ArrayList<>(); methods.addAll(Arrays.asList(SWCommand.class.getDeclaredMethods()));
int count = 0;
while (current != null && count < 4) {
methods.addAll(Arrays.asList(current.getDeclaredMethods()));
current = current.getSuperclass();
count++;
}
System.out.println(methods);
return methods; return methods;
} }
@ -209,28 +193,30 @@ public abstract class SWCommand {
commandList.forEach(subCommand -> { commandList.forEach(subCommand -> {
StringBuilder st = new StringBuilder(); StringBuilder st = new StringBuilder();
st.append("§8/§7").append(command.getName()).append(" "); st.append("§8/§7").append(command.getName()).append(" ");
st.append("§7").append(String.join(" ", subCommand.subCommand)).append(" "); st.append("§7").append(String.join(" ", subCommand.subCommand));
int i = 1; String cmd = Arrays.stream(subCommand.parameters)
while (i < subCommand.parameters.length) { .skip(1)
Parameter parameter = subCommand.parameters[i]; .map(parameter -> {
Name name = parameter.getAnnotation(Name.class); Name name = parameter.getAnnotation(Name.class);
st.append("§8[§7"); if (name != null) {
if (name != null) { return name.name();
st.append(name.name()); } else {
} else { return parameter.getName();
st.append(parameter.getName()); }
} })
st.append("§8]"); .map(param -> "§8[§e" + param + "§8]")
i++; .collect(Collectors.joining(" "));
} st.append(cmd);
if (subCommand.varArgType != null) { if (subCommand.varArgType != null) {
st.append("§7..."); st.append("§7...");
} }
st.append("§8 - §7Description Here"); if (!subCommand.description.isEmpty()) {
st.append("§8 - §7").append(subCommand.description);
}
help.add(st.toString()); help.add(st.toString());
}); });
} }
sender.sendMessage("§7----==== §e" + command.getName() + "§7====----"); sender.sendMessage("§7----==== §e" + command.getName() + " §7====----");
help.forEach(sender::sendMessage); help.forEach(sender::sendMessage);
} }
@ -240,6 +226,8 @@ public abstract class SWCommand {
protected @interface Register { protected @interface Register {
String[] value() default {}; String[] value() default {};
String description() default "";
boolean help() default false; boolean help() default false;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

Datei anzeigen

@ -34,6 +34,7 @@ class SubCommand {
private SWCommand swCommand; private SWCommand swCommand;
private Method method; private Method method;
String description;
Parameter[] parameters; Parameter[] parameters;
String[] subCommand; String[] subCommand;
TypeMapper<?>[] arguments; TypeMapper<?>[] arguments;
@ -41,9 +42,10 @@ class SubCommand {
private Function<CommandSender, ?> commandSenderFunction; private Function<CommandSender, ?> commandSenderFunction;
Class<?> varArgType = null; Class<?> varArgType = null;
SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map<String, TypeMapper<?>> localTypeMapper) { SubCommand(SWCommand swCommand, Method method, String description, String[] subCommand, Map<String, TypeMapper<?>> localTypeMapper) {
this.swCommand = swCommand; this.swCommand = swCommand;
this.method = method; this.method = method;
this.description = description;
parameters = method.getParameters(); parameters = method.getParameters();
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass()); commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());