Fix tristate check event on BungeeCord for console senders
This commit is contained in:
parent
4773934481
commit
d52983c5af
@ -29,26 +29,46 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy of the internal BungeeCord PermissionCheckEvent, returning a tristate instead of a boolean.
|
* Copy of the internal BungeeCord PermissionCheckEvent, returning a tristate instead of a boolean.
|
||||||
*/
|
*/
|
||||||
public class TristateCheckEvent extends Event {
|
public class TristateCheckEvent extends Event {
|
||||||
|
|
||||||
public static Tristate call(CommandSender sender, String permission) {
|
public static Tristate call(CommandSender sender, String permission) {
|
||||||
return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(sender, permission)).getResult();
|
|
||||||
|
// calculate a default value based on the internal behaviour of
|
||||||
|
// ConsoleCommandSender and UserConnection in order to replicate the
|
||||||
|
// behaviour of CommandSender#hasPermission
|
||||||
|
Tristate def = Tristate.UNDEFINED;
|
||||||
|
if (!(sender instanceof ProxiedPlayer)) {
|
||||||
|
// if not a ProxiedPlayer, assume it's console.
|
||||||
|
def = Tristate.TRUE;
|
||||||
|
} else if (sender.getPermissions().contains(permission)) {
|
||||||
|
def = Tristate.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return call(sender, permission, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Tristate call(CommandSender sender, String permission, Tristate def) {
|
||||||
|
Objects.requireNonNull(sender, "sender");
|
||||||
|
Objects.requireNonNull(permission, "permission");
|
||||||
|
Objects.requireNonNull(def, "def");
|
||||||
|
|
||||||
|
TristateCheckEvent event = new TristateCheckEvent(sender, permission, def);
|
||||||
|
return ProxyServer.getInstance().getPluginManager().callEvent(event).getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final CommandSender sender;
|
private final CommandSender sender;
|
||||||
private final String permission;
|
private final String permission;
|
||||||
|
|
||||||
private Tristate result;
|
private Tristate result;
|
||||||
|
|
||||||
public TristateCheckEvent(CommandSender sender, String permission) {
|
private TristateCheckEvent(CommandSender sender, String permission, Tristate result) {
|
||||||
this(sender, permission, sender.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TristateCheckEvent(CommandSender sender, String permission, Tristate result) {
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
|
@ -117,4 +117,21 @@ public class BungeePermissionCheckListener implements Listener {
|
|||||||
this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_PERMISSION_CHECK, name, ContextSet.empty(), permission, result);
|
this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_PERMISSION_CHECK, name, ContextSet.empty(), permission, result);
|
||||||
this.plugin.getPermissionVault().offer(permission);
|
this.plugin.getPermissionVault().offer(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onOtherTristateCheck(TristateCheckEvent e) {
|
||||||
|
if (e.getSender() instanceof ProxiedPlayer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Objects.requireNonNull(e.getPermission(), "permission");
|
||||||
|
Objects.requireNonNull(e.getSender(), "sender");
|
||||||
|
|
||||||
|
String permission = e.getPermission();
|
||||||
|
Tristate result = e.getResult();
|
||||||
|
String name = "internal/" + e.getSender().getName();
|
||||||
|
|
||||||
|
this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_LOOKUP_CHECK, name, ContextSet.empty(), permission, result);
|
||||||
|
this.plugin.getPermissionVault().offer(permission);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user