<commit_before>package dmillerw.lore.common.core.handler;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import dmillerw.lore.LoreExpansion;
import dmillerw.lore.common.command.LoreCommandSender;
import dmillerw.lore.common.item.ItemLorePage;
import dmillerw.lore.common.lore.LoreLoader;
import dmillerw.lore.common.lore.PlayerHandler;
import dmillerw.lore.common.lore.data.Lore;
import dmillerw.lore.common.lore.data.LoreKey;
import dmillerw.lore.common.network.packet.PacketClientNotification;
import dmillerw.lore.common.network.packet.PacketHandler;
import dmillerw.lore.common.network.packet.PacketSyncLore;
import net.minecraft.command.CommandHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import org.lwjgl.input.Keyboard;

/**
 * @author dmillerw
 */
public class PlayerTickHandler {

	@SubscribeEvent
	public void onPlayerTick(TickEvent.PlayerTickEvent event) {
		boolean notifiedThisTick = false;
		if (event.phase == TickEvent.Phase.START && event.side == Side.SERVER) {
			if (!event.player.capabilities.isCreativeMode) {
				for (int i=0; i<event.player.inventory.getSizeInventory(); i++) {
					ItemStack stack = event.player.inventory.getStackInSlot(i);

					if (stack != null && stack.getItem() == LoreExpansion.lorePage) {
						LoreKey key = ItemLorePage.getLore(stack);
						if (key != null) {
							Lore lore = LoreLoader.INSTANCE.getLore(key);

							if (lore == null) {
								LoreExpansion.logger.warn("Found item with invalid lore. Resetting");
								stack.setTagCompound(new NBTTagCompound());
								return;
							}

							PlayerHandler.getCollectedLore(event.player).addLore(key);

							PacketSyncLore.updateLore((EntityPlayerMP) event.player);

							PacketHandler.INSTANCE.sendTo(new PacketClientNotification(key.page, key.dimension, PacketClientNotification.PICKUP), (EntityPlayerMP) event.player);

							CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
							LoreCommandSender commandSender = new LoreCommandSender(event.player);
							for (String str : lore.commands.pickup) {
								ch.executeCommand(commandSender, str);
							}

							if (lore.notify && !notifiedThisTick) {
								event.player.addChatComponentMessage(new ChatComponentText("You've discovered a new lore page. Press " + Keyboard.getKeyName(KeyHandler.INSTANCE.key.getKeyCode()) + " to view"));
								notifiedThisTick = true;
							}

							event.player.inventory.setInventorySlotContents(i, null);
							event.player.inventory.markDirty();
						}
					}
				}
			}
		}
	}

}<commit_msg>Only fire picked up notification once per stack (in case of multiples)<commit_after>package dmillerw.lore.common.core.handler;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import dmillerw.lore.LoreExpansion;
import dmillerw.lore.common.command.LoreCommandSender;
import dmillerw.lore.common.item.ItemLorePage;
import dmillerw.lore.common.lore.LoreLoader;
import dmillerw.lore.common.lore.PlayerHandler;
import dmillerw.lore.common.lore.data.Lore;
import dmillerw.lore.common.lore.data.LoreKey;
import dmillerw.lore.common.network.packet.PacketClientNotification;
import dmillerw.lore.common.network.packet.PacketHandler;
import dmillerw.lore.common.network.packet.PacketSyncLore;
import net.minecraft.command.CommandHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import org.lwjgl.input.Keyboard;

/**
 * @author dmillerw
 */
public class PlayerTickHandler {

    private boolean notifiedThisTick = false;

	@SubscribeEvent
	public void onPlayerTick(TickEvent.PlayerTickEvent event) {
		if (event.phase == TickEvent.Phase.START && event.side == Side.SERVER) {
			if (!event.player.capabilities.isCreativeMode) {
				for (int i=0; i<event.player.inventory.getSizeInventory(); i++) {
					ItemStack stack = event.player.inventory.getStackInSlot(i);

					if (stack != null && stack.getItem() == LoreExpansion.lorePage) {
						LoreKey key = ItemLorePage.getLore(stack);
						if (key != null) {
							Lore lore = LoreLoader.INSTANCE.getLore(key);

							if (lore == null) {
								LoreExpansion.logger.warn("Found item with invalid lore. Resetting");
								stack.setTagCompound(new NBTTagCompound());
								return;
							}

							PlayerHandler.getCollectedLore(event.player).addLore(key);

							PacketSyncLore.updateLore((EntityPlayerMP) event.player);

							PacketHandler.INSTANCE.sendTo(new PacketClientNotification(key.page, key.dimension, PacketClientNotification.PICKUP), (EntityPlayerMP) event.player);

							CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
							LoreCommandSender commandSender = new LoreCommandSender(event.player);
							for (String str : lore.commands.pickup) {
								ch.executeCommand(commandSender, str);
							}

							if (lore.notify && !notifiedThisTick) {
								event.player.addChatComponentMessage(new ChatComponentText("You've discovered a new lore page. Press " + Keyboard.getKeyName(KeyHandler.INSTANCE.key.getKeyCode()) + " to view"));
								notifiedThisTick = true;
							}

							event.player.inventory.setInventorySlotContents(i, null);
							event.player.inventory.markDirty();

                            return;
						}

                        // Only set this to false if no lore has been updated this tick
                        notifiedThisTick = false;
					}
				}
			}
		}
	}

}
{'fraction_non_alphanumeric': 0.11139369277721262, 'fraction_numerical': 0.00033909799932180403, 'mean_word_length': 3.9654882154882154, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6890573', 'n_tokens_mistral': 2221, 'n_tokens_neox': 1858, 'n_words': 304}