From 5bd160b0c984ef6f9a27002dc50a8dc3ae2732b7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Mar 2021 08:59:12 +0100 Subject: [PATCH] Optimize SWCommand --- .../src/de/steamwar/command/SWCommand.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index eac71c3..8c24bad 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -26,6 +26,7 @@ import java.lang.annotation.*; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.*; +import java.util.function.BiConsumer; import java.util.function.IntPredicate; import static de.steamwar.command.SWCommandUtils.getAnnotation; @@ -77,7 +78,7 @@ public abstract class SWCommand { Set commandMethods = new HashSet<>(); for (Method method : getClass().getDeclaredMethods()) { - add(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, method1, parameters) -> { + add(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, parameters) -> { try { method.setAccessible(true); Object object = method.invoke(this); @@ -86,7 +87,7 @@ public abstract class SWCommand { throw new SecurityException(e.getMessage(), e); } }); - add(Register.class, method, i -> i == 0, true, null, (anno, method1, parameters) -> { + add(Register.class, method, i -> i == 0, true, null, (anno, parameters) -> { for (int i = 1; i < parameters.length; i++) { Parameter parameter = parameters[i]; Class clazz = parameter.getType(); @@ -105,14 +106,14 @@ public abstract class SWCommand { } commandMethods.add(method); }); - add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, method1, parameters) -> { + add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> { commandHelpSet.add(new SubCommand(this, method)); }); } commandMethods.forEach(method -> commandSet.add(new SubCommand(this, method))); } - private void add(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, SWConsumer consumer) { + private void add(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer consumer) { T anno = getAnnotation(method, annotation); if (anno == null) { return; @@ -128,12 +129,7 @@ public abstract class SWCommand { if (returnType != null && method.getReturnType() != returnType) { return; } - consumer.consume(anno, method, parameters); - } - - @FunctionalInterface - private interface SWConsumer { - void consume(T anno, Method method, Parameter[] parameters); + consumer.accept(anno, parameters); } @Retention(RetentionPolicy.RUNTIME)