Log checks made against non Player command senders in LP bungee

This commit is contained in:
Luck 2018-02-16 13:41:21 +00:00
parent 765f9d2545
commit f1047df98e
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 39 additions and 17 deletions

View File

@ -27,35 +27,35 @@ package me.lucko.luckperms.bungee.event;
import me.lucko.luckperms.api.Tristate; 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.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;
/** /**
* 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(ProxiedPlayer player, String permission) {
return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(sender, permission)).getResult(); return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(player, permission)).getResult();
} }
private final CommandSender sender; private final ProxiedPlayer player;
private final String permission; private final String permission;
private Tristate result; private Tristate result;
public TristateCheckEvent(CommandSender sender, String permission) { public TristateCheckEvent(ProxiedPlayer player, String permission) {
this(sender, permission, sender.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED); this(player, permission, player.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED);
} }
public TristateCheckEvent(CommandSender sender, String permission, Tristate result) { public TristateCheckEvent(ProxiedPlayer player, String permission, Tristate result) {
this.sender = sender; this.player = player;
this.permission = permission; this.permission = permission;
this.result = result; this.result = result;
} }
public CommandSender getSender() { public ProxiedPlayer getPlayer() {
return this.sender; return this.player;
} }
public String getPermission() { public String getPermission() {
@ -73,7 +73,7 @@ public class TristateCheckEvent extends Event {
@Override @Override
public String toString() { public String toString() {
return "TristateCheckEvent(" + return "TristateCheckEvent(" +
"sender=" + this.sender + ", " + "player=" + this.player + ", " +
"permission=" + this.permission + ", " + "permission=" + this.permission + ", " +
"result=" + this.result + ")"; "result=" + this.result + ")";
} }

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.bungee.listeners;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.bungee.LPBungeePlugin; import me.lucko.luckperms.bungee.LPBungeePlugin;
import me.lucko.luckperms.bungee.event.TristateCheckEvent; import me.lucko.luckperms.bungee.event.TristateCheckEvent;
import me.lucko.luckperms.common.config.ConfigKeys; 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.EventHandler;
import net.md_5.bungee.event.EventPriority; import net.md_5.bungee.event.EventPriority;
import java.util.Objects;
public class BungeePermissionCheckListener implements Listener { public class BungeePermissionCheckListener implements Listener {
private final LPBungeePlugin plugin; private final LPBungeePlugin plugin;
@ -52,6 +55,9 @@ public class BungeePermissionCheckListener implements Listener {
return; return;
} }
Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(e.getSender(), "sender");
ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
@ -69,13 +75,12 @@ public class BungeePermissionCheckListener implements Listener {
e.setHasPermission(result.asBoolean()); e.setHasPermission(result.asBoolean());
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler
public void onPlayerTristateCheck(TristateCheckEvent e) { public void onPlayerTristateCheck(TristateCheckEvent e) {
if (!(e.getSender() instanceof ProxiedPlayer)) { ProxiedPlayer player = e.getPlayer();
return;
}
ProxiedPlayer player = ((ProxiedPlayer) e.getSender()); Objects.requireNonNull(e.getPermission(), "permission");
Objects.requireNonNull(player, "player");
User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId()); User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
if (user == null) { if (user == null) {
@ -91,4 +96,21 @@ public class BungeePermissionCheckListener implements Listener {
e.setResult(result); 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);
}
} }