Add more TypeMapper capabilities
Dieser Commit ist enthalten in:
Ursprung
56c3e730a9
Commit
25d72ab376
@ -37,7 +37,7 @@ 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 were tried to map
|
// The second argument can only be a varArgs string of what arguments were tried to map
|
||||||
@Register(help = true)
|
@Register(help = true)
|
||||||
public void testHelp(Player player, String... args) {
|
public void testHelp(Player player, String... args) {
|
||||||
player.sendMessage("This is your help message");
|
player.sendMessage("This is your help message");
|
||||||
@ -68,7 +68,7 @@ public class TestCommand extends SWCommand {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return new TypeMapper<Material>() {
|
return new TypeMapper<Material>() {
|
||||||
@Override
|
@Override
|
||||||
public Material map(String s) {
|
public Material map(String[] previous, String s) {
|
||||||
return Material.valueOf(s.toUpperCase());
|
return Material.valueOf(s.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ public class SWCommandUtils {
|
|||||||
arguments[arguments.length - 1] = varArgument;
|
arguments[arguments.length - 1] = varArgument;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) {
|
for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) {
|
||||||
arguments[i + 1] = parameters[i].map(args[index]);
|
arguments[i + 1] = parameters[i].map(Arrays.copyOf(args, Math.min(index - 1, 0)), args[index]);
|
||||||
index++;
|
index++;
|
||||||
if (arguments[i + 1] == null) {
|
if (arguments[i + 1] == null) {
|
||||||
throw new CommandParseException();
|
throw new CommandParseException();
|
||||||
@ -128,7 +128,7 @@ public class SWCommandUtils {
|
|||||||
arguments[arguments.length - 1] = varArgument;
|
arguments[arguments.length - 1] = varArgument;
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
Object value = parameters[parameters.length - 1].map(args[index]);
|
Object value = parameters[parameters.length - 1].map(Arrays.copyOf(args, Math.min(index - 1, 0)), args[index]);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new CommandParseException();
|
throw new CommandParseException();
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ public class SWCommandUtils {
|
|||||||
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, BiFunction<CommandSender, String, List<String>> tabCompleter) {
|
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, BiFunction<CommandSender, String, List<String>> tabCompleter) {
|
||||||
return new TypeMapper<T>() {
|
return new TypeMapper<T>() {
|
||||||
@Override
|
@Override
|
||||||
public T map(String s) {
|
public T map(String[] previous, String s) {
|
||||||
return mapper.apply(s);
|
return mapper.apply(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class SubCommand {
|
|||||||
String s = argsList.remove(0);
|
String s = argsList.remove(0);
|
||||||
if (argsList.isEmpty()) return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s);
|
if (argsList.isEmpty()) return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s);
|
||||||
try {
|
try {
|
||||||
if (argument.map(s) == null) {
|
if (argument.map(Arrays.copyOf(args, argsList.size()), s) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -126,7 +126,7 @@ class SubCommand {
|
|||||||
String s = argsList.remove(0);
|
String s = argsList.remove(0);
|
||||||
if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s);
|
if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s);
|
||||||
try {
|
try {
|
||||||
if (arguments[arguments.length - 1].map(s) == null) {
|
if (arguments[arguments.length - 1].map(Arrays.copyOf(args, argsList.size()), s) == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -24,7 +24,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TypeMapper<T> {
|
public interface TypeMapper<T> {
|
||||||
T map(String s);
|
T map(String[] previousArguments, String s);
|
||||||
|
|
||||||
List<String> tabCompletes(CommandSender commandSender, String[] previousArguments, String s);
|
List<String> tabCompletes(CommandSender commandSender, String[] previousArguments, String s);
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren