SteamWar/SpigotCore
Archiviert
13
0

Fix SWCommand.Register

Fix SWCommand.Mapper
Dieser Commit ist enthalten in:
yoyosource 2021-03-25 13:35:51 +01:00
Ursprung 9adf9f139b
Commit 09e6f0baa8
3 geänderte Dateien mit 28 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,23 @@
package de.steamwar.acommand;
import de.steamwar.command.SWCommand;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class TestCommand extends SWCommand {
public TestCommand() {
super("test");
}
@Register
public void test(Player player) {
}
@Register({"two"})
public void testTwo(Player player, int i, @Mapper("Hello World") Material material) {
}
}

Datei anzeigen

@ -105,7 +105,7 @@ public abstract class SWCommand {
String name = clazz.getTypeName();
Mapper mapper = parameter.getAnnotation(Mapper.class);
if (mapper != null) {
name = mapper.mapper();
name = mapper.value();
}
if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name)) return false;
}
@ -124,13 +124,13 @@ public abstract class SWCommand {
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
protected @interface Register {
String[] subCommand() default {};
String[] value() default {};
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
protected @interface Mapper {
String mapper();
String value();
}
}

Datei anzeigen

@ -25,7 +25,7 @@ class SubCommand {
Parameter[] parameters = method.getParameters();
commandSenderFunction = sender -> parameters[0].getType().cast(sender);
SWCommand.Register register = method.getAnnotation(SWCommand.Register.class);
subCommand = register.subCommand();
subCommand = register.value();
arguments = new TypeMapper[parameters.length - 1];
for (int i = 1; i < parameters.length; i++) {
@ -59,7 +59,7 @@ class SubCommand {
String name = clazz.getTypeName();
SWCommand.Mapper mapper = parameter.getAnnotation(SWCommand.Mapper.class);
if (mapper != null) {
name = mapper.mapper();
name = mapper.value();
}
arguments[i] = SWCommandUtils.MAPPER_FUNCTIONS.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION);