<commit_before>package vg.civcraft.mc.civmodcore.api;

import com.google.common.base.Preconditions;
import java.util.Iterator;
import java.util.Objects;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import vg.civcraft.mc.civmodcore.util.NullCoalescing;

/**
 * Class of utility functions for Recipes.
 */
public final class RecipeAPI {

	/**
	 * Determines whether a shaped recipe matches another recipe.
	 *
	 * @param base The base recipe to base the matching upon.
	 * @param other The other recipe, the unknown.
	 * @return Returns true if the other recipe matches the base.
	 */
	public static boolean matchRecipe(ShapedRecipe base, Recipe other) {
		if (base == null) {
			return false;
		}
		ShapedRecipe shaped = NullCoalescing.chain(() -> (ShapedRecipe) other);
		if (shaped == null) {
			return false;
		}
		if (!base.getKey().equals(shaped.getKey())) {
			return false;
		}
		if (shaped.getIngredientMap().hashCode() != base.getIngredientMap().hashCode()) {
			return false;
		}
		if (!Objects.equals(shaped.getResult(), base.getResult())) {
			return false;
		}
		return true;
	}

	/**
	 * Determines whether a shapeless recipe matches another recipe.
	 *
	 * @param base The base recipe to base the matching upon.
	 * @param other The other recipe, the unknown.
	 * @return Returns true if the other recipe matches the base.
	 */
	public static boolean matchRecipe(ShapelessRecipe base, Recipe other) {
		if (base == null) {
			return false;
		}
		ShapelessRecipe shapeless = NullCoalescing.chain(() -> (ShapelessRecipe) other);
		if (shapeless == null) {
			return false;
		}
		if (!base.getKey().equals(shapeless.getKey())) {
			return false;
		}
		if (shapeless.getIngredientList().hashCode() != base.getIngredientList().hashCode()) {
			return false;
		}
		if (!Objects.equals(shapeless.getResult(), base.getResult())) {
			return false;
		}
		return true;
	}

	/**
	 * Remove a shaped recipe from Bukkit's registered recipes list.
	 *
	 * @param recipe The shaped recipe to deregister.
	 * @return Returns true if the recipe was de-registered, or wasn't ever registered.
	 */
	public static boolean removeRecipe(ShapedRecipe recipe) {
		Preconditions.checkArgument(recipe != null);
		Iterator<Recipe> iterator = Bukkit.getServer().recipeIterator();
		while (iterator.hasNext()) {
			if (!matchRecipe(recipe, iterator.next())) {
				continue;
			}
			iterator.remove();
			return true;
		}
		return true;
	}

	/**
	 * Remove a shapeless recipe from Bukkit's registered recipes list.
	 *
	 * @param recipe The shapeless recipe to deregister.
	 * @return Returns true if the recipe was de-registered, or wasn't ever registered.
	 */
	public static boolean removeRecipe(ShapelessRecipe recipe) {
		Preconditions.checkArgument(recipe != null);
		Iterator<Recipe> iterator = Bukkit.getServer().recipeIterator();
		while (iterator.hasNext()) {
			if (!matchRecipe(recipe, iterator.next())) {
				continue;
			}
			iterator.remove();
			return true;
		}
		return false;
	}

}
<commit_msg>RecipeAPI update<commit_after>package vg.civcraft.mc.civmodcore.api;

import java.util.Iterator;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.inventory.Recipe;
import vg.civcraft.mc.civmodcore.util.NullCoalescing;

/**
 * Class of utility functions for Recipes.
 */
public final class RecipeAPI {

	/**
	 * Determines whether a recipe matches another recipe.
	 *
	 * @param base The base recipe to base the matching upon.
	 * @param other The other recipe, the unknown.
	 * @return Returns true if the other recipe matches the base.
	 *
	 * @apiNote This matcher pretty much assumes that all recipes are keyed. If other kinds of recipes come up that
	 *     aren't keyed, then support here can be added. But until then? /shrug
	 */
	public static boolean matchRecipe(Recipe base, Recipe other) {
		if (base == null) {
			return false;
		}
		if (base instanceof Keyed && other instanceof Keyed) {
			return NullCoalescing.equalsNotNull(
					((Keyed) base).getKey(),
					((Keyed) other).getKey());
		}
		return false;
	}

	/**
	 * Registers a recipe to the Bukkit server.
	 *
	 * @param recipe The recipe to register.
	 * @return Returns true if the recipe was registered.
	 *
	 * @apiNote This is to prevent thrown exceptions for re-registered recipes. Since registrations often happen within
	 *     a plugin's onEnable() method, an exception here will actually disable the plugin entirely, which is a bit
	 *     disproportionate. You should check the returned boolean to see whether the registration was successful and
	 *     handle that accordingly.
	 */
	public static boolean registerRecipe(Recipe recipe) {
		if (recipe == null) {
			return false;
		}
		try {
			return Bukkit.getServer().addRecipe(recipe);
		}
		catch (Exception exception) {
			return false;
		}
	}

	/**
	 * Removes a recipe from Bukkit's registered recipes list.
	 *
	 * @param recipe The shaped recipe to deregister.
	 * @return Returns true if the recipe was de-registered, or wasn't ever registered.
	 */
	public static boolean removeRecipe(Recipe recipe) {
		Iterator<Recipe> iterator = Bukkit.getServer().recipeIterator();
		while (iterator.hasNext()) {
			if (!matchRecipe(recipe, iterator.next())) {
				continue;
			}
			iterator.remove();
			return true;
		}
		return true;
	}

}

{'fraction_non_alphanumeric': 0.10863922877271041, 'fraction_numerical': 0.0, 'mean_word_length': 3.6790980052038162, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '6437567', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1627, 'n_words': 522}