use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaUnsetTemp method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String key = args.get(0);
MutableContextSet context = args.getContextOrDefault(1, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (target.removeIf(DataType.NORMAL, context, NodeType.META.predicate(n -> n.hasExpiry() && n.getMetaKey().equalsIgnoreCase(key)), false)) {
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, target, context);
LoggedAction.build().source(sender).target(target).description("meta", "unsettemp", key, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOESNT_HAVE_TEMP_META.send(sender, target, key, context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class SqlStorage method writeNode.
private static void writeNode(Node node, PreparedStatement ps) throws SQLException {
MutableContextSet contexts = node.getContexts().mutableCopy();
String server = getFirstContextValue(contexts, DefaultContextKeys.SERVER_KEY);
String world = getFirstContextValue(contexts, DefaultContextKeys.WORLD_KEY);
long expiry = node.hasExpiry() ? node.getExpiry().getEpochSecond() : 0L;
ps.setString(2, node.getKey());
ps.setBoolean(3, node.getValue());
ps.setString(4, server);
ps.setString(5, world);
ps.setLong(6, expiry);
ps.setString(7, GsonProvider.normal().toJson(ContextSetJsonSerializer.serialize(contexts)));
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class LuckPermsVaultPermission method getQueryOptions.
// utility method for getting a contexts instance for a given vault lookup.
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
ContextSet context;
Player player = Optional.ofNullable(uuid).flatMap(u -> this.plugin.getBootstrap().getPlayer(u)).orElse(null);
if (player != null) {
context = this.plugin.getContextManager().getContext(player);
} else {
context = this.plugin.getContextManager().getStaticContext();
}
String playerWorld = player == null ? null : player.getWorld().getName();
// if world is not null, we want to do a lookup in that specific world
if (world != null && !world.isEmpty() && !world.equalsIgnoreCase(playerWorld)) {
MutableContextSet mutContext = context.mutableCopy();
context = mutContext;
// remove already accumulated worlds
mutContext.removeAll(DefaultContextKeys.WORLD_KEY);
// add the vault world
mutContext.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase(Locale.ROOT));
}
// if we're using a special vault server
if (useVaultServer()) {
MutableContextSet mutContext = context instanceof MutableContextSet ? (MutableContextSet) context : context.mutableCopy();
context = mutContext;
// remove the normal server context from the set
mutContext.remove(DefaultContextKeys.SERVER_KEY, getServer());
// add the vault specific server
if (!getVaultServer().equals("global")) {
mutContext.add(DefaultContextKeys.SERVER_KEY, getVaultServer());
}
}
boolean op = false;
if (player != null) {
op = player.isOp();
} else if (uuid != null && UniqueIdType.determineType(uuid, this.plugin).getType().equals("npc")) {
op = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_OP_STATUS);
}
QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder();
builder.context(context);
builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, isIncludeGlobal());
if (op) {
builder.option(BukkitContextManager.OP_OPTION, true);
}
return builder.build();
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentAddTemp method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST);
Duration duration = args.getDuration(1);
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(2).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = args.getContextOrDefault(2, plugin);
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return;
}
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, group, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (group.getName().equalsIgnoreCase(target.getIdentifier().getName())) {
Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
return;
}
DataMutateResult.WithMergedNode result = target.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
if (result.getResult().wasSuccessful()) {
duration = result.getMergedNode().getExpiryDuration();
Message.SET_TEMP_INHERIT_SUCCESS.send(sender, target, group, duration, context);
LoggedAction.build().source(sender).target(target).description("parent", "addtemp", group.getName(), duration, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_TEMP_INHERITS.send(sender, target, group, context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ParentRemove method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder target, ArgumentList args, String label, CommandPermission permission) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
String groupName = args.getLowercase(0, DataConstraints.GROUP_NAME_TEST_ALLOW_SPACE);
MutableContextSet context = args.getContextOrDefault(1, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context) || ArgumentPermissions.checkGroup(plugin, sender, groupName, context) || ArgumentPermissions.checkArguments(plugin, sender, permission, groupName)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (target.getType() == HolderType.USER) {
User user = (User) target;
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(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(groupName);
if (shouldPrevent) {
Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
return;
}
}
DataMutateResult result = target.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
if (result.wasSuccessful()) {
Message.UNSET_INHERIT_SUCCESS.send(sender, target, Component.text(groupName), context);
LoggedAction.build().source(sender).target(target).description("parent", "remove", groupName, context).build().submit(plugin, sender);
if (target.getType() == HolderType.USER) {
plugin.getUserManager().giveDefaultIfNeeded((User) target);
}
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOES_NOT_INHERIT.send(sender, target, Component.text(groupName), context);
}
}
Aggregations