use of fr.xephi.authme.permission.DefaultPermission 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.DefaultPermission in project AuthMeReloaded by AuthMe.
the class HelpProviderTest method setDefaultHelpMessages.
private static void setDefaultHelpMessages(HelpMessagesService helpMessagesService) {
given(helpMessagesService.buildLocalizedDescription(any(CommandDescription.class))).willAnswer(new ReturnsArgumentAt(0));
for (HelpMessage key : HelpMessage.values()) {
String text = key.name().replace("_", " ").toLowerCase();
given(helpMessagesService.getMessage(key)).willReturn(text.substring(0, 1).toUpperCase() + text.substring(1));
}
for (DefaultPermission permission : DefaultPermission.values()) {
String text = permission.name().replace("_", " ").toLowerCase();
given(helpMessagesService.getMessage(permission)).willReturn(text.substring(0, 1).toUpperCase() + text.substring(1));
}
for (HelpSection section : HelpSection.values()) {
String text = section.name().replace("_", " ").toLowerCase();
given(helpMessagesService.getMessage(section)).willReturn(text.substring(0, 1).toUpperCase() + text.substring(1));
}
}
use of fr.xephi.authme.permission.DefaultPermission in project AuthMeReloaded by AuthMe.
the class HelpTranslationGenerator method generateHelpMessageEntries.
/**
* Generates entries for a complete help text file.
*
* @return help text entries to save
*/
private Map<String, Object> generateHelpMessageEntries() {
Map<String, Object> messageEntries = new LinkedHashMap<>(HelpMessage.values().length);
for (HelpMessage message : HelpMessage.values()) {
messageEntries.put(message.getEntryKey(), helpMessagesService.getMessage(message));
}
Map<String, String> defaultPermissions = new LinkedHashMap<>();
for (DefaultPermission defaultPermission : DefaultPermission.values()) {
defaultPermissions.put(HelpMessagesService.getDefaultPermissionsSubPath(defaultPermission), helpMessagesService.getMessage(defaultPermission));
}
messageEntries.put("defaultPermissions", defaultPermissions);
Map<String, String> sectionEntries = new LinkedHashMap<>(HelpSection.values().length);
for (HelpSection section : HelpSection.values()) {
sectionEntries.put(section.getEntryKey(), helpMessagesService.getMessage(section));
}
Map<String, Object> commandEntries = new LinkedHashMap<>();
for (CommandDescription command : commandInitializer.getCommands()) {
generateCommandEntries(command, commandEntries);
}
return ImmutableMap.of("common", messageEntries, "section", sectionEntries, "commands", commandEntries);
}
Aggregations