List<Map<String, Object>> zonesData = TABLES.get(TABLE_ZONE).loadList();
List<Map<String, Object>> groupPermissions = TABLES.get(TABLE_GROUP_PERMISSIONS).loadList();
List<Map<String, Object>> userPermissions = TABLES.get(TABLE_USER_PERMISSIONS).loadList();
// Create server-zone
ServerZone serverZone = null;
for (Map<String, Object> zoneData : zonesData)
if (zoneData.get("type").equals(0))
{
serverZone = new ServerZone();
zones.put(serverZone.getId(), serverZone);
break;
}
// Check if server-zone could be created - otherwise save was corrupt or just not present
if (serverZone == null)
{
OutputHandler.felog.severe("Error loading permissions: Missing server-zone");
db.createStatement().executeUpdate(TABLES.get(TABLE_ZONE).createTruncate());
return null;
}
// Create world-zones
for (Map<String, Object> zoneData : zonesData)
if (zoneData.get("type").equals(1))
{
WorldZone zone = new WorldZone(serverZone, (Integer) zoneData.get("dimension"), (Integer) zoneData.get("id"));
zones.put(zone.getId(), zone);
}
// Create area-zones
for (Map<String, Object> zoneData : zonesData)
if (zoneData.get("type").equals(2))
{
WorldZone parentZone = (WorldZone) zones.get(zoneData.get("parent_id"));
if (parentZone != null)
{
AreaBase area = AreaBase.fromString((String) zoneData.get("area"));
if (area != null)
{
AreaZone zone = new AreaZone(parentZone, (String) zoneData.get("name"), area, (Integer) zoneData.get("id"));
zones.put(zone.getId(), zone);
}
}
}
// Apply group permissions
for (Map<String, Object> permData : groupPermissions)
{
Zone zone = zones.get(permData.get("zone_id"));
if (zone != null)
{
zone.setGroupPermissionProperty((String) permData.get("group"), (String) permData.get("permission"), (String) permData.get("value"));
}
}
// Apply user permissions
for (Map<String, Object> permData : userPermissions)
{
Zone zone = zones.get(permData.get("zone_id"));
if (zone != null)
{
zone.setPlayerPermissionProperty(new UserIdent((String) permData.get("user")), (String) permData.get("permission"),
(String) permData.get("value"));
}
}
// Load maxZoneId
try
{
serverZone.setMaxZoneId(Integer.parseInt(infoData.get(INFO_MAX_ZONE_ID)));
}
catch (NumberFormatException e)
{
}
// Make sure maxZoneId is valid
for (Zone zone : zones.values())
if (zone.getId() > serverZone.getMaxZoneID())
serverZone.setMaxZoneId(zone.getId());
// Add user to groups by fe.internal.player.groups permission
for (UserIdent ident : serverZone.getPlayerPermissions().keySet())
{
String groupList = serverZone.getPlayerPermission(ident, FEPermissions.PLAYER_GROUPS);
serverZone.clearPlayerPermission(ident, FEPermissions.PLAYER_GROUPS);
if (groupList == null)
continue;
String[] groups = groupList.split(",");
for (String group : groups)
{
serverZone.addPlayerToGroup(ident, group);
}
}
return serverZone;
}