From f1047df98e506d7d4452d07310fdeb510e427378 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 16 Feb 2018 13:41:21 +0000 Subject: [PATCH] Log checks made against non Player command senders in LP bungee --- .../bungee/event/TristateCheckEvent.java | 24 +++++++------- .../BungeePermissionCheckListener.java | 32 ++++++++++++++++--- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/event/TristateCheckEvent.java b/bungee/src/main/java/me/lucko/luckperms/bungee/event/TristateCheckEvent.java index 4b707b21..17b0fc84 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/event/TristateCheckEvent.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/event/TristateCheckEvent.java @@ -27,35 +27,35 @@ package me.lucko.luckperms.bungee.event; import me.lucko.luckperms.api.Tristate; -import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Event; /** - * 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 static Tristate call(CommandSender sender, String permission) { - return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(sender, permission)).getResult(); + public static Tristate call(ProxiedPlayer player, String permission) { + return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(player, permission)).getResult(); } - private final CommandSender sender; + private final ProxiedPlayer player; private final String permission; private Tristate result; - public TristateCheckEvent(CommandSender sender, String permission) { - this(sender, permission, sender.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED); + public TristateCheckEvent(ProxiedPlayer player, String permission) { + this(player, permission, player.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED); } - public TristateCheckEvent(CommandSender sender, String permission, Tristate result) { - this.sender = sender; + public TristateCheckEvent(ProxiedPlayer player, String permission, Tristate result) { + this.player = player; this.permission = permission; this.result = result; } - public CommandSender getSender() { - return this.sender; + public ProxiedPlayer getPlayer() { + return this.player; } public String getPermission() { @@ -73,7 +73,7 @@ public class TristateCheckEvent extends Event { @Override public String toString() { return "TristateCheckEvent(" + - "sender=" + this.sender + ", " + + "player=" + this.player + ", " + "permission=" + this.permission + ", " + "result=" + this.result + ")"; } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java index 3a91bfe4..55ddb641 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/listeners/BungeePermissionCheckListener.java @@ -27,6 +27,7 @@ package me.lucko.luckperms.bungee.listeners; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; +import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.bungee.LPBungeePlugin; import me.lucko.luckperms.bungee.event.TristateCheckEvent; import me.lucko.luckperms.common.config.ConfigKeys; @@ -39,6 +40,8 @@ import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventPriority; +import java.util.Objects; + public class BungeePermissionCheckListener implements Listener { private final LPBungeePlugin plugin; @@ -52,6 +55,9 @@ public class BungeePermissionCheckListener implements Listener { return; } + Objects.requireNonNull(e.getPermission(), "permission"); + Objects.requireNonNull(e.getSender(), "sender"); + ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); @@ -69,13 +75,12 @@ public class BungeePermissionCheckListener implements Listener { e.setHasPermission(result.asBoolean()); } - @EventHandler(priority = EventPriority.HIGH) + @EventHandler public void onPlayerTristateCheck(TristateCheckEvent e) { - if (!(e.getSender() instanceof ProxiedPlayer)) { - return; - } + ProxiedPlayer player = e.getPlayer(); - ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); + Objects.requireNonNull(e.getPermission(), "permission"); + Objects.requireNonNull(player, "player"); User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); if (user == null) { @@ -91,4 +96,21 @@ public class BungeePermissionCheckListener implements Listener { e.setResult(result); } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onOtherPermissionCheck(PermissionCheckEvent e) { + if (e.getSender() instanceof ProxiedPlayer) { + return; + } + + Objects.requireNonNull(e.getPermission(), "permission"); + Objects.requireNonNull(e.getSender(), "sender"); + + String permission = e.getPermission(); + Tristate result = Tristate.fromBoolean(e.hasPermission()); + String name = "internal/" + e.getSender().getName(); + + this.plugin.getVerboseHandler().offerCheckData(CheckOrigin.PLATFORM_PERMISSION_CHECK, name, ContextSet.empty(), permission, result); + this.plugin.getPermissionVault().offer(permission); + } }