private static String[] getPermissions(Player p, String s) {
    PluginManager pm = Bukkit.getPluginManager();
    if (pm.isPluginEnabled("PermissionsEx") && isForceThis(0)) {
      return getAllPEXPlayerPerms(p, s);
    }
    if (pm.isPluginEnabled("PermissionsBukkit") && isForceThis(1)) {
      return new String[0];
    }
    if (pm.isPluginEnabled("bPermissions") && isForceThis(2)) {
      Permission ps[] =
          ApiLayer.getPermissions(p.getWorld().getName(), CalculableType.USER, p.getName());
      List<String> sr = new LinkedList<String>();
      Permission apermission[];
      int k = (apermission = ps).length;
      for (int j = 0; j < k; j++) {
        Permission px = apermission[j];
        sr.add(px.nameLowerCase());
      }

      for (int i = 0; i < sr.size(); i++) {
        if (!sr.get(i).startsWith(s)) {
          sr.remove(i);
          i--;
        }
      }

      String lz[] = sr.toArray(new String[0]);
      sr.clear();
      return lz;
    }
    if (pm.isPluginEnabled("GroupManager") && isForceThis(3)) {
      GroupManager ps = (GroupManager) pm.getPlugin("GroupManager");
      List<String> sr = new LinkedList<String>();
      User user = ps.getWorldsHolder().getWorldData(p).getUser(p.getName());
      sr.addAll(user.getPermissionList());
      sr.addAll(user.getGroup().getPermissionList());
      String a;
      for (Iterator<String> iterator = user.getGroup().getInherits().iterator();
          iterator.hasNext();
          sr.add(a)) {
        a = iterator.next();
      }

      for (int i = 0; i < sr.size(); i++) {
        if (!sr.get(i).startsWith(s)) {
          sr.remove(i);
          i--;
        }
      }

      String lz[] = sr.toArray(new String[0]);
      sr.clear();
      return lz;
    } else {
      return new String[0];
    }
  }
示例#2
0
 /**
  * Adds a single permission (String, Boolean) to a user or a group
  *
  * @param world
  * @param type
  * @param name
  * @param permissionToAdd
  */
 public static void addPermission(
     String world, CalculableType type, String name, Permission permissionToAdd) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   c.addPermission(permissionToAdd.name(), permissionToAdd.isTrue());
 }
示例#3
0
  private void loadUnsafe() throws Exception {
    boolean autoSave = wm.getAutoSave();
    wm.setAutoSave(false);
    if (!ufile.exists()) {
      if (ufile.getParentFile() != null) ufile.getParentFile().mkdirs();
      ufile.createNewFile();
      gfile.createNewFile();
    } else {
      uconfig = new YamlConfiguration();
      gconfig = new YamlConfiguration();
      uconfig.load(ufile);
      gconfig.load(gfile);
    }
    /*
     * Load the users
     */
    ConfigurationSection usersConfig = uconfig.getConfigurationSection(USERS);
    if (usersConfig != null) {

      Set<String> names = usersConfig.getKeys(false);

      for (String name : names) {
        List<String> nPerm = usersConfig.getStringList(name + "." + PERMISSIONS);
        List<String> nGroup = usersConfig.getStringList(name + "." + GROUPS);
        Set<Permission> perms = Permission.loadFromString(nPerm);
        // Create the new user
        User user = new User(name, nGroup, perms, getName(), this);
        // MetaData
        ConfigurationSection meta = usersConfig.getConfigurationSection(name + "." + META);
        if (meta != null) {
          Set<String> keys = meta.getKeys(false);
          if (keys != null && keys.size() > 0)
            for (String key : keys) user.setValue(key, meta.get(key).toString());
        }
        // Upload to API
        add(user);
      }
    }
    /*
     * Load the groups
     */
    ConfigurationSection groupsConfig = gconfig.getConfigurationSection(GROUPS);
    if (groupsConfig != null) {

      Set<String> names = groupsConfig.getKeys(false);

      for (String name : names) {
        List<String> nPerm = groupsConfig.getStringList(name + "." + PERMISSIONS);
        List<String> nGroup = groupsConfig.getStringList(name + "." + GROUPS);

        Set<Permission> perms = Permission.loadFromString(nPerm);
        // Create the new group
        Group group = new Group(name, nGroup, perms, getName(), this);
        // MetaData
        ConfigurationSection meta = groupsConfig.getConfigurationSection(name + "." + META);
        if (meta != null) {
          Set<String> keys = meta.getKeys(false);
          if (keys != null && keys.size() > 0)
            for (String key : keys) group.setValue(key, meta.get(key).toString());
        }
        // Upload to API
        add(group);
      }
    }

    // for (Calculable user : getAll(CalculableType.USER)) {
    // try {
    //	user.calculateEffectivePermissions();
    // user.calculateEffectiveMeta();
    // } catch (RecursiveGroupException e) {
    //	System.err.println(e.getMessage());
    // }
    // }
    for (Player player : this.permissions.getServer().getOnlinePlayers()) {
      String name = player.getName();
      String world = player.getWorld().getName();
      if (wm.getWorld(world) == this) {
        getUser(name).calculateEffectivePermissions();
      }
    }
    wm.setAutoSave(autoSave);
  }