use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionCheckInherits 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);
InheritanceInfo result = holder.searchForInheritedMatch(NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
String location = result.getLocation().orElse(null);
if (location == null || location.equalsIgnoreCase(holder.getObjectName())) {
location = "self";
}
String s = MessageUtils.formatTristate(result.getResult());
Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context), String.valueOf(location));
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class PermissionSetTemp 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 node = ArgumentParser.parseString(0, args);
boolean value = ArgumentParser.parseBoolean(1, args);
long duration = ArgumentParser.parseDuration(2, args);
TemporaryModifier modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = ArgumentParser.parseContext(3, 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, node)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Map.Entry<DataMutateResult, Node> result = holder.setPermission(NodeFactory.builder(node).setValue(value).withExtraContext(context).setExpiry(duration).build(), modifier);
if (result.getKey().asBoolean()) {
duration = result.getValue().getExpiryUnixTime();
Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("permission", "settemp", node, value, duration, context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
}
use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.
the class MetaSet 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 key = args.get(0);
String value = args.get(1);
MutableContextSet context = ArgumentParser.parseContext(2, 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, key)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).build();
if (holder.hasPermission(n).asBoolean()) {
Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
holder.clearMetaKeys(key, context, false);
holder.setPermission(n);
TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context))).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥'));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "set", key, value, 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 MetaSetTemp 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 key = args.get(0);
String value = args.get(1);
long duration = ArgumentParser.parseDuration(2, args);
TemporaryModifier modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
MutableContextSet context = ArgumentParser.parseContext(3, 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, key)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).setExpiry(duration).build();
if (holder.hasPermission(n).asBoolean()) {
Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
holder.clearMetaKeys(key, context, true);
duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime();
TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥'));
builder.applyDeep(c -> c.hoverEvent(event));
sender.sendMessage(builder.build());
ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "settemp", key, value, duration, 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 MetaUnsetTemp 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 key = args.get(0);
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, key)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
if (holder.clearMetaKeys(key, context, true)) {
Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "unsettemp", key, context).build().submit(plugin, sender);
StorageAssistant.save(holder, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context));
return CommandResult.STATE_ERROR;
}
}
Aggregations