Skip to content

GH-938 Fix Players in vanish can still be messaged by manually typing their name #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.function.Predicate;

@LiteArgument(type = Player.class)

@FeatureDocs(
name = "Vanish tabulation",
description = "EternalCore prevents non-admin players from seeing vanished players in the commands like /tpa."
+ " To re-enable this feature for specific players, grant them the eternalcore.vanish.tabulation.see permission."
)
public class PlayerArgument extends AbstractViewerArgument<Player> {

private final Server server;
Expand All @@ -41,14 +49,13 @@ public ParseResult<Player> parse(Invocation<CommandSender> invocation, String ar
return ParseResult.failure(translation.argument().offlinePlayer());
}

if (this.vanishService.isVanished(target) && !this.canSeeVanished(invocation.sender())) {
return ParseResult.failure(translation.argument().offlinePlayer());
}

return ParseResult.success(target);
}

@FeatureDocs(
name = "Vanish tabulation",
description = "EternalCore prevents non-admin players from seeing vanished players in the commands like /tpa."
+ " To re-enable this feature for specific players, grant them the eternalcore.vanish.tabulation.see permission."
)
@Override
public SuggestionResult suggest(
Invocation<CommandSender> invocation,
Expand All @@ -57,12 +64,19 @@ public SuggestionResult suggest(
) {
CommandSender sender = invocation.sender();
return this.server.getOnlinePlayers().stream()
.filter(player -> this.canSeeVanished(sender) || !this.vanishService.isVanished(player.getUniqueId()))
.filter(player -> canSee(sender, player))
.map(Player::getName)
.collect(SuggestionResult.collector());
}

public boolean canSeeVanished(CommandSender sender) {
private boolean canSee(CommandSender sender, Player player) {
if (this.canSeeVanished(sender)) {
return true;
}
return !this.vanishService.isVanished(player.getUniqueId());
}

private boolean canSeeVanished(CommandSender sender) {
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_TABULATION_PERMISSION);
}
}