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.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<Material>() {
return new TypeMapper<>() {
@Override
public Material map(String s) {
return Material.valueOf(s.toUpperCase());
}
@Override
public List<String> tabCompletes(String s) {
public List<String> tabCompletes(CommandSender commandSender, String[] previous, String s) {
return tabCompletes;
}
};

Datei anzeigen

@ -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();
}
}