Commands.showCommandHelpAndUsage(sender, "cex_enchant", alias);
return true;
}
List<Enchantment> matches = ClosestMatches.enchantments(args[1]);
Enchantment ench;
if (matches.size() > 0){
ench = matches.get(0);
} else {
LogHelper.showInfo("enchantNotFound", sender, ChatColor.RED);
return true;
}
if (!inHand.containsEnchantment(ench)){
LogHelper.showInfo("enchantRemoveNotFound#####[" + ChatColor.GOLD + Utils.userFriendlyNames(inHand.getType().name()), sender);
return true;
}
inHand.removeEnchantment(ench);
LogHelper.showInfo("enchantRemoveSuccess#####[ " + ChatColor.GOLD + Utils.userFriendlyNames(ench.getName()) + ChatColor.AQUA + "#####from#####[ " + Utils.userFriendlyNames(inHand.getType().name()), sender);
}
return true;
}
List<Enchantment> matches = ClosestMatches.enchantments(args[0]);
Enchantment ench = null;
if (args[0].equalsIgnoreCase("all")){
if (Permissions.checkPerms(sender, "cex.enchant.all")){
if (matches.size() > 0){
ench = matches.get(0);
} else {
LogHelper.showInfo("enchantNotFound", sender, ChatColor.RED);
return true;
}
if (args.length > 3){
Commands.showCommandHelpAndUsage(sender, "cex_enchant", alias);
return true;
}
if (args.length == 3){
if (args[1].matches(CommandsEX.intRegex)){
Integer.valueOf(args[1]);
} else {
LogHelper.showInfo("valueNotNumeric", sender, ChatColor.RED);
return true;
}
if (args[2].equalsIgnoreCase("-u") || args[2].equalsIgnoreCase("unsafe")){
unSafe = true;
}
} else if (args.length == 2){
if (args[1].equalsIgnoreCase("-u") || args[1].equalsIgnoreCase("unsafe")){
unSafe = true;
}
}
int count = 0;
if (inHand.getType().equals(Material.AIR)){
LogHelper.showInfo("enchantFist", sender, ChatColor.RED);
return true;
}
for (Enchantment en : Enchantment.values()){
if (player.hasPermission("cex.enchant." + en.getName().toLowerCase().replaceAll("_", ""))){
int enchantLevel = level;
if (level == -1 || enchantLevel > en.getMaxLevel()){
enchantLevel = en.getMaxLevel();
}
if (en.canEnchantItem(inHand)){
inHand.addEnchantment(en, enchantLevel);
count++;
} else {
if (unSafe){
inHand.addUnsafeEnchantment(en, enchantLevel);
count++;
}
}
}
}
LogHelper.showInfo("enchantAddedAll#####[" + ChatColor.GOLD + count + ChatColor.AQUA + " #####enchantEnchantments", sender);
}
return true;
}
if (matches.size() > 0){
ench = matches.get(0);
} else {
LogHelper.showInfo("enchantNotFound", sender, ChatColor.RED);
return true;
}
if (!player.hasPermission("cex.enchant." + ench.getName().toLowerCase().replaceAll("_", ""))){
LogHelper.showInfo("enchantEnchantmentNoPerm", sender, ChatColor.RED);
return true;
}
boolean nonNumeric = false;
if (args.length == 2){
if (args[1].equalsIgnoreCase("-u") || args[1].equalsIgnoreCase("unsafe")){
unSafe = true;
} else if (args[1].matches(CommandsEX.intRegex)){
level = Integer.valueOf(args[1]);
} else {
nonNumeric = true;
}
}
if (args.length == 3){
if (args[2].equalsIgnoreCase("-u") || args[2].equalsIgnoreCase("unsafe")){
unSafe = true;
} else if (args[1].matches(CommandsEX.intRegex)){
level = Integer.valueOf(args[1]);
} else {
nonNumeric = true;
}
}
if (inHand.getType().equals(Material.AIR)){
LogHelper.showInfo("enchantFist", sender, ChatColor.RED);
return true;
}
if (!ench.canEnchantItem(inHand) && !unSafe){
LogHelper.showInfo("enchantNotSafe", sender, ChatColor.RED);
return true;
}
if (nonNumeric){
LogHelper.showInfo("valueNotNumeric", sender, ChatColor.RED);
return true;
}
if (level == -1 || level > ench.getMaxLevel()){
level = ench.getMaxLevel();
}
if (unSafe){
inHand.addUnsafeEnchantment(ench, level);
} else {
inHand.addEnchantment(ench, level);
}
LogHelper.showInfo("enchantAdded#####[" + ChatColor.GOLD + Utils.userFriendlyNames(ench.getName())
+ ChatColor.AQUA + " (" + ChatColor.GOLD + ench.getId() + ChatColor.AQUA + ") #####enchantAddedLevel#####["
+ ChatColor.GOLD + level, sender);
return true;
}