<commit_before>package com.skelril.aurora;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.session.PersistentSession;
import com.sk89q.commandbook.session.SessionComponent;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.skelril.aurora.events.EggDropEvent;
import com.skelril.aurora.events.EggHatchEvent;
import com.skelril.aurora.util.ChanceUtil;
import com.skelril.aurora.util.ChatUtil;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.Depend;
import com.zachsthings.libcomponents.InjectComponent;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import com.zachsthings.libcomponents.config.ConfigurationBase;
import com.zachsthings.libcomponents.config.Setting;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@ComponentInformation(friendlyName = "Eggs", desc = "Mob Eggs")
@Depend(components = {SessionComponent.class})
public class EggComponent extends BukkitComponent implements Listener, Runnable {

    private final CommandBook inst = CommandBook.inst();
    private final Server server = CommandBook.server();

    @InjectComponent
    SessionComponent sessions;

    private WorldGuardPlugin worldGuard;
    private LocalConfiguration config;

    @Override
    public void enable() {

        config = configure(new LocalConfiguration());
        //noinspection AccessStaticViaInstance
        inst.registerEvents(this);
        registerCommands(Commands.class);

        setUpWorldGuard();

        server.getScheduler().scheduleSyncRepeatingTask(inst, this, 20 * 2, 120);
    }

    @Override
    public void reload() {

        super.reload();
        configure(config);
    }

    private static class LocalConfiguration extends ConfigurationBase {

        @Setting("enable-easter-eggs")
        public boolean enableEasterEggs = true;
        @Setting("enable-halloween-eggs")
        public boolean enableHalloweenEggs = true;
        @Setting("strict-mode")
        public boolean strictMode = true;
    }

    @Override
    public void run() {

        for (World world : server.getWorlds()) {
            for (Item item : world.getEntitiesByClass(Item.class)) {

                ItemStack itemStack = item.getItemStack();
                if (itemStack.getTypeId() != ItemID.SPAWN_EGG || item.getTicksLived() < 720) continue;

                // Attempt to hatch the egg
                hatchEgg(item);
            }
        }
    }

    private void setUpWorldGuard() {

        Plugin plugin = server.getPluginManager().getPlugin("WorldGuard");

        // WorldGuard may not be loaded
        if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            worldGuard = null;
        }

