<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.ChatColor;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.HashSet;
import java.util.Random;

/**
 * The Bukkit event listening class for the GuardDogs plugin
 */
public class EventListener implements Listener {
    protected GuardDogs plugin;
    private Random random = new Random();

    public EventListener(GuardDogs plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
        if (!(event.getRightClicked() instanceof Wolf)) {
            return;
        }

        Wolf wolf = (Wolf) event.getRightClicked();
        Player player = event.getPlayer();

        if (player.getItemInHand().getType().equals(plugin.createMat)) {
            if (!wolf.isTamed()) {
                player.sendMessage(ChatColor.RED + "You can't make this dog your guard dog as it isn't tamed!");
                return;
            }

            if (!wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "You can't make this dog your guard dog as it isn't yours!");
                return;
            }

            if (plugin.createGuard(wolf, 0, 0, 0)) {
                player.getInventory().removeItem(new ItemStack(plugin.createMat, 1));
                player.sendMessage(ChatColor.DARK_GREEN + "Guard dog" + ChatColor.GREEN + " ready for action");
            } else {
                player.sendMessage(ChatColor.RED + "This is already your guard dog!");
            }

        } else if (player.getItemInHand().getType().equals(plugin.disableMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't disable it.");
                return;
            }

            if (plugin.removeGuard(wolf)) {
                player.sendMessage(ChatColor.DARK_GREEN + "Guard dog " + ChatColor.AQUA + "disabled.");
            } else {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog, it's just a normal dog!");
            }
        } else if (player.getItemInHand().getType().equals(plugin.ignoreMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't set it's ignores.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't set it's ignores.");
                return;
            }

            if (plugin.settingIgnore.containsKey(player)) {
                player.sendMessage(ChatColor.RED + "You already started setting an ignore for another guard dog, " +
                        "cancelling old process...");
            }

            player.sendMessage(ChatColor.MAGIC + "M" + ChatColor.RESET + ChatColor.DARK_AQUA + " Type the name of the " +
                    "player you wish to have this guard dog ignore.");

            plugin.settingIgnore.put(player, wolf);
        } else if (player.getItemInHand().getType().equals(plugin.extraDamageMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't have it deal extra damage.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't have it " +
                        "deal extra damage.");
                return;
            }

            if (!plugin.extraDamage) {
                player.sendMessage(ChatColor.RED + "Guard dogs extra damage is disabled on this server!");
                return;
            }

