Skip to content

Commit

Permalink
Polish command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofpu committed Jan 28, 2024
1 parent 5bb3b25 commit d71ec5c
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,20 @@ public void init(final BukkitPlugin plugin) {

registerExceptions(commandHandler);

commandHandler.setHelpWriter((command, actor) -> String.format("/%s %s - %s", command.getPath().toRealString(), command.getUsage(), command.getDescription()));
commandHandler.registerContextResolver((Class) MinimalCommandHelp.class, new MinimalCommandHelpResolver(commandHandler));
commandHandler.setHelpWriter((command, actor) -> {
String description = command.getDescription();
if (description == null) {
description = "No description provided!";
}
CommandPath commandPath = command.getPath();
String last = commandPath.getLast();
if (commandPath.getFirst().equals(last)) {
return ChatUtil.colorize(String.format("&8|-> /&e%s &f%s &8- &7%s", commandPath.toRealString(), command.getUsage(), description));
}
String pathExcludingLast = commandPath.toRealString().replace(" " + last, "");
return ChatUtil.colorize(String.format("&8|-> /&e%s &f%s &e%s &r&8- &7%s", pathExcludingLast, last, command.getUsage(), description).trim());
});

commandHandler.register(new PluginCommandHolder(plugin));
commandHandler.register(new DeveloperCommandHolder(plugin));
Expand All @@ -50,20 +62,6 @@ public void init(final BukkitPlugin plugin) {
}
});

commandHandler.setHelpWriter((command, actor) -> {
String description = command.getDescription();
if (description == null) {
description = "No description provided!";
}
CommandPath commandPath = command.getPath();
String last = commandPath.getLast();
if (commandPath.getFirst().equals(last)) {
return ChatUtil.colorize(String.format("&8|-> /&e%s &f%s &8- &7%s", commandPath.toRealString(), command.getUsage(), description));
}
String pathExcludingLast = commandPath.toRealString().replace(" " + last, "");
return ChatUtil.colorize(String.format("&8|-> /&e%s &f%s &e%s &r&8- &7%s", pathExcludingLast, last, command.getUsage(), description).trim());
});

Arrays.stream(new CoreCommandExtension().commands(plugin.bridgeSystem(), plugin.setupSystem()))
.forEach(coreCommand -> {
String mainPath = "speedbridge %s".replace("%s", coreCommand.name()).trim();
Expand Down

0 comments on commit d71ec5c

Please sign in to comment.