<commit_before>package com.elmakers.mine.bukkit.spell.builtin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.CommandBlock;
import org.bukkit.configuration.ConfigurationSection;

import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.block.MaterialAndData;
import com.elmakers.mine.bukkit.block.batch.SimulateBatch;
import com.elmakers.mine.bukkit.utilities.TextUtils;
import com.elmakers.mine.bukkit.utility.AscendingPair;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;
import com.elmakers.mine.bukkit.utility.Messages;
import com.elmakers.mine.bukkit.utility.RandomUtils;
import com.elmakers.mine.bukkit.utility.WeightedPair;

public class AnimateSpell extends SimulateSpell 
{
	private static Random random = new Random();
	private LinkedList<WeightedPair<Integer>> levelWeights = null;

	public final static String[] ANIMATE_PARAMETERS = {
		"animate", "sim_check_destructible", "seed_radius", "restricted", "obworld", "btarget"
	};
	
	@SuppressWarnings("deprecation")
    @Override
	public SpellResult onCast(ConfigurationSection parameters) 
	{
		if (parameters.getBoolean("animate", false))
		{
			return super.onCast(parameters);
		}
		
		final Block targetBlock = getTargetBlock();
		if (targetBlock == null) 
		{
			return SpellResult.NO_TARGET;
		}
		if (!hasBuildPermission(targetBlock)) 
		{
			return SpellResult.INSUFFICIENT_PERMISSION;
		}
		MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
		if (parameters.contains("material")) {
			targetMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", targetMaterial);
			addDestructible(targetMaterial.getMaterial());
		}

		Set<Material> restricted = controller.getMaterialSet(parameters.getString("restricted", "restricted"));
		if (restricted.contains(targetMaterial.getMaterial()))
		{
			return SpellResult.RESTRICTED;
		}

		if (!isDestructible(targetBlock)) {
			return SpellResult.INSUFFICIENT_PERMISSION;
		}

		int seedRadius = parameters.getInt("seed_radius", 0);
		if (seedRadius > 0) {
			for (int dx = -seedRadius; dx < seedRadius; dx++) {
				for (int dz = -seedRadius; dz < seedRadius; dz++) {
					for (int dy = -seedRadius; dy < seedRadius; dy++) {
						Block seedBlock = targetBlock.getRelative(dx, dy, dz);
						if (isDestructible(seedBlock)) {
							targetMaterial.modify(seedBlock);
						}
					}
				}<commit_msg>Prevent casting Animate on any restricted material<commit_after>package com.elmakers.mine.bukkit.spell.builtin;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.CommandBlock;
import org.bukkit.configuration.ConfigurationSection;

import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.block.MaterialAndData;
import com.elmakers.mine.bukkit.block.batch.SimulateBatch;
import com.elmakers.mine.bukkit.utilities.TextUtils;
import com.elmakers.mine.bukkit.utility.AscendingPair;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;
import com.elmakers.mine.bukkit.utility.Messages;
import com.elmakers.mine.bukkit.utility.RandomUtils;
import com.elmakers.mine.bukkit.utility.WeightedPair;

public class AnimateSpell extends SimulateSpell 
{
	private static Random random = new Random();
	private LinkedList<WeightedPair<Integer>> levelWeights = null;

	public final static String[] ANIMATE_PARAMETERS = {
		"animate", "sim_check_destructible", "seed_radius", "restricted", "obworld", "btarget"
	};
	
	@SuppressWarnings("deprecation")
    @Override
	public SpellResult onCast(ConfigurationSection parameters) 
	{
		if (parameters.getBoolean("animate", false))
		{
			return super.onCast(parameters);
		}
		
		final Block targetBlock = getTargetBlock();
		if (targetBlock == null) 
		{
			return SpellResult.NO_TARGET;
		}
		if (!hasBuildPermission(targetBlock)) 
		{
			return SpellResult.INSUFFICIENT_PERMISSION;
		}
		MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
		if (parameters.contains("material")) {
			targetMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", targetMaterial);
			addDestructible(targetMaterial.getMaterial());
		}

        if (!mage.isSuperPowered()) {
            Set<Material> restricted = controller.getMaterialSet("restricted");
            if (restricted.contains(targetMaterial.getMaterial())) {
                return SpellResult.RESTRICTED;
            }

            if (parameters.contains("restricted")) {
                String customRestricted = parameters.getString("restricted");
                if (customRestricted != null && customRestricted.length() > 0 && !customRestricted.equals("restricted")) {
                    restricted = controller.getMaterialSet(customRestricted);
                    if (restricted.contains(targetMaterial.getMaterial())) {
                        return SpellResult.RESTRICTED;
                    }
                }
            }
        }

		if (!isDestructible(targetBlock)) {
			return SpellResult.INSUFFICIENT_PERMISSION;
		}

		int seedRadius = parameters.getInt("seed_radius", 0);
		if (seedRadius > 0) {
			for (int dx = -seedRadius; dx < seedRadius; dx++) {
				for (int dz = -seedRadius; dz < seedRadius; dz++) {
					for (int dy = -seedRadius; dy < seedRadius; dy++) {
						Block seedBlock = targetBlock.getRelative(dx, dy, dz);
						if (isDestructible(seedBlock)) {
							targetMaterial.modify(seedBlock);
						}
					}
				}
{'fraction_non_alphanumeric': 0.11407160699417153, 'fraction_numerical': 0.0008326394671107411, 'mean_word_length': 4.263803680981595, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 12, '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': '3957699', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1801, 'n_words': 338}