// Path: src/main/java/org/tyrannyofheaven/bukkit/util/ToHStringUtils.java
// public static boolean hasText(String text) {
//     return text != null && text.trim().length() > 0;
// }
// 
// Path: src/main/java/org/tyrannyofheaven/bukkit/util/ToHMessageUtils.java
// public static void sendMessage(CommandSender sender, String format, Object... args) {
//     String message = String.format(format, args);
//     for (String line : message.split("\n")) {
//         sender.sendMessage(line);
//     }
// }


import static org.tyrannyofheaven.bukkit.util.ToHStringUtils.hasText;
import static org.tyrannyofheaven.bukkit.util.ToHMessageUtils.sendMessage;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permissible;
/*
 * Copyright 2011 ZerothAngel <zerothangel@tyrannyofheaven.org>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tyrannyofheaven.bukkit.util.permissions;



/**
 * Utilities for checking permissions and displaying error messages.
 * 
 * @author zerothangel
 */
public class PermissionUtils {

    private PermissionUtils() {
        throw new AssertionError("Don't instantiate me!");
    }

    /**
     * Test if a permissible has multiple permissions.
     * 
     * @param permissible the permissible
     * @param all true if all permissions are required
     * @param permissions the permissions
     * @return true if conditions are met
     */
    public static boolean hasPermissions(Permissible permissible, boolean all, String... permissions) {
        return hasPermissions(permissible, all, false, permissions);
    }

    /**
     * Test if a permissible has multiple permissions.
     * 
     * @param permissible the permissible
     * @param all true if all permissions are required
     * @param checkNegations true if any explicitly false permission should mean
     *     the check fails. Only valid when all is false.
     * @param permissions the permissions
     * @return true if conditions are met
     */
    public static boolean hasPermissions(Permissible permissible, boolean all, boolean checkNegations, String... permissions) {
        if (permissions == null || permissions.length == 0) return true;
        
        if (all) {
            for (String permission : permissions) {
// Path: src/main/java/org/tyrannyofheaven/bukkit/util/ToHStringUtils.java
// public static boolean hasText(String text) {
//     return text != null && text.trim().length() > 0;
// }
// 
// Path: src/main/java/org/tyrannyofheaven/bukkit/util/ToHMessageUtils.java
// public static void sendMessage(CommandSender sender, String format, Object... args) {
//     String message = String.format(format, args);
//     for (String line : message.split("\n")) {
//         sender.sendMessage(line);
//     }
// }


// Path: src/main/java/org/tyrannyofheaven/bukkit/util/permissions/PermissionUtils.java
import static org.tyrannyofheaven.bukkit.util.ToHStringUtils.hasText;
import static org.tyrannyofheaven.bukkit.util.ToHMessageUtils.sendMessage;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permissible;

/*
 * Copyright 2011 ZerothAngel <zerothangel@tyrannyofheaven.org>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tyrannyofheaven.bukkit.util.permissions;



/**
 * Utilities for checking permissions and displaying error messages.
 * 
 * @author zerothangel
 */
public class PermissionUtils {

    private PermissionUtils() {
        throw new AssertionError("Don't instantiate me!");
    }

    /**
     * Test if a permissible has multiple permissions.
     * 
     * @param permissible the permissible
     * @param all true if all permissions are required
     * @param permissions the permissions
     * @return true if conditions are met
     */
    public static boolean hasPermissions(Permissible permissible, boolean all, String... permissions) {
        return hasPermissions(permissible, all, false, permissions);
    }

    /**
     * Test if a permissible has multiple permissions.
     * 
     * @param permissible the permissible
     * @param all true if all permissions are required
     * @param checkNegations true if any explicitly false permission should mean
     *     the check fails. Only valid when all is false.
     * @param permissions the permissions
     * @return true if conditions are met
     */
    public static boolean hasPermissions(Permissible permissible, boolean all, boolean checkNegations, String... permissions) {
        if (permissions == null || permissions.length == 0) return true;
        
        if (all) {
            for (String permission : permissions) {
                if (!hasText(permission))