Skip to content

Commit

Permalink
temporary fix to the Unknown command problem in Paper
Browse files Browse the repository at this point in the history
  • Loading branch information
Revxrsal committed Sep 27, 2023
1 parent 0271257 commit 7a1a673
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.mojang.brigadier.LiteralMessage;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import revxrsal.commands.CommandHandler;
import revxrsal.commands.bukkit.BukkitBrigadier;
Expand Down Expand Up @@ -56,6 +57,10 @@ public NodeParser(BukkitBrigadier brigadier) {
this.brigadier = brigadier;
}

private Node createExecutableNode(ArgumentBuilder<?, ?> builder) {
return Node.from(builder).canBeExecuted(brigadier);
}

public List<Node> parse(CommandHandler handler) {
List<Node> nodes = new ArrayList<>();
for (CommandCategory category : handler.getCategories().values()) {
Expand All @@ -70,7 +75,7 @@ public List<Node> parse(CommandHandler handler) {
private List<Node> createNodes(CommandParameter parameter) {
if (parameter.isSwitch()) {
String switchLiteral = parameter.getCommandHandler().getSwitchPrefix() + parameter.getSwitchName();
return singletonList(new Node(literal(switchLiteral)));
return singletonList(createExecutableNode(literal(switchLiteral)));
}
if (parameter.getType() == Either.class) {
EitherParameter[] either = EitherParameter.create(parameter);
Expand All @@ -83,7 +88,7 @@ private List<Node> createNodes(CommandParameter parameter) {
ArgumentType<?> argumentType = brigadier.getArgumentType(parameter);
boolean isLast = parameter.getCommandIndex() == command.getValueParameters().size() - 1;

Node node = new Node(argument(parameter.getName(), argumentType));
Node node = createExecutableNode(argument(parameter.getName(), argumentType));
node.require(generateRequirement(parameter));
node.suggest(createSuggestionProvider(brigadier, parameter));
if (isLast)
Expand All @@ -92,7 +97,7 @@ private List<Node> createNodes(CommandParameter parameter) {
}

public Node create(CommandCategory category) {
Node node = new Node(literal(category.getName()));
Node node = createExecutableNode(literal(category.getName()));
node.require(generateRequirement(category));

for (CommandCategory subcategory : category.getCategories().values()) {
Expand All @@ -116,7 +121,7 @@ private Predicate<Object> generateRequirement(PermissionHolder holder) {
}

public Node create(ExecutableCommand command) {
Node node = new Node(literal(command.getName()));
Node node = createExecutableNode(literal(command.getName()));
node.require(generateRequirement(command));
addExecutables(command, node);
return node;
Expand Down Expand Up @@ -154,7 +159,7 @@ private void addParameterNodes(ExecutableCommand command, Node targetNode) {
}

private void addFlagParameter(CommandParameter parameter, ArrayList<Node> lastNodes) {
Node flagLiteral = new Node(literal(parameter.getCommandHandler().getFlagPrefix() + parameter.getFlagName()));
Node flagLiteral = createExecutableNode(literal(parameter.getCommandHandler().getFlagPrefix() + parameter.getFlagName()));
flagLiteral.require(generateRequirement(parameter));

if (parameter.isOptional())
Expand Down

0 comments on commit 7a1a673

Please sign in to comment.