Make HelpMessage more advanced
Dieser Commit ist enthalten in:
Ursprung
e56d4c0e42
Commit
7e733fca7c
@ -36,8 +36,9 @@ public class TestCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// One Help Command, the first Parameter should be some kind of CommandSender
|
// 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
|
@RegisterHelp
|
||||||
public void testHelp(Player player) {
|
public void testHelp(Player player, String... args) {
|
||||||
player.sendMessage("This is your help message");
|
player.sendMessage("This is your help message");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +90,12 @@ public abstract class SWCommand {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> {
|
add(RegisterHelp.class, method, i -> i != 1, true, null, (anno, parameters) -> {
|
||||||
|
if (!parameters[parameters.length - 1].isVarArgs()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (parameters[parameters.length - 1].getType().getComponentType() != String.class) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
commandHelpSet.add(new SubCommand(this, method, anno.value()));
|
commandHelpSet.add(new SubCommand(this, method, anno.value()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
class SubCommand {
|
class SubCommand {
|
||||||
@ -63,7 +60,7 @@ class SubCommand {
|
|||||||
for (Enum<?> enumConstant : enumClass.getEnumConstants()) {
|
for (Enum<?> enumConstant : enumClass.getEnumConstants()) {
|
||||||
tabCompletes.add(enumConstant.name().toLowerCase());
|
tabCompletes.add(enumConstant.name().toLowerCase());
|
||||||
}
|
}
|
||||||
arguments[i] = SWCommandUtils.createMapper(s -> SWCommandUtils.ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes);
|
arguments[i - 1] = SWCommandUtils.createMapper(s -> SWCommandUtils.ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +69,7 @@ class SubCommand {
|
|||||||
name = mapper.value();
|
name = mapper.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
arguments[i] = SWCommandUtils.MAPPER_FUNCTIONS.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION);
|
arguments[i - 1] = SWCommandUtils.MAPPER_FUNCTIONS.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +77,9 @@ class SubCommand {
|
|||||||
if (args.length < arguments.length - 1) {
|
if (args.length < arguments.length - 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!varArgs && args.length > arguments.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Object[] objects = SWCommandUtils.generateArgumentArray(arguments, args, varArgs, subCommand);
|
Object[] objects = SWCommandUtils.generateArgumentArray(arguments, args, varArgs, subCommand);
|
||||||
objects[0] = commandSenderFunction.apply(commandSender);
|
objects[0] = commandSenderFunction.apply(commandSender);
|
||||||
@ -97,7 +97,7 @@ class SubCommand {
|
|||||||
if (!varArgs && args.length < arguments.length - 1) {
|
if (!varArgs && args.length < arguments.length - 1) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<String> argsList = Arrays.asList(args);
|
List<String> argsList = new LinkedList<>(Arrays.asList(args));
|
||||||
for (String value : subCommand) {
|
for (String value : subCommand) {
|
||||||
String s = argsList.remove(0);
|
String s = argsList.remove(0);
|
||||||
if (argsList.isEmpty()) return Collections.singletonList(value);
|
if (argsList.isEmpty()) return Collections.singletonList(value);
|
||||||
@ -107,7 +107,9 @@ class SubCommand {
|
|||||||
String s = argsList.remove(0);
|
String s = argsList.remove(0);
|
||||||
if (argsList.isEmpty()) return argument.tabCompletes(s);
|
if (argsList.isEmpty()) return argument.tabCompletes(s);
|
||||||
try {
|
try {
|
||||||
argument.map(s);
|
if (argument.map(s) == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren