PlotSquared/Core/src/main/java/com/plotsquared/core/command/Info.java

192 lines
8.0 KiB
Java
Raw Normal View History

/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* 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.
*
* 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.
*
* 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-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;
import com.plotsquared.core.configuration.caption.Caption;
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;
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;
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;
Pull/2693 (#2694) * Commit WIP flag work. * More ported flag types, and additions to the flag API. * Make PlotFlag more generic to allow generic flag creation * Pull Captions methods into a Caption interface. * Port MusicFlag * Port flight flag * Port UntrustedVisitFlag * Port DenyExitFlag * Remove paper suggestion * Make ListFlag lists immutable * Update Flag containers. Add javadocs. Add missing methods. * Port description flag * Port greeting and farewell flags * Port weather flag * Move getExample implementation to BooleanFlag * Port reserved flags * Port all boolean flags. * Remove unused flag types * Invert liquid-flow flag * Find the real (legacy) flag name * Change NOITFY -> NOTIFY in Captions * Make IntegerFlag extendable * Port integer flags * Update Flag command to current API state * Begin remaking flag command * Create DoubleFlag + extract common parsing stuff * Supply arguments in flag parse exceptions * Implement missing flag subcommands * Update Flag command to current API state * Implement PriceFlag * Port deny-teleport * Port gamemode flags * Port BreakFlag * Port PlaceFlag * Port UseFlag * Remove old unused flag constants * Port blocked-cmds flag * Fix entity util * Port TimeFlag * Use CaptionUtility for formatting * Port keep flag * Fix imports * Reformat code * Remove unused classes * Fix MainUtil.java * Remove FlagCmd * Add flag info header and footer * Comment out flag related stuff in SchematicHandler * Remove FlagManager * Finalize Plot.java * Finalize PlotArea.java * Finalize PlotListener * Fix API issues * Fix a bunch of compile errors * Fix `/plot flag remove` * Fix initialization of GlobalFlagContainer * Apply API changes to events * Update SQLManager to new API * Invert default value for DenyExitFlag * Replace flag.getValue().toString() with flag.toString() * Make FlagContainer instance in Plot final * Fix various command issues * Clean up PlotSettings * Don't show internal flags in flag list * Fix `/plot flag add` * Remove the info inventory as it's 100% broken * Add plot info entries and fix up the default format * Fix default flag state in Captions * 781c200 part 2 * Fix odd grammar in captions * Fix odd grammar in captions v2 * Add create table statements for plot_flags * Remove old flag references in SQLManager * Use the new plot_flags table * Add tab completion to `/plot flag` * Improve parse error handling * Make flag permission check recognize parse exceptions * Initial progress towards flag conversion * Fix minor issues * Don't validate flags during flag conversion * Allow unrecognized flags to be parsed * Filter out internal flags from command sugguestions * Use the wrong caption when there's no plot description set * Limit command suggestions for boolean flags * Make blocktypelistflags accept blockcategories * Require categories to be prefixed with '#' and fix some minor display issues * Fix plot database conversion * Update PlotFlagEvent.java Updated return description * Fix command annotation wrapping * Add FLAG_UPDATE event for FlagContainer listeners * Make getParentContainer nullable * Document castUnsafe in FlagContainer * Document FlagContainer constructors * Add missing documentation to FlagContainer * Document FlagParseException * Fix wording in FlagContainer javadoc * Document InternalFlag * Document PlotFlag * Minor changes * Remove revisit comments Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
2020-02-24 18:42:02 +01:00
@CommandDeclaration(command = "info",
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
@Override
public boolean onCommand(final PlotPlayer<?> player, String[] args) {
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) {
// TODO: (re?)implement /plot info inv. (it was never properly implemented)
case "trusted", "alias", "biome", "denied", "flags", "id", "size", "members", "creationdate", "seen", "owner", "rating", "likes" ->
plot = Plot
.getPlotFromString(player, null, false);
default -> {
plot = Plot.getPlotFromString(player, arg, false);
2015-09-13 06:04:31 +02:00
if (args.length == 2) {
arg = args[1];
2015-09-13 06:04:31 +02:00
} else {
arg = null;
}
}
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-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"));
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) {
args = new String[0];
2015-09-13 06:04:31 +02:00
} else {
args = new String[]{args[1]};
2014-11-05 04:42:08 +01:00
}
}
2019-03-30 12:50:32 +01:00
// hide-info flag
Pull/2693 (#2694) * Commit WIP flag work. * More ported flag types, and additions to the flag API. * Make PlotFlag more generic to allow generic flag creation * Pull Captions methods into a Caption interface. * Port MusicFlag * Port flight flag * Port UntrustedVisitFlag * Port DenyExitFlag * Remove paper suggestion * Make ListFlag lists immutable * Update Flag containers. Add javadocs. Add missing methods. * Port description flag * Port greeting and farewell flags * Port weather flag * Move getExample implementation to BooleanFlag * Port reserved flags * Port all boolean flags. * Remove unused flag types * Invert liquid-flow flag * Find the real (legacy) flag name * Change NOITFY -> NOTIFY in Captions * Make IntegerFlag extendable * Port integer flags * Update Flag command to current API state * Begin remaking flag command * Create DoubleFlag + extract common parsing stuff * Supply arguments in flag parse exceptions * Implement missing flag subcommands * Update Flag command to current API state * Implement PriceFlag * Port deny-teleport * Port gamemode flags * Port BreakFlag * Port PlaceFlag * Port UseFlag * Remove old unused flag constants * Port blocked-cmds flag * Fix entity util * Port TimeFlag * Use CaptionUtility for formatting * Port keep flag * Fix imports * Reformat code * Remove unused classes * Fix MainUtil.java * Remove FlagCmd * Add flag info header and footer * Comment out flag related stuff in SchematicHandler * Remove FlagManager * Finalize Plot.java * Finalize PlotArea.java * Finalize PlotListener * Fix API issues * Fix a bunch of compile errors * Fix `/plot flag remove` * Fix initialization of GlobalFlagContainer * Apply API changes to events * Update SQLManager to new API * Invert default value for DenyExitFlag * Replace flag.getValue().toString() with flag.toString() * Make FlagContainer instance in Plot final * Fix various command issues * Clean up PlotSettings * Don't show internal flags in flag list * Fix `/plot flag add` * Remove the info inventory as it's 100% broken * Add plot info entries and fix up the default format * Fix default flag state in Captions * 781c200 part 2 * Fix odd grammar in captions * Fix odd grammar in captions v2 * Add create table statements for plot_flags * Remove old flag references in SQLManager * Use the new plot_flags table * Add tab completion to `/plot flag` * Improve parse error handling * Make flag permission check recognize parse exceptions * Initial progress towards flag conversion * Fix minor issues * Don't validate flags during flag conversion * Allow unrecognized flags to be parsed * Filter out internal flags from command sugguestions * Use the wrong caption when there's no plot description set * Limit command suggestions for boolean flags * Make blocktypelistflags accept blockcategories * Require categories to be prefixed with '#' and fix some minor display issues * Fix plot database conversion * Update PlotFlagEvent.java Updated return description * Fix command annotation wrapping * Add FLAG_UPDATE event for FlagContainer listeners * Make getParentContainer nullable * Document castUnsafe in FlagContainer * Document FlagContainer constructors * Add missing documentation to FlagContainer * Document FlagParseException * Fix wording in FlagContainer javadoc * Document InternalFlag * Document PlotFlag * Minor changes * Remove revisit comments Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com> Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com>
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")) {
if (!player
.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE.toString())) {
2020-07-22 00:08:51 +02:00
player.sendMessage(
TranslatableCaption.of("permission.no_permission"),
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}
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"),
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;
}
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) {
info = getCaption(arg);
2015-09-13 06:04:31 +02:00
if (info == null) {
if (Settings.Ratings.USE_LIKES) {
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"));
} else {
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"));
}
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;
}
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<>();
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));
if (player.hasPermission(Permission.PERMISSION_AREA_INFO_FORCE) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
2021-03-28 17:39:02 +02:00
}
return commands;
}
private Caption getCaption(String string) {
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
}
2014-09-22 13:02:14 +02:00
}