<commit_before>/*
    GriefPrevention Server Plugin for Minecraft
    Copyright (C) 2012 <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package me.ryanhamshire.GriefPrevention;

import org.spongepowered.api.block.BlockTransaction;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.monster.Enderman;
import org.spongepowered.api.entity.living.monster.Silverfish;
import org.spongepowered.api.entity.living.monster.Wither;
import org.spongepowered.api.entity.living.monster.Zombie;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.potion.PotionEffectType;
import org.spongepowered.api.potion.PotionEffectTypes;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;

//handles events related to entities
public class EntityEventHandler {

    // convenience reference for the singleton datastore
    private DataStore dataStore;

    public EntityEventHandler(DataStore dataStore) {
        this.dataStore = dataStore;
    }

    @Listener(order = Order.EARLY)
    public void onChangeBlockBreak(ChangeBlockEvent.Break event) {
        final Cause cause = event.getCause();
        final Entity entity = cause.first(Entity.class).orElse(null);
        if (entity != null) {
            for (BlockTransaction transaction : event.getTransactions()) {
                final BlockType originalType = transaction.getOriginal().getState().getType();
                final BlockType finalType = transaction.getFinalReplacement().getState().getType();

                if (!GriefPrevention.instance.config_endermenMoveBlocks && entity instanceof Enderman) {
                    transaction.setIsValid(false);
                } else if (!GriefPrevention.instance.config_silverfishBreakBlocks && entity instanceof Silverfish) {
                    transaction.setIsValid(false);
                } else if (GriefPrevention.instance.config_claims_worldModes.get(event.getTargetWorld()) != ClaimsMode.Disabled && entity instanceof
                        Wither) {
                    transaction.setIsValid(false);
                } else if (!GriefPrevention.instance.config_zombiesBreakDoors && isTypeDoor(originalType) && entity instanceof Zombie) {
                    transaction.setIsValid(false);
                } else if (finalType.equals(BlockTypes.DIRT) && originalType.equals(BlockTypes.FARMLAND)) {
                    if (!GriefPrevention.instance.config_creaturesTrampleCrops) {
                        transaction.setIsValid(false);
                    } else {
                        final Optional<Entity> optPassenger = entity.get(Keys.PASSENGER);
                        if (optPassenger.isPresent() && optPassenger.get() instanceof Player) {
                            transaction.setIsValid(false);
                        }
                    }
                }
            }
        }
    }

    private boolean isTypeDoor(BlockType type) {
        return type.equals(BlockTypes.ACACIA_DOOR) || type.equals(BlockTypes.BIRCH_DOOR) || type.equals(BlockTypes.DARK_OAK_DOOR) || type.equals
                (BlockTypes.JUNGLE_DOOR) || type.equals(BlockTypes.SPRUCE_DOOR) || type.equals(BlockTypes.WOODEN_DOOR);
    }

    // don't allow endermen to change blocks
   /* @Listener(ignoreCancelled = true, order = Order.EARLY)
    public void onEntityChangeBLock(ChangeBlockEvent event) {
        // sand cannon fix - when the falling block doesn't fall straight down,
        // take additional anti-grief steps
        if (event.getEntityType() == EntityType.FALLING_BLOCK) {
            FallingBlock entity = (FallingBlock) event.getEntity();
            Block block = event.getBlock();

            // if changing a block TO air, this is when the falling block
            // formed. note its original location
            if (event.getTo() == Material.AIR) {
                entity.setMetadata("GP_FALLINGBLOCK", new FixedMetadataValue(GriefPrevention.instance, block.getLocation()));
            }
            // otherwise, the falling block is forming a block. compare new
            // location to original source
            else {
                List<MetadataValue> values = entity.getMetadata("GP_FALLINGBLOCK");

                // if we're not sure where this entity came from (maybe another<commit_msg>Use Data API to figure out this is a door.<commit_after>/*
    GriefPrevention Server Plugin for Minecraft
    Copyright (C) 2012 <NAME>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package me.ryanhamshire.GriefPrevention;

import org.spongepowered.api.block.BlockTransaction;
import org.spongepowered.api.block.BlockType;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.monster.Enderman;
import org.spongepowered.api.entity.living.monster.Silverfish;
import org.spongepowered.api.entity.living.monster.Wither;
import org.spongepowered.api.entity.living.monster.Zombie;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.potion.PotionEffectType;
import org.spongepowered.api.potion.PotionEffectTypes;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;

//handles events related to entities
public class EntityEventHandler {

    // convenience reference for the singleton datastore
    private DataStore dataStore;

    public EntityEventHandler(DataStore dataStore) {
        this.dataStore = dataStore;
    }

    @Listener(order = Order.EARLY)
    public void onChangeBlockBreak(ChangeBlockEvent.Break event) {
        final Cause cause = event.getCause();
        final Entity entity = cause.first(Entity.class).orElse(null);
        if (entity != null) {
            for (BlockTransaction transaction : event.getTransactions()) {
                final BlockType originalType = transaction.getOriginal().getState().getType();
                final BlockType finalType = transaction.getFinalReplacement().getState().getType();

                if (!GriefPrevention.instance.config_endermenMoveBlocks && entity instanceof Enderman) {
                    transaction.setIsValid(false);
                } else if (!GriefPrevention.instance.config_silverfishBreakBlocks && entity instanceof Silverfish) {
                    transaction.setIsValid(false);
                } else if (GriefPrevention.instance.config_claims_worldModes.get(event.getTargetWorld()) != ClaimsMode.Disabled && entity instanceof
                        Wither) {
                    transaction.setIsValid(false);
                } else if (!GriefPrevention.instance.config_zombiesBreakDoors && transaction.getOriginal().get(Keys.HINGE_POSITION).isPresent() && entity
                        instanceof Zombie) {
                    transaction.setIsValid(false);
                } else if (finalType.equals(BlockTypes.DIRT) && originalType.equals(BlockTypes.FARMLAND)) {
                    if (!GriefPrevention.instance.config_creaturesTrampleCrops) {
                        transaction.setIsValid(false);
                    } else {
                        final Optional<Entity> optPassenger = entity.get(Keys.PASSENGER);
                        if (optPassenger.isPresent() && optPassenger.get() instanceof Player) {
                            transaction.setIsValid(false);
                        }
                    }
                }
            }
        }
    }

    // don't allow endermen to change blocks
   /* @Listener(ignoreCancelled = true, order = Order.EARLY)
    public void onEntityChangeBLock(ChangeBlockEvent event) {
        // sand cannon fix - when the falling block doesn't fall straight down,
        // take additional anti-grief steps
        if (event.getEntityType() == EntityType.FALLING_BLOCK) {
            FallingBlock entity = (FallingBlock) event.getEntity();
            Block block = event.getBlock();

            // if changing a block TO air, this is when the falling block
            // formed. note its original location
            if (event.getTo() == Material.AIR) {
                entity.setMetadata("GP_FALLINGBLOCK", new FixedMetadataValue(GriefPrevention.instance, block.getLocation()));
            }
            // otherwise, the falling block is forming a block. compare new
            // location to original source
            else {
                List<MetadataValue> values = entity.getMetadata("GP_FALLINGBLOCK");

                // if we're not sure where this entity came from (maybe another
{'fraction_non_alphanumeric': 0.08630721489526764, 'fraction_numerical': 0.000969743987587277, 'mean_word_length': 2.695091365102114, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5215287', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2645, 'n_words': 698}