use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class GroupSetDisplayName method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), group)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String name = ArgumentParser.parseString(0, args);
String previousName = group.getDisplayName().orElse(null);
if (previousName == null && name.equals(group.getName())) {
Message.GROUP_SET_DISPLAY_NAME_DOESNT_HAVE.send(sender, group.getName());
return CommandResult.STATE_ERROR;
}
if (name.equals(previousName)) {
Message.GROUP_SET_DISPLAY_NAME_ALREADY_HAS.send(sender, group.getName(), name);
return CommandResult.STATE_ERROR;
}
Group existing = plugin.getGroupManager().getByDisplayName(name);
if (existing != null && !group.equals(existing)) {
Message.GROUP_SET_DISPLAY_NAME_ALREADY_IN_USE.send(sender, name, existing.getName());
return CommandResult.STATE_ERROR;
}
group.removeIf(n -> n.getPermission().startsWith("displayname."));
if (name.equals(group.getName())) {
Message.GROUP_SET_DISPLAY_NAME_REMOVED.send(sender, group.getName());
ExtendedLogEntry.build().actor(sender).acted(group).action("setdisplayname", name).build().submit(plugin, sender);
StorageAssistant.save(group, sender, plugin);
return CommandResult.SUCCESS;
}
group.setPermission(NodeFactory.builder("displayname." + name).build());
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName());
ExtendedLogEntry.build().actor(sender).acted(group).action("setdisplayname", name).build().submit(plugin, sender);
StorageAssistant.save(group, sender, plugin);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.Group 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.Group in project LuckPerms by lucko.
the class MetaInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(ChatMetaType type, PermissionHolder holder, String label, LocalizedNode node) {
if (!node.getLocation().equals(holder.getObjectName())) {
// inherited.
Group group = holder.getPlugin().getGroupManager().getIfLoaded(node.getLocation());
if (group != null) {
holder = group;
}
}
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> ¥a" + type.getEntry(node).getKey() + " ¥7- ¥r" + type.getEntry(node).getValue(), " ", "¥7Click to remove this " + type.name().toLowerCase() + " from " + holder.getFriendlyName()), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.model.Group 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.common.model.Group in project LuckPerms by lucko.
the class UserSwitchPrimaryGroup method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) {
// cast to user
// although this command is build as a sharedsubcommand,
// it is only added to the listings for users.
User user = ((User) holder);
if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, user)) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
String opt = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD);
if (!opt.equals("stored")) {
Message.USER_PRIMARYGROUP_WARN_OPTION.send(sender, opt);
}
Group group = plugin.getGroupManager().getIfLoaded(args.get(0).toLowerCase());
if (group == null) {
Message.DOES_NOT_EXIST.send(sender, args.get(0).toLowerCase());
return CommandResult.INVALID_ARGS;
}
if (user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(group.getName())) {
Message.USER_PRIMARYGROUP_ERROR_ALREADYHAS.send(sender, user.getFriendlyName(), group.getFriendlyName());
return CommandResult.STATE_ERROR;
}
if (!user.inheritsGroup(group)) {
Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getFriendlyName(), group.getName());
user.setPermission(NodeFactory.buildGroupNode(group.getName()).build());
}
user.getPrimaryGroup().setStoredValue(group.getName());
Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getFriendlyName(), group.getFriendlyName());
ExtendedLogEntry.build().actor(sender).acted(user).action("parent", "switchprimarygroup", group.getName()).build().submit(plugin, sender);
StorageAssistant.save(user, sender, plugin);
return CommandResult.SUCCESS;
}
Aggregations