use of me.lucko.luckperms.api.context.MutableContextSet 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.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentRemoveTemp 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.parseNameWithSpace(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (ArgumentPermissions.checkArguments(plugin, sender, permission, groupName)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).setExpiry(10L).withExtraContext(context).build());
if (result.asBoolean()) {
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "removetemp", groupName, context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
}
use of me.lucko.luckperms.api.context.MutableContextSet 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.api.context.MutableContextSet 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.api.context.MutableContextSet in project LuckPerms by lucko.
the class ArgumentParser method parseContext.
public static MutableContextSet parseContext(int fromIndex, List<String> args, LuckPermsPlugin plugin) throws CommandException {
if (args.size() > fromIndex) {
MutableContextSet set = MutableContextSet.create();
List<String> contexts = args.subList(fromIndex, args.size());
for (int i = 0; i < contexts.size(); i++) {
String pair = contexts.get(i);
// one of the first two values, and doesn't have a key
if (i <= 1 && !pair.contains("=")) {
String key = i == 0 ? Contexts.SERVER_KEY : Contexts.WORLD_KEY;
set.add(key, pair);
continue;
}
int index = pair.indexOf('=');
if (index == -1) {
continue;
}
String key = pair.substring(0, index);
if (key.equals("") || key.trim().isEmpty()) {
continue;
}
String value = pair.substring(index + 1);
if (value.equals("") || value.trim().isEmpty()) {
continue;
}
set.add(key, value);
}
return sanitizeContexts(set);
} else {
return sanitizeContexts(plugin.getConfiguration().getContextsFile().getDefaultContexts().mutableCopy());
}
}
Aggregations