Fixing some stuff after testing

This commit is contained in:
boy0001
2015-07-28 03:28:39 +10:00
parent 5b2e83587b
commit 955fa674d0
16 changed files with 79 additions and 86 deletions

View File

@ -33,18 +33,18 @@ public class HelpMenu {
}
public HelpMenu generateMaxPages() {
this._maxPage = Math.min(_commands.size() / PER_PAGE, 1);
this._maxPage = Math.max(_commands.size() - 1 / PER_PAGE, 1);
return this;
}
public HelpMenu generatePage(int currentPage) {
public HelpMenu generatePage(int currentPage, String label) {
if (currentPage > _maxPage) {
currentPage = _maxPage;
}
_page = new HelpPage(_commandCategory, currentPage, _maxPage);
int max = Math.min((currentPage * PER_PAGE) + PER_PAGE, _commands.size());
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), _commands.size());
for (int i = currentPage * PER_PAGE; i < max; i++) {
_page.addHelpItem(new HelpObject(_commands.get(i)));
_page.addHelpItem(new HelpObject(_commands.get(i), label));
}
return this;
}

View File

@ -10,14 +10,9 @@ public class HelpObject {
private final Command _command;
private final String _rendered;
public HelpObject(final Command command) {
public HelpObject(final Command command, String label) {
this._command = command;
String rendered = C.HELP_ITEM.s();
this._rendered = rendered
.replace("%usage%", _command.getUsage())
.replace("%alias%", _command.getAliases().size() > 0 ? StringMan.join(_command.getAliases(), "|") : "")
.replace("%desc%", _command.getDescription())
.replace("%arguments%", buildArgumentList(_command.getRequiredArguments())); // TODO Make configurable
this._rendered = StringMan.replaceAll(C.HELP_ITEM.s(), "%usage%", _command.getUsage(), "[%alias%]", _command.getAliases().size() > 0 ? "(" + StringMan.join(_command.getAliases(), "|") + ")" : "","%desc%", _command.getDescription(),"%arguments%", buildArgumentList(_command.getRequiredArguments()), "{label}", label);
}
@Override
@ -26,8 +21,11 @@ public class HelpObject {
}
private String buildArgumentList(Argument[] arguments) {
if (arguments == null) {
return "";
}
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

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