SteamWar/SpigotCore
Archiviert
13
0

CommandFramework3 #94

Manuell gemergt
Zeanon hat 71 Commits von CommandFramework3 nach master 2021-03-30 21:15:40 +02:00 zusammengeführt
2 geänderte Dateien mit 18 neuen und 20 gelöschten Zeilen
Nur Änderungen aus Commit 6ac208dc56 werden angezeigt - Alle Commits anzeigen

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