Skip to content

Commit

Permalink
Fixed pesky issue with command help and cleaned the code up a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
MuresanSergiu committed Jul 20, 2015
1 parent b127e56 commit 555582c
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions src/main/java/myessentials/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,50 +338,47 @@ public static boolean callSubFunctions(ICommandSender sender, List<String> args,
}
}

sendHelpMessage(sender, callersPermNode, null, local);
sendHelpMessage(sender, callersPermNode, local);
return false;
}

/**
* Sends the help message for the permission node with the arguments.
* Sends the help message for the permission node.
*/
public static void sendHelpMessage(ICommandSender sender, String permBase, List<String> args, Localization local) {
String node;
if (args == null || args.isEmpty()) {
//If no arguments are provided then we check for the base permission
node = permBase;
} else {
node = getPermissionNodeFromArgs(args, permBase);
}


String command = "/" + commandNames.get(permBase);

if(args != null) {
String prevNode = permBase;
for (String s : args) {
String t = getSubCommandNode(s, prevNode);
if (t != null) {
command += " " + s;
prevNode = t;
} else
break;
}
}
public static void sendHelpMessage(ICommandSender sender, String sendHelpNode, Localization local) {
ChatUtils.sendChat(sender, getCommandLineFromNode(sendHelpNode));

ChatUtils.sendChat(sender, command);
List<String> scList = getSubCommandsList(node);
List<String> scList = getSubCommandsList(sendHelpNode);
if (scList == null || scList.isEmpty()) {
ChatUtils.sendChat(sender, " " + local.getLocalization(node + ".help"));
ChatUtils.sendChat(sender, " " + local.getLocalization(sendHelpNode + ".help"));
} else {
List<String> nameList = new ArrayList<String>();
for(String s : scList) {
nameList.add(commandNames.get(s));
}
Collections.sort(nameList);
for (String s : nameList) {
ChatUtils.sendChat(sender, " " + s + ": " + local.getLocalization(getSubCommandNode(s, node) + ".help"));
ChatUtils.sendChat(sender, " " + s + ": " + local.getLocalization(getSubCommandNode(s, sendHelpNode) + ".help"));
}
}
}

/**
* It will construct and return the command line, that a player needs to execute, to call the method linked to the sent permNode.
*/
public static String getCommandLineFromNode(String permNode) {
Stack<String> commandStack = new Stack<String>();
String currentNode = permNode;
while(currentNode != null) {
commandStack.push(commandNames.get(currentNode));
currentNode = commandParents.get(currentNode);
}

String command = "/";
while(!commandStack.isEmpty()) {
command += commandStack.pop() + " ";
}

return command;
}
}

0 comments on commit 555582c

Please sign in to comment.