From 308356de80181bac7be74189f7785bd2dad0b0fc Mon Sep 17 00:00:00 2001 From: Luck Date: Tue, 5 May 2020 17:24:44 +0100 Subject: [PATCH] Refactor group name parsing in commands --- .../command/utils/StorageAssistant.java | 20 ++++++++----------- .../commands/group/GroupParentCommand.java | 7 ++++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java b/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java index 2ec49aaa3..66547dfa2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java +++ b/common/src/main/java/me/lucko/luckperms/common/command/utils/StorageAssistant.java @@ -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) { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java index 852188226..1abd8f69a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupParentCommand.java @@ -80,7 +80,12 @@ public class GroupParentCommand extends ParentCommand { @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