From 96953bdec40be6e8cc478e2eba0cd45d840fbd48 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 20 Jun 2022 19:35:02 +0200 Subject: [PATCH] Update stuff --- src/de/steamwar/command/AbstractSWCommand.java | 12 ++---------- src/de/steamwar/command/TabCompletionCache.java | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index ad249cb..1de5785 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -111,7 +111,7 @@ public abstract class AbstractSWCommand { for (Method method : methods) { Cached cached = method.getAnnotation(Cached.class); addMapper(Mapper.class, method, i -> i == 0, false, AbstractTypeMapper.class, (anno, typeMapper) -> { - addToCache(cached, typeMapper); + TabCompletionCache.add(typeMapper, cached); if (anno.local()) { localTypeMapper.putIfAbsent(anno.value(), (AbstractTypeMapper) typeMapper); } else { @@ -119,7 +119,7 @@ public abstract class AbstractSWCommand { } }); addMapper(ClassMapper.class, method, i -> i == 0, false, AbstractTypeMapper.class, (anno, typeMapper) -> { - addToCache(cached, typeMapper); + TabCompletionCache.add(typeMapper, cached); if (anno.local()) { localTypeMapper.putIfAbsent(anno.value().getTypeName(), (AbstractTypeMapper) typeMapper); } else { @@ -213,14 +213,6 @@ public abstract class AbstractSWCommand { initialized = true; } - private void addToCache(Cached cached, AbstractTypeMapper typeMapper) { - if (cached != null) { - TabCompletionCache.cached.add(typeMapper); - if (cached.global()) TabCompletionCache.global.add(typeMapper); - TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration())); - } - } - private void add(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer consumer) { T[] anno = SWCommandUtils.getAnnotation(method, annotation); if (anno == null || anno.length == 0) return; diff --git a/src/de/steamwar/command/TabCompletionCache.java b/src/de/steamwar/command/TabCompletionCache.java index aa60cc6..258b253 100644 --- a/src/de/steamwar/command/TabCompletionCache.java +++ b/src/de/steamwar/command/TabCompletionCache.java @@ -15,6 +15,14 @@ public class TabCompletionCache { Set> global = new HashSet<>(); Map, Long> cacheDuration = new HashMap<>(); + void add(AbstractTypeMapper typeMapper, AbstractSWCommand.Cached cached) { + if (cached != null) { + TabCompletionCache.cached.add(typeMapper); + if (cached.global()) TabCompletionCache.global.add(typeMapper); + TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration())); + } + } + @EqualsAndHashCode @AllArgsConstructor private static class Key {