Skip to content

Commit

Permalink
Add vanish permission check for player tab suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Dec 1, 2024
1 parent 9978731 commit 425b530
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public SuggestionResult suggest(
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";
}
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,13 @@ public boolean isVanished(Player player) {
}
return false;
}

@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."
)
public boolean canSeeVanished(CommandSender sender) {
return sender.hasPermission(VanishPermissionConstant.VANISH_SEE_PERMISSION);
}
}

0 comments on commit 425b530

Please sign in to comment.