001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.command;
020
021import com.plotsquared.core.configuration.caption.TranslatableCaption;
022import com.plotsquared.core.player.PlotPlayer;
023import com.plotsquared.core.plot.Plot;
024import com.plotsquared.core.util.StringMan;
025import com.plotsquared.core.util.task.RunnableVal2;
026import com.plotsquared.core.util.task.RunnableVal3;
027import net.kyori.adventure.text.Component;
028import net.kyori.adventure.text.minimessage.tag.Tag;
029import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
030
031import java.util.List;
032import java.util.concurrent.CompletableFuture;
033
034@CommandDeclaration(command = "near",
035        aliases = "n",
036        usage = "/plot near",
037        category = CommandCategory.INFO,
038        requiredType = RequiredType.PLAYER)
039public class Near extends Command {
040
041    public Near() {
042        super(MainCommand.getInstance(), true);
043    }
044
045    @Override
046    public CompletableFuture<Boolean> execute(
047            PlotPlayer<?> player, String[] args,
048            RunnableVal3<Command, Runnable, Runnable> confirm,
049            RunnableVal2<Command, CommandResult> whenDone
050    ) throws CommandException {
051        final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
052        player.sendMessage(
053                TranslatableCaption.of("near.plot_near"),
054                TagResolver.resolver("list", Tag.inserting(Component.text(StringMan.join(plot.getPlayersInPlot(), ", "))))
055        );
056        return CompletableFuture.completedFuture(true);
057    }
058
059    private List<PlotPlayer<?>> getPlayersInPlotVisible(Plot plot, PlotPlayer<?> executor) {
060        return plot.getPlayersInPlot().stream().filter(executor::canSee).toList();
061    }
062
063}