SteamWar/SpigotCore
Archiviert
13
0

Removed cluttered Annotations

Dieser Commit ist enthalten in:
yoyosource 2021-03-30 08:21:55 +02:00
Ursprung 7bc47a8997
Commit 6ac208dc56
2 geänderte Dateien mit 18 neuen und 20 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.acommand;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays; 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 // 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 // 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) { public void testHelp(Player player, String... args) {
player.sendMessage("This is your help message"); player.sendMessage("This is your help message");
} }
@ -65,14 +66,14 @@ public class TestCommand extends SWCommand {
.map(Material::name) .map(Material::name)
.map(String::toLowerCase) .map(String::toLowerCase)
.collect(Collectors.toList()); .collect(Collectors.toList());
return new TypeMapper<Material>() { return new TypeMapper<>() {
@Override @Override
public Material map(String s) { public Material map(String s) {
return Material.valueOf(s.toUpperCase()); return Material.valueOf(s.toUpperCase());
} }
@Override @Override
public List<String> tabCompletes(String s) { public List<String> tabCompletes(CommandSender commandSender, String[] previous, String s) {
return tabCompletes; return tabCompletes;
} }
}; };

Datei anzeigen

@ -80,15 +80,19 @@ public abstract class SWCommand {
for (Method method : getClass().getDeclaredMethods()) { for (Method method : getClass().getDeclaredMethods()) {
addMapper(Mapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> { 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) -> { addMapper(ClassMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> {
SWCommandUtils.addMapper(anno.value().getTypeName(), typeMapper); SWCommandUtils.addMapper(anno.value().getTypeName(), typeMapper);
}); });
addMapper(LocalMapper.class, method, i -> i != 0, false, TypeMapper.class, (anno, typeMapper) -> { add(Register.class, method, i -> i != 2, true, null, (anno, parameters) -> {
localTypeMapper.put(anno.value(), typeMapper); if (!anno.help()) {
}); return;
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> { }
if (!parameters[parameters.length - 1].isVarArgs()) { if (!parameters[parameters.length - 1].isVarArgs()) {
return; return;
} }
@ -100,6 +104,9 @@ public abstract class SWCommand {
} }
for (Method method : getClass().getDeclaredMethods()) { for (Method method : getClass().getDeclaredMethods()) {
add(Register.class, method, i -> i == 0, true, null, (anno, parameters) -> { add(Register.class, method, i -> i == 0, true, null, (anno, parameters) -> {
if (anno.help()) {
return;
}
for (int i = 1; i < parameters.length; i++) { for (int i = 1; i < parameters.length; i++) {
Parameter parameter = parameters[i]; Parameter parameter = parameters[i];
Class<?> clazz = parameter.getType(); Class<?> clazz = parameter.getType();
@ -164,18 +171,14 @@ public abstract class SWCommand {
@Target({ElementType.METHOD}) @Target({ElementType.METHOD})
protected @interface Register { protected @interface Register {
String[] value() default {}; String[] value() default {};
} boolean help() default false;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
protected @interface RegisterHelp {
String[] value() default {};
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.METHOD}) @Target({ElementType.PARAMETER, ElementType.METHOD})
protected @interface Mapper { protected @interface Mapper {
String value(); String value();
boolean local() default false;
} }
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ -183,10 +186,4 @@ public abstract class SWCommand {
protected @interface ClassMapper { protected @interface ClassMapper {
Class<?> value(); Class<?> value();
} }
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
protected @interface LocalMapper {
String value();
}
} }