SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Add potential StartUpTime decrease by lazy loading commands only on usage' (#121) from StartTime into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #121
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-10-22 20:11:38 +02:00
Commit feba7b6eaf

Datei anzeigen

@ -34,6 +34,7 @@ import java.util.stream.Collectors;
public abstract class SWCommand {
private boolean initialized = false;
private final Command command;
private final List<SubCommand> commandList = new ArrayList<>();
private final List<SubCommand> commandHelpList = new ArrayList<>();
@ -47,6 +48,9 @@ public abstract class SWCommand {
this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) {
@Override
public boolean execute(CommandSender sender, String alias, String[] args) {
if (!initialized) {
createMapping();
}
if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false;
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
return false;
@ -54,6 +58,9 @@ public abstract class SWCommand {
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
if (!initialized) {
createMapping();
}
String string = args[args.length - 1].toLowerCase();
return commandList.stream()
.map(s -> s.tabComplete(sender, args))
@ -66,7 +73,9 @@ public abstract class SWCommand {
};
unregister();
register();
}
private synchronized void createMapping() {
Method[] methods = getClass().getDeclaredMethods();
for (Method method : methods) {
addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> {
@ -123,6 +132,7 @@ public abstract class SWCommand {
});
commandHelpList.sort(Comparator.comparingInt(o -> -o.subCommand.length));
}
initialized = true;
}
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {