use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class HolderShowTracks method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) {
if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
try {
plugin.getStorage().loadAllTracks().get();
} catch (Exception e) {
e.printStackTrace();
Message.TRACKS_LOAD_ERROR.send(sender);
return CommandResult.LOADING_ERROR;
}
List<Map.Entry<Track, String>> lines = new ArrayList<>();
if (holder.getType().isUser()) {
// if the holder is a user, we want to query parent groups for tracks
Set<Node> nodes = holder.getEnduringNodes().values().stream().filter(Node::isGroupNode).filter(Node::getValuePrimitive).filter(Node::isPermanent).collect(Collectors.toSet());
for (Node node : nodes) {
String groupName = node.getGroupName();
List<Track> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(groupName)).collect(Collectors.toList());
for (Track t : tracks) {
lines.add(Maps.immutableEntry(t, MessageUtils.getAppendableNodeContextString(node) + "\n" + MessageUtils.listToArrowSep(t.getGroups(), groupName)));
}
}
} else {
// otherwise, just lookup for the actual group
String groupName = ((Group) holder).getName();
List<Track> tracks = plugin.getTrackManager().getAll().values().stream().filter(t -> t.containsGroup(groupName)).collect(Collectors.toList());
for (Track t : tracks) {
lines.add(Maps.immutableEntry(t, MessageUtils.listToArrowSep(t.getGroups(), groupName)));
}
}
if (lines.isEmpty()) {
Message.LIST_TRACKS_EMPTY.send(sender, holder.getFriendlyName());
return CommandResult.SUCCESS;
}
Message.LIST_TRACKS.send(sender, holder.getFriendlyName());
for (Map.Entry<Track, String> line : lines) {
Message.LIST_TRACKS_ENTRY.send(sender, line.getKey().getName(), line.getValue());
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ParentAdd method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String groupName = ArgumentParser.parseName(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return CommandResult.INVALID_ARGS;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
DataMutateResult result = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
if (result.asBoolean()) {
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "add", group.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ParentSet method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String groupName = ArgumentParser.parseName(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return CommandResult.LOADING_ERROR;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
holder.clearParents(context, false);
holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
if (holder.getType().isUser()) {
((User) holder).getPrimaryGroup().setStoredValue(group.getName());
}
Message.SET_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "set", group.getName(), context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ParentSetTrack method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
final String trackName = args.get(0).toLowerCase();
if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
Message.TRACK_INVALID_ENTRY.send(sender, trackName);
return CommandResult.INVALID_ARGS;
}
Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
if (track == null) {
return CommandResult.LOADING_ERROR;
}
if (track.getSize() <= 1) {
Message.TRACK_EMPTY.send(sender, track.getName());
return CommandResult.STATE_ERROR;
}
int index = ArgumentParser.parseIntOrElse(1, args, -1);
String groupName;
if (index > 0) {
List<String> trackGroups = track.getGroups();
if ((index - 1) >= trackGroups.size()) {
Message.DOES_NOT_EXIST.send(sender, index);
return CommandResult.INVALID_ARGS;
}
groupName = track.getGroups().get(index - 1);
} else {
groupName = ArgumentParser.parseName(1, args);
if (!track.containsGroup(groupName)) {
Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
return CommandResult.INVALID_ARGS;
}
}
MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return CommandResult.LOADING_ERROR;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (ArgumentPermissions.checkArguments(plugin, sender, permission, track.getName(), group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "settrack", track.getName(), groupName, context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ArgumentPermissions method checkViewPerms.
/**
* Checks if the sender has permission to view 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 view
* @return true if the sender should NOT be allowed to view the target, true if they should
*/
public static boolean checkViewPerms(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 view themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view.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_VIEW_SELF);
return !globalRet.asBoolean();
}
} else {
// they're trying to view another user
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view.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_VIEW_OTHERS);
return !globalRet.asBoolean();
}
}
} else if (target instanceof Group) {
Group targetGroup = ((Group) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view." + 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_VIEW.apply(targetGroup.getName()));
return !globalRet.asBoolean();
}
} else if (target instanceof Track) {
Track targetTrack = ((Track) target);
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view." + 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_VIEW.apply(targetTrack.getName()));
return !globalRet.asBoolean();
}
}
return false;
}
Aggregations