CommandFramework3 #94
@ -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;
|
||||
Lixfel
hat
Ich denke mal, das throw new SecurityException aus der Zeile drüber wäre auch angebracht. Auf jeden Fall für "RuntimeException". Ich denke mal, das throw new SecurityException aus der Zeile drüber wäre auch angebracht. Auf jeden Fall für "RuntimeException".
|
||||
}
|
||||
|
||||
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
Das ist nicht so das, was ich fürs FightSystem gemeint habe. Ich möchte eigentlich nicht, dass sich der Command merkt, ob er jetzt enabled oder disabled ist, sondern den Command einfach Registrieren und aber auch wieder Entregistrieren können. Dann kann ich nämlich auch bestimmen, wass der Command macht, wenn er "disabled" ist, oder gar komplexere State-Machines umsetzen.
Ok ich gucke, dass ich das eingebaut bekomme, an sich muss ich ja nur unregister können. Weril registerieren tust du ja mit einer Instanz erzeugen,
Dies sollte nun möglich sein.