package me.eddiep.handles.logic;


import me.eddiep.ClassicPhysics;
import me.eddiep.handles.ClassicBlockPlaceEvent;
import me.eddiep.handles.ClassicPhysicsEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.metadata.FixedMetadataValue;


public class LavaLogic extends AbstractLogicContainer {
    @Override
    protected void tickForBlock(Block block, Location location) {
        checkLocation(location.clone().add(1, 0, 0), location);
        checkLocation(location.clone().add(-1, 0, 0), location);
        checkLocation(location.clone().add(0, 0, 1), location);
        checkLocation(location.clone().add(0, 0, -1), location);
        checkLocation(location.clone().add(0, -1, 0), location);
    }

    protected void checkLocation(Location location, Location from) {
        if (location.getWorld() == null || !location.getChunk().isLoaded() || location.getBlock() == null)//World isn't loaded
            return;

        synchronized (ClassicPhysics.Sync) {
            Block block = location.getBlock();
            if (block.hasMetadata("classic_block") && block.isLiquid())
                return;
            Material newBlock = block.getType();

            if (!block.getType().isSolid() && !doesHandle(block.getType())) {
                newBlock = logicFor();
            }

            ClassicPhysicsEvent event = new ClassicPhysicsEvent(location.getBlock(), newBlock, true, location, this, from);
            ClassicPhysics.INSTANCE.getServer().getPluginManager().callEvent(event);
            if (event.isCancelled())
                return;

            if (newBlock != block.getType())
                placeClassicBlock(newBlock, location, from);
            else if (!block.hasMetadata("classic_block")) {
                block.setMetadata("classic_block", new FixedMetadataValue(ClassicPhysics.INSTANCE, true));
                ClassicPhysics.INSTANCE.getServer().getPluginManager().callEvent(new ClassicBlockPlaceEvent(location));
                if (doesHandle(block.getType()))
                    queueBlock(block);
            }
        }
    }

    @Override
    public int updateRate() {
        return 20; //Every other tick
    }

    @Override
    public boolean doesHandle(Material material) {
        return material == Material.LAVA || material == Material.STATIONARY_LAVA;
    }

    @Override
    public Material logicFor() {
        return Material.STATIONARY_LAVA;
    }
}
@@ -1778,24 +1778,324 @@
 _block%22)) %7B%0A
+                if (newBlock.equals(Material.WATER))%0A                    placeClassicBlock(Material.STATIONARY_WATER, location, from);%0A                else if (newBlock.equals(Material.LAVA))%0A                    placeClassicBlock(Material.STATIONARY_LAVA, location, from);%0A                else %7B%0A    
             
@@ -2197,32 +2197,36 @@
                 
+    
 ClassicPhysics.I
@@ -2325,24 +2325,28 @@
             
+    
 if (doesHand
@@ -2386,16 +2386,20 @@
         
+  
+  
 queueBlo
@@ -2409,16 +2409,34 @@
 block);%0A
+                %7D%0A
         

Make it flat when it gets activated