Added command help and fixed a general help command implementation.

This commit is contained in:
Olof Larsson 2011-12-15 16:37:49 +01:00
parent 5ee13b7af9
commit 1a8a8e0e21
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package com.massivecraft.mcore1.cmd;
import java.util.ArrayList;
import com.massivecraft.mcore1.MPlugin;
import com.massivecraft.mcore1.cmd.MCommand;
public class HelpCommand extends MCommand
{
private HelpCommand()
{
super();
this.addAliases("?", "h", "help");
this.setDesc("");
this.addOptionalArg("page","1");
}
@Override
public void perform()
{
if (this.commandChain.size() == 0) return;
MCommand parentCommand = this.commandChain.get(this.commandChain.size()-1);
ArrayList<String> lines = new ArrayList<String>();
lines.addAll(p().txt.parse(parentCommand.getHelp()));
for(MCommand subCommand : parentCommand.getSubCommands())
{
if (subCommand.visibleTo(sender))
{
lines.add(subCommand.getUseageTemplate(this.commandChain, true));
}
}
Integer pagenumber = this.argAs(0, Integer.class, 1);
if (pagenumber == null) return;
sendMessage(p().txt.getPage(lines, pagenumber, "Help for command \""+parentCommand.getAliases().get(0)+"\""));
}
@Override
public MPlugin p()
{
if (this.commandChain.size() == 0) return null;
return this.commandChain.get(this.commandChain.size()-1).p();
}
private static HelpCommand instance = new HelpCommand();
public static HelpCommand getInstance()
{
return instance;
}
}

View File

@ -95,6 +95,13 @@ public abstract class MCommand
public String getDescPermission() { return this.descPermission; }
public void setDescPermission(String val) { this.descPermission = val; }
// FIELD: help
// This is a multi-line help text for the command.
protected List<String> help = new ArrayList<String>();
public void setHelp(List<String> val) { this.help = val; }
public void setHelp(String... val) { this.help = Arrays.asList(val); }
public List<String> getHelp() { return this.help; }
// FIELD: visibilityMode
protected VisibilityMode visibilityMode;
public VisibilityMode getVisibilityMode() { return this.visibilityMode; }