Dieser Commit ist enthalten in:
Ursprung
d9bb62d5f3
Commit
cc5d435199
@ -21,5 +21,6 @@ package de.steamwar.command;
|
|||||||
|
|
||||||
public enum GuardCheckType {
|
public enum GuardCheckType {
|
||||||
COMMAND,
|
COMMAND,
|
||||||
|
HELP_COMMAND,
|
||||||
TAB_COMPLETE
|
TAB_COMPLETE
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ public abstract class SWCommand {
|
|||||||
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
|
Bukkit.getLogger().log(Level.WARNING, () -> "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>(), localGuardChecker));
|
commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>(), localGuardChecker, true));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
@ -131,7 +131,7 @@ public abstract class SWCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper, localGuardChecker));
|
commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper, localGuardChecker, false));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.commandList.sort((o1, o2) -> {
|
this.commandList.sort((o1, o2) -> {
|
||||||
|
@ -43,10 +43,12 @@ class SubCommand {
|
|||||||
private Function<CommandSender, ?> commandSenderFunction;
|
private Function<CommandSender, ?> commandSenderFunction;
|
||||||
private GuardChecker guardChecker;
|
private GuardChecker guardChecker;
|
||||||
Class<?> varArgType = null;
|
Class<?> varArgType = null;
|
||||||
|
private boolean help = false;
|
||||||
|
|
||||||
SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map<String, TypeMapper<?>> localTypeMapper, Map<String, GuardChecker> localGuardChecker) {
|
SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map<String, TypeMapper<?>> localTypeMapper, Map<String, GuardChecker> localGuardChecker, boolean help) {
|
||||||
this.swCommand = swCommand;
|
this.swCommand = swCommand;
|
||||||
this.method = method;
|
this.method = method;
|
||||||
|
this.help = help;
|
||||||
|
|
||||||
Parameter[] parameters = method.getParameters();
|
Parameter[] parameters = method.getParameters();
|
||||||
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());
|
commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass());
|
||||||
@ -116,13 +118,13 @@ class SubCommand {
|
|||||||
objects[0] = commandSenderFunction.apply(commandSender);
|
objects[0] = commandSenderFunction.apply(commandSender);
|
||||||
for (int i = 0; i < objects.length; i++) {
|
for (int i = 0; i < objects.length; i++) {
|
||||||
GuardChecker current;
|
GuardChecker current;
|
||||||
if (i == 0 && guardChecker != null) {
|
if (i == 0) {
|
||||||
current = guardChecker;
|
current = guardChecker;
|
||||||
} else {
|
} else {
|
||||||
current = guards[i - 1];
|
current = guards[i - 1];
|
||||||
}
|
}
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
GuardResult guardResult = current.guard(commandSender, GuardCheckType.COMMAND, new String[0], null);
|
GuardResult guardResult = current.guard(commandSender, help ? GuardCheckType.HELP_COMMAND : GuardCheckType.COMMAND, new String[0], null);
|
||||||
if (guardResult != GuardResult.ALLOWED) {
|
if (guardResult != GuardResult.ALLOWED) {
|
||||||
if (guardResult == GuardResult.DENIED) {
|
if (guardResult == GuardResult.DENIED) {
|
||||||
throw new CommandNoHelpException();
|
throw new CommandNoHelpException();
|
||||||
@ -133,6 +135,8 @@ class SubCommand {
|
|||||||
}
|
}
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(swCommand, objects);
|
method.invoke(swCommand, objects);
|
||||||
|
} catch (CommandNoHelpException e) {
|
||||||
|
throw e;
|
||||||
} catch (IllegalAccessException | RuntimeException | InvocationTargetException e) {
|
} catch (IllegalAccessException | RuntimeException | InvocationTargetException e) {
|
||||||
throw new SecurityException(e.getMessage(), e);
|
throw new SecurityException(e.getMessage(), e);
|
||||||
} catch (CommandParseException e) {
|
} catch (CommandParseException e) {
|
||||||
@ -156,16 +160,17 @@ class SubCommand {
|
|||||||
if (!value.equalsIgnoreCase(s)) return null;
|
if (!value.equalsIgnoreCase(s)) return null;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
int guardIndex = 0;
|
||||||
for (TypeMapper<?> argument : arguments) {
|
for (TypeMapper<?> argument : arguments) {
|
||||||
String s = argsList.remove(0);
|
String s = argsList.remove(0);
|
||||||
if (argsList.isEmpty()) {
|
if (argsList.isEmpty()) {
|
||||||
if (guards[index] != null && guards[index].guard(commandSender, GuardCheckType.TAB_COMPLETE, Arrays.copyOf(args, args.length - 1), s) != GuardResult.ALLOWED) {
|
if (guards[guardIndex] != null && guards[guardIndex].guard(commandSender, GuardCheckType.TAB_COMPLETE, Arrays.copyOf(args, args.length - 1), s) != GuardResult.ALLOWED) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s);
|
return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (guards[index] != null && guards[index].guard(commandSender, GuardCheckType.TAB_COMPLETE, Arrays.copyOf(args, index), s) != GuardResult.ALLOWED) {
|
if (guards[guardIndex] != null && guards[guardIndex].guard(commandSender, GuardCheckType.TAB_COMPLETE, Arrays.copyOf(args, index), s) != GuardResult.ALLOWED) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (argument.map(commandSender, Arrays.copyOf(args, index), s) == null) {
|
if (argument.map(commandSender, Arrays.copyOf(args, index), s) == null) {
|
||||||
@ -175,6 +180,7 @@ class SubCommand {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
guardIndex++;
|
||||||
}
|
}
|
||||||
if (varArgType != null && !argsList.isEmpty()) {
|
if (varArgType != null && !argsList.isEmpty()) {
|
||||||
while (!argsList.isEmpty()) {
|
while (!argsList.isEmpty()) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren