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

Add parameter to check for explicit permission state #48

Open
wants to merge 1 commit 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
Expand Up @@ -10,7 +10,7 @@ public class PlayerFactory extends com.mineaurion.aurionchat.common.player.Playe

private final BukkitAudiences audiences;

public PlayerFactory(AurionChat plugin){
public PlayerFactory(AurionChat plugin) {
super(true);
this.audiences = plugin.getAudiences();
}
Expand All @@ -31,7 +31,10 @@ protected void sendMessage(Player player, Component message) {
}

@Override
protected boolean hasPermission(Player player, String permission) {
return player.hasPermission(permission);
protected boolean hasPermission(Player player, String permission, boolean explicitly) {
return explicitly
? player.getEffectivePermissions().stream()
.anyMatch(perm -> permission.equals(perm.getPermission()))
: player.hasPermission(permission);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public AurionChatPlayer(Player player, AbstractAurionChat plugin){
this.setCurrentChannel(DEFAULT_CHANNEL);
this.setChannels(new HashSet<>(Collections.singletonList(DEFAULT_CHANNEL)));
for(String channel: plugin.getConfigurationAdapter().getChannels().keySet()){
if(player.hasPermission("aurionchat.joinchannel." + channel)){
if(player.hasPermission("aurionchat.joinchannel." + channel, true)){
this.addChannel(channel);
this.setCurrentChannel(channel);
} else if (player.hasPermission("aurionchat.listenchannel." + channel)) {
} else if (player.hasPermission("aurionchat.listenchannel." + channel, true)) {
this.addChannel(channel);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mineaurion.aurionchat.common;

import net.luckperms.api.LuckPerms;
import net.luckperms.api.cacheddata.CachedPermissionData;
import net.luckperms.api.model.user.User;
import net.luckperms.api.util.Tristate;

import java.util.Optional;
import java.util.UUID;
Expand All @@ -26,7 +28,12 @@ public Optional<String> getPlayerSuffix(UUID uuid) {
return Optional.ofNullable(getUser(uuid).getCachedData().getMetaData().getSuffix());
}

public boolean hasPermission(UUID uuid, String permission){
return getUser(uuid).getCachedData().getPermissionData().checkPermission(permission).asBoolean();
public boolean hasPermission(UUID uuid, String permission, boolean explicitly){
Tristate result = getUser(uuid)
.getCachedData()
.getPermissionData()
.queryPermission(permission)
.result();
return explicitly ? result == Tristate.TRUE : result != Tristate.FALSE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void sendMessage(Component message) {
}

@Override
public boolean hasPermission(String permission) {
return this.factory.hasPermission(player, permission);
public boolean hasPermission(String permission, boolean explicitly) {
return this.factory.hasPermission(player, permission, explicitly);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ public interface Player {

void sendMessage(Component message);

boolean hasPermission(String permission);
default boolean hasPermission(String permission) {
return hasPermission(permission, false);
}

boolean hasPermission(String permission, boolean explicitly);

String getPreffix();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public String getSuffix(T player){
return luckPermsUtils != null ? luckPermsUtils.getPlayerSuffix(getUUID(player)).orElse("") : "";
};

protected boolean hasPermission(T player, String permission) {
return luckPermsUtils.hasPermission(getUUID(player), permission);
protected boolean hasPermission(T player, String permission, boolean explicitly) {
return luckPermsUtils.hasPermission(getUUID(player), permission, explicitly);
}

public final Player wrap(T player){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.util.Tristate;

import java.util.UUID;

Expand All @@ -28,7 +29,8 @@ protected void sendMessage(ServerPlayer player, Component message) {
}

@Override
protected boolean hasPermission(ServerPlayer player, String permission) {
return player.hasPermission(permission);
protected boolean hasPermission(ServerPlayer player, String permission, boolean explicitly) {
Tristate tristate = player.permissionValue(permission);
return explicitly ? tristate == Tristate.TRUE : tristate != Tristate.FALSE;
}
}
Loading