Package com.forgeessentials.api.permissions

Examples of com.forgeessentials.api.permissions.ServerZone


            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;
        }
View Full Code Here


    public ZonedPermissionHelper()
    {
        FMLCommonHandler.instance().bus().register(this);
        rootZone = new RootZone(this);
        rootZone.setServerZone(new ServerZone(rootZone));
    }
View Full Code Here

    public boolean load()
    {
        if (persistenceProvider != null)
        {
            ServerZone serverZone = persistenceProvider.load();
            if (serverZone != null)
            {
                // Set new server zone
                rootZone.setServerZone(serverZone);
                serverZone.rebuildZonesMap();
                dirty = false;
                return true;
            }
        }
        return false;
View Full Code Here

    {
        File path = basePath;
        try
        {
            // Create ServerZone and load permissions
            ServerZone serverZone = new ServerZone();
            loadZonePermissions(path, serverZone);

            readUserGroupPermissions(serverZone);

            int maxId = 2;

            File[] worldDirs = path.listFiles(directoryFilter);
            if (worldDirs == null)
            {
                OutputHandler.felog.severe("Error loading permissions: invalid path");
                return null;
            }
            for (File worldPath : worldDirs)
            {
                try
                {
                    File worldFile = new File(worldPath, "world.xml");
                    if (!worldFile.exists())
                        continue;
                    Properties worldProperties = new Properties();
                    worldProperties.loadFromXML(new BufferedInputStream(new FileInputStream(worldFile)));

                    // Read world data
                    int worldId = Integer.parseInt(worldProperties.getProperty("id"));
                    maxId = Math.max(maxId, worldId);

                    int dimensionID = Integer.parseInt(worldProperties.getProperty("dimId"));

                    // Create WorldZone and load permissions
                    WorldZone worldZone = new WorldZone(serverZone, dimensionID, worldId);
                    loadZonePermissions(worldPath, worldZone);

                    for (File areaPath : worldPath.listFiles(directoryFilter))
                    {
                        try
                        {
                            File areaFile = new File(areaPath, "area.xml");
                            if (!areaFile.exists())
                                continue;
                            Properties areaProperties = new Properties();
                            areaProperties.loadFromXML(new BufferedInputStream(new FileInputStream(areaFile)));

                            // Read area data
                            int areaId = Integer.parseInt(areaProperties.getProperty("id"));
                            maxId = Math.max(maxId, areaId);

                            String name = areaProperties.getProperty("name");
                            int x1 = Integer.parseInt(areaProperties.getProperty("x1"));
                            int y1 = Integer.parseInt(areaProperties.getProperty("y1"));
                            int z1 = Integer.parseInt(areaProperties.getProperty("z1"));
                            int x2 = Integer.parseInt(areaProperties.getProperty("x2"));
                            int y2 = Integer.parseInt(areaProperties.getProperty("y2"));
                            int z2 = Integer.parseInt(areaProperties.getProperty("z2"));
                            if (name == null)
                                throw new IllegalArgumentException();

                            // Create AreaZone and load permissions
                            AreaZone areaZone = new AreaZone(worldZone, name, new AreaBase(new Point(x1, y1, z1), new Point(x2, y2, z2)), areaId);
                            loadZonePermissions(areaPath, areaZone);
                        }
                        catch (IllegalArgumentException | IOException e)
                        {
                            OutputHandler.felog.severe("Error reading area " + worldPath.getName() + "/" + areaPath.getName());
                        }
                    }
                }
                catch (NumberFormatException | IOException e)
                {
                    OutputHandler.felog.severe("Error reading world " + worldPath.getName());
                }
            }

            File serverFile = new File(path, "server.xml");
            if (serverFile.exists())
            {
                try
                {
                    Properties serverProperties = new Properties();
                    serverProperties.loadFromXML(new BufferedInputStream(new FileInputStream(serverFile)));
                    serverZone.setMaxZoneId(Integer.parseInt(serverProperties.getProperty("maxZoneId")));
                }
                catch (IllegalArgumentException | IOException e)
                {
                    OutputHandler.felog.severe("Error reading server data " + serverFile.getName());
                    serverZone.setMaxZoneId(maxId);
                }
            }
            else
            {
                serverZone.setMaxZoneId(maxId);
            }

            return serverZone;
        }
        catch (Exception e)
View Full Code Here

TOP

Related Classes of com.forgeessentials.api.permissions.ServerZone

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.