<commit_before>package us.corenetwork.tradecraft;

import net.minecraft.server.v1_7_R1.*;
import net.minecraft.util.com.google.common.reflect.Reflection;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.craftbukkit.v1_7_R1.util.CraftMagicNumbers;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

/**
 * Created by Matej on 23.2.2014.
 */
public class CustomVillager extends EntityVillager {
    private String carreer = "NOT_INITIALIZED";
    private MerchantRecipeList trades;
    private String lastTradingPlayer = null;

    //Schedules after window closes
    private boolean createNewTier = false;
    private boolean restockAll = false;

    public CustomVillager(World world) {
        super(world);

        init();
    }

    public CustomVillager(World world, int i) {
        super(world, i);

       init();
    }

    private void init()
    {
        trades = new MerchantRecipeList();

        Bukkit.getScheduler().scheduleSyncDelayedTask(TradeCraftPlugin.instance, new Runnable()
        {
            @Override
            public void run()
            {
                loadVillagerData();
                loadTradesFromDB();

                if (trades.size() == 0)
                {
                    addTier(0);
                }
            }
        });
    }

    @Override
    public EntityAgeable createChild(EntityAgeable entityAgeable) {
        return b(entityAgeable);
    }


    /**
     * Returns list of offers
     */
    @Override
    public MerchantRecipeList getOffers(EntityHuman entityHuman) {
        if (trades == null || trades.size() == 0)
        {
            Console.severe("Villager " + uniqueID.toString() + " has no trades!");

            CustomRecipe recipe = new CustomRecipe(new ItemStack((Block) Block.REGISTRY.a("diamond_block"), 65), new ItemStack((Block) Block.REGISTRY.a("dirt"), 1));
            //recipe.lockManually();

            MerchantRecipeList list = new MerchantRecipeList();
            list.add(recipe);

            return list;
        }

        return trades;
    }

    /**
     * Activated when new player starts trading (or null when nobody is trading)
     */
    @Override
    public void a_(EntityHuman entityHuman)
    {
        if (entityHuman == null) //Nobody is trading now
        {
            if (createNewTier)
            {
                addTier(getLastTier() + 1);
                refreshAll();

                //Particle effects and increasing village population
                Village village = (Village) ReflectionUtils.get(EntityVillager.class, this, "village");

                if (village != null && lastTradingPlayer != null) {
                    Bukkit.broadcastMessage("Reputation UP!");
                    this.world.broadcastEntityEffect(this, (byte) 14);
                    village.a(lastTradingPlayer, 1);
                }

                //Particle effect when adding tier
                this.addEffect(new MobEffect(MobEffectList.REGENERATION.id, 200, 0));
            }
            else if (restockAll)
            {
                refreshAll();
            }

            restockAll = false;
            createNewTier = false;
        }
        else
            Bukkit.broadcastMessage("Trading with: " + carreer);

        super.a_(entityHuman);
    }

