コード例 #1
0
ファイル: AutoUpdate.java プロジェクト: russjr08/NewBukkit
 private boolean hasPermission(Permissible player, String node) {
   if (player.isPermissionSet(node)) return player.hasPermission(node);
   while (node.contains(".")) {
     node = node.substring(0, node.lastIndexOf("."));
     if (player.isPermissionSet(node)) return player.hasPermission(node);
     if (player.isPermissionSet(node + ".*")) return player.hasPermission(node + ".*");
   }
   if (player.isPermissionSet("*")) return player.hasPermission("*");
   return player.isOp();
 }
コード例 #2
0
  /**
   * 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))
          throw new IllegalArgumentException("permission must have a value");

        if (!permissible.hasPermission(permission)) return false;
      }
      return true;
    } else {
      if (!checkNegations) {
        for (String permission : permissions) {
          if (!hasText(permission))
            throw new IllegalArgumentException("permission must have a value");

          if (permissible.hasPermission(permission)) {
            return true; // short-circuit true
          }
        }
        return false;
      } else {
        boolean found = false;
        for (String permission : permissions) {
          if (!hasText(permission))
            throw new IllegalArgumentException("permission must have a value");

          if (permissible.hasPermission(permission)) {
            found = true; // no short-circuit; check all (for negations)
          } else if (permissible.isPermissionSet(permission)) {
            return false; // short-circuit negation
          }
        }
        return found;
      }
    }
  }