Ejemplo n.º 1
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();
 }
Ejemplo n.º 2
0
  /**
   * 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);
    }
  }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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;
      }
    }
  }
Ejemplo n.º 5
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;
	}