package com.elmakers.mine.bukkit.world.block.builtin;

import java.util.Deque;
import java.util.Random;
import javax.annotation.Nonnull;

import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

import com.elmakers.mine.bukkit.api.automata.Automaton;
import com.elmakers.mine.bukkit.utility.RandomUtils;
import com.elmakers.mine.bukkit.utility.WeightedPair;
import com.elmakers.mine.bukkit.world.BlockResult;
import com.elmakers.mine.bukkit.world.block.BlockRule;

public class AutomatonRule extends BlockRule {
    private Deque<WeightedPair<String>> automatonProbability;
    private ConfigurationSection parameters;

    @Override
    public boolean onLoad(ConfigurationSection parameters) {
        RandomUtils.populateStringProbabilityMap(automatonProbability, parameters, "automaton");
        this.parameters = parameters.getConfigurationSection("automaton_parameters");
        return !automatonProbability.isEmpty();
    }

    @Override
    @Nonnull
    public BlockResult onHandle(Block block, Random random, Player cause) {
        String automatonKey = RandomUtils.weightedRandom(automatonProbability);

        if (automatonKey.equalsIgnoreCase("none")) {
            return BlockResult.SKIP;
        }
        try {
            BlockResult result = BlockResult.valueOf(automatonKey.toUpperCase());
            return result;
        } catch (Exception ignore) {
        }

        Location location = block.getLocation();
        Automaton automaton = controller.addAutomaton(location, automatonKey, null, null, parameters);
        return automaton == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
    }
}

@@ -48,16 +48,45 @@
 iltin;%0A%0A
+import java.util.ArrayDeque;%0A
 import j
@@ -359,24 +359,79 @@
 .Automaton;%0A
+import com.elmakers.mine.bukkit.api.magic.MaterialSet;%0A
 import com.e
@@ -679,16 +679,49 @@
 kRule %7B%0A
+    private MaterialSet replace;%0A
     priv
@@ -772,16 +772,37 @@
 bability
+ = new ArrayDeque%3C%3E()
 ;%0A    pr
@@ -1095,24 +1095,122 @@
 rameters%22);%0A
+        replace = controller.getMaterialSetManager().fromConfig(parameters.getString(%22replace%22));%0A
         retu
@@ -1351,24 +1351,131 @@
 er cause) %7B%0A
+        if (replace != null && !replace.testBlock(block)) %7B%0A            return BlockResult.SKIP;%0A        %7D%0A
         Stri

Add replace parameter to Automaton rule