description = "Swap <permission> and <targetPermission> in permission list. Could be number or permission itself")
public void userSwapPermission(PermissionsEx plugin, CommandSender sender, Map<String, String> args) {
String groupName = this.autoCompleteGroupName(args.get("group"));
String worldName = this.autoCompleteWorldName(args.get("world"));
PermissionGroup group = plugin.getPermissionsManager().getGroup(groupName);
if (group == null) {
sender.sendMessage(ChatColor.RED + "Group \"" + groupName + "\" doesn't exist.");
return;
}
List<String> permissions = group.getOwnPermissions(worldName);
try {
int sourceIndex = this.getPosition(this.autoCompletePermission(group, args.get("permission"), worldName, "permission"), permissions);
int targetIndex = this.getPosition(this.autoCompletePermission(group, args.get("targetPermission"), worldName, "targetPermission"), permissions);
String targetPermission = permissions.get(targetIndex);
permissions.set(targetIndex, permissions.get(sourceIndex));
permissions.set(sourceIndex, targetPermission);
group.setPermissions(permissions, worldName);
sender.sendMessage("Permissions swapped!");
} catch (Throwable e) {
sender.sendMessage(ChatColor.RED + "Error: " + e.getMessage());
}