use of fr.xephi.authme.permission.PermissionNode in project AuthMeReloaded by AuthMe.
the class HelpProvider method addPermissionsInfo.
/**
* Adds help info about the given command's permissions into the provided list.
*
* @param command the command to generate permissions info for
* @param sender the command sender, used to evaluate permissions
* @param lines the output collection to add the info to
*/
private void addPermissionsInfo(CommandDescription command, CommandSender sender, List<String> lines) {
PermissionNode permission = command.getPermission();
if (permission == null) {
return;
}
lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpSection.PERMISSIONS) + ":");
boolean hasPermission = permissionsManager.hasPermission(sender, permission);
lines.add(String.format(" " + ChatColor.YELLOW + ChatColor.ITALIC + "%s" + ChatColor.GRAY + " (%s)", permission.getNode(), getLocalPermissionText(hasPermission)));
// Addendum to the line to specify whether the sender has permission or not when default is OP_ONLY
final DefaultPermission defaultPermission = permission.getDefaultPermission();
String addendum = "";
if (DefaultPermission.OP_ONLY.equals(defaultPermission)) {
addendum = " (" + getLocalPermissionText(defaultPermission.evaluate(sender)) + ")";
}
lines.add(ChatColor.GOLD + helpMessagesService.getMessage(HelpMessage.DEFAULT) + ": " + ChatColor.GRAY + ChatColor.ITALIC + helpMessagesService.getMessage(defaultPermission) + addendum);
// Evaluate if the sender has permission to the command
ChatColor permissionColor;
String permissionText;
if (permissionsManager.hasPermission(sender, command.getPermission())) {
permissionColor = ChatColor.GREEN;
permissionText = getLocalPermissionText(true);
} else {
permissionColor = ChatColor.DARK_RED;
permissionText = getLocalPermissionText(false);
}
lines.add(String.format(ChatColor.GOLD + " %s: %s" + ChatColor.ITALIC + "%s", helpMessagesService.getMessage(HelpMessage.RESULT), permissionColor, permissionText));
}
use of fr.xephi.authme.permission.PermissionNode in project AuthMeReloaded by AuthMe.
the class GeneratePluginYml method gatherChildren.
private Map<String, Boolean> gatherChildren(String parentNode) {
String parentPath = parentNode.replaceAll("\\.\\*$", "");
Map<String, Boolean> children = new TreeMap<>();
for (PermissionNode node : permissionNodes) {
if (node.getNode().startsWith(parentPath)) {
children.put(node.getNode(), Boolean.TRUE);
}
}
return children;
}
use of fr.xephi.authme.permission.PermissionNode in project AuthMeReloaded by AuthMe.
the class HasPermissionCheckerTest method shouldShowSuccessfulTestWithRegularPlayer.
@Test
public void shouldShowSuccessfulTestWithRegularPlayer() {
// given
String name = "Chuck";
Player player = mock(Player.class);
given(bukkitService.getPlayerExact(name)).willReturn(player);
PermissionNode permission = AdminPermission.CHANGE_EMAIL;
given(permissionsManager.hasPermission(player, permission)).willReturn(true);
CommandSender sender = mock(CommandSender.class);
// when
hasPermissionChecker.execute(sender, asList(name, permission.getNode()));
// then
verify(bukkitService).getPlayerExact(name);
verify(permissionsManager).hasPermission(player, permission);
verify(sender).sendMessage(argThat(containsString("Success: player '" + player.getName() + "' has permission '" + permission.getNode() + "'")));
}
use of fr.xephi.authme.permission.PermissionNode in project AuthMeReloaded by AuthMe.
the class GeneratePluginYml method generatePermissions.
private Map<String, Object> generatePermissions() {
PermissionNodesGatherer gatherer = new PermissionNodesGatherer();
Map<String, String> permissionDescriptions = gatherer.gatherNodesWithJavaDoc();
permissionNodes = gatherer.getPermissionClasses().stream().map(clz -> clz.getEnumConstants()).flatMap((PermissionNode[] nodes) -> Arrays.stream(nodes)).collect(Collectors.toList());
Map<String, Object> descriptions = new TreeMap<>();
for (PermissionNode node : permissionNodes) {
descriptions.put(node.getNode(), buildPermissionEntry(node, permissionDescriptions.get(node.getNode())));
}
addWildcardPermissions(descriptions);
return descriptions;
}
use of fr.xephi.authme.permission.PermissionNode in project AuthMeReloaded by AuthMe.
the class CommonServiceTest method shouldCheckPermission.
@Test
public void shouldCheckPermission() {
// given
Player player = mock(Player.class);
PermissionNode permission = PlayerPermission.CHANGE_PASSWORD;
given(permissionsManager.hasPermission(player, permission)).willReturn(true);
// when
boolean result = commonService.hasPermission(player, permission);
// then
verify(permissionsManager).hasPermission(player, permission);
assertThat(result, equalTo(true));
}
Aggregations