package net.otfeg.itemedit;

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 AddEchantment implements CommandExecutor {

	private Enchant enchant;

	public AddEchantment(Enchant enchant) {
		this.enchant = enchant;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command command, String label,
			String[] args) {
		int level = 0;
		if(!(sender instanceof Player)){
			sender.sendMessage("Can only be used by a player");
			return false;
		}
		Enchantment enchantment = this.enchant.getEnchantment(args[0]);
		if(enchantment==null){
			sender.sendMessage("Invalid Enchantment");
			return false;
		}
		try{
			level = Integer.parseInt(args[1]);
		}catch(NumberFormatException e){
			sender.sendMessage("Level must be a number.");
		}
		Player player = (Player) sender;
		player.getItemInHand().addUnsafeEnchantment(enchantment, level);
		
		return false;
	}

}

@@ -22,16 +22,45 @@
 medit;%0A%0A
+import org.bukkit.ChatColor;%0A
 import o
@@ -86,16 +86,16 @@
 ommand;%0A
-
 import o
@@ -248,16 +248,84 @@
 layer;%0A%0A
+import java.lang.NumberFormatException;%0Aimport java.lang.Override;%0A%0A
 public c
@@ -471,17 +471,20 @@
 nt;%0A%09%7D%0A%0A
-%09
+    
 @Overrid
@@ -485,17 +485,20 @@
 verride%0A
-%09
+    
 public b
@@ -566,20 +566,17 @@
 g label,
-%0A%09%09%09
+ 
 String%5B%5D
@@ -584,18 +584,24 @@
 args) %7B%0A
-%09%09
+        
 int leve
@@ -608,15 +608,22 @@
 l = 
-0;%0A%09%09
+1;%0A        
 if
+ 
 (!(s
@@ -647,21 +647,31 @@
 Player))
+ 
 %7B%0A
-%09%09%09
+            
 sender.s
@@ -685,64 +685,217 @@
 age(
-%22Can only be used by a player%22);%0A%09%09%09return false;%0A%09%09%7D%0A%09%09
+ChatColor.RED + %22You can't do that!%22);%0A            return true;%0A        %7D%0A        Player player = (Player)sender;%0A        if (args.length %3C 1 %7C%7C args.length %3E 2) %7B%0A            return false;%0A        %7D%0A%0A        
 Ench
@@ -958,12 +958,20 @@
 %5D);%0A
-%09%09
+%0A        
 if
+ 
 (enc
@@ -982,20 +982,32 @@
 ment
+ 
 ==
+ 
 null)
+ 
 %7B%0A
-%09%09%09
+            
 send
@@ -1021,16 +1021,32 @@
 Message(
+ChatColor.RED + 
 %22Invalid
@@ -1046,17 +1046,17 @@
 Invalid 
-E
+e
 nchantme
@@ -1065,39 +1065,70 @@
 %22);%0A
-%09%09%09return false;%0A%09%09%7D%0A%09%09
+            return true;%0A        %7D%0A%0A        
 try
+ 
 %7B%0A
-%09%09%09
+            
 leve
@@ -1162,16 +1162,24 @@
 %5D);%0A
-%09%09%7D
+        %7D 
 catch
+ 
 (Num
@@ -1202,14 +1202,25 @@
 on e
-)%7B%0A%09%09%09
+x) %7B%0A            
 send
@@ -1234,16 +1234,32 @@
 Message(
+ChatColor.RED + 
 %22Level m
@@ -1277,54 +1277,56 @@
 mber
-.
 %22);%0A
-%09%09%7D%0A%09%09Player player = (Player) sender;%0A%09%09
+            return true;%0A        %7D%0A%0A        
 play
@@ -1390,28 +1390,12 @@
 l);%0A
-%09%09%0A%09%09return false;%0A%09
+    
 %7D%0A%0A%7D

Fix misc errors, add some input parsing