mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 12:46:46 +01:00
* Respect non-visible players in tab completion (Closes #3263) * Deprecate old Tab-Complete methods instead of hard-replacing them * wtf git * Mark for removal, useless new-lines * Pass ConsolePlayer.getConsole() instead of Nullable param
This commit is contained in:
parent
541255fe7e
commit
e322ee85fd
@ -166,7 +166,7 @@ public class Add extends Command {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -856,11 +856,11 @@ public class Area extends SubCommand {
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -916,11 +916,11 @@ public class Cluster extends SubCommand {
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_CLUSTER) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class Deny extends SubCommand {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
private void handleKick(PlotPlayer<?> player, Plot plot) {
|
||||
|
@ -70,11 +70,11 @@ public class Dislike extends SubCommand {
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -173,11 +173,11 @@ public class Download extends SubCommand {
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_DOWNLOAD) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
private void upload(PlotPlayer<?> player, Plot plot) {
|
||||
|
@ -176,11 +176,11 @@ public class Grant extends Command {
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_GRANT_SINGLE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -307,11 +307,11 @@ public class Inbox extends SubCommand {
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.CHAT) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_INBOX) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public class Info extends SubCommand {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_AREA_INFO_FORCE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
|
||||
return commands;
|
||||
|
@ -220,11 +220,11 @@ public class Like extends SubCommand {
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ public class ListCmd extends SubCommand {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_LIST_PLAYER) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
|
||||
return commands;
|
||||
|
@ -209,7 +209,7 @@ public class Owner extends SetCommand {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -292,11 +292,11 @@ public class Rate extends SubCommand {
|
||||
.map(completion -> new Command(null, true, completion, "", RequiredType.PLAYER, CommandCategory.INFO) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_RATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
private static class MutableInt {
|
||||
|
@ -142,7 +142,7 @@ public class Remove extends SubCommand {
|
||||
if (plot == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return TabCompletions.completeAddedPlayers(plot, String.join(",", args).trim(),
|
||||
return TabCompletions.completeAddedPlayers(player, plot, String.join(",", args).trim(),
|
||||
Collections.singletonList(player.getName())
|
||||
);
|
||||
}
|
||||
|
@ -317,11 +317,11 @@ public class SchematicCmd extends SubCommand {
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_SCHEMATIC) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ public class Set extends SubCommand {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_SET) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
} else if (args.length > 1) {
|
||||
|
@ -305,11 +305,11 @@ public class Template extends SubCommand {
|
||||
) {
|
||||
}).collect(Collectors.toCollection(LinkedList::new));
|
||||
if (Permissions.hasPermission(player, Permission.PERMISSION_TEMPLATE) && args[0].length() > 0) {
|
||||
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
commands.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public class Trust extends Command {
|
||||
|
||||
@Override
|
||||
public Collection<Command> tab(final PlotPlayer<?> player, final String[] args, final boolean space) {
|
||||
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
|
||||
return TabCompletions.completePlayers(player, String.join(",", args).trim(), Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -334,7 +334,7 @@ public class Visit extends Command {
|
||||
public Collection<Command> tab(PlotPlayer<?> player, String[] args, boolean space) {
|
||||
final List<Command> completions = new ArrayList<>();
|
||||
switch (args.length - 1) {
|
||||
case 0 -> completions.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
|
||||
case 0 -> completions.addAll(TabCompletions.completePlayers(player, args[0], Collections.emptyList()));
|
||||
case 1 -> {
|
||||
completions.addAll(
|
||||
TabCompletions.completeAreas(args[1]));
|
||||
|
@ -32,11 +32,13 @@ import com.plotsquared.core.command.Command;
|
||||
import com.plotsquared.core.command.CommandCategory;
|
||||
import com.plotsquared.core.command.RequiredType;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -80,12 +82,31 @@ public final class TabCompletions {
|
||||
* @param input Command input
|
||||
* @param existing Players that should not be included in completions
|
||||
* @return List of completions
|
||||
* @deprecated In favor {@link #completePlayers(PlotPlayer, String, List)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static @NonNull List<Command> completePlayers(
|
||||
final @NonNull String input,
|
||||
final @NonNull List<String> existing
|
||||
) {
|
||||
return completePlayers("players", input, existing, uuid -> true);
|
||||
return completePlayers(ConsolePlayer.getConsole(), input, existing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tab completions corresponding to player names. This uses the UUID pipeline
|
||||
* cache, so it will complete will all names known to PlotSquared
|
||||
*
|
||||
* @param input Command input
|
||||
* @param issuer The player who issued the tab completion
|
||||
* @param existing Players that should not be included in completions
|
||||
* @return List of completions
|
||||
*/
|
||||
public static @NonNull List<Command> completePlayers(
|
||||
final @NonNull PlotPlayer<?> issuer,
|
||||
final @NonNull String input,
|
||||
final @NonNull List<String> existing
|
||||
) {
|
||||
return completePlayers("players", issuer, input, existing, uuid -> true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,12 +116,32 @@ public final class TabCompletions {
|
||||
* @param input Command input
|
||||
* @param existing Players that should not be included in completions
|
||||
* @return List of completions
|
||||
*
|
||||
* @deprecated In favor {@link #completeAddedPlayers(PlotPlayer, Plot, String, List)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static @NonNull List<Command> completeAddedPlayers(
|
||||
final @NonNull Plot plot,
|
||||
final @NonNull String input, final @NonNull List<String> existing
|
||||
) {
|
||||
return completePlayers("added" + plot, input, existing,
|
||||
return completeAddedPlayers(ConsolePlayer.getConsole(), plot, input, existing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tab completions corresponding to player names added to the given plot.
|
||||
*
|
||||
* @param issuer The player who issued the tab completion
|
||||
* @param plot Plot to complete added players for
|
||||
* @param input Command input
|
||||
* @param existing Players that should not be included in completions
|
||||
* @return List of completions
|
||||
*/
|
||||
public static @NonNull List<Command> completeAddedPlayers(
|
||||
final @NonNull PlotPlayer<?> issuer,
|
||||
final @NonNull Plot plot,
|
||||
final @NonNull String input, final @NonNull List<String> existing
|
||||
) {
|
||||
return completePlayers("added" + plot, issuer, input, existing,
|
||||
uuid -> plot.getMembers().contains(uuid)
|
||||
|| plot.getTrusted().contains(uuid)
|
||||
|| plot.getDenied().contains(uuid)
|
||||
@ -222,9 +263,28 @@ public final class TabCompletions {
|
||||
* @param existing Players that should not be included in completions
|
||||
* @param uuidFilter Filter applied before caching values
|
||||
* @return List of completions
|
||||
* @deprecated In favor {@link #completePlayers(String, PlotPlayer, String, List, Predicate)}
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
private static List<Command> completePlayers(
|
||||
final @NonNull String cacheIdentifier,
|
||||
final @NonNull String input, final @NonNull List<String> existing,
|
||||
final @NonNull Predicate<UUID> uuidFilter
|
||||
) {
|
||||
return completePlayers(cacheIdentifier, ConsolePlayer.getConsole(), input, existing, uuidFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cacheIdentifier Cache key
|
||||
* @param issuer The player who issued the tab completion
|
||||
* @param input Command input
|
||||
* @param existing Players that should not be included in completions
|
||||
* @param uuidFilter Filter applied before caching values
|
||||
* @return List of completions
|
||||
*/
|
||||
private static List<Command> completePlayers(
|
||||
final @NonNull String cacheIdentifier,
|
||||
final @NonNull PlotPlayer<?> issuer,
|
||||
final @NonNull String input, final @NonNull List<String> existing,
|
||||
final @NonNull Predicate<UUID> uuidFilter
|
||||
) {
|
||||
@ -246,9 +306,13 @@ public final class TabCompletions {
|
||||
final Collection<? extends PlotPlayer<?>> onlinePlayers = PlotSquared.platform().playerManager().getPlayers();
|
||||
players = new ArrayList<>(onlinePlayers.size());
|
||||
for (final PlotPlayer<?> player : onlinePlayers) {
|
||||
if (uuidFilter.test(player.getUUID())) {
|
||||
players.add(player.getName());
|
||||
if (!uuidFilter.test(player.getUUID())) {
|
||||
continue;
|
||||
}
|
||||
if (issuer != null && !issuer.canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
players.add(player.getName());
|
||||
}
|
||||
}
|
||||
return filterCached(players, input, existing);
|
||||
|
Loading…
Reference in New Issue
Block a user