Refactor group name parsing in commands

This commit is contained in:
Luck 2020-05-05 17:24:44 +01:00
parent 8771d4c5e5
commit 308356de80
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 14 additions and 13 deletions

View File

@ -45,19 +45,15 @@ public final class StorageAssistant {
private StorageAssistant() {}
public static Group loadGroup(String target, Sender sender, LuckPermsPlugin plugin, boolean auditTemporary) {
Group group = plugin.getStorage().loadGroup(target).join().orElse(null);
Group group = plugin.getGroupManager().getByDisplayName(target);
if (group != null) {
target = group.getName();
}
group = plugin.getStorage().loadGroup(target).join().orElse(null);
if (group == null) {
// failed to load, but it might be a display name.
group = plugin.getGroupManager().getByDisplayName(target);
// nope, not a display name
if (group == null) {
Message.GROUP_NOT_FOUND.send(sender, target);
return null;
}
// it was a display name, we need to reload
plugin.getStorage().loadGroup(group.getName()).join();
Message.GROUP_NOT_FOUND.send(sender, target);
return null;
}
if (auditTemporary) {

View File

@ -80,7 +80,12 @@ public class GroupParentCommand extends ParentCommand<Group, String> {
@Override
protected String parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
return target.toLowerCase();
Group group = plugin.getGroupManager().getByDisplayName(target);
if (group != null) {
return group.getName();
} else {
return target.toLowerCase();
}
}
@Override