mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 20:24:43 +02:00
Fixing some stuff after testing
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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) : "";
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user