<commit_before>package io.totemo.leprechauns;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import com.darkblade12.particleeffect.ParticleEffect;
import com.google.common.collect.Lists;

// ----------------------------------------------------------------------------
/**
 * Leprechauns plugin, command handling and event handler.
 *
 * Leprechauns turns hostile mobs into leprechauns.
 *
 * The main features are:
 * <ul>
 * <li>The plugin affects hostile mobs in a single configured world (by default,
 * the overworld) only. Spawner mobs are not modified.</li>
 * <li>Affected hostile mobs are replaced with baby zombies dressed in green
 * leather armour (or skinned with a server reosource pack), referred to as
 * leprechauns.</li>
 * <li>For custom mobs to drop special drops when they die, they must have been
 * recently hurt by a player.</li>
 * <li>Leprechauns are armed with shillelaghs (enchanted sticks) and shamrocks
 * (enchanted lily pads), with a small chance of the held item dropping.</li>
 * <li>Leprechauns also drop various potions named as alcoholic beverages, as
 * well as gold nuggets named as coins.</li>
 * <li>Leprechauns have custom Irish names.</li>
 * <li>Injured leprechauns run away from the player.</li>
 * <li>A small percentage of leprechauns drop a piece of paper named a
 * "Treasure Map", which has as its lore the coordinates of a pot of gold (POG).
 * </li>
 * <li>A POG is a cauldron that is spawned into the affected world (only) for a
 * limited period of time within a range of distances from the leprechaun's
 * death point.</li>
 * <li>The POG is marked with a rainbow of coloured particles. If the player
 * breaks it or moves to within 5 blocks of it, then it disappears and drops
 * configurable loot (typically gold blocks, ingots and nuggets).</li>
 * </ul>
 */
public class Leprechauns extends JavaPlugin implements Listener {
    /**
     * Configuration wrapper instance.
     */
    public static Configuration CONFIG = new Configuration();

