Dieser Commit ist enthalten in:
Ursprung
61999b0507
Commit
b4df616bc4
@ -165,7 +165,7 @@ class CommandPart<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Collection<String> tabCompletes(T sender, String[] args, List<Object> mappedArgs, int startIndex) {
|
private Collection<String> tabCompletes(T sender, String[] args, List<Object> mappedArgs, int startIndex) {
|
||||||
return TabCompletionCache.tabComplete(sender, args[startIndex], (AbstractTypeMapper<Object, ?>) typeMapper, command, () -> {
|
return TabCompletionCache.tabComplete(sender, args[startIndex], (AbstractTypeMapper<Object, ?>) typeMapper, () -> {
|
||||||
try {
|
try {
|
||||||
return typeMapper.tabCompletes(sender, new PreviousArguments(Arrays.copyOf(args, startIndex), mappedArgs.toArray()), args[startIndex]);
|
return typeMapper.tabCompletes(sender, new PreviousArguments(Arrays.copyOf(args, startIndex), mappedArgs.toArray()), args[startIndex]);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -57,22 +57,23 @@ public class TabCompletionCache {
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private static class TabCompletions {
|
private static class TabCompletions {
|
||||||
private AbstractSWCommand<?> command;
|
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
private Collection<String> tabCompletions;
|
private Collection<String> tabCompletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<String> tabComplete(Object sender, String arg, AbstractTypeMapper<Object, ?> typeMapper, AbstractSWCommand<?> command, Supplier<Collection<String>> tabCompleteSupplier) {
|
Collection<String> tabComplete(Object sender, String arg, AbstractTypeMapper<Object, ?> typeMapper, Supplier<Collection<String>> tabCompleteSupplier) {
|
||||||
if (!cached.contains(typeMapper)) return tabCompleteSupplier.get();
|
if (!cached.contains(typeMapper)) return tabCompleteSupplier.get();
|
||||||
|
|
||||||
String normalizedArg = typeMapper.normalize(sender, arg);
|
String normalizedArg = typeMapper.normalize(sender, arg);
|
||||||
if (normalizedArg == null) normalizedArg = "";
|
if (normalizedArg == null) normalizedArg = "";
|
||||||
Key key = global.contains(typeMapper) ? new Key(null, normalizedArg, typeMapper) : new Key(sender, normalizedArg, typeMapper);
|
Key key = new Key(global.contains(typeMapper) ? null : sender, normalizedArg, typeMapper);
|
||||||
|
|
||||||
TabCompletions tabCompletions = tabCompletionCache.computeIfAbsent(key, ignore -> {
|
TabCompletions tabCompletions = tabCompletionCache.computeIfAbsent(key, ignore -> {
|
||||||
return new TabCompletions(command, System.currentTimeMillis(), tabCompleteSupplier.get());
|
return new TabCompletions(System.currentTimeMillis(), tabCompleteSupplier.get());
|
||||||
});
|
});
|
||||||
if (tabCompletions.command != command || System.currentTimeMillis() - tabCompletions.timestamp > cacheDuration.get(typeMapper)) {
|
|
||||||
tabCompletions = new TabCompletions(command, System.currentTimeMillis(), tabCompleteSupplier.get());
|
if (System.currentTimeMillis() - tabCompletions.timestamp > cacheDuration.get(typeMapper)) {
|
||||||
tabCompletionCache.put(key, tabCompletions);
|
tabCompletions.tabCompletions = tabCompleteSupplier.get();
|
||||||
}
|
}
|
||||||
tabCompletions.timestamp = System.currentTimeMillis();
|
tabCompletions.timestamp = System.currentTimeMillis();
|
||||||
return tabCompletions.tabCompletions;
|
return tabCompletions.tabCompletions;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren