public void importPermissions3() {
WorldPermissionsManager wpm = Permissions.getWorldPermissionsManager();
for (World world : plugin.getServer().getWorlds()) {
PermissionSet ps = wpm.getPermissionSet(world);
WorldPermissions wp = ps.getWorldPermissions();
File users = new File("plugins/Permissions/" + world.getName()
+ "/users.yml");
File groups = new File("plugins/Permissions/" + world.getName()
+ "/groups.yml");
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) {
User user = wp.getUser(player);
try {
List<String> p = uConfig.getList("users."+player+".permissions");
List<String> i = uConfig.getList("users."+player+".groups");
if(p != null)
user.getPermissions().addAll(Permission.loadFromString(p));
if(i != null) {
user.getGroupsAsString().clear();
user.getGroupsAsString().addAll(i);
}
} catch (Exception e) {
System.err.println("Error importing user: "+player);
}
}
if (groupsList != null)
for (String group : groupsList) {
Group gr = wp.getGroup(group);
try {
List<String> p = gConfig.getStringList("groups."+group+".permissions");
List<String> i = gConfig.getStringList("groups."+group+".inheritance");
if(p != null)
gr.getPermissions().addAll(Permission.loadFromString(p));
if(i != null)
gr.getGroupsAsString().addAll(i);
} catch (Exception e) {
System.err.println("Error importing group: "+group);
}
}
wp.save();
}
}