    /**
     * This plugin, accessible as, effectively, a singleton.
     */
    public static Leprechauns PLUGIN;

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
     */
    @Override
    public void onEnable() {
        PLUGIN = this;
        LEPRECHAUN_META = new FixedMetadataValue(this, "Leprechaun");

        saveDefaultConfig();
        CONFIG.reload();

        getServer().getPluginManager().registerEvents(this, this);

        // Every tick, do particle effects for the pots of gold.
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
            @Override
            public void run() {
                _potManager.tickAll();
            }
        }, 1, 1);
    }

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.plugin.java.JavaPlugin#onDisable()
     */
    @Override
    public void onDisable() {
        Bukkit.getScheduler().cancelTasks(this);
        _potManager.removeAll();
    }

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender,
     *      org.bukkit.command.Command, java.lang.String, java.lang.String[])
     */
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase(getName())) {
            if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
                CONFIG.reload();
                sender.sendMessage(ChatColor.GOLD + getName() + " configuration reloaded.");
                return true;
            }
        }

        sender.sendMessage(ChatColor.RED + "Invalid command syntax.");
        return true;
    }

    // ------------------------------------------------------------------------
    /**
     * In the configured World, replace all hostile natural spawns with baby
     * zombies, dressed as leprechauns.
     *
     * Spawner-spawned mobs are not affected in any way.
     */
    @EventHandler(ignoreCancelled = true)
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if (!CONFIG.isAffectedWorld(event)) {
            return;
        }

        if (event.getSpawnReason() == SpawnReason.NATURAL && isEligibleHostileMob(event.getEntityType())) {
            Entity originalMob = event.getEntity();
            Location loc = originalMob.getLocation();
            originalMob.remove();
            spawnLeprechaun(loc);

            if (CONFIG.DEBUG_SPAWN_NATURAL) {
                getLogger().info("Spawned leprechaun at " + Util.formatLocation(loc));
            }
        }
    }

    // ------------------------------------------------------------------------
    /**
     * When the plugin is disabled, remove all spawned pots of gold.
     */
    @EventHandler(ignoreCancelled = true)
    public void onPluginDisable(@SuppressWarnings("unused") PluginDisableEvent event) {

    }

    // ------------------------------------------------------------------------
    /**
     * If a player breaks a pot of gold, do treasure drops and stop that pot's
     * particle effects.
     */
    @EventHandler(ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {
        Block block = event.getBlock();
        Location loc = block.getLocation();
        if (!CONFIG.isAffectedWorld(loc.getWorld())) {
            return;
        }

        PotOfGold pot = _potManager.getPotOfGold(block);
        if (pot != null) {
            // Prevent the cauldron break from being logged by LogBlock.
            event.setCancelled(true);
<commit_msg>Minor doc comment corrections. Removed unused method.<commit_after>package io.totemo.leprechauns;

import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import com.darkblade12.particleeffect.ParticleEffect;
import com.google.common.collect.Lists;

// ----------------------------------------------------------------------------
/**
 * Leprechauns plugin, command handling and event handler.
 *
 * Leprechauns turns hostile mobs into leprechauns.
 *
 * The main features are:
 * <ul>
 * <li>The plugin affects hostile mobs in a single configured world (by default,
 * the overworld) only. Spawner mobs are not modified.</li>
 * <li>Affected hostile mobs are replaced with baby zombies dressed in green
 * leather armour (or skinned with a server reosource pack), referred to as
 * leprechauns.</li>
 * <li>For custom mobs to drop special drops when they die, they must have been
 * recently hurt by a player.</li>
 * <li>Leprechauns are armed with shillelaghs (enchanted sticks) and shamrocks
 * (enchanted lily pads), with a small chance of the held item dropping.</li>
 * <li>Leprechauns also drop various potions named as alcoholic beverages, as
 * well as gold nuggets named as coins.</li>
 * <li>Leprechauns have custom Irish names.</li>
 * <li>Injured leprechauns run away from the player.</li>
 * <li>A small percentage of leprechauns drop a piece of paper named a
 * "Treasure Map", which has as its lore the coordinates of a pot of gold (POG).
 * </li>
 * <li>A POG is a cauldron that is spawned into the affected world (only) for a
 * limited period of time within a range of distances from the leprechaun's
 * death point.</li>
 * <li>The POG is marked with a rainbow of coloured particles. If the player
 * breaks it or moves to within 5 blocks of it, then it disappears and drops
 * configurable loot (typically gold carrots, ingots and nuggets).</li>
 * </ul>
 */
public class Leprechauns extends JavaPlugin implements Listener {
    /**
     * Configuration wrapper instance.
     */
    public static Configuration CONFIG = new Configuration();

    /**
     * This plugin, accessible as, effectively, a singleton.
     */
    public static Leprechauns PLUGIN;

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.plugin.java.JavaPlugin#onEnable()
     */
    @Override
    public void onEnable() {
        PLUGIN = this;
        LEPRECHAUN_META = new FixedMetadataValue(this, "Leprechaun");

        saveDefaultConfig();
        CONFIG.reload();

        getServer().getPluginManager().registerEvents(this, this);

        // Every tick, do particle effects for the pots of gold.
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
            @Override
            public void run() {
                _potManager.tickAll();
            }
        }, 1, 1);
    }

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.plugin.java.JavaPlugin#onDisable()
     */
    @Override
    public void onDisable() {
        Bukkit.getScheduler().cancelTasks(this);
        _potManager.removeAll();
    }

    // ------------------------------------------------------------------------
    /**
     * @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender,
     *      org.bukkit.command.Command, java.lang.String, java.lang.String[])
     */
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase(getName())) {
            if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
                CONFIG.reload();
                sender.sendMessage(ChatColor.GOLD + getName() + " configuration reloaded.");
                return true;
            }
        }

        sender.sendMessage(ChatColor.RED + "Invalid command syntax.");
        return true;
    }

    // ------------------------------------------------------------------------
    /**
     * In the configured World, replace all hostile natural spawns with zombies,
     * dressed as leprechauns.
     *
     * Spawner-spawned mobs are not affected in any way.
     */
    @EventHandler(ignoreCancelled = true)
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if (!CONFIG.isAffectedWorld(event)) {
            return;
        }

        if (event.getSpawnReason() == SpawnReason.NATURAL && isEligibleHostileMob(event.getEntityType())) {
            Entity originalMob = event.getEntity();
            Location loc = originalMob.getLocation();
            originalMob.remove();
            spawnLeprechaun(loc);

            if (CONFIG.DEBUG_SPAWN_NATURAL) {
                getLogger().info("Spawned leprechaun at " + Util.formatLocation(loc));
            }
        }
    }

    // ------------------------------------------------------------------------
    /**
     * If a player breaks a pot of gold, do treasure drops and stop that pot's
     * particle effects.
     */
    @EventHandler(ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {
        Block block = event.getBlock();
        Location loc = block.getLocation();
        if (!CONFIG.isAffectedWorld(loc.getWorld())) {
            return;
        }

        PotOfGold pot = _potManager.getPotOfGold(block);
        if (pot != null) {
            // Prevent the cauldron break from being logged by LogBlock.
            event.setCancelled(true);

{'fraction_non_alphanumeric': 0.1655920281359906, 'fraction_numerical': 0.0010257913247362252, 'mean_word_length': 2.3024437454633437, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '4881042', 'n_tokens_mistral': 3904, 'n_tokens_neox': 3734, 'n_words': 1019}