Example #1
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);
  }