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.minimessage.Template; 028 029import java.util.List; 030import java.util.concurrent.CompletableFuture; 031 032@CommandDeclaration(command = "near", 033 aliases = "n", 034 usage = "/plot near", 035 category = CommandCategory.INFO, 036 requiredType = RequiredType.PLAYER) 037public class Near extends Command { 038 039 public Near() { 040 super(MainCommand.getInstance(), true); 041 } 042 043 @Override 044 public CompletableFuture<Boolean> execute( 045 PlotPlayer<?> player, String[] args, 046 RunnableVal3<Command, Runnable, Runnable> confirm, 047 RunnableVal2<Command, CommandResult> whenDone 048 ) throws CommandException { 049 final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot")); 050 player.sendMessage( 051 TranslatableCaption.of("near.plot_near"), 052 Template.of("list", StringMan.join(getPlayersInPlotVisible(plot, player), ", ")) 053 ); 054 return CompletableFuture.completedFuture(true); 055 } 056 057 private List<PlotPlayer<?>> getPlayersInPlotVisible(Plot plot, PlotPlayer<?> executor) { 058 return plot.getPlayersInPlot().stream().filter(executor::canSee).toList(); 059 } 060 061}