<commit_before>package com.splunk.logtosplunk.event_loggers;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.splunk.logtosplunk.LogToSplunkMod;
import com.splunk.logtosplunk.SplunkMessagePreparer;
import com.splunk.logtosplunk.actions.BlockEventAction;
import com.splunk.logtosplunk.loggable_events.LoggableBlockEvent;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/**
 * Handles the logging of block events.
 */
public class BlockEventLogger {
    private static final String LOG_NAME_MODIFIER = " - BLOCK";
    private static final Logger logger = LogManager.getLogger(LogToSplunkMod.LOGGER_NAME + LOG_NAME_MODIFIER);

    /**
     * Prepares and forwards data to be sent to splunk.
     */
    private SplunkMessagePreparer messagePreparer;

    /**
     * Constructor.
     *
     * @param messagePreparer used to process this classes captured data.
     */
    public BlockEventLogger(SplunkMessagePreparer messagePreparer) {
        this.messagePreparer = messagePreparer;
    }

    /**
     * Captures Block BreakEvents and sends them to the message preparer.
     *
     * @param event The captured BreakEvent.
     */
    @SubscribeEvent
    @SideOnly(Side.SERVER)
    public void captureBreakEvent(BlockEvent.BreakEvent event) {
        logAndSend(getLoggableBlockBreakPlaceEvent(BlockEventAction.BREAK, event));
    }

    /**
     * Captures Block PlaceEvents and sends them to the message preparer.
     *
     * @param event The captured PlaceEvent.
     */
    @SubscribeEvent
    @SideOnly(Side.SERVER)
    public void capturePlaceEvent(BlockEvent.PlaceEvent event) {
        logAndSend(getLoggableBlockBreakPlaceEvent(BlockEventAction.PLACE, event));
    }

    private LoggableBlockEvent getLoggableBlockBreakPlaceEvent(BlockEventAction action, BlockEvent event) {
        Block block = event.state.getBlock();
        String base_type = block.getUnlocalizedName();
        World w = event.world;
        Item item =  Item.getItemFromBlock(block);
        int damVal = block.getDamageValue(event.world, event.pos);
        ItemStack stack = new ItemStack(block, 1, damVal);
        String blockName = item.getItemStackDisplayName(stack).replace(' ', '_');
        Vec3 coords = new Vec3(event.pos.getX(), event.pos.getY(), event.pos.getZ());
        String playerName = null;
        if (event instanceof BlockEvent.BreakEvent) {
            playerName = ((BlockEvent.BreakEvent) event).getPlayer().getName();
        } else if (event instanceof BlockEvent.PlaceEvent) {
            playerName = ((BlockEvent.PlaceEvent) event).player.getName();
        }
        return new LoggableBlockEvent(action, w.getWorldTime(), w.getWorldInfo().getWorldName(), coords)
                .setBlockName(blockName).setPlayerName(playerName).setBaseType(base_type);
    }

    /**
     * Logs via Log4j and forwards the messgage to the message preparer.
     *
     * @param loggable The message to log.
     */
    private void logAndSend(LoggableBlockEvent loggable) {
        logger.debug(loggable);
        messagePreparer.writeMessage(loggable);
    }
}<commit_msg>Added some more detailed block logging<commit_after>package com.splunk.logtosplunk.event_loggers;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.splunk.logtosplunk.LogToSplunkMod;
import com.splunk.logtosplunk.SplunkMessagePreparer;
import com.splunk.logtosplunk.actions.BlockEventAction;
import com.splunk.logtosplunk.loggable_events.LoggableBlockEvent;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/**
 * Handles the logging of block events.
 */
public class BlockEventLogger {
    private static final String LOG_NAME_MODIFIER = " - BLOCK";
    private static final Logger logger = LogManager.getLogger(LogToSplunkMod.LOGGER_NAME + LOG_NAME_MODIFIER);

    /**
     * Prepares and forwards data to be sent to splunk.
     */
    private SplunkMessagePreparer messagePreparer;

    /**
     * Constructor.
     *
     * @param messagePreparer used to process this classes captured data.
     */
    public BlockEventLogger(SplunkMessagePreparer messagePreparer) {
        this.messagePreparer = messagePreparer;
    }

    /**
     * Captures Block BreakEvents and sends them to the message preparer.
     *
     * @param event The captured BreakEvent.
     */
    @SubscribeEvent
    @SideOnly(Side.SERVER)
    public void captureBreakEvent(BlockEvent.BreakEvent event) {
        logAndSend(getLoggableBlockBreakPlaceEvent(BlockEventAction.BREAK, event));
    }

    /**
     * Captures Block PlaceEvents and sends them to the message preparer.
     *
     * @param event The captured PlaceEvent.
     */
    @SubscribeEvent
    @SideOnly(Side.SERVER)
    public void capturePlaceEvent(BlockEvent.PlaceEvent event) {
        logAndSend(getLoggableBlockBreakPlaceEvent(BlockEventAction.PLACE, event));
    }

    private LoggableBlockEvent getLoggableBlockBreakPlaceEvent(BlockEventAction action, BlockEvent event) {

        Block block = event.state.getBlock();
        String base_type = block.getUnlocalizedName();
        World w = event.world;
        Item item = Item.getItemFromBlock(block);

        String blockName = null;
        if (item != null) {
            int damVal = block.getDamageValue(event.world, event.pos);
            ItemStack stack = new ItemStack(block, 1, damVal);
            blockName = item.getItemStackDisplayName(stack).replace(' ', '_');
        } else {

            blockName = base_type;
            if (event instanceof BlockEvent.PlaceEvent) {
                blockName = ((BlockEvent.PlaceEvent) event).itemInHand.getDisplayName();
            }
        }
        Vec3 coords = new Vec3(event.pos.getX(), event.pos.getY(), event.pos.getZ());
        String playerName = null;
        if (event instanceof BlockEvent.BreakEvent) {
            playerName = ((BlockEvent.BreakEvent) event).getPlayer().getName();
        } else if (event instanceof BlockEvent.PlaceEvent) {
            playerName = ((BlockEvent.PlaceEvent) event).player.getName();
        }
        return new LoggableBlockEvent(action, w.getWorldTime(), w.getWorldInfo().getWorldName(), coords)
                .setBlockName(blockName).setPlayerName(playerName).setBaseType(base_type);
    }

    /**
     * Logs via Log4j and forwards the messgage to the message preparer.
     *
     * @param loggable The message to log.
     */
    private void logAndSend(LoggableBlockEvent loggable) {
        logger.debug(loggable);
        messagePreparer.writeMessage(loggable);
    }
}
{'fraction_non_alphanumeric': 0.09527754763877382, 'fraction_numerical': 0.0019331676332504833, 'mean_word_length': 3.3397243858597965, 'pattern_counts': {'":': 0, '<': 3, '<?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': '535014', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2108, 'n_words': 444}