Automatic addition of the HelpCommand.
This commit is contained in:
parent
8f11f59c12
commit
7ff0b99596
@ -3,6 +3,9 @@ package com.massivecraft.massivecore.cmd;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
@ -58,4 +61,23 @@ public class HelpCommand extends MassiveCommand
|
||||
message(Txt.getPage(lines, page, "Help for command \"" + parentCommand.getAliases().get(0) + "\"", this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisibleTo(CommandSender sender)
|
||||
{
|
||||
boolean visible = super.isVisibleTo(sender);
|
||||
if ( ! (this.hasParentCommand() && visible)) return visible;
|
||||
|
||||
int pageHeight = (sender instanceof Player) ? Txt.PAGEHEIGHT_PLAYER : Txt.PAGEHEIGHT_CONSOLE;
|
||||
int size = this.getParentCommand().getSubCommands().size();
|
||||
|
||||
if (size <= pageHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -132,6 +132,11 @@ public class MassiveCommand
|
||||
|
||||
public void addSubCommand(MassiveCommand subCommand, int index)
|
||||
{
|
||||
if (this.subCommands.isEmpty() && ! (subCommand instanceof HelpCommand))
|
||||
{
|
||||
this.subCommands.add(0, HelpCommand.get());
|
||||
index++;
|
||||
}
|
||||
subCommand.addToCommandChain(this);
|
||||
this.subCommands.add(index, subCommand);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user