use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentAddTemp 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);
long duration = ArgumentParser.parseDuration(1, args);
TemporaryModifier modifier = ArgumentParser.parseTemporaryModifier(2, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = ArgumentParser.parseContext(2, 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;
}
if (group.getName().equalsIgnoreCase(holder.getObjectName())) {
Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
Map.Entry<DataMutateResult, Node> ret = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).setExpiry(duration).withExtraContext(context).build(), modifier);
if (ret.getKey().asBoolean()) {
duration = ret.getValue().getExpiryUnixTime();
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "addtemp", group.getName(), duration, context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_TEMP_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 ParentClear 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;
}
int before = holder.getEnduringNodes().size();
MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (context.isEmpty()) {
holder.clearParents(true);
} else {
holder.clearParents(context, true);
}
int changed = before - holder.getEnduringNodes().size();
if (changed == 1) {
Message.PARENT_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
} else {
Message.PARENT_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "clear", 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 ParentClearTrack 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 before = holder.getEnduringNodes().size();
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, track.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (context.isEmpty()) {
holder.removeIf(node -> node.isGroupNode() && track.containsGroup(node.getGroupName()));
} else {
holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
}
if (holder.getType().isUser()) {
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
}
int changed = before - holder.getEnduringNodes().size();
if (changed == 1) {
Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed);
} else {
Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed);
}
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "cleartrack", track.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 ParentRemove 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;
}
if (holder.getType().isUser()) {
User user = (User) holder;
boolean shouldPrevent = plugin.getConfiguration().get(ConfigKeys.PREVENT_PRIMARY_GROUP_REMOVAL) && context.isEmpty() && plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD).equals("stored") && user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(groupName);
if (shouldPrevent) {
Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
return CommandResult.STATE_ERROR;
}
}
DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).withExtraContext(context).build());
if (result.asBoolean()) {
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "remove", groupName, context).build().submit(plugin, sender);
if (holder.getType().isUser()) {
plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
}
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOES_NOT_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 PermissionCheck method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String node = ArgumentParser.parseString(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
Tristate result = holder.hasPermission(NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
String s = MessageUtils.formatTristate(result);
Message.CHECK_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context));
return CommandResult.SUCCESS;
}
Aggregations