<commit_before>/*
 * Copyright (c) 2015, ArdiMaster
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be
 *    used to endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

package org.bitbucket.ardimaster.guarddogs;

import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/**
 * GuardDogs main class
 *
 * @author ArdiMaster
 */
public class GuardDogs extends JavaPlugin {

    /**
     * The name of the configuration file
     */
    protected String configFileName = "config.yml";
    /** This HashSet holds all the guard dogs */
    protected HashSet<Wolf> guards = new HashSet<>();
    /** This HashMap contains the allocation of guard dogs --> targets */
    protected HashMap<Wolf, LivingEntity> guardTargets = new HashMap<>();
    /** This HashMap contains the allocation of guard dogs --> location */
    protected HashMap<Wolf, Location> guardPositions = new HashMap<>();
    /** This HashMap contains the allocation of guard dogs --> their wait countdown */
    protected HashMap<Wolf, Integer> guardWaits = new HashMap<>();
    /** This HashMap contains the allocation of guard dogs --> their ignored players */
    protected HashMap<Wolf, HashSet<String>> guardIgnores = new HashMap<>();
    /** This HashMap contains the allocation of players --> the guard dogs whose ignores players are currently set */
    protected HashMap<Player, Wolf> settingIgnore = new HashMap<>();
    /** This boolean is true when guard dog targets are currently determined  */
    protected boolean targetDetermination = false;
    /** The materials required to create / disable a guard dog or to set his ignores */
    protected Material createMat, disableMat, ignoreMat = null;
    /** The repeating Bukkit task for guard dogs target determination */
    private BukkitTask targetDeterminer;
    /** The repeating Bukkit task for guard dogs countdowns */
    private BukkitTask guardTicker;
    /**
     * The Plugin Metrics / MCStats instance
     */
    private Metrics metrics;

    /** Method ran when plugin gets enabled by server  */
    @Override
    public void onEnable() {
        loadGuards();
        targetDeterminer = new TargetDeterminer(this).runTaskTimer(this, 30 * 20, 10);
        guardTicker = new GuardTicker(this).runTaskTimer(this, 15 * 20, 10);
        getServer().getPluginManager().registerEvents(new EventListener(this), this);
        try {
            metrics = new Metrics(this);
        } catch (IOException e) {
            logMessage("Could not start metrics! Is outbound communication blocked, or is the server offline?");
            e.printStackTrace();
        }
        metrics.start();
    }

    /** Method ran when plugin gets disabled by server */
    @Override
    public void onDisable() {
        targetDeterminer.cancel();
        guardTicker.cancel();
        saveGuards();
    }

    /**
     * Method invoked to print informational log messages
     *
     * @param message The message to print
     */
    public void logMessage(String message) {
        getLogger().info("[" + getDescription().getName() + " " + getDescription().getVersion() + "] " + message);
    }

    /**
     * This method handles the creation of guard dogs
     *
     * @param wolf The wolf supposed to become a guard dog
     * @return Returns false if the given wolf already is a guard dog, returns true otherwise.
     */
    public boolean createGuard(Wolf wolf) {
        if (guards.contains(wolf)) {
            return false;<commit_msg>Added check for new versions<commit_after>/*
 * Copyright (c) 2015, ArdiMaster
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be
 *    used to endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

package org.bitbucket.ardimaster.guarddogs;

import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;

/**
 * GuardDogs main class
 *
 * @author ArdiMaster
 */
public class GuardDogs extends JavaPlugin {

    /**
     * The name of the configuration file
     */
    protected String configFileName = "config.yml";
    /** This HashSet holds all the guard dogs */
    protected HashSet<Wolf> guards = new HashSet<>();
    /** This HashMap contains the allocation of guard dogs --> targets */
    protected HashMap<Wolf, LivingEntity> guardTargets = new HashMap<>();
    /** This HashMap contains the allocation of guard dogs --> location */
    protected HashMap<Wolf, Location> guardPositions = new HashMap<>();
    /** This HashMap contains the allocation of guard dogs --> their wait countdown */
    protected HashMap<Wolf, Integer> guardWaits = new HashMap<>();
    /** This HashMap contains the allocation of guard dogs --> their ignored players */
    protected HashMap<Wolf, HashSet<String>> guardIgnores = new HashMap<>();
    /** This HashMap contains the allocation of players --> the guard dogs whose ignores players are currently set */
    protected HashMap<Player, Wolf> settingIgnore = new HashMap<>();
    /** This boolean is true when guard dog targets are currently determined  */
    protected boolean targetDetermination = false;
    /** The materials required to create / disable a guard dog or to set his ignores */
    protected Material createMat, disableMat, ignoreMat = null;
    /**
     * The ,ost recent version available for download, as determined in onEnable
     */
    protected String currentVersion;
    /** The repeating Bukkit task for guard dogs target determination */
    private BukkitTask targetDeterminer;
    /** The repeating Bukkit task for guard dogs countdowns */
    private BukkitTask guardTicker;
    /** The Plugin Metrics / MCStats instance */
    private Metrics metrics;

    /** Method ran when plugin gets enabled by server  */
    @Override
    public void onEnable() {
        loadGuards();
        targetDeterminer = new TargetDeterminer(this).runTaskTimer(this, 30 * 20, 10);
        guardTicker = new GuardTicker(this).runTaskTimer(this, 15 * 20, 10);
        getServer().getPluginManager().registerEvents(new EventListener(this), this);
        try {
            metrics = new Metrics(this);
            metrics.start();
        } catch (IOException e) {
            logMessage("Could not start metrics! Is outbound communication blocked, or is the server offline?");
            e.printStackTrace();
        }

        getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
            @Override
            public void run() {
                try {
                    URL url = new URL("http://files.diepixelecke.tk/GuardDogs/currentVersion.txt");
                    Scanner s = new Scanner(url.openStream());
                    currentVersion = s.nextLine();
                    s.close();
                    if (currentVersion.equals(getDescription().getVersion())) {
                        logMessage("Plugin up-to-date.");
                    } else {
                        logMessage("An update was found! The newest version is " + currentVersion +
                                ", you are still running " + getDescription().getVersion() + "! Grab it at " +
                                "http://dev.bukkit.org/bukkit-plugins/guard-dogs");
                    }
                } catch (IOException e) {
                    logMessage("Could not check for updates! Please check manually at " +
                            "http://dev.bukkit.org/bukkit-plugins/guard-dogs");
                    e.printStackTrace();
                    currentVersion = getDescription().getVersion();
                }
            }
        });
    }

    /** Method ran when plugin gets disabled by server */
    @Override
    public void onDisable() {
        targetDeterminer.cancel();
        guardTicker.cancel();
        saveGuards();
    }

    /**
     * Method invoked to print informational log messages
     *
     * @param message The message to print
     */
    public void logMessage(String message) {
        getLogger().info("[" + getDescription().getName() + " " + getDescription().getVersion() + "] " + message);
    }

    /**
     * This method handles the creation of guard dogs
     *
     * @param wolf The wolf supposed to become a guard dog
     * @return Returns false if the given wolf already is a guard dog, returns true otherwise.
     */
    public boolean createGuard(Wolf wolf) {
        if (guards.contains(wolf)) {
            return false;
{'fraction_non_alphanumeric': 0.08766548272521796, 'fraction_numerical': 0.003067484662576687, 'mean_word_length': 3.0171854734111543, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2555568', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2981, 'n_words': 1225}