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
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #121 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
feba7b6eaf
@ -34,6 +34,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public abstract class SWCommand {
|
public abstract class SWCommand {
|
||||||
|
|
||||||
|
private boolean initialized = false;
|
||||||
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<>();
|
||||||
@ -47,6 +48,9 @@ public abstract class SWCommand {
|
|||||||
this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) {
|
this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) {
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(CommandSender sender, String alias, String[] args) {
|
public boolean execute(CommandSender sender, String alias, String[] args) {
|
||||||
|
if (!initialized) {
|
||||||
|
createMapping();
|
||||||
|
}
|
||||||
if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false;
|
if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false;
|
||||||
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
|
commandHelpList.stream().anyMatch(s -> s.invoke(sender, args));
|
||||||
return false;
|
return false;
|
||||||
@ -54,6 +58,9 @@ public abstract class SWCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
|
||||||
|
if (!initialized) {
|
||||||
|
createMapping();
|
||||||
|
}
|
||||||
String string = args[args.length - 1].toLowerCase();
|
String string = args[args.length - 1].toLowerCase();
|
||||||
return commandList.stream()
|
return commandList.stream()
|
||||||
.map(s -> s.tabComplete(sender, args))
|
.map(s -> s.tabComplete(sender, args))
|
||||||
@ -66,7 +73,9 @@ public abstract class SWCommand {
|
|||||||
};
|
};
|
||||||
unregister();
|
unregister();
|
||||||
register();
|
register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void createMapping() {
|
||||||
Method[] methods = getClass().getDeclaredMethods();
|
Method[] methods = getClass().getDeclaredMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> {
|
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));
|
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) {
|
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren