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() { public Player player() {
return (Player) sender(); return (Player) sender();
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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