use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class ContextSetJsonSerializer method deserialize.
public static ContextSet deserialize(JsonElement element) {
Preconditions.checkArgument(element.isJsonObject());
JsonObject jsonObject = element.getAsJsonObject();
Set<Map.Entry<String, JsonElement>> entries = jsonObject.entrySet();
if (entries.isEmpty()) {
return ImmutableContextSetImpl.EMPTY;
}
MutableContextSet contextSet = new MutableContextSetImpl();
for (Map.Entry<String, JsonElement> entry : entries) {
String k = entry.getKey();
JsonElement v = entry.getValue();
if (v.isJsonArray()) {
JsonArray values = v.getAsJsonArray();
for (JsonElement value : values) {
contextSet.add(k, value.getAsString());
}
} else {
contextSet.add(k, v.getAsString());
}
}
return contextSet;
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaAddChatMeta 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;
}
int priority = args.getPriority(0);
String meta = args.get(1);
MutableContextSet context = args.getContextOrDefault(2, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
DataMutateResult result = target.setNode(DataType.NORMAL, this.type.builder(meta, priority).withContext(context).build(), true);
if (result.wasSuccessful()) {
Message.ADD_CHATMETA_SUCCESS.send(sender, target, this.type, meta, priority, context);
LoggedAction.build().source(sender).target(target).description("meta", "add" + this.type.name().toLowerCase(Locale.ROOT), priority, meta, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.ALREADY_HAS_CHAT_META.send(sender, target, this.type, meta, priority, context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaClear 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;
}
NodeType<?> type = null;
if (!args.isEmpty()) {
String typeId = args.get(0).toLowerCase(Locale.ROOT);
if (typeId.equals("any") || typeId.equals("all") || typeId.equals("*")) {
type = NodeType.META_OR_CHAT_META;
}
if (typeId.equals("chat") || typeId.equals("chatmeta")) {
type = NodeType.CHAT_META;
}
if (typeId.equals("meta")) {
type = NodeType.META;
}
if (typeId.equals("prefix") || typeId.equals("prefixes")) {
type = NodeType.PREFIX;
}
if (typeId.equals("suffix") || typeId.equals("suffixes")) {
type = NodeType.SUFFIX;
}
if (type != null) {
args.remove(0);
}
}
if (type == null) {
type = NodeType.META_OR_CHAT_META;
}
int before = target.normalData().size();
MutableContextSet context = args.getContextOrDefault(0, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (context.isEmpty()) {
target.removeIf(DataType.NORMAL, null, type::matches, false);
} else {
target.removeIf(DataType.NORMAL, context, type::matches, false);
}
int changed = before - target.normalData().size();
Message.META_CLEAR_SUCCESS.send(sender, target, type.name().toLowerCase(Locale.ROOT), context, changed);
LoggedAction.build().source(sender).target(target).description("meta", "clear", context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaUnset 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_SUCCESS.send(sender, key, target, context);
LoggedAction.build().source(sender).target(target).description("meta", "unset", key, context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
} else {
Message.DOESNT_HAVE_META.send(sender, target, key, context);
}
}
use of net.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class HolderClear method execute.
@Override
public void execute(LuckPermsPlugin plugin, Sender sender, T target, ArgumentList args, String label) throws CommandException {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), target)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
int before = target.normalData().size();
MutableContextSet context = args.getContextOrDefault(0, plugin);
if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context) || ArgumentPermissions.checkGroup(plugin, sender, target, context)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return;
}
if (context.isEmpty()) {
target.clearNodes(DataType.NORMAL, null, true);
} else {
target.clearNodes(DataType.NORMAL, context, true);
}
int changed = before - target.normalData().size();
Message.CLEAR_SUCCESS.send(sender, target, context, changed);
LoggedAction.build().source(sender).target(target).description("clear", context).build().submit(plugin, sender);
StorageAssistant.save(target, sender, plugin);
}
Aggregations