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-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-08-04 16:07:07 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.Caption;
|
2020-07-22 19:42:22 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.StaticCaption;
|
2020-07-22 00:08:51 +02:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.database.DBFunc;
|
2021-01-09 22:28:41 +01:00
|
|
|
import com.plotsquared.core.permissions.Permission;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
|
|
|
import com.plotsquared.core.plot.flag.implementations.HideInfoFlag;
|
2021-03-28 17:39:02 +02:00
|
|
|
import com.plotsquared.core.util.TabCompletions;
|
2022-05-14 17:05:28 +02:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
|
|
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
2016-03-23 02:41:37 +01:00
|
|
|
|
2021-03-28 17:39:02 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2020-02-24 18:42:02 +01:00
|
|
|
@CommandDeclaration(command = "info",
|
2021-01-09 22:28:41 +01:00
|
|
|
aliases = "i",
|
|
|
|
usage = "/plot info <id> [-f to force info]",
|
|
|
|
category = CommandCategory.INFO)
|
2019-04-24 00:48:22 +02:00
|
|
|
public class Info extends SubCommand {
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
2015-07-03 04:11:41 +02:00
|
|
|
Plot plot;
|
2016-02-10 19:59:51 +01:00
|
|
|
String arg;
|
2015-09-13 06:04:31 +02:00
|
|
|
if (args.length > 0) {
|
2016-02-10 19:59:51 +01:00
|
|
|
arg = args[0];
|
2015-09-13 06:04:31 +02:00
|
|
|
switch (arg) {
|
2021-12-30 15:41:31 +01:00
|
|
|
// TODO: (re?)implement /plot info inv. (it was never properly implemented)
|
2023-03-06 11:38:30 +01:00
|
|
|
case "trusted", "alias", "biome", "denied", "flags", "id", "size", "members", "creationdate", "seen", "owner", "rating", "likes" ->
|
|
|
|
plot = Plot
|
|
|
|
.getPlotFromString(player, null, false);
|
2021-05-15 20:39:16 +02:00
|
|
|
default -> {
|
2020-07-19 14:23:55 +02:00
|
|
|
plot = Plot.getPlotFromString(player, arg, false);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (args.length == 2) {
|
2015-07-03 04:11:41 +02:00
|
|
|
arg = args[1];
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2015-07-03 04:11:41 +02:00
|
|
|
arg = null;
|
|
|
|
}
|
2021-05-15 20:39:16 +02:00
|
|
|
}
|
2015-06-24 05:48:23 +02:00
|
|
|
}
|
2016-02-10 19:59:51 +01:00
|
|
|
if (plot == null) {
|
|
|
|
plot = player.getCurrentPlot();
|
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2016-02-10 19:59:51 +01:00
|
|
|
arg = null;
|
|
|
|
plot = player.getCurrentPlot();
|
2015-07-03 04:11:41 +02:00
|
|
|
}
|
2015-09-13 06:04:31 +02:00
|
|
|
if (plot == null) {
|
2020-07-22 00:08:51 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
2015-06-24 05:31:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-03-30 12:50:32 +01:00
|
|
|
|
2015-09-13 06:04:31 +02:00
|
|
|
if (arg != null) {
|
|
|
|
if (args.length == 1) {
|
2015-06-24 05:31:13 +02:00
|
|
|
args = new String[0];
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2021-01-09 22:28:41 +01:00
|
|
|
args = new String[]{args[1]};
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-30 12:50:32 +01:00
|
|
|
|
|
|
|
// hide-info flag
|
2020-02-24 18:42:02 +01:00
|
|
|
if (plot.getFlag(HideInfoFlag.class)) {
|
2019-03-30 12:50:32 +01:00
|
|
|
boolean allowed = false;
|
|
|
|
for (final String argument : args) {
|
|
|
|
if (argument.equalsIgnoreCase("-f")) {
|
2019-08-07 02:35:36 +02:00
|
|
|
if (!player
|
2021-01-09 22:28:41 +01:00
|
|
|
.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE.toString())) {
|
2020-07-22 00:08:51 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("permission.no_permission"),
|
2022-05-14 17:05:28 +02:00
|
|
|
TagResolver.resolver(
|
|
|
|
"node",
|
|
|
|
Tag.inserting(Permission.PERMISSION_AREA_INFO_FORCE)
|
|
|
|
)
|
2020-07-22 00:08:51 +02:00
|
|
|
);
|
2019-03-30 12:50:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
allowed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!allowed) {
|
2020-07-22 00:08:51 +02:00
|
|
|
player.sendMessage(TranslatableCaption.of("info.plot_info_hidden"));
|
2019-03-30 12:50:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 02:41:37 +01:00
|
|
|
boolean hasOwner = plot.hasOwner();
|
2014-11-05 04:42:08 +01:00
|
|
|
// Wildcard player {added}
|
2018-11-14 23:51:56 +01:00
|
|
|
boolean containsEveryone = plot.getTrusted().contains(DBFunc.EVERYONE);
|
|
|
|
boolean trustedEveryone = plot.getMembers().contains(DBFunc.EVERYONE);
|
2014-11-05 04:42:08 +01:00
|
|
|
// Unclaimed?
|
2015-09-13 06:04:31 +02:00
|
|
|
if (!hasOwner && !containsEveryone && !trustedEveryone) {
|
2020-07-22 00:08:51 +02:00
|
|
|
player.sendMessage(
|
|
|
|
TranslatableCaption.of("info.plot_info_unclaimed"),
|
2022-05-14 17:05:28 +02:00
|
|
|
TagResolver.resolver(
|
|
|
|
"plot",
|
|
|
|
Tag.inserting(Component.text(plot.getId().getX() + ";" + plot.getId().getY()))
|
|
|
|
)
|
2020-07-22 00:08:51 +02:00
|
|
|
);
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
|
|
|
}
|
2020-08-04 16:07:07 +02:00
|
|
|
Caption info = TranslatableCaption.of("info.plot_info_format");
|
2015-10-07 08:33:33 +02:00
|
|
|
boolean full;
|
2015-09-13 06:04:31 +02:00
|
|
|
if (arg != null) {
|
2015-07-03 04:11:41 +02:00
|
|
|
info = getCaption(arg);
|
2015-09-13 06:04:31 +02:00
|
|
|
if (info == null) {
|
2019-04-22 17:55:05 +02:00
|
|
|
if (Settings.Ratings.USE_LIKES) {
|
2021-01-09 22:28:41 +01:00
|
|
|
player.sendMessage(StaticCaption.of(
|
|
|
|
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
|
|
|
+ "&aowner&7, " + " &alikes"));
|
2019-04-22 17:55:05 +02:00
|
|
|
} else {
|
2021-01-09 22:28:41 +01:00
|
|
|
player.sendMessage(StaticCaption.of(
|
|
|
|
"&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &aseen&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, "
|
|
|
|
+ "&aowner&7, " + " &arating"));
|
2019-04-22 17:55:05 +02:00
|
|
|
}
|
2014-11-05 04:42:08 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-07 08:33:33 +02:00
|
|
|
full = true;
|
2015-09-13 06:04:31 +02:00
|
|
|
} else {
|
2015-10-07 08:33:33 +02:00
|
|
|
full = false;
|
|
|
|
}
|
2020-08-04 16:07:07 +02:00
|
|
|
plot.format(info, player, full).thenAcceptAsync(player::sendMessage);
|
2014-11-05 04:42:08 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2021-03-28 17:39:02 +02:00
|
|
|
@Override
|
|
|
|
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
|
|
|
final List<String> completions = new LinkedList<>();
|
2023-01-15 14:08:59 +01:00
|
|
|
if (player.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE)) {
|
2021-03-28 17:39:02 +02:00
|
|
|
completions.add("-f");
|
|
|
|
}
|
|
|
|
|
|
|
|
final List<Command> commands = completions.stream().filter(completion -> completion
|
2021-08-18 11:58:18 +02:00
|
|
|
.toLowerCase()
|
|
|
|
.startsWith(args[0].toLowerCase()))
|
2021-03-28 17:39:02 +02:00
|
|
|
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
|
|
|
}).collect(Collectors.toCollection(LinkedList::new));
|
|
|
|
|
2023-01-15 14:08:59 +01:00
|
|
|
if (player.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE) && args[0].length() > 0) {
|
2021-10-01 21:52:44 +02:00
|
|
|
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
2021-03-28 17:39:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return commands;
|
|
|
|
}
|
|
|
|
|
2020-08-04 16:07:07 +02:00
|
|
|
private Caption getCaption(String string) {
|
2021-05-15 20:39:16 +02:00
|
|
|
return switch (string) {
|
|
|
|
case "trusted" -> TranslatableCaption.of("info.plot_info_trusted");
|
|
|
|
case "alias" -> TranslatableCaption.of("info.plot_info_alias");
|
|
|
|
case "biome" -> TranslatableCaption.of("info.plot_info_biome");
|
|
|
|
case "denied" -> TranslatableCaption.of("info.plot_info_denied");
|
|
|
|
case "flags" -> TranslatableCaption.of("info.plot_info_flags");
|
|
|
|
case "id" -> TranslatableCaption.of("info.plot_info_id");
|
|
|
|
case "size" -> TranslatableCaption.of("info.plot_info_size");
|
|
|
|
case "members" -> TranslatableCaption.of("info.plot_info_members");
|
|
|
|
case "owner" -> TranslatableCaption.of("info.plot_info_owner");
|
|
|
|
case "rating" -> TranslatableCaption.of("info.plot_info_rating");
|
|
|
|
case "likes" -> TranslatableCaption.of("info.plot_info_likes");
|
|
|
|
case "seen" -> TranslatableCaption.of("info.plot_info_seen");
|
|
|
|
case "creationdate" -> TranslatableCaption.of("info.plot_info_creationdate");
|
|
|
|
default -> null;
|
|
|
|
};
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|