
/*
 * This file is part of
 * ExtraHardMode Server Plugin for Minecraft
 *
 * Copyright (C) 2012 Ryan Hamshire
 * Copyright (C) 2013 Diemex
 *
 * ExtraHardMode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ExtraHardMode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero Public License
 * along with ExtraHardMode.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.extrahardmode.task;


import com.extrahardmode.ExtraHardMode;
import com.extrahardmode.config.RootConfig;
import com.extrahardmode.config.RootNode;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;

/**
 * Task to remove exposed torches.
 */
public class RemoveExposedTorchesTask implements Runnable
{
    /**
     * Plugin instance.
     */
    private final ExtraHardMode plugin;

    /**
     * Chunk to iterate over.
     */
    private final Chunk chunk;

    /**
     * Config instance
     */
    private final RootConfig CFG;


    /**
     * Constructor.
     *
     * @param plugin - Plugin instance.
     * @param chunk  - Target chunk.
     */
    public RemoveExposedTorchesTask(ExtraHardMode plugin, Chunk chunk)
    {
        this.plugin = plugin;
        this.chunk = chunk;
        CFG = this.plugin.getModuleForClass(RootConfig.class);
    }


    @Override
    public void run()
    {
        final boolean rainBreaksTorches = CFG.getBoolean(RootNode.RAIN_BREAKS_TORCHES, this.chunk.getWorld().getName());
        final boolean snowBreaksCrops = CFG.getBoolean(RootNode.SNOW_BREAKS_CROPS, this.chunk.getWorld().getName());

        if (this.chunk.getWorld().hasStorm())
        {
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    /* Biome is saved on a per column basis */
                    Biome biome = chunk.getBlock(x, z, 1).getBiome();
                    loopDown:
                    for (int y = chunk.getWorld().getMaxHeight() - 1; y > 0; y--)
                    {
                        Block block = chunk.getBlock(x, y, z);
                        Material blockType = block.getType();

                        switch (blockType)
                        {
                            case AIR: /* we continue down until we hit something which isn't AIR */
                                continue loopDown;
                            case TORCH:
                            {
                                if (rainBreaksTorches && biome != Biome.DESERT && biome != Biome.DESERT_HILLS)
                                {
                                    /* Reduce lag by torches lying on the ground */
                                    if (plugin.getRandom().nextInt(5) == 1)
                                    {
                                        block.breakNaturally();
                                    } else
                                    {
                                        block.setType(Material.AIR);
                                    }
                                }
                                break loopDown;
                            }
                            case CROPS:
                            case MELON_STEM:
                            case CARROT:
                            case PUMPKIN_STEM:
                            case POTATO:
                            case RED_ROSE:
                            case YELLOW_FLOWER:
                            case LONG_GRASS:
                            {
                                if (snowBreaksCrops)
                                {
                                    switch (biome)
                                    {
                                        case FROZEN_OCEAN:
                                        case FROZEN_RIVER:
                                        case ICE_MOUNTAINS:
                                        case ICE_PLAINS:
                                        case TAIGA:
                                        case TAIGA_HILLS:
                                        {
                                            if (plugin.getRandom().nextInt(5) == 1)
                                                block.breakNaturally();
                                            //Snow can't be placed if its tilled soil
                                            if (block.getRelative(BlockFace.DOWN).getType() == Material.SOIL)
                                                block.getRelative(BlockFace.DOWN).setType(Material.DIRT);
                                            block.setType(Material.SNOW);
                                            if (plugin.getRandom().nextBoolean())
                                            {
                                                block.setData((byte) 1);
                                            } else
                                            {
                                                block.setData((byte) 2);
                                            }
                                        }
                                    }
                                }
                                break loopDown;
                            }
                            default: /* Anything which isn't AIR will protect torches and Crops */
                            {
                                break loopDown;
                            }
                        }
                    }
                }
            }
        }
    }
}

@@ -1006,39 +1006,8 @@
 al;%0A
-import org.bukkit.block.Biome;%0A
 impo
@@ -1934,16 +1934,93 @@
 sCrops =
+ CFG.getBoolean(RootNode.WEAK_FOOD_CROPS, this.chunk.getWorld().getName()) &&
  CFG.get
@@ -2351,18 +2351,25 @@
     
-Biome biom
+double temperatur
 e = 
@@ -2395,20 +2395,26 @@
 , 1).get
-Biom
+Temperatur
 e();%0A   
@@ -3021,61 +3021,95 @@
  && 
-biome != Biome.DESERT && biome != Biome.DESERT_HILLS)
+temperature %3C 1.0) //excludes warmer biomes like mesa and desert in which no rain falls
 %0A   
@@ -4136,528 +4136,101 @@
 rops
-)%0A                                %7B%0A                                    switch (biome)%0A                                    %7B%0A                                        case FROZEN_OCEAN:%0A                                        case FROZEN_RIVER:%0A                                        case ICE_MOUNTAINS:%0A                                        case ICE_PLAINS:%0A                                        case TAIGA:%0A                                        case TAIGA_HILLS:%0A                                        %7B%0A        
+ && temperature %3C= 0.15) //cold biomes in which snow falls%0A                                %7B%0A
     
@@ -4337,32 +4337,24 @@
             
-       
- 
 block.breakN
@@ -4361,32 +4361,24 @@
 aturally();%0A
-        
             
@@ -4475,32 +4475,24 @@
             
-        
 if (block.ge
@@ -4581,32 +4581,24 @@
             
-     
-   
 block.getRel
@@ -4643,24 +4643,16 @@
 .DIRT);%0A
-        
         
@@ -4741,32 +4741,24 @@
             
-        
 if (plugin.g
@@ -4819,34 +4819,18 @@
         
-  
-      %7B%0A        
+%7B%0A
         
@@ -4922,39 +4922,23 @@
         
-       
- 
 %7D else%0A
-        
         
@@ -5003,32 +5003,24 @@
             
-        
 block.setDat
@@ -5036,96 +5036,8 @@
 2);%0A
-                                            %7D%0A                                        %7D%0A
     

Use the biome temperatures instead of hardcoded biomes