Only set executor when the command is executable
This commit is contained in:
parent
c88b267758
commit
f5e230945d
2 changed files with 18 additions and 4 deletions
|
|
@ -257,8 +257,10 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
||||||
@Nonnull final BiPredicate<S, String> permissionChecker) {
|
@Nonnull final BiPredicate<S, String> permissionChecker) {
|
||||||
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder.<S>literal(root.getLiteral())
|
final LiteralArgumentBuilder<S> literalArgumentBuilder = LiteralArgumentBuilder.<S>literal(root.getLiteral())
|
||||||
.requires(sender -> permissionChecker.test(sender, cloudCommand.getNodeMeta().getOrDefault("permission", "")))
|
.requires(sender -> permissionChecker.test(sender, cloudCommand.getNodeMeta().getOrDefault("permission", "")));
|
||||||
.executes(executor);
|
if (cloudCommand.isLeaf() && cloudCommand.getValue() != null) {
|
||||||
|
literalArgumentBuilder.executes(executor);
|
||||||
|
}
|
||||||
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
|
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
|
||||||
for (final CommandTree.Node<CommandComponent<C, ?>> child : cloudCommand.getChildren()) {
|
for (final CommandTree.Node<CommandComponent<C, ?>> child : cloudCommand.getChildren()) {
|
||||||
constructedRoot.addChild(this.constructCommandNode(child, permissionChecker, executor, suggestionProvider).build());
|
constructedRoot.addChild(this.constructCommandNode(child, permissionChecker, executor, suggestionProvider).build());
|
||||||
|
|
@ -283,8 +285,10 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
argumentBuilder = RequiredArgumentBuilder
|
argumentBuilder = RequiredArgumentBuilder
|
||||||
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getLeft())
|
.<S, Object>argument(root.getValue().getName(), (ArgumentType<Object>) pair.getLeft())
|
||||||
.suggests(provider)
|
.suggests(provider)
|
||||||
.requires(sender -> permissionChecker.test(sender, root.getNodeMeta().getOrDefault("permission", "")))
|
.requires(sender -> permissionChecker.test(sender, root.getNodeMeta().getOrDefault("permission", "")));
|
||||||
.executes(executor);
|
}
|
||||||
|
if (root.isLeaf() || !root.getValue().isRequired()) {
|
||||||
|
argumentBuilder.executes(executor);
|
||||||
}
|
}
|
||||||
for (final CommandTree.Node<CommandComponent<C, ?>> node : root.getChildren()) {
|
for (final CommandTree.Node<CommandComponent<C, ?>> node : root.getChildren()) {
|
||||||
argumentBuilder.then(constructCommandNode(node, permissionChecker, executor, suggestionProvider));
|
argumentBuilder.then(constructCommandNode(node, permissionChecker, executor, suggestionProvider));
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@ package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.components.StaticComponent;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
||||||
|
import com.intellectualsites.commands.components.standard.BooleanComponent;
|
||||||
|
import com.intellectualsites.commands.components.standard.DoubleComponent;
|
||||||
import com.intellectualsites.commands.components.standard.EnumComponent;
|
import com.intellectualsites.commands.components.standard.EnumComponent;
|
||||||
|
import com.intellectualsites.commands.components.standard.FloatComponent;
|
||||||
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
||||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||||
|
|
@ -136,6 +139,13 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
c.getSender().asPlayer().teleport(world.getSpawnLocation());
|
c.getSender().asPlayer().teleport(world.getSpawnLocation());
|
||||||
c.getSender().sendMessage("Teleported.");
|
c.getSender().sendMessage("Teleported.");
|
||||||
})
|
})
|
||||||
|
.build())
|
||||||
|
.command(mgr.commandBuilder("brigadier")
|
||||||
|
.component(FloatComponent.required("float"))
|
||||||
|
.component(DoubleComponent.required("double"))
|
||||||
|
.component(IntegerComponent.required("int"))
|
||||||
|
.component(BooleanComponent.required("bool"))
|
||||||
|
.component(StringComponent.required("string"))
|
||||||
.build());
|
.build());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue