Add SubCommand.parameters
Add SWCommand.internalHelp
Dieser Commit ist enthalten in:
Ursprung
b91e898560
Commit
ffef7f0bcb
@ -34,6 +34,9 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public abstract class SWCommand {
|
public abstract class SWCommand {
|
||||||
|
|
||||||
|
private boolean hasHelp = false;
|
||||||
|
private final List<String> help = new ArrayList<>();
|
||||||
|
|
||||||
private final Command command;
|
private final Command command;
|
||||||
private final List<SubCommand> commandList = new ArrayList<>();
|
private final List<SubCommand> commandList = new ArrayList<>();
|
||||||
private final List<SubCommand> commandHelpList = new ArrayList<>();
|
private final List<SubCommand> commandHelpList = new ArrayList<>();
|
||||||
@ -87,6 +90,14 @@ 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") && method.getDeclaringClass() == SWCommand.class) {
|
||||||
|
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.value(), new HashMap<>()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -166,6 +177,36 @@ public abstract class SWCommand {
|
|||||||
SWCommandUtils.commandMap.register("steamwar", this.command);
|
SWCommandUtils.commandMap.register("steamwar", this.command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
private void internalHelp(CommandSender sender, String... args){
|
||||||
|
if (help.isEmpty()) {
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
if (subCommand.varArgType != null) {
|
||||||
|
st.append("§7...");
|
||||||
|
}
|
||||||
|
help.add(st.toString());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
sender.sendMessage("§7Help§8: §e" + command.getName());
|
||||||
|
help.forEach(sender::sendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD})
|
||||||
@Repeatable(Register.Registeres.class)
|
@Repeatable(Register.Registeres.class)
|
||||||
@ -196,4 +237,10 @@ public abstract class SWCommand {
|
|||||||
|
|
||||||
boolean local() default false;
|
boolean local() default false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.PARAMETER})
|
||||||
|
protected @interface Name {
|
||||||
|
String name();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ class SubCommand {
|
|||||||
|
|
||||||
private SWCommand swCommand;
|
private SWCommand swCommand;
|
||||||
private Method method;
|
private Method method;
|
||||||
|
Parameter[] parameters;
|
||||||
String[] subCommand;
|
String[] subCommand;
|
||||||
TypeMapper<?>[] arguments;
|
TypeMapper<?>[] arguments;
|
||||||
private Predicate<CommandSender> commandSenderPredicate;
|
private Predicate<CommandSender> commandSenderPredicate;
|
||||||
@ -44,7 +45,7 @@ class SubCommand {
|
|||||||
this.swCommand = swCommand;
|
this.swCommand = swCommand;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
|
||||||
Parameter[] parameters = method.getParameters();
|
parameters = method.getParameters();
|
||||||
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());
|
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());
|
||||||
commandSenderFunction = sender -> parameters[0].getType().cast(sender);
|
commandSenderFunction = sender -> parameters[0].getType().cast(sender);
|
||||||
this.subCommand = subCommand;
|
this.subCommand = subCommand;
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren