Skip to content

Commit

Permalink
Add BladeConfiguration.helpSorter to sort commands in help output
Browse files Browse the repository at this point in the history
  • Loading branch information
vaperion committed Jul 22, 2023
1 parent deb8adf commit 9d87ec1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ allprojects {
}

group = 'me.vaperion.blade'
version = '3.0.5'
version = '3.0.6'

// workaround for gradle issue: https://github.com/gradle/gradle/issues/17236#issuecomment-894385386
tasks.withType(Copy).all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ public class BukkitHelpGenerator implements HelpGenerator {
@NotNull
@Override
public List<String> generate(@NotNull Context context, @NotNull List<Command> commands) {
commands = commands.stream().distinct().filter(c -> !c.isHidden()).collect(Collectors.toList());
commands = commands.stream()
.distinct()
.filter(c -> !c.isHidden())
.sorted(context.blade().getConfiguration().getHelpSorter())
.collect(Collectors.toList());

int originalCount = commands.size();
commands = commands.stream().filter(c -> context.blade().getPermissionTester().testPermission(context, c))
commands = commands.stream()
.filter(c -> context.blade().getPermissionTester().testPermission(context, c))
.collect(Collectors.toList());

if (originalCount != 0 && commands.size() == 0) {
if (originalCount != 0 && commands.isEmpty()) {
return Collections.singletonList(ChatColor.RED + context.blade().getConfiguration().getDefaultPermissionMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.Getter;
import lombok.Setter;
import me.vaperion.blade.command.Command;
import me.vaperion.blade.util.Preconditions;

import java.util.Comparator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
Expand All @@ -26,6 +28,8 @@ public final class BladeConfiguration {
private HelpGenerator helpGenerator;
private TabCompleter tabCompleter;

private Comparator<Command> helpSorter = Comparator.comparing(Command::getUsageAlias);

public void validate() {
Preconditions.checkNotNull(pluginInstance, "Plugin instance cannot be null.");
Preconditions.checkNotNull(fallbackPrefix, "Fallback prefix cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ public class VelocityHelpGenerator implements HelpGenerator {

@Override
public @NotNull List<String> generate(@NotNull Context context, @NotNull List<Command> commands) {
commands = commands.stream().distinct().filter(c -> !c.isHidden()).collect(Collectors.toList());
commands = commands.stream()
.distinct()
.filter(c -> !c.isHidden())
.sorted(context.blade().getConfiguration().getHelpSorter())
.collect(Collectors.toList());

int originalCount = commands.size();
commands = commands.stream().filter(c -> context.blade().getPermissionTester().testPermission(context, c))
commands = commands.stream()
.filter(c -> context.blade().getPermissionTester().testPermission(context, c))
.collect(Collectors.toList());

if (originalCount != 0 && commands.size() == 0) {
if (originalCount != 0 && commands.isEmpty()) {
return Collections.singletonList("&c" + context.blade().getConfiguration().getDefaultPermissionMessage());
}

Expand Down

0 comments on commit 9d87ec1

Please sign in to comment.