<commit_before>package net.darkhax.bookshelf.buff;

import java.util.*;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;

import net.darkhax.bookshelf.common.EntityProperties;

public class BuffHelper {
    
    /**
     * Retrieves a List of BuffEffects from a living Entity.
     *
     * @param entity: The entity to retrieve the effects from.
     * @return List<BuffEffect>: A list of all BuffEffects applied to the entity passed.
     */
    public static List<BuffEffect> getEntityEffects (EntityLivingBase entity) {
        
        return EntityProperties.getProperties(entity).getBuffs();
    }
    
    /**
     * Retrieves a BuffEffect from the passed entity, that represents the passed Buff.
     *
     * @param entity: The entity to find the BuffEffect on.
     * @param buff: The Buff you are looking for.
     * @return BuffEffect: The BuffEffect you are looking for. Null if not found.
     */
    public static BuffEffect getEntityBuffEffect (EntityLivingBase entity, Buff buff) {
        
        for (BuffEffect effect : getEntityEffects(entity))
            if (effect.getBuff().equals(buff))
                return effect;
                
        return null;
    }
    
    /**
     * Updates a BuffEffect on an entity.
     *
     * @param world: The world the entity is in.
     * @param entity: The Entity to update on.
     * @param effect: The effect to update.
     */
    public static boolean addOrUpdateBuff (World world, EntityLivingBase entity, BuffEffect effect) {
        
        if (entity != null) {
            
            List<BuffEffect> list = getEntityEffects(entity);
            if (hasBuff(entity, effect.getBuff())) {
                
                for (BuffEffect buffE : list) {
                    if (buffE.getBuff().equals(effect.getBuff())) {
                        list.remove(buffE);
                        break;
                    }
                }
            }
            
            list.add(effect);
            
            if (!world.isRemote) {
                EntityProperties.getProperties(entity).setBuffs(list).sync();
            }
            
            return true;
        }
        return false;
        
    }
    
    /**
     * A check to see if an Entity has a certain buff.
     *
     * @param entity: The entity to check.
     * @param buff: The Buff to check for.
     * @return boolean: Whether or not the entity has the Buff.
     */
    public static boolean hasBuff (EntityLivingBase entity, Buff buff) {
        
        for (BuffEffect effect : getEntityEffects(entity))
            if (effect.getBuff().equals(buff))
                return true;
                
        return false;
    }
    
    /**
     * Attempts to cure all buff effects using the ItemStack passed.
     *
     * @param entity: The entity trying to be cured.
     * @param stack: The cure ItemStack being used.
     */
    public static void cureBuffs (EntityLivingBase entity, ItemStack stack) {
        
        List<BuffEffect> list = getEntityEffects(entity);
        
        for (Iterator<BuffEffect> iterator = list.iterator(); iterator.hasNext();) {
            BuffEffect effect = iterator.next();
            
            if (effect.getBuff().shouldBeCured(entity, stack)) {
                iterator.remove();
            }
        }
        
        EntityProperties.getProperties(entity).setBuffs(list).sync();
    }
    
    /**
     * Writes a list of BuffEffect to an NBTTagCompound.
     *
     * @param buffs: A List of buffs to write to a tag.
     * @return NBTTagList: An NBTTagList containing a list of tags, each containg buff data.
     */
    public static NBTTagList writeNBT (List<BuffEffect> buffs) {
        
        NBTTagList nbtList = new NBTTagList();
        
        for (BuffEffect effect : buffs) {
            NBTTagCompound buffNBT = new NBTTagCompound();
            effect.writeToNBT(buffNBT);
            nbtList.appendTag(buffNBT);
        }
        return nbtList;
    }
    
    /**
     * Reads a list of BuffEffects from an NBTTagList.
     *
     * @param list: The NBTTagList to read from.
     * @return List<BuffEffect>: A list of BuffEffect that were stored in the NBTTagList.
     */
    public static List<BuffEffect> readNBT (NBTTagList list) {
        
        List<BuffEffect> effects = new ArrayList<BuffEffect>();
        
        if (list != null) {
            
            for (int i = 0; i < list.tagCount(); i++) {
                
                NBTTagCompound tag = list.getCompoundTagAt(i);
                BuffEffect buff = BuffEffect.readFromNBT(tag);
                effects.add(buff);
            }
        }
        
        return effects;
    }<commit_msg>A tiny bit of clean up. <commit_after>package net.darkhax.bookshelf.buff;

import java.util.*;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;

import net.darkhax.bookshelf.common.EntityProperties;

public class BuffHelper {
    
