<commit_before>/*
 * This file is part of Politics.
 *
 * Copyright (c) 2012-2012, VolumetricPixels <http://volumetricpixels.com/>
 * Politics is licensed under the Affero General Public License Version 3.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.volumetricpixels.politics.protection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.spout.api.Spout;
import org.spout.api.geo.Protection;
import org.spout.api.geo.World;
import org.spout.api.geo.discrete.Point;
import org.spout.api.plugin.services.ProtectionService;

import com.volumetricpixels.politics.Politics;

/**
 * The ProtectionService of Politics
 */
public class PoliticsProtectionService extends ProtectionService {
    private static PoliticsProtectionService instance;

    private final List<Protection> protections = new ArrayList<Protection>();

    public PoliticsProtectionService() {
        instance = this;

        Spout.getEventManager().registerEvents(new PoliticsProtectionServiceListener(), Politics.getPlugin());
    }

    public boolean addProtection(final Protection prot) {
        if (prot != null && protections.contains(prot) == false) {
            return protections.add(prot);
        }
        return false;
    }

    public boolean removeProtection(final Protection prot) {
        if (prot != null) {
            if (protections.contains(prot)) {
                return protections.add(prot);
            }
        }
        return false;
    }

    @Override
    public Collection<Protection> getAllProtections() {
        return protections;
    }

    @Override
    public Collection<Protection> getAllProtections(final World world) {
        final Collection<Protection> result = new ArrayList<Protection>();
        for (final Protection p : protections) {
            if (p.getWorld().equals(world)) {
                result.add(p);
            }
        }
        return result;
    }

    @Override
    public Collection<Protection> getAllProtections(final Point location) {
        final Collection<Protection> result = new ArrayList<Protection>();
        for (final Protection p : protections) {
            if (p.contains(location)) {
                result.add(p);
            }
        }
        return result;
    }

    @Override
    public Protection getProtection(final String name) {
        return null;
    }

    public static PoliticsProtectionService getInstance() {
        return instance;
    }
}
<commit_msg>Implements getProtection... Having Plots as Protections may end up being changed<commit_after>/*
 * This file is part of Politics.
 *
 * Copyright (c) 2012-2012, VolumetricPixels <http://volumetricpixels.com/>
 * Politics is licensed under the Affero General Public License Version 3.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.volumetricpixels.politics.protection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.spout.api.Spout;
import org.spout.api.geo.Protection;
import org.spout.api.geo.World;
import org.spout.api.geo.discrete.Point;
import org.spout.api.plugin.services.ProtectionService;

import com.volumetricpixels.politics.Politics;

import static java.lang.Integer.parseInt;

/**
 * The ProtectionService of Politics
 */
public class PoliticsProtectionService extends ProtectionService {
    private static PoliticsProtectionService instance;

    private final List<Protection> protections = new ArrayList<Protection>();

    public PoliticsProtectionService() {
        instance = this;

        Spout.getEventManager().registerEvents(new PoliticsProtectionServiceListener(), Politics.getPlugin());
    }

    public boolean addProtection(final Protection prot) {
        if (prot != null && protections.contains(prot) == false) {
            return protections.add(prot);
        }
        return false;
    }

    public boolean removeProtection(final Protection prot) {
        if (prot != null) {
            if (protections.contains(prot)) {
                return protections.add(prot);
            }
        }
        return false;
    }

    @Override
    public Collection<Protection> getAllProtections() {
        return protections;
    }

    @Override
    public Collection<Protection> getAllProtections(final World world) {
        final Collection<Protection> result = new ArrayList<Protection>();
        for (final Protection p : protections) {
            if (p.getWorld().equals(world)) {
                result.add(p);
            }
        }
        return result;
    }

    @Override
    public Collection<Protection> getAllProtections(final Point location) {
        final Collection<Protection> result = new ArrayList<Protection>();
        for (final Protection p : protections) {
            if (p.contains(location)) {
                result.add(p);
            }
        }
        return result;
    }

    @Override
    public Protection getProtection(final String name) {
        String[] split = name.split(",");
        Point point = new Point(Spout.getEngine().getWorld(split[0]), parseInt(split[1]), parseInt(split[2]), parseInt(split[3]));
        return Politics.getWorld(point.getWorld()).getPlotAt(point.getBlockX(), point.getBlockY(), point.getBlockZ());
    }

    public static PoliticsProtectionService getInstance() {
        return instance;
    }
}

{'fraction_non_alphanumeric': 0.091005291005291, 'fraction_numerical': 0.0036281179138321997, 'mean_word_length': 2.985542168674699, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5940076', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1687, 'n_words': 547}