Add config to control whether display names are returned by the Vault hook

This commit is contained in:
Luck 2021-01-09 20:36:08 +00:00
parent 443ea510bb
commit 505c073c8e
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 22 additions and 10 deletions

View File

@ -176,7 +176,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
@Override
public String[] getGroups() {
return this.plugin.getGroupManager().getAll().values().stream()
.map(Group::getPlainDisplayName)
.map(this::groupName)
.toArray(String[]::new);
}
@ -252,10 +252,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
return user.getOwnNodes(NodeType.INHERITANCE, queryOptions).stream()
.map(n -> {
Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
if (group != null) {
return group.getPlainDisplayName();
}
return n.getGroupName();
return group != null ? groupName(group) : n.getGroupName();
})
.toArray(String[]::new);
}
@ -274,11 +271,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
String value = metaData.getPrimaryGroup(MetaCheckEvent.Origin.THIRD_PARTY_API);
Group group = getGroup(value);
if (group != null) {
return group.getPlainDisplayName();
}
return value;
return group != null ? groupName(group) : value;
}
@Override
@ -328,6 +321,14 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
return this.plugin.getGroupManager().getByDisplayName(name);
}
private String groupName(Group group) {
if (this.plugin.getConfiguration().get(ConfigKeys.VAULT_GROUP_USE_DISPLAYNAMES)) {
return group.getPlainDisplayName();
} else {
return group.getName();
}
}
private boolean checkGroupExists(String group) {
return this.plugin.getGroupManager().getByDisplayName(group) != null;
}

View File

@ -587,6 +587,12 @@ commands-allow-op: true
# option to 'true.
vault-unsafe-lookups: false
# If LuckPerms should use the 'display name' of a group when returning groups in Vault API calls.
#
# - When this option is set to true, the display name of the group is returned.
# - When this option is set to false, the standard name/id of the group is returned.
vault-group-use-displaynames: true
# Controls which group LuckPerms should use for NPC players when handling Vault requests.
#
# - As NPCs aren't actually real players, LuckPerms does not load any user data for them. This

View File

@ -446,6 +446,11 @@ public final class ConfigKeys {
*/
public static final ConfigKey<Boolean> VAULT_UNSAFE_LOOKUPS = booleanKey("vault-unsafe-lookups", false);
/**
* If LuckPerms should use the 'display name' of a group when returning groups in Vault API calls.
*/
public static final ConfigKey<Boolean> VAULT_GROUP_USE_DISPLAYNAMES = booleanKey("vault-group-use-displaynames", true);
/**
* Controls which group LuckPerms should use for NPC players when handling Vault requests
*/