Add SubCommand.description
Dieser Commit ist enthalten in:
Ursprung
8985393fe1
Commit
4b23274f8d
@ -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");
|
||||
return;
|
||||
}
|
||||
if (method.getName().equals("internalHelp")) {
|
||||
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<>()));
|
||||
commandHelpList.add(new SubCommand(this, method, anno.description(), anno.value(), new HashMap<>()));
|
||||
});
|
||||
}
|
||||
for (Method method : methods) {
|
||||
@ -123,7 +114,7 @@ public abstract class SWCommand {
|
||||
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) -> {
|
||||
@ -171,15 +162,8 @@ public abstract class SWCommand {
|
||||
}
|
||||
|
||||
private List<Method> methods() {
|
||||
Class<?> current = getClass();
|
||||
List<Method> methods = new ArrayList<>();
|
||||
int count = 0;
|
||||
while (current != null && count < 4) {
|
||||
methods.addAll(Arrays.asList(current.getDeclaredMethods()));
|
||||
current = current.getSuperclass();
|
||||
count++;
|
||||
}
|
||||
System.out.println(methods);
|
||||
List<Method> methods = Arrays.asList(getClass().getDeclaredMethods());
|
||||
methods.addAll(Arrays.asList(SWCommand.class.getDeclaredMethods()));
|
||||
return methods;
|
||||
}
|
||||
|
||||
@ -209,28 +193,30 @@ public abstract class SWCommand {
|
||||
commandList.forEach(subCommand -> {
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append("§8/§7").append(command.getName()).append(" ");
|
||||
st.append("§7").append(String.join(" ", subCommand.subCommand)).append(" ");
|
||||
int i = 1;
|
||||
while (i < subCommand.parameters.length) {
|
||||
Parameter parameter = subCommand.parameters[i];
|
||||
Name name = parameter.getAnnotation(Name.class);
|
||||
st.append("§8[§7");
|
||||
if (name != null) {
|
||||
st.append(name.name());
|
||||
} else {
|
||||
st.append(parameter.getName());
|
||||
}
|
||||
st.append("§8]");
|
||||
i++;
|
||||
}
|
||||
st.append("§7").append(String.join(" ", subCommand.subCommand));
|
||||
String cmd = Arrays.stream(subCommand.parameters)
|
||||
.skip(1)
|
||||
.map(parameter -> {
|
||||
Name name = parameter.getAnnotation(Name.class);
|
||||
if (name != null) {
|
||||
return name.name();
|
||||
} else {
|
||||
return parameter.getName();
|
||||
}
|
||||
})
|
||||
.map(param -> "§8[§e" + param + "§8]")
|
||||
.collect(Collectors.joining(" "));
|
||||
st.append(cmd);
|
||||
if (subCommand.varArgType != null) {
|
||||
st.append("§7...");
|
||||
}
|
||||
st.append("§8 - §7Description Here");
|
||||
if (!subCommand.description.isEmpty()) {
|
||||
st.append("§8 - §7").append(subCommand.description);
|
||||
}
|
||||
help.add(st.toString());
|
||||
});
|
||||
}
|
||||
sender.sendMessage("§7----==== §e" + command.getName() + "§7====----");
|
||||
sender.sendMessage("§7----==== §e" + command.getName() + " §7====----");
|
||||
help.forEach(sender::sendMessage);
|
||||
}
|
||||
|
||||
@ -240,6 +226,8 @@ public abstract class SWCommand {
|
||||
protected @interface Register {
|
||||
String[] value() default {};
|
||||
|
||||
String description() default "";
|
||||
|
||||
boolean help() default false;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -34,6 +34,7 @@ class SubCommand {
|
||||
|
||||
private SWCommand swCommand;
|
||||
private Method method;
|
||||
String description;
|
||||
Parameter[] parameters;
|
||||
String[] subCommand;
|
||||
TypeMapper<?>[] arguments;
|
||||
@ -41,9 +42,10 @@ class SubCommand {
|
||||
private Function<CommandSender, ?> commandSenderFunction;
|
||||
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.method = method;
|
||||
this.description = description;
|
||||
|
||||
parameters = method.getParameters();
|
||||
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren