Skip to content

Commit

Permalink
Do not tab complete vanished players
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffp1 committed Aug 5, 2023
1 parent 8459181 commit 4854599
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/net/coreprotect/command/TabHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
Expand All @@ -18,6 +19,7 @@
import org.bukkit.util.StringUtil;

import net.coreprotect.config.ConfigHandler;
import net.coreprotect.utility.Util;

public class TabHandler implements TabCompleter {

Expand Down Expand Up @@ -170,7 +172,7 @@ else if ((currentArg.startsWith("u:") || currentArg.startsWith("user:") || curre
arg = split[1];
}

List<String> completions = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
List<String> completions = Bukkit.getOnlinePlayers().stream().filter(Predicate.not(Util::isVanished)).map(Player::getName).collect(Collectors.toList());
for (int index = 0; index < completions.size(); index++) {
completions.set(index, filter + completions.get(index));
}
Expand Down Expand Up @@ -338,7 +340,7 @@ else if (argument0.equals("purge") && sender.hasPermission("coreprotect.purge"))
}
else if ((sender.hasPermission("coreprotect.lookup") && (argument0.equals("l") || argument0.equals("lookup"))) || (sender.hasPermission("coreprotect.rollback") && (argument0.equals("rollback") || argument0.equals("rb") || argument0.equals("ro"))) || (sender.hasPermission("coreprotect.restore") && (argument0.equals("restore") || argument0.equals("rs") || argument0.equals("re")))) {
List<String> completions = new ArrayList<>(filterParams(true, argument0, argument1, hasUser, hasAction, hasInclude, hasExclude, hasRadius, hasTime, hasContainer, hasCount, hasPreview, pageLookup, validContainer));
completions.addAll(Bukkit.getOnlinePlayers().stream().filter(player -> player.getName().toLowerCase(Locale.ROOT).startsWith(argument1)).map(Player::getName).collect(Collectors.toList()));
completions.addAll(Bukkit.getOnlinePlayers().stream().filter(Predicate.not(Util::isVanished)).filter(player -> player.getName().toLowerCase(Locale.ROOT).startsWith(argument1)).map(Player::getName).collect(Collectors.toList()));
return StringUtil.copyPartialMatches(argument1, completions, new ArrayList<>(completions.size()));
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/coreprotect/utility/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.io.BukkitObjectOutputStream;

Expand Down Expand Up @@ -1640,4 +1641,10 @@ public static boolean isSideGlowing(boolean isFront, int data) {
return ((isFront && (data == 1 || data == 3)) || (!isFront && (data == 2 || data == 3)));
}

public static boolean isVanished(Player player) {
for (MetadataValue meta : player.getMetadata("vanished")) {
if (meta.asBoolean()) return true;
}
return false;
}
}

0 comments on commit 4854599

Please sign in to comment.