    /**
     * Activated when player makes a trade
     */
    @Override
    public void a(MerchantRecipe vanillaRecipe)
    {
        // Yes/No sound
        this.makeSound("mob.villager.yes", this.bf(), this.bg());

        //Refrehs inventory
        EntityHuman human = b();
        if (human != null && human instanceof EntityPlayer)
        {
            final org.bukkit.entity.Player player = ((EntityPlayer) human).getBukkitEntity();
            Bukkit.getScheduler().runTask(TradeCraftPlugin.instance, new Runnable()
            {
                @Override
                public void run()
                {
                    player.updateInventory();
                }
            });
            ((EntityPlayer) human).updateInventory(human.activeContainer);

            lastTradingPlayer = human.getName();
        }

        CustomRecipe recipe = (CustomRecipe) vanillaRecipe;
        if (trades == null)<commit_msg>Add carreer name to the window<commit_after>package us.corenetwork.tradecraft;

import net.minecraft.server.v1_7_R1.*;
import net.minecraft.util.com.google.common.reflect.Reflection;
import org.bukkit.Bukkit;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.craftbukkit.v1_7_R1.util.CraftMagicNumbers;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

/**
 * Created by Matej on 23.2.2014.
 */
public class CustomVillager extends EntityVillager {
    private String carreer = "NOT_INITIALIZED";
    private MerchantRecipeList trades;
    private String lastTradingPlayer = null;

    //Schedules after window closes
    private boolean createNewTier = false;
    private boolean restockAll = false;

    public CustomVillager(World world) {
        super(world);

        init();
    }

    public CustomVillager(World world, int i) {
        super(world, i);

       init();
    }

    private void init()
    {
        trades = new MerchantRecipeList();

        Bukkit.getScheduler().scheduleSyncDelayedTask(TradeCraftPlugin.instance, new Runnable()
        {
            @Override
            public void run()
            {
                loadVillagerData();
                loadTradesFromDB();

                if (trades.size() == 0)
                {
                    addTier(0);
                }
            }
        });
    }

    @Override
    public EntityAgeable createChild(EntityAgeable entityAgeable) {
        return b(entityAgeable);
    }


    /**
     * Returns list of offers
     */
    @Override
    public MerchantRecipeList getOffers(EntityHuman entityHuman) {
        if (trades == null || trades.size() == 0)
        {
            Console.severe("Villager " + uniqueID.toString() + " has no trades!");

            CustomRecipe recipe = new CustomRecipe(new ItemStack((Block) Block.REGISTRY.a("diamond_block"), 65), new ItemStack((Block) Block.REGISTRY.a("dirt"), 1));
            //recipe.lockManually();

            MerchantRecipeList list = new MerchantRecipeList();
            list.add(recipe);

            return list;
        }

        return trades;
    }

    /**
     * Activated when new player starts trading (or null when nobody is trading)
     */
    @Override
    public void a_(EntityHuman entityHuman)
    {
        if (entityHuman == null) //Nobody is trading now
        {
            if (createNewTier)
            {
                addTier(getLastTier() + 1);
                refreshAll();

                //Particle effects and increasing village population
                Village village = (Village) ReflectionUtils.get(EntityVillager.class, this, "village");

                if (village != null && lastTradingPlayer != null) {
                    Bukkit.broadcastMessage("Reputation UP!");
                    this.world.broadcastEntityEffect(this, (byte) 14);
                    village.a(lastTradingPlayer, 1);
                }

                //Particle effect when adding tier
                this.addEffect(new MobEffect(MobEffectList.REGENERATION.id, 200, 0));
            }
            else if (restockAll)
            {
                refreshAll();
            }

            restockAll = false;
            createNewTier = false;
        }
        else
            Bukkit.broadcastMessage("Trading with: " + carreer);

        super.a_(entityHuman);
    }

    @Override
    public String getCustomName()
    {
        return carreer;
    }

    /**
     * Activated when player makes a trade
     */
    @Override
    public void a(MerchantRecipe vanillaRecipe)
    {
        // Yes/No sound
        this.makeSound("mob.villager.yes", this.bf(), this.bg());

        //Refrehs inventory
        EntityHuman human = b();
        if (human != null && human instanceof EntityPlayer)
        {
            final org.bukkit.entity.Player player = ((EntityPlayer) human).getBukkitEntity();
            Bukkit.getScheduler().runTask(TradeCraftPlugin.instance, new Runnable()
            {
                @Override
                public void run()
                {
                    player.updateInventory();
                }
            });
            ((EntityPlayer) human).updateInventory(human.activeContainer);

            lastTradingPlayer = human.getName();
        }

        CustomRecipe recipe = (CustomRecipe) vanillaRecipe;
        if (trades == null)
{'fraction_non_alphanumeric': 0.10002247696111485, 'fraction_numerical': 0.006068779501011463, 'mean_word_length': 1.8846029173419774, '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': '6359', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2375, 'n_words': 534}