use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ArgumentPermissions method checkModifyPerms.
/**
* Checks if the sender has permission to modify the given target
*
* @param plugin the plugin instance
* @param sender the sender to check
* @param base the base permission for the command
* @param target the object the sender is truing to modify
* @return true if the sender should NOT be allowed to modify the target, true if they should
*/
public static boolean checkModifyPerms(LuckPermsPlugin plugin, Sender sender, CommandPermission base, Object target) {
if (!plugin.getConfiguration().get(ConfigKeys.USE_ARGUMENT_BASED_COMMAND_PERMISSIONS)) {
return false;
}
if (target instanceof User) {
User targetUser = ((User) target);
if (targetUser.getUuid().equals(sender.getUuid())) {
// the sender is trying to edit themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.self");
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(USER_MODIFY_SELF);
return !globalRet.asBoolean();
}
} else {
// they're trying to edit another user
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.others");
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(USER_MODIFY_OTHERS);
return !globalRet.asBoolean();
}
}
} else if (target instanceof Group) {
Group targetGroup = ((Group) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify." + targetGroup.getName());
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(GROUP_MODIFY.apply(targetGroup.getName()));
return !globalRet.asBoolean();
}
} else if (target instanceof Track) {
Track targetTrack = ((Track) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify." + targetTrack.getName());
if (ret != Tristate.UNDEFINED) {
return !ret.asBoolean();
} else {
// fallback to the global perm if the one for the specific command is undefined
Tristate globalRet = sender.getPermissionValue(TRACK_MODIFY.apply(targetTrack.getName()));
return !globalRet.asBoolean();
}
} else {
throw new IllegalStateException();
}
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class StorageAssistant method loadGroup.
public static Group loadGroup(String target, Sender sender, LuckPermsPlugin plugin, boolean auditTemporary) {
// special handling for the importer
if (sender.isImport()) {
Group group = plugin.getGroupManager().getIfLoaded(target);
if (group == null) {
Message.GROUP_NOT_FOUND.send(sender, target);
}
return group;
}
Group group = plugin.getStorage().loadGroup(target).join().orElse(null);
if (group == null) {
// failed to load, but it might be a display name.
group = plugin.getGroupManager().getByDisplayName(target);
// nope, not a display name
if (group == null) {
Message.GROUP_NOT_FOUND.send(sender, target);
return null;
}
// it was a display name, we need to reload
plugin.getStorage().loadGroup(group.getName()).join();
}
if (auditTemporary) {
group.auditTemporaryPermissions();
}
return group;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥r" + node.getMeta().getKey() + " ¥7- ¥r" + node.getMeta().getValue(), " ", "¥7Click to remove this meta pair from " + holder.getFriendlyName()), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class DeleteGroup method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
if (args.isEmpty()) {
sendUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
String groupName = args.get(0).toLowerCase();
if (groupName.equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)) {
Message.DELETE_GROUP_ERROR_DEFAULT.send(sender);
return CommandResult.INVALID_ARGS;
}
Group group = plugin.getStorage().loadGroup(groupName).join().orElse(null);
if (group == null) {
Message.GROUP_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;
}
try {
plugin.getStorage().deleteGroup(group, DeletionCause.COMMAND).get();
} catch (Exception e) {
e.printStackTrace();
Message.DELETE_ERROR.send(sender, group.getFriendlyName());
return CommandResult.FAILURE;
}
Message.DELETE_SUCCESS.send(sender, group.getFriendlyName());
ExtendedLogEntry.build().actor(sender).actedName(groupName).type(LogEntry.Type.GROUP).action("delete").build().submit(plugin, sender);
plugin.getUpdateTaskBuffer().request();
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class GroupClone method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), group)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String newGroupName = args.get(0).toLowerCase();
if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) {
Message.GROUP_INVALID_ENTRY.send(sender, newGroupName);
return CommandResult.INVALID_ARGS;
}
Group newGroup = plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).join();
if (newGroup == null) {
Message.GROUP_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;
}
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), newGroup)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
newGroup.replaceEnduringNodes(group.getEnduringNodes());
Message.CLONE_SUCCESS.send(sender, group.getName(), newGroup.getName());
ExtendedLogEntry.build().actor(sender).acted(newGroup).action("clone", group.getName()).build().submit(plugin, sender);
StorageAssistant.save(newGroup, sender, plugin);
return CommandResult.SUCCESS;
}
Aggregations