@Override
  public List<String> getTabCompletionOptions(
      MinecraftServer server,
      ICommandSender iCommandSender,
      String[] typedValue,
      @Nullable BlockPos pos) {
    if (!PlayerMPUtil.isPlayer(iCommandSender)) {
      return null;
    }
    if (typedValue.length == 1) {

      EntityPlayerMP player = (EntityPlayerMP) PlayerMPUtil.castToPlayer(iCommandSender);
      if (player == null) {
        return null;
      }

      ItemStack stack = player.getHeldItemMainhand();
      if (stack == null) {
        return null;
      }

      // Get Enchantment List
      @SuppressWarnings("unchecked")
      List<String> validEnchantmentNames = new ArrayList<String>();
      Map<String, Enchantment> validEnchantments = new HashMap<String, Enchantment>();
      for (Enchantment enchantment : Enchantment.REGISTRY) {
        if (enchantment != null) {
          String name = I18n.translateToLocal(enchantment.getName()).replaceAll(" ", "");
          validEnchantmentNames.add(name);
        }
      }

      String[] validEnchantmentArray = new String[validEnchantmentNames.size()];
      validEnchantmentArray = validEnchantmentNames.toArray(validEnchantmentArray);
      return CommandBase.getListOfStringsMatchingLastWord(typedValue, validEnchantmentArray);
    }

    return null;
  }
  @SuppressWarnings("Duplicates")
  @Override
  public void execute(MinecraftServer server, ICommandSender iCommandSender, String[] args)
      throws CommandException {
    if (args.length == 0) {
      ChatHelper.sendMessage(
          iCommandSender, TextFormatting.RED + "Usage: /enchantforce <enchantmentname> [level]");
      return;
    }

    if (!PlayerMPUtil.isPlayer(iCommandSender)) {
      ChatHelper.sendMessage(iCommandSender, "Cannot enchant an item for CONSOLE");
      return;
    }

    String enchantstring = args[0];

    EntityPlayerMP player = (EntityPlayerMP) PlayerMPUtil.castToPlayer(iCommandSender);
    if (player == null) {
      ChatHelper.sendMessage(
          iCommandSender, "Cannot enchant an item for " + iCommandSender.getName());
      return;
    }

    ItemStack stack = player.getHeldItemMainhand();
    if (stack == null) {
      ChatHelper.sendMessage(iCommandSender, TextFormatting.RED + "Invalid Item held");
      return;
    }

    // Get Enchantment List
    @SuppressWarnings("unchecked")
    List<String> validEnchantmentNames = new ArrayList<String>();
    Map<String, Enchantment> validEnchantments = new HashMap<String, Enchantment>();
    for (Enchantment enchantment : Enchantment.REGISTRY) {
      if (enchantment != null) {
        String name = I18n.translateToLocal(enchantment.getName()).replaceAll(" ", "");
        validEnchantmentNames.add(name);
        validEnchantments.put(name.toLowerCase(), enchantment);
      }
    }

    @SuppressWarnings("unchecked")
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
    Enchantment enchantment = validEnchantments.get(enchantstring.toLowerCase());
    if (enchantment == null) {
      ChatHelper.sendMessage(
          iCommandSender, TextFormatting.RED + "Invalid enchantment: " + enchantstring);
      return;
    }

    int enchantlevel = enchantment.getMaxLevel();
    if (args.length == 2) {
      enchantlevel = CommandBase.parseInt(args[1]);
    }

    enchantments.put(enchantment, enchantlevel);

    EnchantmentHelper.setEnchantments(enchantments, stack);

    ChatHelper.sendMessage(
        iCommandSender,
        TextFormatting.GOLD
            + "Enchanted "
            + stack.getDisplayName()
            + " with "
            + TextFormatting.AQUA
            + enchantstring
            + TextFormatting.GOLD
            + " ("
            + TextFormatting.LIGHT_PURPLE
            + enchantlevel
            + TextFormatting.GOLD
            + ")");
    ChatHelper.sendAdminMessage(
        iCommandSender,
        "Enchanted "
            + stack.getDisplayName()
            + " with "
            + enchantstring
            + " ("
            + enchantlevel
            + ")");
  }
 @Override
 public boolean checkPermission(MinecraftServer server, ICommandSender iCommandSender) {
   return PlayerMPUtil.isOperatorOrConsole(iCommandSender);
 }