use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class CheckCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
String target = args.get(0);
String permission = args.get(1);
User user;
UUID u = Uuids.parseNullable(target);
if (u != null) {
user = plugin.getUserManager().getIfLoaded(u);
} else {
user = plugin.getUserManager().getByUsername(target);
}
if (user == null) {
Message.USER_NOT_ONLINE.send(sender, target);
return CommandResult.STATE_ERROR;
}
Tristate tristate = user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts())).getPermissionValue(permission, CheckOrigin.INTERNAL);
Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, MessageUtils.formatTristate(tristate));
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class LogNotify method setIgnoring.
private static void setIgnoring(LuckPermsPlugin plugin, UUID uuid, boolean state) {
User user = plugin.getUserManager().getIfLoaded(uuid);
if (user == null) {
return;
}
if (state) {
// add the perm
user.setPermission(NodeFactory.make("luckperms.log.notify.ignoring"));
} else {
// remove the perm
user.removeIf(n -> n.getPermission().equalsIgnoreCase("luckperms.log.notify.ignoring"));
}
plugin.getStorage().noBuffer().saveUser(user).join();
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class StorageAssistant method save.
public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
if (holder.getType().isUser()) {
User user = ((User) holder);
save(user, sender, plugin);
} else if (holder.getType().isGroup()) {
Group group = ((Group) holder);
save(group, sender, plugin);
} else {
throw new IllegalArgumentException();
}
}
use of me.lucko.luckperms.common.model.User 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.common.model.User 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;
}
}
Aggregations