Skip to content
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

GH-878 Add vanish permission check for player tab suggestions #878

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
@@ -1,5 +1,6 @@
package com.eternalcode.core.bridge.litecommand.argument;

import com.eternalcode.annotations.scan.feature.FeatureDocs;
import com.eternalcode.core.feature.vanish.VanishService;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.lite.LiteArgument;
Expand Down Expand Up @@ -44,15 +45,21 @@ public ParseResult<Player> parse(Invocation<CommandSender> invocation, String ar
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.see permission."
)
@Override
public SuggestionResult suggest(
Invocation<CommandSender> invocation,
Argument<Player> argument,
SuggestionContext context
) {
CommandSender sender = invocation.sender();
return this.server.getOnlinePlayers().stream()
.filter(player -> !this.vanishService.isVanished(player.getUniqueId()))
.map(player -> player.getName())
.filter(player -> this.vanishService.canSeeVanished(sender) || !this.vanishService.isVanished(player.getUniqueId()))
.map(Player::getName)
.collect(SuggestionResult.collector());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.eternalcode.core.feature.vanish;

class VanishPermissionConstant {

static final String VANISH_SEE_PERMISSION = "eternalcore.vanish.see";
Rollczi marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.eternalcode.core.feature.vanish;

import com.eternalcode.annotations.scan.feature.FeatureDocs;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.component.Service;
import java.util.UUID;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;

Expand Down Expand Up @@ -34,4 +36,8 @@ public boolean isVanished(Player player) {
}
return false;
}

public boolean canSeeVanished(CommandSender sender) {
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_PERMISSION);
}
vLuckyyy marked this conversation as resolved.
Show resolved Hide resolved
}