package me.happypikachu.BattleTags;

import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;

import com.massivecraft.factions.Conf;

public class BattleTags extends JavaPlugin {
	
	@Override
	public void onEnable() {
		saveDefaultConfig();
        getConfig().options().header("BattleTags+ v" + getDescription().getVersion() + " Configuration" + 
				"\nby HappyPikachu -aka- FlyingPikachu" +
				"\n" + 
			    "\nIf you experience a problem with this config when starting" +
			    "\nyour server, make sure that you're using spaces and not tabs." + 
			    "\nCheck that all apostrophes are escaped. For example, \"can't\"" + 
			    "\nbecomes \"can\\'t\"." +
        		"\n");
        getConfig().options().copyHeader(true);
        for (World world: getServer().getWorlds()) {
        	if (getServer().getPluginManager().getPlugin("Factions") != null) {
        		getConfig().addDefault("Factions." + world.getName(), Conf.worldsNoClaiming.contains(world.getName()) ? false:true);
        	}
		}
        for (World world: getServer().getWorlds()) {
        	if (getServer().getPluginManager().getPlugin("War") != null) {
        		getConfig().addDefault("War." + world.getName(), true); //derp
        	}
		}
        getConfig().options().copyDefaults(true);
        saveConfig();
        
        if (getServer().getPluginManager().getPlugin("Factions") != null) {
        	getServer().getPluginManager().registerEvents(new BattleTagsFactionsListener(this), this);
        	getLogger().info("Hooked into Factions.");
        }
        if (getServer().getPluginManager().getPlugin("War") != null) {
        	getServer().getPluginManager().registerEvents(new BattleTagsWarListener(this), this);
        	getLogger().info("Hooked into War.");
        }
        getServer().getPluginManager().registerEvents(new BattleTagsPlayerListener(this), this);
	}
	
	@Override
	public void onDisable() {
	}
}