            int damage = plugin.guardExtraDamage.get(wolf);
            if (damage < 2) {
                player.getInventory().remove(new ItemStack(plugin.extraDamageMat, 1));
                damage++;
                plugin.guardExtraDamage.put(wolf, damage);
                player.sendMessage(ChatColor.GREEN + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.GREEN +
                        "'s extra damage is now " + ChatColor.AQUA + damage + ChatColor.GREEN + " half-hearts");
            } else {
                // TODO: Make maximum amount of extra damage configurable
                player.sendMessage(ChatColor.RED + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.RED +
                        "'s extra damage is already at maximum!");
            }
        } else if (player.getItemInHand().getType().equals(plugin.igniteChanceMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't have it ignite it's enemies.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't have it " +
                        "ignite it's enemies.");
                return;
            }

            if (!plugin.extraDamage) {
                player.sendMessage(ChatColor.RED + "Guard dogs igniting their enemies is disabled on this server!");
                return;
            }

            int chance = plugin.guardIgniteChance.get(wolf);
            if (chance < 6) {
                player.getInventory().remove(new ItemStack(plugin.igniteChanceMat, 1));
                chance++;
                plugin.guardExtraDamage.put(wolf, chance);
                player.sendMessage(ChatColor.GREEN + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.GREEN +
                        "'s chance to ignite it's enemy is now " + ChatColor.AQUA + chance + ChatColor.GREEN + " %");
            } else {
                // TODO: Make maximum chance configurable
                player.sendMessage(ChatColor.RED + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.RED +
                        "'s chance to ignite it's enemies is already at maximum!");
            }
        } else if (player.getItemInHand().getType().equals(plugin.teleportMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't have it teleport home when it's low on health.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't have it " +
                        "teleport home when it's low on health.");<commit_msg>Fixed typos. Done implementing special abilities. Closes #1<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.ChatColor;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.util.HashSet;
import java.util.Random;

/**
 * The Bukkit event listening class for the GuardDogs plugin
 */
public class EventListener implements Listener {
    protected GuardDogs plugin;
    private Random random = new Random();

    public EventListener(GuardDogs plugin) {
        this.plugin = plugin;
    }

    @EventHandler
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
        if (!(event.getRightClicked() instanceof Wolf)) {
            return;
        }

        Wolf wolf = (Wolf) event.getRightClicked();
        Player player = event.getPlayer();

        if (player.getItemInHand().getType().equals(plugin.createMat)) {
            if (!wolf.isTamed()) {
                player.sendMessage(ChatColor.RED + "You can't make this dog your guard dog as it isn't tamed!");
                return;
            }

            if (!wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "You can't make this dog your guard dog as it isn't yours!");
                return;
            }

            if (plugin.createGuard(wolf, 0, 0, 0)) {
                player.getInventory().removeItem(new ItemStack(plugin.createMat, 1));
                player.sendMessage(ChatColor.DARK_GREEN + "Guard dog" + ChatColor.GREEN + " ready for action");
            } else {
                player.sendMessage(ChatColor.RED + "This is already your guard dog!");
            }

        } else if (player.getItemInHand().getType().equals(plugin.disableMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't disable it.");
                return;
            }

            if (plugin.removeGuard(wolf)) {
                player.sendMessage(ChatColor.DARK_GREEN + "Guard dog " + ChatColor.AQUA + "disabled.");
            } else {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog, it's just a normal dog!");
            }
        } else if (player.getItemInHand().getType().equals(plugin.ignoreMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't set it's ignores.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't set it's ignores.");
                return;
            }

            if (plugin.settingIgnore.containsKey(player)) {
                player.sendMessage(ChatColor.RED + "You already started setting an ignore for another guard dog, " +
                        "cancelling old process...");
            }

            player.sendMessage(ChatColor.MAGIC + "M" + ChatColor.RESET + ChatColor.DARK_AQUA + " Type the name of the " +
                    "player you wish to have this guard dog ignore.");

            plugin.settingIgnore.put(player, wolf);
        } else if (player.getItemInHand().getType().equals(plugin.extraDamageMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't have it deal extra damage.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't have it " +
                        "deal extra damage.");
                return;
            }

            if (!plugin.extraDamage) {
                player.sendMessage(ChatColor.RED + "Guard dogs extra damage is disabled on this server!");
                return;
            }

            int damage = plugin.guardExtraDamage.get(wolf);
            if (damage < 2) {
                player.getInventory().remove(new ItemStack(plugin.extraDamageMat, 1));
                damage++;
                plugin.guardExtraDamage.put(wolf, damage);
                player.sendMessage(ChatColor.GREEN + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.GREEN +
                        "'s extra damage is now " + ChatColor.AQUA + damage + ChatColor.GREEN + " half-hearts");
            } else {
                // TODO: Make maximum amount of extra damage configurable
                player.sendMessage(ChatColor.RED + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.RED +
                        "'s extra damage is already at maximum!");
            }
        } else if (player.getItemInHand().getType().equals(plugin.igniteChanceMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't have it ignite its enemies.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't have it " +
                        "ignite its enemies.");
                return;
            }

            if (!plugin.extraDamage) {
                player.sendMessage(ChatColor.RED + "Guard dogs igniting their enemies is disabled on this server!");
                return;
            }

            int chance = plugin.guardIgniteChance.get(wolf);
            if (chance < 6) {
                player.getInventory().remove(new ItemStack(plugin.igniteChanceMat, 1));
                chance++;
                plugin.guardExtraDamage.put(wolf, chance);
                player.sendMessage(ChatColor.GREEN + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.GREEN +
                        "'s chance to ignite its enemy is now " + ChatColor.AQUA + chance + ChatColor.GREEN + " %");
            } else {
                // TODO: Make maximum chance configurable
                player.sendMessage(ChatColor.RED + "This " + ChatColor.DARK_GREEN + "Guard Dog" + ChatColor.RED +
                        "'s chance to ignite its enemies is already at maximum!");
            }
        } else if (player.getItemInHand().getType().equals(plugin.teleportMat)) {
            if (!wolf.isTamed() || !wolf.getOwner().equals(player)) {
                player.sendMessage(ChatColor.RED + "This isn't your dog. Thus, it can't be your guard dog. " +
                        "Thus, you can't have it teleport home when it's low on health.");
                return;
            }

            if (!plugin.guards.contains(wolf)) {
                player.sendMessage(ChatColor.RED + "This isn't a guard dog. Thus, you can't have it " +
                        "teleport home when it's low on health.");
{'fraction_non_alphanumeric': 0.10184682237914178, 'fraction_numerical': 0.001683867463335144, 'mean_word_length': 2.164489515297353, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6889785', 'n_tokens_mistral': 5130, 'n_tokens_neox': 4708, 'n_words': 1494}