package kernitus.plugin.OldCombatMechanics;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;

public class OCMCommandHandler implements CommandExecutor {

	private OCMMain plugin;

	public OCMCommandHandler(OCMMain instance) {
		this.plugin = instance;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

		if (label.equalsIgnoreCase("oldcombatmechanics") || label.equalsIgnoreCase("ocm")) {

			if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {// Reloads config

				plugin.reloadConfig();

				for (World world : Bukkit.getServer().getWorlds()) {

					for (Player player : world.getPlayers()) {

						if (plugin.getConfig().getBoolean("plugin-active")) {// Setting to no cooldown

							AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
							double baseValue = attribute.getBaseValue();
							if (baseValue != 1024) {
								attribute.setBaseValue(1024);
								player.saveData();
							}

						}

					}

				}

				sender.sendMessage(ChatColor.GOLD + "OldCombatMechanics " + ChatColor.GREEN + "Config file reloaded");

			} else {// Tells user about available commands

				OCMUpdateChecker updateChecker = new OCMUpdateChecker(plugin);

				PluginDescriptionFile pdf = plugin.getDescription();

				sender.sendMessage(ChatColor.GOLD + "OldCombatMechanics by kernitus version " + pdf.getVersion());
				sender.sendMessage(ChatColor.GREEN + "You can use " + ChatColor.ITALIC + "/ocm reload "
						+ ChatColor.RESET + ChatColor.GREEN + "to reload the config file");

				// Update check
				if (plugin.getConfig().getBoolean("update-checker")) {

					if (updateChecker.updateNeeded()) {

						sender.sendMessage(ChatColor.BLUE + "An update of OldCombatMechanics to version "
								+ updateChecker.getVersion() + " is available!");

						sender.sendMessage(
								ChatColor.BLUE + "Link to download it: " + ChatColor.GRAY + updateChecker.getLink());
					}

				}

			}

		}

		return false;

	}

}
@@ -702,65 +702,125 @@
 %0D%0A%09%09
-if (label.equalsIgnoreCase(%22oldcombatmechanics%22) %7C%7C l
+// Using cmd.getLabel() will always return the main label,%0D%0A%09%09// even if you're using an alias.%0D%0A%09%09if (cmd.getL
 abel
+()
 .equ
@@ -834,19 +834,34 @@
 reCase(%22
-ocm
+OldCombatMechanics
 %22)) %7B%0D%0A%0D
@@ -971,24 +971,103 @@
 onfig();%0D%0A%0D%0A
+%09%09%09%09boolean plugin_active = plugin.getConfig().getBoolean(%22plugin-active%22);%0D%0A%0D%0A
 %09%09%09%09for (Wor
@@ -1169,97 +1169,8 @@
 %0D%0A%0D%0A
-%09%09%09%09%09%09if (plugin.getConfig().getBoolean(%22plugin-active%22)) %7B// Setting to no cooldown%0D%0A%0D%0A%09
 %09%09%09%09
@@ -1261,17 +1261,16 @@
 %0D%0A%09%09%09%09%09%09
-%09
 double b
@@ -1307,22 +1307,83 @@
 lue();%0D%0A
+%0D%0A
 %09%09%09%09%09%09
+if (plugin_active) %7B // Setting to no cooldown%0D%0A%0D%0A%09%09%09%09    %09
 %09if (bas
@@ -1401,16 +1401,18 @@
 024) %7B%0D%0A
+%0D%0A
 %09%09%09%09%09%09%09%09
@@ -1466,24 +1466,181 @@
 aveData();%0D%0A
+%0D%0A%09%09%09%09%09%09%09%7D%0D%0A%0D%0A%09%09%09%09%09%09%7D else %7B // Re-enabling cooldown%0D%0A%0D%0A%09%09%09%09%09%09%09if (baseValue == 1024) %7B%0D%0A%0D%0A%09%09%09%09%09%09%09%09attribute.setBaseValue(4);%0D%0A%09%09%09%09%09%09%09%09player.saveData();%0D%0A%0D%0A
 %09%09%09%09%09%09%09%7D%0D%0A%0D%0A

Apply / Remove cooldown effect on plugin reload