Hows this?

This commit is contained in:
boy0001
2015-09-13 14:04:31 +10:00
parent 1cccdd9d4d
commit 5137b23357
379 changed files with 18471 additions and 28437 deletions

View File

@ -7,62 +7,52 @@ import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.Command;
public class HelpMenu
{
public class HelpMenu {
public static final int PER_PAGE = 5;
private final PlotPlayer _player;
private HelpPage _page = new HelpPage(CommandCategory.ACTIONS, 0, 0);
private int _maxPage;
private CommandCategory _commandCategory;
private List<Command<PlotPlayer>> _commands;
public HelpMenu(final PlotPlayer player)
{
public HelpMenu(final PlotPlayer player) {
_player = player;
}
public HelpMenu setCategory(final CommandCategory commandCategory)
{
public HelpMenu setCategory(final CommandCategory commandCategory) {
_commandCategory = commandCategory;
return this;
}
public HelpMenu getCommands()
{
public HelpMenu getCommands() {
_commands = MainCommand.getCommands(_commandCategory, _player);
return this;
}
public HelpMenu generateMaxPages()
{
public HelpMenu generateMaxPages() {
_maxPage = Math.max((_commands.size() - 1) / PER_PAGE, 0);
return this;
}
public HelpMenu generatePage(int currentPage, final String label)
{
if (currentPage > _maxPage)
{
public HelpMenu generatePage(int currentPage, final String label) {
if (currentPage > _maxPage) {
currentPage = _maxPage;
}
if (currentPage < 0)
{
if (currentPage < 0) {
currentPage = 0;
}
_page = new HelpPage(_commandCategory, currentPage, _maxPage);
final int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), _commands.size());
for (int i = currentPage * PER_PAGE; i < max; i++)
{
for (int i = currentPage * PER_PAGE; i < max; i++) {
_page.addHelpItem(new HelpObject(_commands.get(i), label));
}
return this;
}
public void render()
{
public void render() {
_page.render(_player);
}
}

View File

@ -5,32 +5,29 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.Command;
public class HelpObject
{
public class HelpObject {
private final Command _command;
private final String _rendered;
public HelpObject(final Command command, final String label)
{
public HelpObject(final Command command, final String label) {
_command = command;
_rendered = StringMan.replaceAll(C.HELP_ITEM.s(), "%usage%", _command.getUsage().replaceAll("\\{label\\}", label), "[%alias%]",
_command.getAliases().size() > 0 ? "(" + StringMan.join(_command.getAliases(), "|") + ")" : "", "%desc%", _command.getDescription(), "%arguments%",
buildArgumentList(_command.getRequiredArguments()), "{label}", label);
}
@Override
public String toString()
{
public String toString() {
return _rendered;
}
private String buildArgumentList(final Argument[] arguments)
{
if (arguments == null) { return ""; }
private String buildArgumentList(final Argument[] arguments) {
if (arguments == null) {
return "";
}
final StringBuilder builder = new StringBuilder();
for (final Argument<?> argument : arguments)
{
for (final Argument<?> argument : arguments) {
builder.append("[").append(argument.getName()).append(" (").append(argument.getExample()).append(")],");
}
return arguments.length > 0 ? builder.substring(0, builder.length() - 1) : "";

View File

@ -8,41 +8,30 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
public class HelpPage
{
public class HelpPage {
private final List<HelpObject> _helpObjecs;
private final String _header;
public HelpPage(final CommandCategory category, final int currentPage, final int maxPages)
{
public HelpPage(final CommandCategory category, final int currentPage, final int maxPages) {
_helpObjecs = new ArrayList<>();
_header = C.HELP_PAGE_HEADER.s()
.replace("%category%", category == null ? "ALL" : category.toString())
.replace("%current%", (currentPage + 1) + "")
.replace("%max%", (maxPages + 1) + "");
_header = C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "ALL" : category.toString()).replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + "");
}
public void render(final PlotPlayer player)
{
if (_helpObjecs.size() < 1)
{
public void render(final PlotPlayer player) {
if (_helpObjecs.size() < 1) {
MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)");
}
else
{
} else {
MainUtil.sendMessage(player, C.HELP_HEADER.s(), false);
MainUtil.sendMessage(player, _header, false);
for (final HelpObject object : _helpObjecs)
{
for (final HelpObject object : _helpObjecs) {
MainUtil.sendMessage(player, object.toString(), false);
}
MainUtil.sendMessage(player, C.HELP_FOOTER.s(), false);
}
}
public void addHelpItem(final HelpObject object)
{
public void addHelpItem(final HelpObject object) {
_helpObjecs.add(object);
}
}