        //noinspection ConstantConditions
        worldGuard = (WorldGuardPlugin) plugin;
    }

    public void eggOn(Player player) {

        for (EggType eggType : EggType.values()) {
            if (eggType == EggType.INVALID) continue;
            sessions.getSession(EggState.class, player).setEggDrop(eggType, true);
        }
    }

    public void eggOn(Player player, EggType eggType) {

        if (eggType.equals(EggType.INVALID)) eggOn(player);
        else sessions.getSession(EggState.class, player).setEggDrop(eggType, true);
    }

    public boolean allowedEggs(Player player, EggType eggType) {

        return sessions.getSession(EggState.class, player).getEggDropAllowed(eggType);
    }

    public void eggOff(Player player) {

        for (EggType eggType : EggType.values()) {
            if (eggType == EggType.INVALID) continue;
            sessions.getSession(EggState.class, player).setEggDrop(eggType, false);
        }
    }

    public void eggOff(Player player, EggType eggType) {

        if (eggType.equals(EggType.INVALID)) eggOff(player);
        else sessions.getSession(EggState.class, player).setEggDrop(eggType, false);
    }

    @EventHandler(ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {

        Player player = event.getPlayer();

        Block block = event.getBlock();
        World world = block.getWorld();
        int blockType = block.getTypeId();

        if (isEggDroppingBlock(blockType)) {
            if (inst.hasPermission(player, "aurora.egg.easter") && allowedEggs(player, EggType.EASTER)
                    && config.enableEasterEggs && !ChanceUtil.getChance(5, 6)) {

                for (short c = 0; c < ChanceUtil.getRangedRandom(7, 17); c++) {
                    EggEntity attemptedEgg;<commit_msg>Fixed Spawn Eggs spawning on cancelled block breaks<commit_after>package com.skelril.aurora;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.commandbook.session.PersistentSession;
import com.sk89q.commandbook.session.SessionComponent;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.DefaultFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.skelril.aurora.events.EggDropEvent;
import com.skelril.aurora.events.EggHatchEvent;
import com.skelril.aurora.util.ChanceUtil;
import com.skelril.aurora.util.ChatUtil;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.Depend;
import com.zachsthings.libcomponents.InjectComponent;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import com.zachsthings.libcomponents.config.ConfigurationBase;
import com.zachsthings.libcomponents.config.Setting;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;

import java.util.Set;
import java.util.concurrent.TimeUnit;

@ComponentInformation(friendlyName = "Eggs", desc = "Mob Eggs")
@Depend(components = {SessionComponent.class})
public class EggComponent extends BukkitComponent implements Listener, Runnable {

    private final CommandBook inst = CommandBook.inst();
    private final Server server = CommandBook.server();

    @InjectComponent
    SessionComponent sessions;

    private WorldGuardPlugin worldGuard;
    private LocalConfiguration config;

    @Override
    public void enable() {

        config = configure(new LocalConfiguration());
        //noinspection AccessStaticViaInstance
        inst.registerEvents(this);
        registerCommands(Commands.class);

        setUpWorldGuard();

        server.getScheduler().scheduleSyncRepeatingTask(inst, this, 20 * 2, 120);
    }

    @Override
    public void reload() {

        super.reload();
        configure(config);
    }

    private static class LocalConfiguration extends ConfigurationBase {

        @Setting("enable-easter-eggs")
        public boolean enableEasterEggs = true;
        @Setting("enable-halloween-eggs")
        public boolean enableHalloweenEggs = true;
        @Setting("strict-mode")
        public boolean strictMode = true;
    }

    @Override
    public void run() {

        for (World world : server.getWorlds()) {
            for (Item item : world.getEntitiesByClass(Item.class)) {

                ItemStack itemStack = item.getItemStack();
                if (itemStack.getTypeId() != ItemID.SPAWN_EGG || item.getTicksLived() < 720) continue;

                // Attempt to hatch the egg
                hatchEgg(item);
            }
        }
    }

    private void setUpWorldGuard() {

        Plugin plugin = server.getPluginManager().getPlugin("WorldGuard");

        // WorldGuard may not be loaded
        if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            worldGuard = null;
        }

        //noinspection ConstantConditions
        worldGuard = (WorldGuardPlugin) plugin;
    }

    public void eggOn(Player player) {

        for (EggType eggType : EggType.values()) {
            if (eggType == EggType.INVALID) continue;
            sessions.getSession(EggState.class, player).setEggDrop(eggType, true);
        }
    }

    public void eggOn(Player player, EggType eggType) {

        if (eggType.equals(EggType.INVALID)) eggOn(player);
        else sessions.getSession(EggState.class, player).setEggDrop(eggType, true);
    }

    public boolean allowedEggs(Player player, EggType eggType) {

        return sessions.getSession(EggState.class, player).getEggDropAllowed(eggType);
    }

    public void eggOff(Player player) {

        for (EggType eggType : EggType.values()) {
            if (eggType == EggType.INVALID) continue;
            sessions.getSession(EggState.class, player).setEggDrop(eggType, false);
        }
    }

    public void eggOff(Player player, EggType eggType) {

        if (eggType.equals(EggType.INVALID)) eggOff(player);
        else sessions.getSession(EggState.class, player).setEggDrop(eggType, false);
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onBlockBreak(BlockBreakEvent event) {

        Player player = event.getPlayer();

        Block block = event.getBlock();
        World world = block.getWorld();
        int blockType = block.getTypeId();

        if (isEggDroppingBlock(blockType)) {
            if (inst.hasPermission(player, "aurora.egg.easter") && allowedEggs(player, EggType.EASTER)
                    && config.enableEasterEggs && !ChanceUtil.getChance(5, 6)) {

                for (short c = 0; c < ChanceUtil.getRangedRandom(7, 17); c++) {
                    EggEntity attemptedEgg;
{'fraction_non_alphanumeric': 0.10252822091613023, 'fraction_numerical': 0.0069036290698759216, 'mean_word_length': 3.3313131313131312, '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': '5541509', 'n_tokens_mistral': 3319, 'n_tokens_neox': 3131, 'n_words': 618}