Exemplo n.º 1
0
  public void importYML() throws Exception {
    for (World world : plugin.getServer().getWorlds()) {
      de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());
      File perms = new File("plugins/bPermissions/worlds/" + world.getName() + ".yml");
      if (perms.exists()) {
        System.out.println("Importing world: " + world.getName());
        YamlConfiguration pConfig = new YamlConfiguration(); // new Configuration(perms);
        pConfig.load(perms);
        // Here we grab the different bits and bobs
        ConfigurationSection users = pConfig.getConfigurationSection("players");
        ConfigurationSection groups = pConfig.getConfigurationSection("groups");

        // Load users
        if (users != null && users.getKeys(false) != null && users.getKeys(false).size() > 0) {
          Set<String> u = users.getKeys(false);
          for (String usr : u) {
            System.out.println("Importing user: "******"Importing group: " + grp);
            List<String> p = groups.getStringList(grp);
            if (p != null && p.size() > 0)
              for (String perm : p)
                wd.getGroup(grp).getPermissions().add(Permission.loadFromString(perm));
          }
        }
      }
      // Forgot to save after importing!
      wd.save();
    }
    wm.cleanup();
  }
Exemplo n.º 2
0
  public void importPermissions3() throws Exception {
    for (World world : plugin.getServer().getWorlds()) {
      de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());

      File users = new File("plugins/Permissions/" + world.getName() + "/users.yml");
      File groups = new File("plugins/Permissions/" + world.getName() + "/groups.yml");

      if (users.exists() && groups.exists()) {
        System.out.println("Importing world: " + world.getName());

        YamlConfiguration uConfig = new YamlConfiguration();
        YamlConfiguration gConfig = new YamlConfiguration();
        try {
          uConfig.load(users);
          gConfig.load(groups);
        } catch (Exception e) {
          e.printStackTrace();
        }
        ConfigurationSection usConfig = uConfig.getConfigurationSection("users");
        ConfigurationSection grConfig = gConfig.getConfigurationSection("groups");

        Set<String> usersList = null;
        if (usConfig != null) usersList = usConfig.getKeys(false);
        Set<String> groupsList = null;
        if (grConfig != null) groupsList = grConfig.getKeys(false);

        if (usersList != null)
          for (String player : usersList) {
            System.out.println("Importing user: "******"users." + player + ".permissions");
              List<String> i = uConfig.getStringList("users." + player + ".groups");

              String prefix = uConfig.getString("users." + player + ".info." + "prefix");
              String suffix = uConfig.getString("users." + player + ".info." + "suffix");

              if (p != null) user.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) {
                user.getGroupsAsString().clear();
                user.getGroupsAsString().addAll(i);
              }
              if (prefix != null) user.setValue("prefix", prefix);
              if (suffix != null) user.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing user: "******"Importing group: " + group);
            Group gr = wd.getGroup(group);
            try {
              List<String> p = gConfig.getStringList("groups." + group + ".permissions");
              List<String> i = gConfig.getStringList("groups." + group + ".inheritance");

              String prefix = gConfig.getString("groups." + group + ".info." + "prefix");
              String suffix = gConfig.getString("groups." + group + ".info." + "suffix");
              if (p != null) gr.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) gr.getGroupsAsString().addAll(i);
              if (prefix != null) gr.setValue("prefix", prefix);
              if (suffix != null) gr.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing group: " + group);
            }
          }
        wd.save();
      }
    }
    wm.cleanup();
  }
Exemplo n.º 3
0
  public void importGroupManager() throws Exception {
    for (World world : plugin.getServer().getWorlds()) {
      de.bananaco.bpermissions.api.World wd = wm.getWorld(world.getName());

      File users = new File("plugins/GroupManager/worlds/" + world.getName() + "/users.yml");
      File groups = new File("plugins/GroupManager/worlds/" + world.getName() + "/groups.yml");

      if (users.exists() && groups.exists()) {
        System.out.println("Importing world: " + world.getName());

        YamlConfiguration uConfig = new YamlConfiguration();
        YamlConfiguration gConfig = new YamlConfiguration();
        try {
          uConfig.load(users);
          gConfig.load(groups);
        } catch (Exception e) {
          e.printStackTrace();
        }
        ConfigurationSection usConfig = uConfig.getConfigurationSection("users");
        ConfigurationSection grConfig = gConfig.getConfigurationSection("groups");

        Set<String> usersList = null;
        if (usConfig != null) usersList = usConfig.getKeys(false);
        Set<String> groupsList = null;
        if (grConfig != null) groupsList = grConfig.getKeys(false);

        if (usersList != null)
          for (String player : usersList) {
            System.out.println("Importing user: "******"users." + player + ".permissions");
              List<String> i = uConfig.getStringList("users." + player + ".subgroups");
              i.add(uConfig.getString("users." + player + ".group"));

              String prefix = uConfig.getString("users." + player + ".info." + "prefix");
              String suffix = uConfig.getString("users." + player + ".info." + "suffix");

              if (p != null) user.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) {
                user.getGroupsAsString().clear();
                user.getGroupsAsString().addAll(i);
              }
              if (prefix != null) user.setValue("prefix", prefix);
              if (suffix != null) user.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing user: "******"Importing group: " + group);
            Group gr = wd.getGroup(group);
            try {
              List<String> p = gConfig.getStringList("groups." + group + ".permissions");
              List<String> i = gConfig.getStringList("groups." + group + ".inheritance");

              String prefix = gConfig.getString("groups." + group + ".info." + "prefix");
              String suffix = gConfig.getString("groups." + group + ".info." + "suffix");

              if (gConfig.getBoolean("groups." + group + ".default")) {
                wd.setDefaultGroup(group);
                System.out.println("DEFAULT GROUP DETECTED: " + group);
              }
              if (p != null) gr.getPermissions().addAll(Permission.loadFromString(p));
              if (i != null) {
                List<String> fp = new ArrayList<String>();
                for (int j = 0; j < i.size(); j++) {
                  String fpp = i.get(j);
                  if (fpp.startsWith("g:")) {
                    // do nothing
                  } else {
                    fp.add(fpp);
                  }
                }
                i.clear();
                i.addAll(fp);
                gr.getGroupsAsString().addAll(i);
              }
              if (prefix != null) gr.setValue("prefix", prefix);
              if (suffix != null) gr.setValue("suffix", suffix);
            } catch (Exception e) {
              System.err.println("Error importing group: " + group);
            }
          }
        wd.save();
      }
    }
    wm.cleanup();
  }