From 2ad2dc29e458d997e61ac3fbd48fd35f05d8d59d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 29 Mar 2021 22:20:03 +0200 Subject: [PATCH] Add SWCommand.ClassMapper --- .../src/de/steamwar/command/SWCommand.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index ed6c7c1..3b4b6e7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -89,6 +89,15 @@ public abstract class SWCommand { throw new SecurityException(e.getMessage(), e); } }); + add(ClassMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, parameters) -> { + try { + method.setAccessible(true); + Object object = method.invoke(this); + SWCommandUtils.addMapper(anno.value().getTypeName(), (TypeMapper) object); + } catch (Exception e) { + throw new SecurityException(e.getMessage(), e); + } + }); add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> { if (!parameters[parameters.length - 1].isVarArgs()) { return; @@ -167,4 +176,11 @@ public abstract class SWCommand { String value(); } + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD}) + protected @interface ClassMapper { + Class value(); + } + }