<commit_before>/*
 * This file is part of
 * ExtraHardMode Server Plugin for Minecraft
 *
 * Copyright (C) 2012 <NAME>
 * Copyright (C) 2013 Diemex
 *
 * ExtraHardMode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ExtraHardMode 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 General Public License for more details.
 *
 * You should have received a copy of the GNU Affero Public License
 * along with ExtraHardMode.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.extrahardmode.features.monsters;


import com.extrahardmode.ExtraHardMode;
import com.extrahardmode.config.ExplosionType;
import com.extrahardmode.config.RootConfig;
import com.extrahardmode.config.RootNode;
import com.extrahardmode.config.messages.MessageConfig;
import com.extrahardmode.module.EntityHelper;
import com.extrahardmode.module.UtilityModule;
import com.extrahardmode.service.ListenerModule;
import com.extrahardmode.task.CreateExplosionTask;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

/**
 * Changes to Blazes including:
 * <p/>
 * spawn in the Nether everywhere , multiply on death , more loot , magmacubes explode on death and turn into Blazes
 * <p/>
 * spawn at lavalevel in the OverWorld , explode on death in the Overworld , no blazerods in the OverWorld
 */
public class Blazes extends ListenerModule
{
    private ExtraHardMode plugin = null;

    private RootConfig CFG = null;

    private final MessageConfig messages;

    private UtilityModule utils = null;


    public Blazes(ExtraHardMode plugin)
    {
        super(plugin);
        this.plugin = plugin;
        CFG = plugin.getModuleForClass(RootConfig.class);
        messages = plugin.getModuleForClass(MessageConfig.class);
        utils = plugin.getModuleForClass(UtilityModule.class);
    }


    /**
     * When an Entity spawns,
     * <p/>
     * handles all the extra spawns for Blazes in the OverWorld and Nether
     */
    @EventHandler(priority = EventPriority.LOW)
    public void onEntitySpawn(CreatureSpawnEvent event)
    {
        Location location = event.getLocation();
        World world = location.getWorld();

        final int bonusNetherBlazeSpawnPercent = CFG.getInt(RootNode.BONUS_NETHER_BLAZE_SPAWN_PERCENT, world.getName());
        final int nearBedrockSpawnPercent = CFG.getInt(RootNode.NEAR_BEDROCK_BLAZE_SPAWN_PERCENT, world.getName());

        LivingEntity entity = event.getEntity();
        EntityType entityType = entity.getType();

        // FEATURE: more blazes in nether
        if (entityType == EntityType.PIG_ZOMBIE)
        {
            if (plugin.random(bonusNetherBlazeSpawnPercent))
            {
                event.setCancelled(true);
                entityType = EntityType.BLAZE;

                // FEATURE: magma cubes spawn with blazes
                if (plugin.random(bonusNetherBlazeSpawnPercent))
                {
                    MagmaCube cube = (MagmaCube) (EntityHelper.spawn(location, EntityType.MAGMA_CUBE));
                    cube.setSize(1);
                }
                EntityHelper.spawn(location, entityType);
                //TODO EhmBlazeSpawnEvent (Nether)
            }
        }

        // FEATURE: blazes near bedrock
        if (entityType == EntityType.SKELETON && world.getEnvironment() == World.Environment.NORMAL && location.getBlockY() < 20)
        {
            if (plugin.random(nearBedrockSpawnPercent))
            {
                event.setCancelled(true);
                entityType = EntityType.BLAZE;
                EntityHelper.spawn(location, entityType);
                //TODO EhmBlazeSpawnEvent (OverWorld)
            }
        }
    }


