Skip to content

Commit

Permalink
List subcommands in a logical order in help.
Browse files Browse the repository at this point in the history
  • Loading branch information
totemo committed Jul 15, 2019
1 parent ede8272 commit 1c92ced
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
Expand All @@ -14,17 +15,19 @@ public abstract class AbstractCommand {

protected VillagerUtils plugin;
private final String permission;
private final HashMap<String, AbstractCommand> subCommands;
private final Map<String, AbstractCommand> subCommands;

public AbstractCommand(VillagerUtils plugin, String permission) {
this.plugin = plugin;
this.permission = permission;
this.subCommands = new HashMap<String, AbstractCommand>();
this.subCommands = new LinkedHashMap<String, AbstractCommand>();
}

public boolean execute(CommandSender sender, String[] args) {
if (!checkPermission(sender))
if (!checkPermission(sender)) {
return false;
}

if (subCommands.size() > 0) {
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: " + getUsage());
Expand Down Expand Up @@ -64,15 +67,8 @@ public Collection<String> getSubCommandNames() {
}

private String getSubcommandsHelp() {
StringBuilder sb = new StringBuilder(ChatColor.GRAY + "Subcommands: ");
Iterator<String> it = subCommands.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
sb.append(key);
if (it.hasNext())
sb.append(", ");
}
return sb.toString();
return ChatColor.DARK_AQUA + "Subcommands: " +
ChatColor.GRAY + subCommands.keySet().stream().collect(Collectors.joining(", "));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ public class VillagerCommand extends AbstractCommand {

public VillagerCommand(VillagerUtils plugin) {
super(plugin, "villagerutils.editvillager");
addSubCommand(new SetNameCommand(plugin));
// Subcommands added in the order listed by /villager help.
addSubCommand(new SpawnCommand(plugin));
addSubCommand(new SetBiomeCommand(plugin));
addSubCommand(new SetProfessionCommand(plugin));
addSubCommand(new SetLevelCommand(plugin));
addSubCommand(new SetNameCommand(plugin));
addSubCommand(new SetStaticCommand(plugin));
addSubCommand(new AddTradeCommand(plugin));
addSubCommand(new RemoveTradeCommand(plugin));
addSubCommand(new ListTradesCommand(plugin));
Expand All @@ -21,8 +24,6 @@ public VillagerCommand(VillagerUtils plugin) {
// addSubCommand(new RefreshTradesCommand(plugin));
addSubCommand(new GetTradeCommand(plugin));
addSubCommand(new SetTradeCommand(plugin));
addSubCommand(new SpawnCommand(plugin));
addSubCommand(new SetStaticCommand(plugin));
}

@Override
Expand Down

0 comments on commit 1c92ced

Please sign in to comment.