    /**
     * Retrieves a List of BuffEffects from a living Entity.
     *
     * @param entity: The entity to retrieve the effects from.
     * @return List<BuffEffect>: A list of all BuffEffects applied to the entity passed.
     */
    public static List<BuffEffect> getEntityEffects (EntityLivingBase entity) {
        
        return EntityProperties.getProperties(entity).getBuffs();
    }
    
    /**
     * Retrieves a BuffEffect from the passed entity, that represents the passed Buff.
     *
     * @param entity: The entity to find the BuffEffect on.
     * @param buff: The Buff you are looking for.
     * @return BuffEffect: The BuffEffect you are looking for. Null if not found.
     */
    public static BuffEffect getEntityBuffEffect (EntityLivingBase entity, Buff buff) {
        
        for (BuffEffect effect : getEntityEffects(entity))
            if (effect.getBuff().equals(buff))
                return effect;
                
        return null;
    }
    
    /**
     * Updates a BuffEffect on an entity.
     *
     * @param world: The world the entity is in.
     * @param entity: The Entity to update on.
     * @param effect: The effect to update.
     */
    public static boolean addOrUpdateBuff (World world, EntityLivingBase entity, BuffEffect effect) {
        
        if (entity != null) {
            
            List<BuffEffect> list = getEntityEffects(entity);
            
            if (hasBuff(entity, effect.getBuff())) {
                
                for (BuffEffect buffE : list) {
                    
                    if (buffE.getBuff().equals(effect.getBuff())) {
                        
                        list.remove(buffE);
                        break;
                    }
                }
            }
            
            list.add(effect);
            
            if (!world.isRemote)
                EntityProperties.getProperties(entity).setBuffs(list).sync();
                
            return true;
        }
        
        return false;
    }
    
    /**
     * A check to see if an Entity has a certain buff.
     *
     * @param entity: The entity to check.
     * @param buff: The Buff to check for.
     * @return boolean: Whether or not the entity has the Buff.
     */
    public static boolean hasBuff (EntityLivingBase entity, Buff buff) {
        
        for (BuffEffect effect : getEntityEffects(entity))
            if (effect.getBuff().equals(buff))
                return true;
                
        return false;
    }
    
    /**
     * Attempts to cure all buff effects using the ItemStack passed.
     *
     * @param entity: The entity trying to be cured.
     * @param stack: The cure ItemStack being used.
     */
    public static void cureBuffs (EntityLivingBase entity, ItemStack stack) {
        
        List<BuffEffect> list = getEntityEffects(entity);
        
        for (Iterator<BuffEffect> iterator = list.iterator(); iterator.hasNext();) {
            
            BuffEffect effect = iterator.next();
            
            if (effect.getBuff().shouldBeCured(entity, stack))
                iterator.remove();
        }
        
        EntityProperties.getProperties(entity).setBuffs(list).sync();
    }
    
    /**
     * Writes a list of BuffEffect to an NBTTagCompound.
     *
     * @param buffs: A List of buffs to write to a tag.
     * @return NBTTagList: An NBTTagList containing a list of tags, each containg buff data.
     */
    public static NBTTagList writeNBT (List<BuffEffect> buffs) {
        
        NBTTagList nbtList = new NBTTagList();
        
        for (BuffEffect effect : buffs) {
            
            NBTTagCompound buffNBT = new NBTTagCompound();
            effect.writeToNBT(buffNBT);
            nbtList.appendTag(buffNBT);
        }
        
        return nbtList;
    }
    
    /**
     * Reads a list of BuffEffects from an NBTTagList.
     *
     * @param list: The NBTTagList to read from.
     * @return List<BuffEffect>: A list of BuffEffect that were stored in the NBTTagList.
     */
    public static List<BuffEffect> readNBT (NBTTagList list) {
        
        List<BuffEffect> effects = new ArrayList<BuffEffect>();
        
        if (list != null) {
            
            for (int i = 0; i < list.tagCount(); i++) {
                
                NBTTagCompound tag = list.getCompoundTagAt(i);
                BuffEffect buff = BuffEffect.readFromNBT(tag);
                effects.add(buff);
            }
        }
        
        return effects;
    }
{'fraction_non_alphanumeric': 0.08676545733265202, 'fraction_numerical': 0.00020439448134900357, 'mean_word_length': 1.7335195530726257, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '7586642', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2623, 'n_words': 784}