Skip to content

Commit

Permalink
Ignore vanished players in TabComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
akshualy committed Jul 10, 2024
1 parent 45f6ef5 commit b2facd4
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
Expand All @@ -18,8 +19,18 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
}

return sender.getServer().getOnlinePlayers().stream()
.filter(player -> player.getName().toLowerCase().startsWith(args[0].toLowerCase()))
.filter(player ->
!isVanished(player) && player.getName().toLowerCase().startsWith(args[0].toLowerCase()))
.map(Player::getName)
.collect(Collectors.toList());
}

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

0 comments on commit b2facd4

Please sign in to comment.