Add more capabilities to TypeMapper.tabCompletes
Dieser Commit ist enthalten in:
Ursprung
529b3daf6c
Commit
8be46cd7bc
@ -29,8 +29,6 @@ import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
import static de.steamwar.command.SWCommandUtils.getAnnotation;
|
||||
|
||||
public abstract class SWCommand {
|
||||
|
||||
private boolean enabled = true;
|
||||
@ -65,7 +63,7 @@ public abstract class SWCommand {
|
||||
if (!enabled) return Collections.emptyList();
|
||||
List<String> strings = new ArrayList<>();
|
||||
for (SubCommand subCommand : commandSet) {
|
||||
List<String> tabCompletes = subCommand.tabComplete(args);
|
||||
List<String> tabCompletes = subCommand.tabComplete(sender, args);
|
||||
if (tabCompletes != null) {
|
||||
strings.addAll(tabCompletes);
|
||||
}
|
||||
@ -124,7 +122,7 @@ public abstract class SWCommand {
|
||||
}
|
||||
|
||||
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {
|
||||
T anno = getAnnotation(method, annotation);
|
||||
T anno = SWCommandUtils.getAnnotation(method, annotation);
|
||||
if (anno == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package de.steamwar.command;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
@ -133,12 +134,26 @@ public class SWCommandUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompletes(String s) {
|
||||
public List<String> tabCompletes(CommandSender commandSender, String s) {
|
||||
return tabCompleter.apply(s);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, BiFunction<CommandSender, String, List<String>> tabCompleter) {
|
||||
return new TypeMapper<T>() {
|
||||
@Override
|
||||
public T map(String s) {
|
||||
return mapper.apply(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, String s) {
|
||||
return tabCompleter.apply(commandSender, s);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Function<String, List<String>> numberCompleter(Function<String, ?> mapper) {
|
||||
return s -> {
|
||||
try {
|
||||
|
@ -100,7 +100,7 @@ class SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> tabComplete(String[] args) {
|
||||
List<String> tabComplete(CommandSender commandSender, String[] args) {
|
||||
if (!varArgs && args.length < arguments.length - 1) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@ -112,7 +112,7 @@ class SubCommand {
|
||||
}
|
||||
for (TypeMapper<?> argument : arguments) {
|
||||
String s = argsList.remove(0);
|
||||
if (argsList.isEmpty()) return argument.tabCompletes(s);
|
||||
if (argsList.isEmpty()) return argument.tabCompletes(commandSender, s);
|
||||
try {
|
||||
if (argument.map(s) == null) {
|
||||
return Collections.emptyList();
|
||||
@ -124,7 +124,7 @@ class SubCommand {
|
||||
if (varArgs && !argsList.isEmpty()) {
|
||||
while (!argsList.isEmpty()) {
|
||||
String s = argsList.remove(0);
|
||||
if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(s);
|
||||
if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(commandSender, s);
|
||||
try {
|
||||
arguments[arguments.length - 1].map(s);
|
||||
} catch (Exception e) {
|
||||
|
@ -19,10 +19,12 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TypeMapper<T> {
|
||||
T map(String s);
|
||||
|
||||
List<String> tabCompletes(String s);
|
||||
List<String> tabCompletes(CommandSender commandSender, String s);
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren