fix subLiterals unknown and the test
All checks were successful
/ test (push) Successful in 1m4s
/ deploy (push) Successful in 1m15s

two stupid bugs...
This commit is contained in:
kento2 2026-08-29 16:20:22 +02:00
parent 77ea59cc92
commit 546be9db36
6 changed files with 32 additions and 41 deletions

View file

@ -20,5 +20,4 @@ public class BukkitCommandContext<C extends CommandContext<C>> extends AbstractC
public Player player() {
return (Player) sender();
}
}

View file

@ -29,7 +29,7 @@ public class BukkitScrowCommand<C extends BukkitCommandContext<C>> extends Comma
commandHandler.invoke(
rootLiteral,
commandContextFactory.createContext(rootLiteral, commandSender),
Stream.of(args).filter(str -> !str.isEmpty())
Stream.of(args).filter(arg -> !arg.isEmpty())
);
return true;
}

View file

@ -26,7 +26,6 @@ public class NodeTreeWalker<C extends CommandContext<C>> {
) {
var cursor = new Cursor(iter);
Literal<C> literal = rootLiteral;
String token;
while (true) {
for (var arg : literal.arguments()) {
@ -36,14 +35,12 @@ public class NodeTreeWalker<C extends CommandContext<C>> {
return res;
}
token = cursor.nextToken();
if (token == null)
var literalName = cursor.nextToken();
if (literalName == null)
break;
var nextLiteral = literal.getSubLiteral(token);
if (nextLiteral == null)
return new WalkResult.LiteralUnknown<>(ctx, literal, token);
if (platformAdapter.checkPermission(ctx, nextLiteral.permission()))
return new WalkResult.LiteralUnknown<>(ctx, literal, token);
var nextLiteral = literal.getSubLiteral(literalName);
if (nextLiteral == null || !platformAdapter.checkPermission(ctx, nextLiteral.permission()))
return new WalkResult.LiteralUnknown<>(ctx, literal, literalName);
literal = nextLiteral;
}

View file

@ -24,36 +24,37 @@ class CommandHandlerTest {
private static final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private static final PrintStream originalOut = System.out;
private final CommandHandler<CommandContextImpl> commandHandler = new CommandHandler<>(new TestPlatform(Collections.emptyList()));
private final CommandHandler<CommandContextImpl> commandHandler = new CommandHandler<>(new TestPlatform());
private final Argument<CommandContextImpl, String> playerArg =
Argument.builder("player", new StringArgumentType<CommandContextImpl>())
.build();
private final Argument<CommandContextImpl, Integer> amountArg =
Argument.builder("amount", new IntegerArgumentType<CommandContextImpl>())
.build();
private final RootLiteral<CommandContextImpl> rootLiteral = Literal.<CommandContextImpl>builder("coins")
.withSyncExecutor(_ -> {
System.out.println("default executor");
})
.withSubLiteral(Literal.<CommandContextImpl>builder("get")
.withArgument(playerArg)
.withSyncExecutor(ctx -> {
var player = ctx.getArg(playerArg);
System.out.println("get executor: player=" + player);
private final RootLiteral<CommandContextImpl> rootLiteral =
Literal.<CommandContextImpl>builder("coins")
.withSyncExecutor(_ -> {
System.out.println("default executor");
})
.build()
)
.withSubLiteral(Literal.<CommandContextImpl>builder("set")
.withArgument(playerArg)
.withArgument(amountArg)
.withSyncExecutor(ctx -> {
var player = ctx.getArg(playerArg);
var amount = ctx.getArg(amountArg);
System.out.println("set executor: player=" + player + " amount=" + amount);
})
.build()
)
.asRootLiteral(MessageStyle.PLAIN);
.withSubLiteral(Literal.<CommandContextImpl>builder("get")
.withArgument(playerArg)
.withSyncExecutor(ctx -> {
var player = ctx.getArg(playerArg);
System.out.println("get executor: player=" + player);
})
.build()
)
.withSubLiteral(Literal.<CommandContextImpl>builder("set")
.withArgument(playerArg)
.withArgument(amountArg)
.withSyncExecutor(ctx -> {
var player = ctx.getArg(playerArg);
var amount = ctx.getArg(amountArg);
System.out.println("set executor: player=" + player + " amount=" + amount);
})
.build()
)
.asRootLiteral(MessageStyle.PLAIN);
@BeforeAll
static void init() {

View file

@ -10,15 +10,9 @@ public class TestPlatform implements PlatformAdapter<CommandContextImpl> {
private final PlainTextComponentSerializer plainText = PlainTextComponentSerializer.plainText();
private final List<String> permissions;
public TestPlatform(List<String> permissions) {
this.permissions = new ArrayList<>(permissions);
}
@Override
public boolean checkPermission(CommandContextImpl ctx, String permission) {
return permissions.contains(permission);
return true;
}
@Override

View file

@ -1,2 +1,2 @@
GROUP = "site.lab0x13.scrow"
VERSION = "1.3.1"
VERSION = "1.3.2"