From 6ac208dc56c0e95b206efb478c7c2de666b367be Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Mar 2021 08:21:55 +0200 Subject: [PATCH] Removed cluttered Annotations --- .../src/de/steamwar/acommand/TestCommand.java | 7 +++-- .../src/de/steamwar/command/SWCommand.java | 31 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java b/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java index 7b77f97..df35220 100644 --- a/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java +++ b/SpigotCore_Main/src/de/steamwar/acommand/TestCommand.java @@ -22,6 +22,7 @@ package de.steamwar.acommand; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Arrays; @@ -37,7 +38,7 @@ public class TestCommand extends SWCommand { // One Help Command, the first Parameter should be some kind of CommandSender // The second argument can only be a varAgrs string of what arguments was tried to map - @RegisterHelp + @Register(help = true) public void testHelp(Player player, String... args) { player.sendMessage("This is your help message"); } @@ -65,14 +66,14 @@ public class TestCommand extends SWCommand { .map(Material::name) .map(String::toLowerCase) .collect(Collectors.toList()); - return new TypeMapper() { + return new TypeMapper<>() { @Override public Material map(String s) { return Material.valueOf(s.toUpperCase()); } @Override - public List tabCompletes(String s) { + public List tabCompletes(CommandSender commandSender, String[] previous, String s) { return tabCompletes; } }; diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 8b4f663..5488b18 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -80,15 +80,19 @@ public abstract class SWCommand { for (Method method : getClass().getDeclaredMethods()) { addMapper(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> { - SWCommandUtils.addMapper(anno.value(), typeMapper); + if (anno.local()) { + localTypeMapper.put(anno.value(), typeMapper); + } else { + SWCommandUtils.addMapper(anno.value(), typeMapper); + } }); addMapper(ClassMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> { SWCommandUtils.addMapper(anno.value().getTypeName(), typeMapper); }); - addMapper(LocalMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> { - localTypeMapper.put(anno.value(), typeMapper); - }); - add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> { + add(Register.class, method, i -> i != 2, true, null, (anno, parameters) -> { + if (!anno.help()) { + return; + } if (!parameters[parameters.length - 1].isVarArgs()) { return; } @@ -100,6 +104,9 @@ public abstract class SWCommand { } for (Method method : getClass().getDeclaredMethods()) { add(Register.class, method, i -> i == 0, true, null, (anno, parameters) -> { + if (anno.help()) { + return; + } for (int i = 1; i < parameters.length; i++) { Parameter parameter = parameters[i]; Class clazz = parameter.getType(); @@ -164,18 +171,14 @@ public abstract class SWCommand { @Target({ElementType.METHOD}) protected @interface Register { String[] value() default {}; - } - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) - protected @interface RegisterHelp { - String[] value() default {}; + boolean help() default false; } @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER, ElementType.METHOD}) protected @interface Mapper { String value(); + boolean local() default false; } @Retention(RetentionPolicy.RUNTIME) @@ -183,10 +186,4 @@ public abstract class SWCommand { protected @interface ClassMapper { Class value(); } - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.METHOD}) - protected @interface LocalMapper { - String value(); - } }