package com.bitlimit.Tweaks;

import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

public class Tweaks extends JavaPlugin {
    private int weatherId;

    @Override
    public void onEnable() {
        new TweaksListener(this);

        this.getCommand("tweaks").setExecutor(new TweaksCommandExecutor(this));
        this.saveConfig();
    }

    @Override
    public void onDisable() {
        this.getServer().getScheduler().cancelTask(this.weatherId);
        this.saveConfig();
    }

    @Override
    public void saveConfig() {
        super.saveConfig();

        this.getConfig().options().copyDefaults(true);
        this.reloadConfig();
        setRepeatingTaskEnabled(this.getConfig().getConfigurationSection("preferences").getBoolean("weather"));
    }

    public void setRepeatingTaskEnabled(boolean enabled) {
        Server server = this.getServer();
        BukkitScheduler scheduler = server.getScheduler();
        if (enabled && this.weatherId == 0) {
            class BitLimitRecurringTask implements Runnable {
                Plugin plugin;

                BitLimitRecurringTask(Plugin p) {
                    plugin = p;
                }

                public void run() {
                    World world = this.plugin.getServer().getWorld(plugin.getConfig().getConfigurationSection("meta").getConfigurationSection("weather").getString("world"));

                    if (!world.hasStorm()) {
                        int weatherDuration = world.getWeatherDuration();
                        double ratio = 0.75; // 75% less often.
                        int calculatedAddback = (int)(1200 * ratio);
                        world.setWeatherDuration(weatherDuration + calculatedAddback);
                    }
                }
            }

            this.weatherId = scheduler.scheduleSyncRepeatingTask(this, new BitLimitRecurringTask(this), 1200L, 1200L);
        } else if (this.weatherId != 0) {
            scheduler.cancelTask(this.weatherId);
            this.weatherId = 0;
        }
    }
}


@@ -195,16 +195,66 @@
 duler;%0A%0A
+import java.util.HashMap;%0Aimport java.util.List;%0A%0A
 public c
@@ -888,19 +888,15 @@
 on(%22
-preferences
+weather
 %22).g
@@ -906,23 +906,23 @@
 oolean(%22
-weather
+enabled
 %22));%0A   
@@ -1358,24 +1358,25 @@
 oid run() %7B%0A
+%09
             
@@ -1383,171 +1383,334 @@
     
-    World world = this.plugin.getServer().getWorld(plugin.getConfig().getConfigurationSection(%22meta%22).getConfigurationSection(%22weather%22).getString(%22world%22));%0A%0A    
+for (HashMap%3CString, Object%3E worldDefinition : (List%3CHashMap%3CString, Object%3E%3E)this.plugin.getConfig().getConfigurationSection(%22weather%22).getList(%22worlds%22))%0A%09                %7B%0A%09%09%09            String worldName = (String)worldDefinition.get(%22name%22);%0A%09%09                World world = this.plugin.getServer().getWorld(worldName);%0A%0A%09%09
     
@@ -1743,19 +1743,25 @@
 Storm())
- %7B%0A
+%0A%09%09      
         
@@ -1754,32 +1754,39 @@
                 
+%7B%0A%09%09%09  
               in
@@ -1833,22 +1833,19 @@
 tion();%0A
-      
+%09%09%09
         
@@ -1856,16 +1856,13 @@
     
-  double
+Float
  rat
@@ -1870,41 +1870,52 @@
 o = 
-0.75; // 75%25 less often.%0A        
+(Float)worldDefinition.get(%22reduction%22);%0A%09%09%09
     
@@ -1931,32 +1931,28 @@
    int c
-alculatedAddback
+ounterAmount
  = (int)
@@ -1967,24 +1967,19 @@
 ratio);%0A
-        
+%09%09%09
         
@@ -2034,31 +2034,44 @@
  + c
-alculatedAddback);%0A    
+ounterAmount);%0A%09%09                %7D%0A%09
     

Read for multiple worlds and their respective reduction rates.