private void dirtyPermissibles(boolean op) {
    Set<Permissible> permissibles = getDefaultPermSubscriptions(op);

    for (Permissible p : permissibles) {
      p.recalculatePermissions();
    }
  }
Beispiel #2
0
 public int broadcast(String message, String permission) {
   int count = 0;
   for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
     if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
       ((CommandSender) permissible).sendMessage(message);
       ++count;
     }
   }
   return count;
 }
Beispiel #3
0
 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();
 }
Beispiel #4
0
	@Override
	public int broadcast(String message, String permission) {
		int count = 0;
		Set<Permissible> permissibles = getPluginManager().getPermissionSubscriptions(permission);

		for (Permissible permissible : permissibles) {
			if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
				CommandSender user = (CommandSender) permissible;
				user.sendMessage(message);
				count++;
			}
		}

		return count;
	}
  /**
   * Require a single permission.
   *
   * @param permissible the permissible to check
   * @param permission the name of the permission
   */
  public static void requirePermission(Permissible permissible, String permission) {
    if (!hasText(permission)) throw new IllegalArgumentException("permission must have a value");

    if (!permissible.hasPermission(permission)) {
      throw new PermissionException(permission);
    }
  }
  /**
   * 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;
      }
    }
  }