2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.command;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2020-07-22 19:42:22 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.StaticCaption;
|
2020-08-07 12:08:03 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
|
|
|
import com.plotsquared.core.util.MathMan;
|
|
|
|
import com.plotsquared.core.util.StringMan;
|
|
|
|
import com.plotsquared.core.util.helpmenu.HelpMenu;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.util.task.RunnableVal2;
|
|
|
|
import com.plotsquared.core.util.task.RunnableVal3;
|
2020-10-17 21:45:43 +02:00
|
|
|
import net.kyori.adventure.text.Component;
|
2020-08-07 12:08:03 +02:00
|
|
|
import net.kyori.adventure.text.TextComponent;
|
|
|
|
import net.kyori.adventure.text.minimessage.Template;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2022-02-08 15:56:29 +01:00
|
|
|
import java.util.ArrayList;
|
2021-05-22 02:23:54 +02:00
|
|
|
import java.util.Collection;
|
2022-02-08 15:56:29 +01:00
|
|
|
import java.util.List;
|
2021-05-22 02:23:54 +02:00
|
|
|
import java.util.Locale;
|
2019-01-21 09:20:33 +01:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
2020-02-24 18:42:02 +01:00
|
|
|
@CommandDeclaration(command = "help",
|
2021-01-09 22:28:41 +01:00
|
|
|
aliases = "?",
|
|
|
|
category = CommandCategory.INFO,
|
2021-05-07 09:59:17 +02:00
|
|
|
usage = "help [category | #]",
|
2021-01-09 22:28:41 +01:00
|
|
|
permission = "plots.use")
|
2016-03-24 10:57:59 +01:00
|
|
|
public class Help extends Command {
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2016-03-24 10:57:59 +01:00
|
|
|
public Help(Command parent) {
|
|
|
|
super(parent, true);
|
|
|
|
}
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
2021-05-01 18:33:02 +02:00
|
|
|
public boolean canExecute(PlotPlayer<?> player, boolean message) {
|
2015-07-26 20:50:54 +02:00
|
|
|
return true;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
|
2020-04-30 12:33:59 +02:00
|
|
|
@Override
|
2021-01-09 22:28:41 +01:00
|
|
|
public CompletableFuture<Boolean> execute(
|
|
|
|
PlotPlayer<?> player, String[] args,
|
|
|
|
RunnableVal3<Command, Runnable, Runnable> confirm,
|
|
|
|
RunnableVal2<Command, CommandResult> whenDone
|
|
|
|
) {
|
2016-03-24 10:57:59 +01:00
|
|
|
switch (args.length) {
|
2016-03-29 23:00:07 +02:00
|
|
|
case 0:
|
2019-01-21 09:20:33 +01:00
|
|
|
return displayHelp(player, null, 0);
|
2016-03-29 23:00:07 +02:00
|
|
|
case 1:
|
2016-03-24 10:57:59 +01:00
|
|
|
if (MathMan.isInteger(args[0])) {
|
|
|
|
try {
|
2019-01-21 09:20:33 +01:00
|
|
|
return displayHelp(player, null, Integer.parseInt(args[0]));
|
2016-05-21 17:54:00 +02:00
|
|
|
} catch (NumberFormatException ignored) {
|
2019-01-21 09:20:33 +01:00
|
|
|
return displayHelp(player, null, 1);
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-21 09:20:33 +01:00
|
|
|
return displayHelp(player, args[0], 1);
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
2016-03-29 23:00:07 +02:00
|
|
|
case 2:
|
2016-03-24 10:57:59 +01:00
|
|
|
if (MathMan.isInteger(args[1])) {
|
|
|
|
try {
|
2019-01-21 09:20:33 +01:00
|
|
|
return displayHelp(player, args[0], Integer.parseInt(args[1]));
|
2016-05-21 17:54:00 +02:00
|
|
|
} catch (NumberFormatException ignored) {
|
2019-01-21 09:20:33 +01:00
|
|
|
return displayHelp(player, args[0], 1);
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
return CompletableFuture.completedFuture(false);
|
2016-03-29 23:00:07 +02:00
|
|
|
default:
|
2020-07-18 15:06:51 +02:00
|
|
|
sendUsage(player);
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
return CompletableFuture.completedFuture(true);
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public CompletableFuture<Boolean> displayHelp(
|
2021-05-01 18:33:02 +02:00
|
|
|
final PlotPlayer<?> player, final String catRaw,
|
2021-01-09 22:28:41 +01:00
|
|
|
final int page
|
|
|
|
) {
|
2019-01-21 09:20:33 +01:00
|
|
|
return CompletableFuture.supplyAsync(() -> {
|
|
|
|
String cat = catRaw;
|
|
|
|
|
|
|
|
CommandCategory catEnum = null;
|
|
|
|
if (cat != null) {
|
2019-08-06 22:08:56 +02:00
|
|
|
if (!"all".equalsIgnoreCase(cat)) {
|
2019-01-21 09:20:33 +01:00
|
|
|
for (CommandCategory c : CommandCategory.values()) {
|
|
|
|
if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString())) {
|
|
|
|
catEnum = c;
|
|
|
|
cat = c.name();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (catEnum == null) {
|
|
|
|
cat = null;
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
if (cat == null && page == 0) {
|
2020-10-17 21:45:43 +02:00
|
|
|
TextComponent.Builder builder = Component.text();
|
2020-08-07 12:08:03 +02:00
|
|
|
builder.append(MINI_MESSAGE.parse(TranslatableCaption.of("help.help_header").getComponent(player)));
|
2019-01-21 09:20:33 +01:00
|
|
|
for (CommandCategory c : CommandCategory.values()) {
|
2022-02-08 15:56:29 +01:00
|
|
|
if (!c.canAccess(player)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-17 21:45:43 +02:00
|
|
|
builder.append(Component.newline()).append(MINI_MESSAGE
|
2021-12-14 23:04:36 +01:00
|
|
|
.parse(
|
2021-08-18 11:58:18 +02:00
|
|
|
TranslatableCaption.of("help.help_info_item").getComponent(player),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("command", "/plot help"),
|
|
|
|
Template.of("category", c.name().toLowerCase()),
|
|
|
|
Template.of("category_desc", c.getComponent(player))
|
2021-01-09 22:28:41 +01:00
|
|
|
));
|
2019-01-21 09:20:33 +01:00
|
|
|
}
|
2020-10-17 21:45:43 +02:00
|
|
|
builder.append(Component.newline()).append(MINI_MESSAGE
|
2021-12-14 23:04:36 +01:00
|
|
|
.parse(
|
2021-08-18 11:58:18 +02:00
|
|
|
TranslatableCaption.of("help.help_info_item").getComponent(player),
|
2021-12-14 23:04:36 +01:00
|
|
|
Template.of("command", "/plot help"),
|
|
|
|
Template.of("category", "all"),
|
|
|
|
Template.of("category_desc", "Display all commands")
|
2021-01-09 22:28:41 +01:00
|
|
|
));
|
|
|
|
builder.append(Component.newline()).append(MINI_MESSAGE.parse(TranslatableCaption
|
|
|
|
.of("help.help_footer")
|
|
|
|
.getComponent(player)));
|
2020-08-07 12:08:03 +02:00
|
|
|
player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(builder.asComponent())));
|
2019-01-21 09:20:33 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(
|
2021-08-18 11:58:18 +02:00
|
|
|
page - 1,
|
|
|
|
getParent().toString(),
|
|
|
|
player
|
|
|
|
)
|
2021-01-09 22:28:41 +01:00
|
|
|
.render();
|
2019-01-21 09:20:33 +01:00
|
|
|
return true;
|
|
|
|
});
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2021-05-22 02:23:54 +02:00
|
|
|
@Override
|
|
|
|
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
2022-02-08 15:56:29 +01:00
|
|
|
final String argument = args[0].toLowerCase(Locale.ENGLISH);
|
|
|
|
List<Command> result = new ArrayList<>();
|
|
|
|
|
|
|
|
for (final CommandCategory category : CommandCategory.values()) {
|
|
|
|
if (!category.canAccess(player)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
String name = category.name().toLowerCase();
|
|
|
|
if (!name.startsWith(argument)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
result.add(new Command(null, false, name, "", RequiredType.NONE, null) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// add the category "all"
|
|
|
|
if ("all".startsWith(argument)) {
|
|
|
|
result.add(new Command(null, false, "all", "", RequiredType.NONE, null) {
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return result;
|
2021-05-22 02:23:54 +02:00
|
|
|
}
|
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|