Skip to content

Commit

Permalink
feat: Use DescriptionFacade instead of Description in cloud commands …
Browse files Browse the repository at this point in the history
…for native descriptions
  • Loading branch information
phinner committed May 30, 2024
1 parent 5afb8bf commit 2285ae3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import mindustry.gen.Player;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.incendo.cloud.Command;
import org.incendo.cloud.description.Description;
import org.incendo.cloud.help.HelpQuery;
import org.incendo.cloud.help.result.MultipleCommandResult;
import org.incendo.cloud.help.result.VerboseCommandResult;
Expand All @@ -44,23 +43,23 @@ final class CloudCommandFacade<C> extends CommandHandler.Command implements Comm
final MindustryCommandManager<C> manager;
private final boolean alias;
private final String realName;
private final Description cloudDescription;
private final DescriptionFacade descriptionFacade;

CloudCommandFacade(
final String name,
final Description description,
final DescriptionFacade description,
final MindustryCommandManager<C> manager,
final boolean alias,
final boolean prefixed) {
super(
(prefixed ? manager.getPlugin().getMetadata().getName() + ":" : "") + name,
"[args...]",
description.textDescription(),
description.getText(),
new CloudCommandRunner<>(name, manager));
this.manager = manager;
this.alias = alias;
this.realName = name;
this.cloudDescription = description;
this.descriptionFacade = description;
}

@Override
Expand All @@ -75,7 +74,7 @@ public String getName() {

@Override
public DescriptionFacade getDescription() {
return this.manager.descriptionMapper().map(this.cloudDescription);
return descriptionFacade;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ public boolean registerCommand(final Command<C> command) {
command.rootComponent().aliases().forEach(this.handler::removeCommand);
}

final var descriptionFacade = this.manager.descriptionMapper().map(description);

// Register with the primary name
this.addCommand(new CloudCommandFacade<>(
command.rootComponent().name(),
description,
descriptionFacade,
this.manager,
false,
this.commands.containsKey(command.rootComponent().name())));

for (final var alias : command.rootComponent().alternativeAliases()) {
if (!this.commands.containsKey(alias)) {
this.addCommand(new CloudCommandFacade<>(alias, description, this.manager, true, false));
this.addCommand(new CloudCommandFacade<>(alias, descriptionFacade, this.manager, true, false));
}
}

Expand Down

0 comments on commit 2285ae3

Please sign in to comment.