    /**
     * When a Blaze dies,
     * <p/>
     * exlode in OverWorld , multiply in the Nether
     */
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event)
    {
        LivingEntity entity = event.getEntity();
        World world = entity.getWorld();

        final boolean bonusLoot = CFG.getBoolean(RootNode.BLAZES_DROP_BONUS_LOOT, world.getName());
        final boolean blazesExplodeOnDeath = CFG.getBoolean(RootNode.BLAZES_EXPLODE_ON_DEATH, world.getName());
        final int blazeSplitPercent = CFG.getInt(RootNode.NETHER_BLAZES_SPLIT_ON_DEATH_PERCENT, world.getName());

        // FEATURE: nether blazes drop extra loot (glowstone and gunpowder)
        if (bonusLoot && entity instanceof Blaze)
        {
            if (world.getEnvironment() == World.Environment.NETHER)
            {
                // 50% chance of each
                if (plugin.getRandom().nextInt(2) == 0)
                {
                    event.getDrops().add(new ItemStack(Material.SULPHUR, 2));
                } else
                {
                    event.getDrops().add(new ItemStack(Material.GLOWSTONE_DUST, 2));
                }
            } else // no drops in the normal world (restricting blaze rods to the
            // nether)
            {
                event.getDrops().clear();
            }
        }

        // FEATURE: blazes explode on death in normal world
        if (blazesExplodeOnDeath && entity instanceof Blaze && world.getEnvironment() == World.Environment.NORMAL)
        {<commit_msg>Fixed blazes from spawners still dropping gunpowder / glowstone<commit_after>/*
 * This file is part of
 * ExtraHardMode Server Plugin for Minecraft
 *
 * Copyright (C) 2012 <NAME>
 * Copyright (C) 2013 Diemex
 *
 * ExtraHardMode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ExtraHardMode 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 General Public License for more details.
 *
 * You should have received a copy of the GNU Affero Public License
 * along with ExtraHardMode.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.extrahardmode.features.monsters;


import com.extrahardmode.ExtraHardMode;
import com.extrahardmode.config.ExplosionType;
import com.extrahardmode.config.RootConfig;
import com.extrahardmode.config.RootNode;
import com.extrahardmode.config.messages.MessageConfig;
import com.extrahardmode.module.EntityHelper;
import com.extrahardmode.module.UtilityModule;
import com.extrahardmode.service.ListenerModule;
import com.extrahardmode.task.CreateExplosionTask;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;

/**
 * Changes to Blazes including:
 * <p/>
 * spawn in the Nether everywhere , multiply on death , more loot , magmacubes explode on death and turn into Blazes
 * <p/>
 * spawn at lavalevel in the OverWorld , explode on death in the Overworld , no blazerods in the OverWorld
 */
public class Blazes extends ListenerModule
{
    private ExtraHardMode plugin;

    private RootConfig CFG;

    private final MessageConfig messages;

    private UtilityModule utils;

    public Blazes(ExtraHardMode plugin)
    {
        super(plugin);
        this.plugin = plugin;
        CFG = plugin.getModuleForClass(RootConfig.class);
        messages = plugin.getModuleForClass(MessageConfig.class);
        utils = plugin.getModuleForClass(UtilityModule.class);
    }


    /**
     * When an Entity spawns,
     * <p/>
     * handles all the extra spawns for Blazes in the OverWorld and Nether
     */
    @EventHandler(priority = EventPriority.LOW)
    public void onEntitySpawn(CreatureSpawnEvent event)
    {
        Location location = event.getLocation();
        World world = location.getWorld();

        final int bonusNetherBlazeSpawnPercent = CFG.getInt(RootNode.BONUS_NETHER_BLAZE_SPAWN_PERCENT, world.getName());
        final int nearBedrockSpawnPercent = CFG.getInt(RootNode.NEAR_BEDROCK_BLAZE_SPAWN_PERCENT, world.getName());

        LivingEntity entity = event.getEntity();
        EntityType entityType = entity.getType();

        // FEATURE: more blazes in nether
        if (entityType == EntityType.PIG_ZOMBIE)
        {
            if (plugin.random(bonusNetherBlazeSpawnPercent))
            {
                event.setCancelled(true);
                entityType = EntityType.BLAZE;

                // FEATURE: magma cubes spawn with blazes
                if (plugin.random(bonusNetherBlazeSpawnPercent))
                {
                    MagmaCube cube = (MagmaCube) (EntityHelper.spawn(location, EntityType.MAGMA_CUBE));
                    cube.setSize(1);
                }
                EntityHelper.spawn(location, entityType);
                //TODO EhmBlazeSpawnEvent (Nether)
            }
        }

        // FEATURE: blazes near bedrock
        if (entityType == EntityType.SKELETON && world.getEnvironment() == World.Environment.NORMAL && location.getBlockY() < 20)
        {
            if (plugin.random(nearBedrockSpawnPercent))
            {
                event.setCancelled(true);
                entityType = EntityType.BLAZE;
                EntityHelper.spawn(location, entityType);
                //TODO EhmBlazeSpawnEvent (OverWorld)
            }
        }
    }


    /**
     * When a Blaze dies,
     * <p/>
     * exlode in OverWorld , multiply in the Nether
     */
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event)
    {
        LivingEntity entity = event.getEntity();
        World world = entity.getWorld();

        final boolean bonusLoot = CFG.getBoolean(RootNode.BLAZES_DROP_BONUS_LOOT, world.getName());
        final boolean blazesExplodeOnDeath = CFG.getBoolean(RootNode.BLAZES_EXPLODE_ON_DEATH, world.getName());
        final int blazeSplitPercent = CFG.getInt(RootNode.NETHER_BLAZES_SPLIT_ON_DEATH_PERCENT, world.getName());

        // FEATURE: nether blazes drop extra loot (glowstone and gunpowder)
        if (bonusLoot && entity instanceof Blaze &&! EntityHelper.isLootLess(entity))
        {
            if (world.getEnvironment() == World.Environment.NETHER)
            {
                // 50% chance of each
                if (plugin.getRandom().nextInt(2) == 0)
                {
                    event.getDrops().add(new ItemStack(Material.SULPHUR, 2));
                } else
                {
                    event.getDrops().add(new ItemStack(Material.GLOWSTONE_DUST, 2));
                }
            } else // no drops in the normal world (restricting blaze rods to the
            // nether)
            {
                event.getDrops().clear();
            }
        }

        // FEATURE: blazes explode on death in normal world
        if (blazesExplodeOnDeath && entity instanceof Blaze && world.getEnvironment() == World.Environment.NORMAL)
        {
{'fraction_non_alphanumeric': 0.08803763440860216, 'fraction_numerical': 0.0030241935483870967, 'mean_word_length': 2.6119538834951457, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '6984146', 'n_tokens_mistral': 3561, 'n_tokens_neox': 3381, 'n_words': 867}