<commit_before>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package com.skelril.skree.content.zone.global.cursedmine;

import com.skelril.nitro.data.util.EnchantmentUtil;
import com.skelril.nitro.probability.Probability;
import com.skelril.nitro.registry.block.DropRegistry;
import com.skelril.skree.content.modifier.Modifiers;
import com.skelril.skree.content.zone.global.cursedmine.hitlist.HitList;
import com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord;
import com.skelril.skree.service.ModifierService;
import net.minecraft.item.ItemPickaxe;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.meta.ItemEnchantment;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.ExperienceOrb;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause;
import org.spongepowered.api.event.entity.DestructEntityEvent;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
import org.spongepowered.api.event.entity.SpawnEntityEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.item.Enchantments;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.util.*;

import static com.skelril.nitro.transformer.ForgeTransformer.tf;

public class CursedMineListener {
    
    private final CursedMineManager manager;

    public CursedMineListener(CursedMineManager manager) {
        this.manager = manager;
    }

    private static Set<BlockType> triggerBlocks = new HashSet<>();

    static {
        triggerBlocks.add(BlockTypes.STONE_BUTTON);
        triggerBlocks.add(BlockTypes.TRIPWIRE);
    }

    @Listener
    public void onPlayerInteract(ChangeBlockEvent event) {
        for (Transaction<BlockSnapshot> block : event.getTransactions()) {
            BlockSnapshot snapshot = block.getOriginal();
            Optional<CursedMineInstance> optInst = manager.getApplicableZone(snapshot);
            if (optInst.isPresent() && triggerBlocks.contains(snapshot.getState().getType())) {
                optInst.get().activatePumps();
                break;
            }
        }
    }

    @Listener
    public void onItemSpawn(SpawnEntityEvent event, @Root BlockSpawnCause spawnCause) {
        for (Entity entity : event.getEntities()) {
            if (entity instanceof Item && manager.getApplicableZone(entity).isPresent()) {
                event.setCancelled(true);
                return;
            }
        }
    }

    private boolean hasSilkTouch(ItemStack stack) {
        Optional<ItemEnchantment> optSilkTouch = EnchantmentUtil.getHighestEnchantment(
                stack,
                Enchantments.SILK_TOUCH
        );

        return optSilkTouch.isPresent();
    }
<commit_msg>Cursed Mine workaround for  SpongeCommon/#771<commit_after>/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package com.skelril.skree.content.zone.global.cursedmine;

import com.skelril.nitro.data.util.EnchantmentUtil;
import com.skelril.nitro.probability.Probability;
import com.skelril.nitro.registry.block.DropRegistry;
import com.skelril.skree.content.modifier.Modifiers;
import com.skelril.skree.content.zone.global.cursedmine.hitlist.HitList;
import com.skelril.skree.content.zone.global.cursedmine.restoration.BlockRecord;
import com.skelril.skree.service.ModifierService;
import net.minecraft.item.ItemPickaxe;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.meta.ItemEnchantment;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.entity.ExperienceOrb;
import org.spongepowered.api.entity.Item;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause;
import org.spongepowered.api.event.entity.DestructEntityEvent;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
import org.spongepowered.api.event.entity.SpawnEntityEvent;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.item.Enchantments;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;

import java.util.*;

import static com.skelril.nitro.transformer.ForgeTransformer.tf;

public class CursedMineListener {
    
    private final CursedMineManager manager;

    public CursedMineListener(CursedMineManager manager) {
        this.manager = manager;
    }

    private static Set<BlockType> triggerBlocks = new HashSet<>();

    static {
        triggerBlocks.add(BlockTypes.STONE_BUTTON);
        triggerBlocks.add(BlockTypes.TRIPWIRE);
    }

    @Listener
    public void onPlayerInteract(ChangeBlockEvent event) {
        for (Transaction<BlockSnapshot> block : event.getTransactions()) {
            BlockSnapshot snapshot = block.getOriginal();
            Optional<CursedMineInstance> optInst = manager.getApplicableZone(snapshot);
            if (optInst.isPresent() && triggerBlocks.contains(snapshot.getState().getType())) {
                optInst.get().activatePumps();
                break;
            }
        }
    }

    @Listener
    public void onItemSpawn(SpawnEntityEvent event, @Root BlockSpawnCause spawnCause) {
        // SpongeCommon/#771
        for (Entity entity : event.getEntities()) {
            if (entity instanceof Item && manager.getApplicableZone(entity).isPresent()) {
                entity.remove();
            }
        }
    }

    private boolean hasSilkTouch(ItemStack stack) {
        Optional<ItemEnchantment> optSilkTouch = EnchantmentUtil.getHighestEnchantment(
                stack,
                Enchantments.SILK_TOUCH
        );

        return optSilkTouch.isPresent();
    }

{'fraction_non_alphanumeric': 0.10095367847411445, 'fraction_numerical': 0.0019073569482288828, 'mean_word_length': 3.897264843228819, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '263408', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2227, 'n_words': 366}