Implement argument based permissions for LP commands - closes #52, #170, #174

This commit is contained in:
Luck
2017-07-07 12:43:13 +01:00
Unverified
parent 9e83a5e4d9
commit 42d48c8da2
59 changed files with 929 additions and 44 deletions
@@ -30,6 +30,7 @@ import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.bungee.event.TristateCheckEvent;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.locale.Message;
@@ -165,6 +166,38 @@ public class BungeeListener implements Listener {
e.setHasPermission(result.asBoolean());
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTristateCheck(TristateCheckEvent e) {
if (!(e.getSender() instanceof ProxiedPlayer)) {
return;
}
final ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(player.getUniqueId()));
if (user == null) {
e.setResult(Tristate.UNDEFINED);
return;
}
Contexts contexts = new Contexts(
plugin.getContextManager().getApplicableContext(player),
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
true,
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
false
);
Tristate result = user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission());
if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
return; // just use the result provided by the proxy when the event was created
}
e.setResult(result);
}
// We don't pre-process all servers, so we have to do it here.
@EventHandler(priority = EventPriority.LOWEST)
public void onServerSwitch(ServerConnectEvent e) {
@@ -25,6 +25,8 @@
package me.lucko.luckperms.bungee;
import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.bungee.event.TristateCheckEvent;
import me.lucko.luckperms.common.commands.sender.SenderFactory;
import me.lucko.luckperms.common.constants.Constants;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
@@ -72,6 +74,11 @@ public class BungeeSenderFactory extends SenderFactory<CommandSender> {
}
}
@Override
protected Tristate getPermissionValue(CommandSender sender, String node) {
return TristateCheckEvent.call(sender, node);
}
@Override
protected boolean hasPermission(CommandSender sender, String node) {
return sender.hasPermission(node);
@@ -0,0 +1,62 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.bungee.event;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
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.plugin.Event;
/**
* Copy of the internal BungeeCord "PermissionCheckEvent", returning a tristate instead of a boolean.
*/
@Getter
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ToString
public class TristateCheckEvent extends Event {
public static Tristate call(CommandSender sender, String permission) {
return ProxyServer.getInstance().getPluginManager().callEvent(new TristateCheckEvent(sender, permission)).getResult();
}
private final CommandSender sender;
private final String permission;
@Setter
private Tristate result;
public TristateCheckEvent(CommandSender sender, String permission) {
this(sender, permission, sender.getPermissions().contains(permission) ? Tristate.TRUE : Tristate.UNDEFINED);
}
}
+9
View File
@@ -104,6 +104,15 @@ temporary-add-behaviour: deny
# directly and indirectly
primary-group-calculation: stored
# If the plugin should check for "extra" permissions with users run LP commands.
#
# These extra permissions allow finer control over what users can do with each command, and
# who they have access to edit.
#
# The permissions are *not* static, unlike the 'base' permisssions, and will depend upon the
# arguments given within the command.
argument-based-command-permissions: false
+1 -1
View File
@@ -3,4 +3,4 @@ version: ${full.version}
description: A permissions plugin
author: Luck
main: me.lucko.luckperms.bungee.LPBungeePlugin
softDepends: ["RedisBungee"]
softDepends: ["RedisBungee"]