Skip to content
This repository has been archived by the owner on Mar 5, 2021. It is now read-only.

Commit

Permalink
Add More in Depth command help option.
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLS3 committed Jul 27, 2017
1 parent 248a6e6 commit db2051d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public abstract class SubCommand {
final private String permission;
final private String usage;
final private String arguments;
private String[] inDepthHelp;

public SubCommand(String name, CommandType type, String permission, String usage, String arguments) {
commandType = type;
Expand Down Expand Up @@ -69,4 +70,15 @@ public String getArguments() {
return arguments;
}

public String[] getInDepthHelp() {
if (inDepthHelp != null) {
return inDepthHelp;
} else {
return new String[]{usage};
}
}

public void setInDepthHelp(String[] inDepthHelp) {
this.inDepthHelp = inDepthHelp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import com.djrapitops.plugin.settings.ColorScheme;
import com.djrapitops.plugin.settings.DefaultMessages;
import com.djrapitops.plugin.utilities.FormattingUtils;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;

/**
* Abstract class for any command that has multiple subcommands.
*
* @author Rsl1122
*
* @param <T> IPlugin implementation type.
* @author Rsl1122
* @since 2.0.0
*/
public abstract class TreeCommand<T extends IPlugin> extends SubCommand {
Expand All @@ -27,7 +29,7 @@ public abstract class TreeCommand<T extends IPlugin> extends SubCommand {
/**
* Class Constructor.
*
* @param plugin Current instance
* @param plugin Current instance
* @param values
* @param helpPrefix
*/
Expand Down Expand Up @@ -90,9 +92,9 @@ private void sendDefaultCommand(ISender sender, String commandLabel, String[] ar
* Checks if Sender has rights to run the command and executes matching
* subcommand.
*
* @param sender source of the command.
* @param sender source of the command.
* @param commandLabel label.
* @param args arguments of the command
* @param args arguments of the command
* @return true
*/
@Override
Expand Down Expand Up @@ -127,8 +129,12 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
return true;
}

String[] realArgs = new String[args.length - 1];
if (args[args.length - 1].equals("?")) {
sender.sendMessage(command.getInDepthHelp());
return true;
}

String[] realArgs = new String[args.length - 1];
System.arraycopy(args, 1, realArgs, 0, args.length - 1);

command.onCommand(sender, commandLabel, realArgs);
Expand All @@ -148,7 +154,7 @@ class HelpCommand<T extends IPlugin> extends SubCommand {
/**
* Subcommand Constructor.
*
* @param plugin Current instance of Plan
* @param plugin Current instance of Plan
* @param command Current instance of PlanCommand
*/
public HelpCommand(T plugin, TreeCommand command) {
Expand All @@ -163,6 +169,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
boolean isConsole = !CommandUtils.isPlayer(sender);
ColorScheme cs = plugin.getColorScheme();
String oColor = cs.getMainColor();
String sColor = cs.getSecondaryColor();
String tColor = cs.getTertiaryColor();

sender.sendMessage(tColor + DefaultMessages.ARROWS_RIGHT.parse() + oColor + " " + StringUtils.capitalize(command.getFirstName()) + " Help");
Expand All @@ -174,6 +181,7 @@ public boolean onCommand(ISender sender, String commandLabel, String[] args) {
.filter(cmd -> !(isConsole && cmd.getCommandType() == CommandType.PLAYER))
.map(cmd -> tColor + " " + DefaultMessages.BALL.toString() + oColor + " /" + command.getHelpCmd() + " " + cmd.getFirstName() + " " + cmd.getArguments() + tColor + " - " + cmd.getUsage())
.forEach(sender::sendMessage);
sender.sendMessage(sColor+" Add ? to the end of the command for more help");
sender.sendMessage(tColor + DefaultMessages.ARROWS_RIGHT.parse());
return true;
}
Expand Down

0 comments on commit db2051d

Please sign in to comment.