/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

package com.skelril.skree.content.world.build;

import com.skelril.skree.SkreePlugin;
import com.skelril.skree.service.internal.world.WorldEffectWrapperImpl;
import org.spongepowered.api.Game;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.entity.living.monster.Monster;
import org.spongepowered.api.event.Subscribe;
import org.spongepowered.api.event.block.BlockBreakEvent;
import org.spongepowered.api.event.entity.EntitySpawnEvent;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.ArrayList;
import java.util.Collection;

import static com.skelril.skree.content.registry.TypeCollections.ore;

public class BuildWorldWrapper extends WorldEffectWrapperImpl {

    private SkreePlugin plugin;
    private Game game;

    public BuildWorldWrapper(SkreePlugin plugin, Game game) {
        this(plugin, game, new ArrayList<>());
    }

    public BuildWorldWrapper(SkreePlugin plugin, Game game, Collection<World> worlds) {
        super("Build", worlds);
        this.plugin = plugin;
        this.game = game;
    }

    @Subscribe
    public void onEntitySpawn(EntitySpawnEvent event) {
        if (!isApplicable(event.getLocation().getExtent())) return;

        // TODO Smarter "should this mob be allowed to spawn" code
        if (event.getEntity() instanceof Monster) {
            event.setCancelled(true);
        }
    }

    @Subscribe
    public void onBlockBreak(BlockBreakEvent event) {
        Location block = event.getBlock();
        if (!isApplicable(block.getExtent())) return;

        if (ore().contains(block.getBlockType())) {
            event.setCancelled(true);
            block.setBlockType(BlockTypes.STONE);
        }
    }
}
@@ -247,24 +247,119 @@
 rld.build;%0A%0A
+import com.flowpowered.math.vector.Vector3d;%0Aimport com.skelril.nitro.probability.Probability;%0A
 import com.s
@@ -572,36 +572,271 @@
 pi.e
-ntity.living.monster.Monster
+ffect.particle.ParticleEffect;%0Aimport org.spongepowered.api.effect.particle.ParticleTypes;%0Aimport org.spongepowered.api.entity.living.monster.Monster;%0Aimport org.spongepowered.api.entity.player.Player;%0Aimport org.spongepowered.api.entity.player.gamemode.GameModes
 ;%0Aim
@@ -933,24 +933,82 @@
 BreakEvent;%0A
+import org.spongepowered.api.event.block.BlockPlaceEvent;%0A
 import org.s
@@ -1051,24 +1051,237 @@
 SpawnEvent;%0A
+import org.spongepowered.api.event.entity.player.PlayerPlaceBlockEvent;%0Aimport org.spongepowered.api.text.TextBuilder;%0Aimport org.spongepowered.api.text.Texts;%0Aimport org.spongepowered.api.text.format.TextColors;%0A
 import org.s
@@ -2541,10 +2541,1798 @@
  %7D%0A    %7D
+%0A%0A    @Subscribe%0A    public void onBlockPlace(BlockPlaceEvent event) %7B%0A        Location loc = event.getBlock();%0A        if (!isApplicable(loc.getExtent())) return;%0A        if (ore().contains(loc.getBlockType())) %7B%0A%0A            if (event instanceof PlayerPlaceBlockEvent) %7B%0A                Player player = ((PlayerPlaceBlockEvent) event).getEntity();%0A%0A                // Allow creative mode players to still place blocks%0A                if (player.getGameModeData().getGameMode() == GameModes.CREATIVE) %7B%0A                    return;%0A                %7D%0A%0A                try %7B%0A                    Vector3d origin = loc.getPosition();%0A                    World world = toWorld.from(loc.getExtent());%0A                    for (int i = 0; i %3C 40; ++i) %7B%0A                        ParticleEffect effect = game.getRegistry().getParticleEffectBuilder(%0A                                ParticleTypes.CRIT_MAGIC%0A                        ).motion(%0A                                new Vector3d(%0A                                        Probability.getRangedRandom(-1, 1),%0A                                        Probability.getRangedRandom(-.7, .7),%0A                                        Probability.getRangedRandom(-1, 1)%0A                                )%0A                        ).count(1).build();%0A%0A                        world.spawnParticles(effect, origin.add(.5, .5, .5));%0A                    %7D%0A%0A                %7D catch (Exception ex) %7B%0A                    TextBuilder builder = Texts.builder().color(TextColors.RED).append(%0A                            Texts.of(%22You find yourself unable to place that block.%22)%0A                    );%0A                    player.sendMessage(/* ChatTypes.SYSTEM, */builder.build());%0A                %7D%0A            %7D%0A            event.setCancelled(true);%0A        %7D%0A    %7D
 %0A%7D

Add code to block placing ores in the build world