<commit_before>package com.laytonsmith.core.functions;

import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.MCMerchantRecipe;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.entities.MCVillager;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.annotations.api;
import com.laytonsmith.core.ArgumentValidation;
import com.laytonsmith.core.MSVersion;
import com.laytonsmith.core.ObjectGenerator;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CInt;
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.CRE.CREBadEntityException;
import com.laytonsmith.core.exceptions.CRE.CRECastException;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CRE.CREIllegalArgumentException;
import com.laytonsmith.core.exceptions.CRE.CRELengthException;
import com.laytonsmith.core.exceptions.CRE.CRENotFoundException;
import com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException;
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.natives.interfaces.Mixed;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Trades {

	public static String docs() {
		return "Functions related to the management of trades and merchants. A trade is a special kind of recipe"
				+ " accessed through the merchant interface. A merchant is a provider of trades,"
				+ " which may or may not be attached to a Villager.";
	}

	@api
	public static class get_merchant_trades extends Recipes.recipeFunction {

		@Override
		public Class<? extends CREThrowable>[] thrown() {
			return new Class[]{CREIllegalArgumentException.class, CREFormatException.class, CREBadEntityException.class};
		}

		@Override
		public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
			CArray ret = new CArray(t);
			for(MCMerchantRecipe mr : GetMerchant(args[0], t).getRecipes()) {
				ret.push(trade(mr, t), t);
			}
			return ret;
		}

		@Override
		public Version since() {
			return MSVersion.V3_3_3;
		}

		@Override
		public String getName() {
			return "get_merchant_trades";
		}

		@Override
		public Integer[] numArgs() {
			return new Integer[]{1};
		}

		@Override
		public String docs() {
			return "array {specifier} Returns a list of trades used by the specified merchant."
					+ " Specifier can be the UUID of an entity or a virtual merchant ID.";
		}
	}

	@api
	public static class set_merchant_trades extends Recipes.recipeFunction {

		@Override
		public Class<? extends CREThrowable>[] thrown() {
			return new Class[]{CREIllegalArgumentException.class, CREFormatException.class, CRECastException.class,
					CREBadEntityException.class, CRENotFoundException.class};
		}

		@Override
		public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
			MCMerchant merchant = GetMerchant(args[0], t);
			CArray trades = Static.getArray(args[1], t);
			List<MCMerchantRecipe> recipes = new ArrayList<>();
			for(Mixed trade : trades.asList()) {
				recipes.add(trade(trade, t));
			}
			merchant.setRecipes(recipes);
			return CVoid.VOID;
		}

		@Override
		public Version since() {
			return MSVersion.V3_3_3;
		}

		@Override
		public String getName() {
			return "set_merchant_trades";
		}

		@Override
		public Integer[] numArgs() {<commit_msg>Fix core error when setting a single trade to a merchant<commit_after>package com.laytonsmith.core.functions;

import com.laytonsmith.PureUtilities.Version;
import com.laytonsmith.abstraction.MCEntity;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCMerchant;
import com.laytonsmith.abstraction.MCMerchantRecipe;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.entities.MCVillager;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.annotations.api;
import com.laytonsmith.core.ArgumentValidation;
import com.laytonsmith.core.MSVersion;
import com.laytonsmith.core.ObjectGenerator;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CInt;
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.CString;
import com.laytonsmith.core.constructs.CVoid;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.CRE.CREBadEntityException;
import com.laytonsmith.core.exceptions.CRE.CRECastException;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CRE.CREIllegalArgumentException;
import com.laytonsmith.core.exceptions.CRE.CRELengthException;
import com.laytonsmith.core.exceptions.CRE.CRENotFoundException;
import com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException;
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.natives.interfaces.Mixed;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Trades {

	public static String docs() {
		return "Functions related to the management of trades and merchants. A trade is a special kind of recipe"
				+ " accessed through the merchant interface. A merchant is a provider of trades,"
				+ " which may or may not be attached to a Villager.";
	}

	@api
	public static class get_merchant_trades extends Recipes.recipeFunction {

		@Override
		public Class<? extends CREThrowable>[] thrown() {
			return new Class[]{CREIllegalArgumentException.class, CREFormatException.class, CREBadEntityException.class};
		}

		@Override
		public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
			CArray ret = new CArray(t);
			for(MCMerchantRecipe mr : GetMerchant(args[0], t).getRecipes()) {
				ret.push(trade(mr, t), t);
			}
			return ret;
		}

		@Override
		public Version since() {
			return MSVersion.V3_3_3;
		}

		@Override
		public String getName() {
			return "get_merchant_trades";
		}

		@Override
		public Integer[] numArgs() {
			return new Integer[]{1};
		}

		@Override
		public String docs() {
			return "array {specifier} Returns a list of trades used by the specified merchant."
					+ " Specifier can be the UUID of an entity or a virtual merchant ID.";
		}
	}

	@api
	public static class set_merchant_trades extends Recipes.recipeFunction {

		@Override
		public Class<? extends CREThrowable>[] thrown() {
			return new Class[]{CREIllegalArgumentException.class, CREFormatException.class, CRECastException.class,
					CREBadEntityException.class, CRENotFoundException.class};
		}

		@Override
		public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException {
			MCMerchant merchant = GetMerchant(args[0], t);
			CArray trades = Static.getArray(args[1], t);
			List<MCMerchantRecipe> recipes = new ArrayList<>();
			if(trades.isAssociative()) {
				throw new CRECastException("Expected non-associative array for list of trade arrays.", t);
			}
			for(Mixed trade : trades.asList()) {
				recipes.add(trade(trade, t));
			}
			merchant.setRecipes(recipes);
			return CVoid.VOID;
		}

		@Override
		public Version since() {
			return MSVersion.V3_3_3;
		}

		@Override
		public String getName() {
			return "set_merchant_trades";
		}

		@Override
		public Integer[] numArgs() {
{'fraction_non_alphanumeric': 0.09881138191859767, 'fraction_numerical': 0.0024012486492976347, 'mean_word_length': 5.071428571428571, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1788346', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2583, 'n_words': 584}