mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-06 07:34:42 +02:00
cleanup
This commit is contained in:
@ -7,7 +7,8 @@ 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;
|
||||
|
||||
@ -17,41 +18,50 @@ public class HelpMenu {
|
||||
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() {
|
||||
this._maxPage = Math.max((_commands.size() - 1) / PER_PAGE, 0);
|
||||
public HelpMenu generateMaxPages()
|
||||
{
|
||||
_maxPage = Math.max((_commands.size() - 1) / PER_PAGE, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HelpMenu generatePage(int currentPage, 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);
|
||||
int max = Math.min((currentPage * PER_PAGE) + (PER_PAGE - 1), _commands.size());
|
||||
for (int i = currentPage * PER_PAGE; i < max; i++) {
|
||||
final 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), label));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
public void render()
|
||||
{
|
||||
_page.render(_player);
|
||||
}
|
||||
|
||||
|
@ -5,27 +5,32 @@ 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, String label) {
|
||||
this._command = command;
|
||||
this._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);
|
||||
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(Argument[] arguments) {
|
||||
if (arguments == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (final Argument<?> argument : arguments) {
|
||||
private String buildArgumentList(final Argument[] arguments)
|
||||
{
|
||||
if (arguments == null) { return ""; }
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
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) : "";
|
||||
|
@ -8,33 +8,41 @@ 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(CommandCategory category, int currentPage, 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) + "");
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user