package io.github.vayleryn.vaylerynessentials.command;

import io.github.vayleryn.vaylerynessentials.VaylerynEssentials;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;

public class EnchantCommand implements CommandExecutor {
	
	private VaylerynEssentials plugin;
	
	public EnchantCommand(VaylerynEssentials plugin) {
		this.plugin = plugin;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if (sender.hasPermission("vayleryn.essentials.command.enchant")) {
			if (sender instanceof Player) {
				Player player = (Player) sender;
				if (player.getItemInHand() != null && player.getItemInHand().getType() != Material.AIR) {
					if (args.length >= 2) {
						if (sender.hasPermission("vayleryn.essentials.command.enchant.unsafe")) {
							if (Enchantment.getByName(args[0].toUpperCase()) != null) {
								try {
									player.getItemInHand().addUnsafeEnchantment(Enchantment.getByName(args[0].toUpperCase()), Integer.parseInt(args[1]));
									sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN + "Successfully enchanted " + player.getItemInHand().getAmount() + " x " + player.getItemInHand().getType() + " with " + Enchantment.getByName(args[0]).getName() + " " + Integer.parseInt(args[1]));
								} catch (NumberFormatException exception) {
									sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "The enchantment level must be a number");
								} catch (IllegalArgumentException exception) {
									sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "Illegal enchantment!");
								}
							} else {
								sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "That enchantment does not exist.");
							}
						} else {
							if (Enchantment.getByName(args[0].toUpperCase()) != null) {
								try {
									player.getItemInHand().addEnchantment(Enchantment.getByName(args[0].toUpperCase()), Integer.parseInt(args[1]));
									sender.sendMessage(plugin.getPrefix() + ChatColor.GREEN + "Successfully enchanted " + player.getItemInHand().getAmount() + " x " + player.getItemInHand().getType() + " with " + Enchantment.getByName(args[0]).getName() + " " + Integer.parseInt(args[1]));
								} catch (NumberFormatException exception) {
									sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "The enchantment level must be a number");
								} catch (IllegalArgumentException exception) {
									sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "Illegal enchantment!");
								}
							} else {
								sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "That enchantment does not exist.");
							}
						}
					} else {
						sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "Usage: /enchant [enchantment] [level]");
					}
				} else {
					sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You must be holding something to enchant it.");
				}
			} else {
				sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "This command cannot be used from console.");
			}
		} else {
			sender.sendMessage(plugin.getPrefix() + ChatColor.RED + "You do not have permission.");
		}
		return true;
	}

}

@@ -1408,32 +1408,46 @@
 etByName(args%5B0%5D
+.toUpperCase()
 ).getName() + %22 
@@ -2351,16 +2351,30 @@
 (args%5B0%5D
+.toUpperCase()
 ).getNam

Fix message not being sent when enchanting an item by command